<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'Vessel',
itemOperations: [
'get' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER') or
is_granted('ROLE_INTERN')
",
'normalization_context' => [
'groups' => 'vessel:item:get',
'enable_max_depth' => true
]
],
'put' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER')
",
'normalization_context' => [
'groups' => 'vessel:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'vessel:item:put',
'enable_max_depth' => true
],
],
'delete' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER')
",
],
],
collectionOperations: [
'get' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER') or
is_granted('ROLE_INTERN')
",
'normalization_context' => [
'groups' => [
'vessel:collection:get',
'createdAt'
],
'enable_max_depth' => true
],
],
'post' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER')
",
'normalization_context' => [
'groups' => 'vessel:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'vessel:collection:post',
'enable_max_depth' => true
],
],
],
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'vesselName' => 'partial',
'imoNumber' => 'partial',
'vesselType' => 'exact',
'dwt' => 'partial',
'yearBuilt' => 'exact',
'imoClass' => 'partial',
'tankCoating' => 'exact',
'createdAt' => 'start'
],
)]
#[ApiFilter(
OrderFilter::class,
properties: [
'vesselName',
'imoNumber',
'vesselType',
'dwt',
'yearBuilt',
'imoClass',
'nitrogenGenerator',
'boxShape',
'openHatch',
'tankCoating',
'createdAt'
],
)]
#[ApiFilter(
BooleanFilter::class,
properties: [
'nitrogenGenerator',
'boxShape',
'openHatch',
],
)]
#[ApiFilter(PropertyFilter::class)]
class Vessel
{
use TimestampableEntity;
public const VESSEL_TYPE_TANKER = 'Tanker';
public const VESSEL_TYPE_BULKER = 'Bulker';
public const VESSEL_TYPES = [
self::VESSEL_TYPE_TANKER,
self::VESSEL_TYPE_BULKER,
];
public const TANKER_TYPE_CHEMICAL = 'Chemical & Oil Carrier';
public const TANKER_TYPE_PRODUCT = 'Product Carrier';
public const TANKER_TYPE_CHEMICAL_BULK = 'Chemical Bulk Tanker';
public const TANKER_TYPE_CHEMICAL_PARCEL = 'Chemical Parcell Tanker';
public const TANKER_TYPE_ASPHALT_BITUMEN = 'Asphalt & Bitumen Carrier';
public const TANKER_TYPE_METHANOL = 'Methanol Carrier';
public const TANKER_TYPE_CHEMICAL_UNKNOWN = 'Chemical Unknown Carrier';
public const TANKER_TYPE_TANKER = 'Tanker';
public const TANKER_TYPE_SHUTTLE = 'Shuttle Tanker';
public const TANKER_TYPE_OIL_BUNKERING = 'Oil Bunkering Tanker';
public const TANKER_TYPE_PRODUCTS_MULTI_PURPOSE = 'Products/Multi-Purpose';
public const TANKER_TYPE_CARGO = 'Cargo';
public const TANKER_TYPES = [
self::TANKER_TYPE_CHEMICAL,
self::TANKER_TYPE_PRODUCT,
self::TANKER_TYPE_CHEMICAL_BULK,
self::TANKER_TYPE_CHEMICAL_PARCEL,
self::TANKER_TYPE_ASPHALT_BITUMEN,
self::TANKER_TYPE_METHANOL,
self::TANKER_TYPE_CHEMICAL_UNKNOWN,
self::TANKER_TYPE_TANKER,
self::TANKER_TYPE_SHUTTLE,
self::TANKER_TYPE_OIL_BUNKERING,
self::TANKER_TYPE_PRODUCTS_MULTI_PURPOSE,
self::TANKER_TYPE_CARGO,
];
public const BULKER_TYPE_AGGREGATES = 'Aggregates Carrier';
public const BULKER_TYPE_BULK = 'Bulk Carrier';
public const BULKER_TYPE_CEMENT = 'Cement Carrier';
public const BULKER_TYPE_DECK = 'Deck Cargo Carrier';
public const BULKER_TYPE_GENERAL = 'General Cargo';
public const BULKER_TYPE_GYPSUM = 'Gypsum Carrier';
public const BULKER_TYPE_HEAVY_LIFT = 'Heavy Lift Cargo Vessel';
public const BULKER_TYPE_LIMESTONE = 'Limestone Carrier';
public const BULKER_TYPE_LIVESTOCK = 'Livestock Carrier';
public const BULKER_TYPE_OPEN_HATCH = 'Open Hatch Carrier';
public const BULKER_TYPE_ORE_SULPHURIC_ACID = 'Ore & Sulphuric Acid Carrier';
public const BULKER_TYPE_ORE = 'Ore Carrier';
public const BULKER_TYPE_ORE_OIL = 'Ore/Oil Carrier';
public const BULKER_TYPE_SALT = 'Salt Carrier';
public const BULKER_TYPE_UREA = 'Urea Carrier';
public const BULKER_TYPES = [
self::BULKER_TYPE_AGGREGATES,
self::BULKER_TYPE_BULK,
self::BULKER_TYPE_CEMENT,
self::BULKER_TYPE_DECK,
self::BULKER_TYPE_GENERAL,
self::BULKER_TYPE_GYPSUM,
self::BULKER_TYPE_HEAVY_LIFT,
self::BULKER_TYPE_LIMESTONE,
self::BULKER_TYPE_LIVESTOCK,
self::BULKER_TYPE_OPEN_HATCH,
self::BULKER_TYPE_ORE_SULPHURIC_ACID,
self::BULKER_TYPE_ORE,
self::BULKER_TYPE_ORE_OIL,
self::BULKER_TYPE_SALT,
self::BULKER_TYPE_UREA,
];
public const TANK_COATING_EPOXY = 'Epoxy';
public const TANK_COATING_ZINC = 'Zinc';
public const TANK_COATING_STAINLESS = 'Stainless';
public const TANK_COATING_ADV_POLYMER = 'Adv. Polymer';
public const TANK_COATING = [
self::TANK_COATING_EPOXY,
self::TANK_COATING_ZINC,
self::TANK_COATING_STAINLESS,
self::TANK_COATING_ADV_POLYMER,
];
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put',
'contract:item:get',
'contract:item:put',
'contract:collection:get',
'contract:collection:post',
'market_rumor:item:get',
'market_rumor:item:put',
'market_rumor:collection:get',
'market_rumor:collection:post'
])]
private ?string $vesselName = null;
#[ORM\Column(type: 'string', nullable: true)]
##[Assert\NotNull]
##[Assert\Type('string')]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?string $imoNumber = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[Assert\Choice(
choices: self::VESSEL_TYPES,
message: 'The type is not valid.'
)]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?string $vesselType = null;
#[ORM\Column(type: 'string', nullable: true)]
##[Assert\Type('string')]
#[Assert\Choice(
choices: self::TANKER_TYPES,
message: 'The type is not valid.'
)]
#[ApiProperty()]
#[Groups([
// 'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?string $tankerType = null;
#[ORM\Column(type: 'string', nullable: true)]
##[Assert\Type('string')]
#[Assert\Choice(
choices: self::BULKER_TYPES,
message: 'The type is not valid.'
)]
#[ApiProperty()]
#[Groups([
// 'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?string $bulkerType = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
##[Assert\Type('string')]
#[Assert\Choice(
choices: self::TANK_COATING,
message: 'The option is not valid.'
)]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?string $tankCoating = null;
#[ORM\Column(type: 'string', nullable: true)]
##[Assert\NotNull]
##[Assert\Type('string')]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?string $dwt = null;
#[ORM\Column(type: 'integer', nullable: true)]
##[Assert\NotNull]
##[Assert\Type('integer')]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?int $yearBuilt = null;
#[ORM\ManyToOne(
targetEntity: Owner::class,
inversedBy: 'vessels'
)]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty()]
#[Groups([
// 'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
#[MaxDepth(1)]
private ?Owner $owner = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty()]
#[Groups([
// 'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?string $observations = null;
#[ORM\Column(type: 'boolean', nullable: true)]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?bool $boxShape = false;
#[ORM\Column(type: 'boolean', nullable: true)]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?bool $openHatch = false;
#[ORM\Column(type: 'boolean', nullable: true)]
#[ApiProperty()]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?bool $nitrogenGenerator = false;
#[ORM\Column(type: 'integer', nullable: true)]
#[ApiProperty()]
##[Assert\Type('integer')]
#[Groups([
'vessel:collection:get',
'vessel:collection:post',
'vessel:item:get',
'vessel:item:put'
])]
private ?int $imoClass = null;
#[ORM\OneToMany(
targetEntity: Contract::class,
mappedBy: 'vessel'
)]
private ?Collection $contracts = null;
#[ORM\OneToMany(
targetEntity: MarketRumor::class,
mappedBy: 'vessel'
)]
private ?Collection $marketRumors = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->contracts = new ArrayCollection();
$this->marketRumors = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setVesselName(?string $vesselName): void
{
$this->vesselName = $vesselName;
}
public function getVesselName(): ?string
{
return $this->vesselName;
}
public function setImoNumber(?string $imoNumber): void
{
$this->imoNumber = $imoNumber;
}
public function getImoNumber(): ?string
{
return $this->imoNumber;
}
public function setVesselType(?string $vesselType): void
{
$this->vesselType = $vesselType;
}
public function getVesselType(): ?string
{
return $this->vesselType;
}
public function setDwt(?string $dwt): void
{
$this->dwt = $dwt;
}
public function getDwt(): ?string
{
return $this->dwt;
}
public function setYearBuilt(?int $yearBuilt): void
{
$this->yearBuilt = $yearBuilt;
}
public function getYearBuilt(): ?int
{
return $this->yearBuilt;
}
public function setTankerType(?string $tankerType): void
{
$this->tankerType = $tankerType;
}
public function getTankerType(): ?string
{
return $this->tankerType;
}
public function setBulkerType(?string $bulkerType): void
{
$this->bulkerType = $bulkerType;
}
public function getBulkerType(): ?string
{
return $this->bulkerType;
}
public function setOwner(?Owner $owner): void
{
$this->owner = $owner;
}
public function getOwner(): ?Owner
{
return $this->owner;
}
public function setObservations(?string $observations): void
{
$this->observations = $observations;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setBoxShape(?bool $boxShape): void
{
$this->boxShape = $boxShape;
}
public function getBoxShape(): ?bool
{
return $this->boxShape ?? false;
}
public function setOpenHatch(?bool $openHatch): void
{
$this->openHatch = $openHatch;
}
public function getOpenHatch(): ?bool
{
return $this->openHatch ?? false;
}
public function setNitrogenGenerator(?bool $nitrogenGenerator): void
{
$this->nitrogenGenerator = $nitrogenGenerator;
}
public function getNitrogenGenerator(): ?bool
{
return $this->nitrogenGenerator ?? false;
}
public function setImoClass(?int $imoClass): void
{
$this->imoClass = $imoClass;
}
public function getImoClass(): ?int
{
return $this->imoClass;
}
public function setTankCoating(?string $tankCoating): void
{
$this->tankCoating = $tankCoating;
}
public function getTankCoating(): ?string
{
return $this->tankCoating;
}
public function getContracts(): Collection
{
return $this->contracts;
}
public function addContract(Contract $contract): self
{
if (!$this->contracts->contains($contract)) {
$this->contracts[] = $contract;
$contract->setVessel($this);
}
return $this;
}
public function removeContract(Contract $contract): self
{
if ($this->contracts->removeElement($contract)) {
if ($contract->getVessel() === $this) {
$contract->setVessel(null);
}
}
return $this;
}
public function getMarketRumors(): Collection
{
return $this->marketRumors;
}
public function addMarketRumor(MarketRumor $marketRumor): self
{
if (!$this->marketRumors->contains($marketRumor)) {
$this->marketRumors[] = $marketRumor;
$marketRumor->setVessel($this);
}
return $this;
}
public function removeMarketRumor(MarketRumor $marketRumor): self
{
if ($this->marketRumors->removeElement($marketRumor)) {
if ($marketRumor->getVessel() === $this) {
$marketRumor->setVessel(null);
}
}
return $this;
}
}