Solve conflict. Added remoteCalendar
testing/ogcore-api/pipeline/head There was a failure building this commit Details

develop-jenkins
Manuel Aranda Rosales 2024-09-30 11:48:35 +02:00
commit 3d78418415
26 changed files with 1142 additions and 1 deletions

6
.env
View File

@ -44,3 +44,9 @@ JWT_PASSPHRASE=8b9154df37ffa91ef9186ce095324e39e50ff3b023bb1ed34383abd019ba4515
OGBOOT_API_URL=http://localhost:8085
OGDHCP_API_URL=http://localhost:8085
###> UDS ###
UDS_AUTH_LOGIN="Usuarios locales"
UDS_AUTH_USERNAME="natiqindel"
UDS_AUTH_PASSWORD="correct horse battery staple"
UDS_URL=https://localhost:8087/uds/rest/
###< UDS ###

View File

@ -0,0 +1,31 @@
resources:
App\Entity\RemoteCalendar:
processor: App\State\Processor\RemoteCalendarProcessor
input: App\Dto\Input\RemoteCalendarInput
output: App\Dto\Output\RemoteCalendarOutput
normalizationContext:
groups: ['default', 'remote-calendar:read']
denormalizationContext:
groups: ['remote-calendar:write']
operations:
ApiPlatform\Metadata\GetCollection:
provider: App\State\Provider\RemoteCalendarProvider
filters:
- 'api_platform.filter.remote_calendar.order'
- 'api_platform.filter.remote_calendar.search'
ApiPlatform\Metadata\Get:
provider: App\State\Provider\RemoteCalendarProvider
ApiPlatform\Metadata\Put:
provider: App\State\Provider\RemoteCalendarProvider
ApiPlatform\Metadata\Patch:
provider: App\State\Provider\RemoteCalendarProvider
ApiPlatform\Metadata\Post: ~
ApiPlatform\Metadata\Delete: ~
properties:
App\Entity\RemoteCalendar:
id:
identifier: false
uuid:
identifier: true

View File

@ -0,0 +1,31 @@
resources:
App\Entity\RemoteCalendarRule:
processor: App\State\Processor\RemoteCalendarRuleProcessor
input: App\Dto\Input\RemoteCalendarRuleInput
output: App\Dto\Output\RemoteCalendarRuleOutput
normalizationContext:
groups: ['default', 'remote-calendar-rule:read']
denormalizationContext:
groups: ['remote-calendar-rule:write']
operations:
ApiPlatform\Metadata\GetCollection:
provider: App\State\Provider\RemoteCalendarRuleProvider
filters:
- 'api_platform.filter.remote_calendar_rule.order'
- 'api_platform.filter.remote_calendar_rule.search'
ApiPlatform\Metadata\Get:
provider: App\State\Provider\RemoteCalendarRuleProvider
ApiPlatform\Metadata\Put:
provider: App\State\Provider\RemoteCalendarRuleProvider
ApiPlatform\Metadata\Patch:
provider: App\State\Provider\RemoteCalendarRuleProvider
ApiPlatform\Metadata\Post: ~
ApiPlatform\Metadata\Delete: ~
properties:
App\Entity\RemoteCalendarRule:
id:
identifier: false
uuid:
identifier: true

View File

@ -11,6 +11,10 @@ services:
bind:
$ogBootApiUrl: '%env(OGBOOT_API_URL)%'
$ogDhcpApiUrl: '%env(OGDHCP_API_URL)%'
$udsAPIurl: '%env(UDS_URL)%'
$udsAuthLogin: '%env(UDS_AUTH_LOGIN)%'
$udsAuthUsername: '%env(UDS_AUTH_USERNAME)%'
$udsAuthPassword: '%env(UDS_AUTH_PASSWORD)%'
App\:
resource: '../src/'
@ -110,6 +114,11 @@ services:
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
App\State\Provider\RemoteCalendarProvider:
bind:
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
App\State\Provider\CommandProvider:
bind:
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
@ -143,3 +152,8 @@ services:
bind:
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
App\State\Provider\RemoteCalendarRuleProvider:
bind:
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'

View File

@ -1,4 +1,16 @@
services:
api_platform.filter.calendar.order:
parent: 'api_platform.doctrine.orm.order_filter'
arguments:
$properties: { 'id': ~, 'name': ~,}
$orderParameterName: 'order'
tags: [ 'api_platform.filter' ]
api_platform.filter.calendar.search:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'id': 'exact', 'name': 'exact'} ]
tags: [ 'api_platform.filter' ]
api_platform.filter.client.order:
parent: 'api_platform.doctrine.orm.order_filter'
arguments:

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240924090429 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE remote_calendar (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_BD3BDE0AD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE remote_calendar_rule (id INT AUTO_INCREMENT NOT NULL, remote_calendar_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, busy_weekdays JSON NOT NULL COMMENT \'(DC2Type:json)\', busy_from_hour DATETIME NOT NULL, busy_to_hour DATETIME NOT NULL, is_remote_available TINYINT(1) NOT NULL, available_from_date DATE NOT NULL, available_to_date DATE NOT NULL, available_reason VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_EE93D058D17F50A6 (uuid), INDEX IDX_EE93D058C56641EE (remote_calendar_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)');
$this->addSql('ALTER TABLE organizational_unit ADD remote_calendar_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2DC56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)');
$this->addSql('CREATE INDEX IDX_749AEB2DC56641EE ON organizational_unit (remote_calendar_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2DC56641EE');
$this->addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE');
$this->addSql('DROP TABLE remote_calendar');
$this->addSql('DROP TABLE remote_calendar_rule');
$this->addSql('DROP INDEX IDX_749AEB2DC56641EE ON organizational_unit');
$this->addSql('ALTER TABLE organizational_unit DROP remote_calendar_id');
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240924095558 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_from_hour busy_from_hour TIME NOT NULL, CHANGE busy_to_hour busy_to_hour TIME NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_from_hour busy_from_hour DATETIME NOT NULL, CHANGE busy_to_hour busy_to_hour DATETIME NOT NULL');
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240924100335 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON remote_calendar (name)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON remote_calendar');
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240924102357 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_weekdays busy_weekdays JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', CHANGE busy_from_hour busy_from_hour TIME DEFAULT NULL, CHANGE busy_to_hour busy_to_hour TIME DEFAULT NULL, CHANGE available_from_date available_from_date DATE DEFAULT NULL, CHANGE available_to_date available_to_date DATE DEFAULT NULL, CHANGE available_reason available_reason VARCHAR(255) DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_weekdays busy_weekdays JSON NOT NULL COMMENT \'(DC2Type:json)\', CHANGE busy_from_hour busy_from_hour TIME NOT NULL, CHANGE busy_to_hour busy_to_hour TIME NOT NULL, CHANGE available_from_date available_from_date DATE NOT NULL, CHANGE available_to_date available_to_date DATE NOT NULL, CHANGE available_reason available_reason VARCHAR(255) NOT NULL');
}
}

View File

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240926085224 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE');
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE remote_calendar_id remote_calendar_id INT NOT NULL');
$this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id) ON DELETE CASCADE');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE');
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE remote_calendar_id remote_calendar_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)');
}
}

View File

@ -4,6 +4,7 @@ namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\OrganizationalUnitOutput;
use App\Dto\Output\RemoteCalendarOutput;
use App\Entity\OrganizationalUnit;
use App\Validator\Constraints\OrganizationalUnitMulticastMode;
use App\Validator\Constraints\OrganizationalUnitMulticastPort;
@ -50,6 +51,9 @@ class OrganizationalUnitInput
#[Assert\Valid()]
public ?NetworkSettingsInput $networkSettings = null;
#[Groups(['organizational-unit:write'])]
public ?RemoteCalendarOutput $remoteCalendar = null;
public function __construct(?OrganizationalUnit $organizationalUnit = null)
{
if (!$organizationalUnit) {
@ -70,6 +74,10 @@ class OrganizationalUnitInput
if ($organizationalUnit->getNetworkSettings()){
$this->networkSettings = new NetworkSettingsInput($organizationalUnit->getNetworkSettings());
}
if ($organizationalUnit->getRemoteCalendar()) {
$this->remoteCalendar = new RemoteCalendarOutput($organizationalUnit->getRemoteCalendar());
}
}
public function createOrUpdateEntity(?OrganizationalUnit $organizationalUnit = null): OrganizationalUnit
@ -94,6 +102,10 @@ class OrganizationalUnitInput
$organizationalUnit->setNetworkSettings($this->networkSettings->createOrUpdateEntity($organizationalUnit->getNetworkSettings()));
}
if ($this->remoteCalendar) {
$organizationalUnit->setRemoteCalendar($this->remoteCalendar->getEntity());
}
return $organizationalUnit;
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\RemoteCalendarRuleOutput;
use App\Entity\RemoteCalendar;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
final class RemoteCalendarInput
{
#[Groups(['remote-calendar:write'])]
#[ApiProperty(description: 'The name of the remote calendar', example: "calendar")]
public ?string $name = null;
/**
* @var RemoteCalendarRuleOutput[]
*/
#[Groups(['remote-calendar:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
public array $remoteCalendarRules = [];
public function __construct(?RemoteCalendar $remoteCalendar = null)
{
if (!$remoteCalendar) {
return;
}
$this->name = $remoteCalendar->getName();
if ($remoteCalendar->getRules()) {
foreach ($remoteCalendar->getRules() as $rule) {
$this->remoteCalendarRules[] = new RemoteCalendarRuleOutput($rule);
}
}
}
public function createOrUpdateEntity(?RemoteCalendar $remoteCalendar = null): RemoteCalendar
{
if (!$remoteCalendar) {
$remoteCalendar = new RemoteCalendar();
}
$remoteCalendar->setName($this->name);
foreach ($this->remoteCalendarRules as $rule) {
$ruleToAdd[] = $rule->getEntity();
}
$remoteCalendar->setRules( $ruleToAdd ?? [] );
return $remoteCalendar;
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\RemoteCalendarOutput;
use App\Entity\RemoteCalendarRule;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
final class RemoteCalendarRuleInput
{
#[Assert\NotNull()]
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The remote calendar of the remote calendar rule')]
public ?RemoteCalendarOutput $remoteCalendar = null;
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The busy week days of the remote calendar rule', example: [1, 2, 3])]
public ?array $busyWeekDays = null;
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The busy from hour of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
public ?string $busyFromHour = null;
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The busy to hour of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
public ?string $busyToHour = null;
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The remote availability of the remote calendar rule', example: true)]
public ?bool $isRemoteAvailable = false;
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The available from date of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
public ?\DateTimeInterface $availableFromDate = null;
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The available to date of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
public ?\DateTimeInterface $availableToDate = null;
#[Groups(['remote-calendar-rule:write'])]
#[ApiProperty(description: 'The reason of the remote calendar rule', example: "reason")]
public ?string $availableReason = null;
public function __construct(?RemoteCalendarRule $remoteCalendarRule = null)
{
if (!$remoteCalendarRule) {
return;
}
$this->remoteCalendar = new RemoteCalendarOutput($remoteCalendarRule->getRemoteCalendar());
$this->busyWeekDays = $remoteCalendarRule->getBusyWeekDays();
$this->busyFromHour = $remoteCalendarRule->getBusyFromHour();
$this->busyToHour = $remoteCalendarRule->getBusyToHour();
$this->isRemoteAvailable = $remoteCalendarRule->isRemoteAvailable();
$this->availableFromDate = $remoteCalendarRule->getAvailableFromDate();
$this->availableToDate = $remoteCalendarRule->getAvailableToDate();
$this->availableReason = $remoteCalendarRule->getAvailableReason();
}
/**
* @throws \Exception
*/
public function createOrUpdateEntity(?RemoteCalendarRule $remoteCalendarRule = null): RemoteCalendarRule
{
if (!$remoteCalendarRule) {
$remoteCalendarRule = new RemoteCalendarRule();
}
$remoteCalendarRule->setRemoteCalendar($this->remoteCalendar->getEntity());
$remoteCalendarRule->setBusyWeekDays($this->busyWeekDays);
$remoteCalendarRule->setBusyFromHour($this->busyFromHour);
$remoteCalendarRule->setBusyToHour($this->busyToHour);
$remoteCalendarRule->setRemoteAvailable($this->isRemoteAvailable);
$remoteCalendarRule->setAvailableFromDate($this->availableFromDate);
$remoteCalendarRule->setAvailableToDate($this->availableToDate);
$remoteCalendarRule->setAvailableReason($this->availableReason);
return $remoteCalendarRule;
}
}

View File

@ -51,6 +51,10 @@ final class OrganizationalUnitOutput extends AbstractOutput
#[Groups(['organizational-unit:read'])]
public array $clients = [];
#[Groups(['organizational-unit:read', "client:read"])]
#[ApiProperty(readableLink: true)]
public ?RemoteCalendarOutput $remoteCalendar = null;
#[Groups(['organizational-unit:read'])]
public \DateTime $createdAt;
@ -70,7 +74,7 @@ final class OrganizationalUnitOutput extends AbstractOutput
$this->capacity = $organizationalUnit->getCapacity();
$this->type = $organizationalUnit->getType();
$this->networkSettings = $organizationalUnit->getNetworkSettings() ? new NetworkSettingsOutput($organizationalUnit->getNetworkSettings()) : null;
$this->remoteCalendar = $organizationalUnit->getRemoteCalendar() ? new RemoteCalendarOutput($organizationalUnit->getRemoteCalendar()) : null;
if ($organizationalUnit->getParent()) {
$this->parent = new self($organizationalUnit->getParent());
}
@ -87,6 +91,7 @@ final class OrganizationalUnitOutput extends AbstractOutput
)->toArray();
}
$this->path = $organizationalUnit->getPath();
$this->createdAt = $organizationalUnit->getCreatedAt();
$this->createdBy = $organizationalUnit->getCreatedBy();

View File

@ -0,0 +1,37 @@
<?php
namespace App\Dto\Output;
use ApiPlatform\Metadata\Get;
use App\Entity\RemoteCalendar;
use App\Entity\RemoteCalendarRule;
use Symfony\Component\Serializer\Annotation\Groups;
#[Get(shortName: 'RemoteCalendar')]
final class RemoteCalendarOutput extends AbstractOutput
{
#[Groups(['remote-calendar:read'])]
public ?string $name = null;
/**
* @var RemoteCalendarRuleOutput[]
*/
#[Groups(['remote-calendar:read'])]
public array $remoteCalendarRules = [];
#[Groups(['remote-calendar:read'])]
public ?\DateTimeInterface $createdAt = null;
public function __construct(RemoteCalendar $remoteCalendar)
{
parent::__construct($remoteCalendar);
$this->name = $remoteCalendar->getName();
$this->remoteCalendarRules = $remoteCalendar->getRules()->map(
fn(RemoteCalendarRule $rule) => new RemoteCalendarRuleOutput($rule)
)->toArray();
$this->createdAt = $remoteCalendar->getCreatedAt();
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Dto\Output;
use ApiPlatform\Metadata\Get;
use App\Entity\RemoteCalendarRule;
use Symfony\Component\Serializer\Annotation\Groups;
#[Get(shortName: 'RemoteCalendarRule')]
final class RemoteCalendarRuleOutput extends AbstractOutput
{
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
public ?array $busyWeekDays = null;
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
public ?string $busyFromHour = null;
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
public ?string $busyToHour = null;
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
public ?bool $isRemoteAvailable = false;
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
public ?\DateTimeInterface $availableFromDate = null;
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
public ?\DateTimeInterface $availableToDate = null;
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
public ?string $availableReason = null;
public function __construct(RemoteCalendarRule $remoteCalendarRule)
{
parent::__construct($remoteCalendarRule);
$this->busyWeekDays = $remoteCalendarRule->getBusyWeekDays();
$this->busyFromHour = $remoteCalendarRule->getBusyFromHour();
$this->busyToHour = $remoteCalendarRule->getBusyToHour();
$this->isRemoteAvailable = $remoteCalendarRule->isRemoteAvailable();
$this->availableFromDate = $remoteCalendarRule->getAvailableFromDate();
$this->availableToDate = $remoteCalendarRule->getAvailableToDate();
$this->availableReason = $remoteCalendarRule->getAvailableReason();
}
}

View File

@ -87,6 +87,10 @@ class OrganizationalUnit extends AbstractEntity
#[ORM\ManyToOne(inversedBy: 'organizationalUnits')]
private ?Subnet $subnet = null;
#[ORM\ManyToOne(targetEntity: RemoteCalendar::class, inversedBy: 'organizationalUnits', cascade: ['persist'])]
#[ORM\JoinColumn(nullable: true)]
private ?RemoteCalendar $remoteCalendar = null;
public function __construct()
{
parent::__construct();
@ -383,4 +387,16 @@ class OrganizationalUnit extends AbstractEntity
return $this;
}
public function getRemoteCalendar(): ?RemoteCalendar
{
return $this->remoteCalendar;
}
public function setRemoteCalendar(?RemoteCalendar $remoteCalendar): static
{
$this->remoteCalendar = $remoteCalendar;
return $this;
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace App\Entity;
use App\Repository\RemoteCalendarRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: RemoteCalendarRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_NAME', fields: ['name'])]
#[UniqueEntity(fields: ['name'], message: 'This name is already in use.')]
class RemoteCalendar extends AbstractEntity
{
use NameableTrait;
/**
* @var Collection<int, OrganizationalUnit>
*/
#[ORM\OneToMany(mappedBy: 'remoteCalendar', targetEntity: OrganizationalUnit::class)]
private Collection $organizationalUnits;
/**
* @var Collection<int, RemoteCalendarRule>
*/
#[ORM\OneToMany(mappedBy: 'remoteCalendar', targetEntity: RemoteCalendarRule::class)]
private Collection $rules;
public function __construct()
{
parent::__construct();
$this->rules = new ArrayCollection();
}
public function getOrganizationalUnits(): Collection
{
return $this->organizationalUnits;
}
public function setOrganizationalUnits(Collection $organizationalUnits): void
{
$this->organizationalUnits = $organizationalUnits;
}
/**
* @return Collection<int, RemoteCalendarRule>
*/
public function getRules(): Collection
{
return $this->rules;
}
public function setRules(array $rules): static
{
$this->rules->clear();
foreach ($rules as $rule){
$this->addRule($rule);
}
return $this;
}
public function addRule(RemoteCalendarRule $rule): static
{
if (!$this->rules->contains($rule)) {
$this->rules->add($rule);
$rule->setRemoteCalendar($this);
}
return $this;
}
public function removeRule(RemoteCalendarRule $rule): static
{
if ($this->rules->removeElement($rule)) {
// set the owning side to null (unless already changed)
if ($rule->getRemoteCalendar() === $this) {
$rule->setRemoteCalendar(null);
}
}
return $this;
}
}

View File

@ -0,0 +1,138 @@
<?php
namespace App\Entity;
use App\Repository\RemoteCalendarRuleRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RemoteCalendarRuleRepository::class)]
class RemoteCalendarRule extends AbstractEntity
{
#[ORM\ManyToOne(inversedBy: 'rules')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?RemoteCalendar $remoteCalendar = null;
#[ORM\Column(type: Types::JSON, nullable: true)]
private array $busyWeekdays = [];
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $busyFromHour = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $busyToHour = null;
#[ORM\Column]
private ?bool $isRemoteAvailable = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $availableFromDate = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $availableToDate = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $availableReason = null;
public function getBusyWeekdays(): array
{
return $this->busyWeekdays;
}
public function setBusyWeekdays(?array $busyWeekdays): static
{
$this->busyWeekdays = $busyWeekdays;
return $this;
}
public function getBusyFromHour(): string
{
return $this->busyFromHour->format('H:i');
}
/**
* @throws \Exception
*/
public function setBusyFromHour(?string $busyFromHour): static
{
$this->busyFromHour = new \DateTimeImmutable($busyFromHour);
return $this;
}
public function getBusyToHour(): string
{
return $this->busyToHour->format('H:i');
}
/**
* @throws \Exception
*/
public function setBusyToHour(?string $busyToHour): static
{
$this->busyToHour = new \DateTimeImmutable($busyToHour);
return $this;
}
public function isRemoteAvailable(): ?bool
{
return $this->isRemoteAvailable;
}
public function setRemoteAvailable(bool $isRemoteAvailable): static
{
$this->isRemoteAvailable = $isRemoteAvailable;
return $this;
}
public function getAvailableFromDate(): ?\DateTimeInterface
{
return $this->availableFromDate;
}
public function setAvailableFromDate(?\DateTimeInterface $availableFromDate): static
{
$this->availableFromDate = $availableFromDate;
return $this;
}
public function getAvailableToDate(): ?\DateTimeInterface
{
return $this->availableToDate;
}
public function setAvailableToDate(?\DateTimeInterface $availableToDate): static
{
$this->availableToDate = $availableToDate;
return $this;
}
public function getAvailableReason(): ?string
{
return $this->availableReason;
}
public function setAvailableReason(?string $availableReason): static
{
$this->availableReason = $availableReason;
return $this;
}
public function getRemoteCalendar(): ?RemoteCalendar
{
return $this->remoteCalendar;
}
public function setRemoteCalendar(?RemoteCalendar $remoteCalendar): static
{
$this->remoteCalendar = $remoteCalendar;
return $this;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Repository;
use App\Entity\RemoteCalendar;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<RemoteCalendar>
*/
class RemoteCalendarRepository extends AbstractRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, RemoteCalendar::class);
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Repository;
use App\Entity\RemoteCalendarRule;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<RemoteCalendarRule>
*/
class RemoteCalendarRuleRepository extends AbstractRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, RemoteCalendarRule::class);
}
}

View File

@ -0,0 +1,88 @@
<?php
namespace App\Service\UDS;
use AllowDynamicProperties;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AllowDynamicProperties]
class UDSClient
{
public function __construct(
private HttpClientInterface $httpClient,
EntityManagerInterface $entityManager,
private string $udsAPIurl,
private string $udsAuthLogin,
private string $udsAuthUsername,
private string $udsAuthPassword,
string $token,
string $scrambler
)
{
}
/**
* @throws TransportExceptionInterface
*/
public function __invoke(): void
{
$this->login();
}
/**
* @throws TransportExceptionInterface
*/
public function login(): void
{
$response = $this->httpClient->request('POST', $this->udsAPIurl . '/auth/login', [
'json' => [
'login' => $this->udsAuthLogin,
'username' => $this->udsAuthUsername,
'password' => $this->udsAuthPassword
]
]);
$data = json_decode($response->getContent(), true);
$this->token = $data['token'];
$this->scrambler = $data['scrambler'];
}
/**
* @throws TransportExceptionInterface
*/
public function getServicePools(): array
{
$response = $this->httpClient->request('GET', $this->udsAPIurl . '/servicespools/overview', [
'headers' => [
'X-Auth-Token' => $this->token,
'Content-Type' => 'application/json',
'Scrambler' => $this->scrambler
]
]);
}
public function getServicePool(string $providerId, string $serviceId): array
{
$response = $this->httpClient->request('GET', $this->udsAPIurl . '/providers/' . $providerId .'/services/'. $serviceId, [
'headers' => [
'X-Auth-Token' => $this->token,
'Content-Type' => 'application/json',
'Scrambler' => $this->scrambler
]
]);
}
public function setServicePool(string $serviceId, array $payload): void
{
$response = $this->httpClient->request('PUT', $this->udsAPIurl . '/servicespools/' . $serviceId, [
'headers' => [
'X-Auth-Token' => $this->token,
'Content-Type' => 'application/json',
'Scrambler' => $this->scrambler
],
'json' => $payload
]);
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace App\State\Processor;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\Validator\ValidatorInterface;
use App\Dto\Input\RemoteCalendarInput;
use App\Dto\Output\RemoteCalendarOutput;
use App\Repository\RemoteCalendarRepository;
readonly class RemoteCalendarProcessor implements ProcessorInterface
{
public function __construct(
private RemoteCalendarRepository $remoteCalendarRepository,
private ValidatorInterface $validator
)
{
}
/**
* @throws \Exception
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarOutput|null
{
switch ($operation){
case $operation instanceof Post:
case $operation instanceof Put:
case $operation instanceof Patch:
return $this->processCreateOrUpdate($data, $operation, $uriVariables, $context);
case $operation instanceof Delete:
return $this->processDelete($data, $operation, $uriVariables, $context);
}
}
/**
* @throws \Exception
*/
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarOutput
{
if (!($data instanceof RemoteCalendarInput)) {
throw new \Exception(sprintf('data is not instance of %s', RemoteCalendarInput::class));
}
$entity = null;
if (isset($uriVariables['uuid'])) {
$entity = $this->remoteCalendarRepository->findOneByUuid($uriVariables['uuid']);
}
$partition = $data->createOrUpdateEntity($entity);
$this->validator->validate($partition);
$this->remoteCalendarRepository->save($partition);
return new RemoteCalendarOutput($partition);
}
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
{
$user = $this->remoteCalendarRepository->findOneByUuid($uriVariables['uuid']);
$this->remoteCalendarRepository->delete($user);
return null;
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace App\State\Processor;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\Validator\ValidatorInterface;
use App\Dto\Input\RemoteCalendarRuleInput;
use App\Dto\Output\RemoteCalendarRuleOutput;
use App\Repository\RemoteCalendarRuleRepository;
readonly class RemoteCalendarRuleProcessor implements ProcessorInterface
{
public function __construct(
private RemoteCalendarRuleRepository $remoteCalendarRuleRepository,
private ValidatorInterface $validator
)
{
}
/**
* @throws \Exception
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarRuleOutput|null
{
switch ($operation){
case $operation instanceof Post:
case $operation instanceof Put:
case $operation instanceof Patch:
return $this->processCreateOrUpdate($data, $operation, $uriVariables, $context);
case $operation instanceof Delete:
return $this->processDelete($data, $operation, $uriVariables, $context);
}
}
/**
* @throws \Exception
*/
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarRuleOutput
{
if (!($data instanceof RemoteCalendarRuleInput)) {
throw new \Exception(sprintf('data is not instance of %s', RemoteCalendarRuleInput::class));
}
$entity = null;
if (isset($uriVariables['uuid'])) {
$entity = $this->remoteCalendarRuleRepository->findOneByUuid($uriVariables['uuid']);
}
$partition = $data->createOrUpdateEntity($entity);
$this->validator->validate($partition);
$this->remoteCalendarRuleRepository->save($partition);
return new RemoteCalendarRuleOutput($partition);
}
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
{
$user = $this->remoteCalendarRuleRepository->findOneByUuid($uriVariables['uuid']);
$this->remoteCalendarRuleRepository->delete($user);
return null;
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace App\State\Provider;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\State\Pagination\TraversablePaginator;
use ApiPlatform\State\ProviderInterface;
use App\Dto\Input\RemoteCalendarInput;
use App\Dto\Output\RemoteCalendarOutput;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
readonly class RemoteCalendarProvider implements ProviderInterface
{
public function __construct(
private ProviderInterface $collectionProvider,
private ProviderInterface $itemProvider
)
{
}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
switch ($operation){
case $operation instanceof GetCollection:
return $this->provideCollection($operation, $uriVariables, $context);
case $operation instanceof Patch:
case $operation instanceof Put:
return $this->provideInput($operation, $uriVariables, $context);
case $operation instanceof Get:
return $this->provideItem($operation, $uriVariables, $context);
}
}
private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object
{
$paginator = $this->collectionProvider->provide($operation, $uriVariables, $context);
$items = new \ArrayObject();
foreach ($paginator->getIterator() as $item){
$items[] = new RemoteCalendarOutput($item);
}
return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems());
}
public function provideItem(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
if (!$item) {
throw new NotFoundHttpException('RemoteCalendar not found');
}
return new RemoteCalendarOutput($item);
}
public function provideInput(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
if (isset($uriVariables['uuid'])) {
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
return $item !== null ? new RemoteCalendarInput($item) : null;
}
return new RemoteCalendarInput();
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace App\State\Provider;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\State\Pagination\TraversablePaginator;
use ApiPlatform\State\ProviderInterface;
use App\Dto\Input\RemoteCalendarRuleInput;
use App\Dto\Output\RemoteCalendarRuleOutput;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
readonly class RemoteCalendarRuleProvider implements ProviderInterface
{
public function __construct(
private ProviderInterface $collectionProvider,
private ProviderInterface $itemProvider
)
{
}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
switch ($operation){
case $operation instanceof GetCollection:
return $this->provideCollection($operation, $uriVariables, $context);
case $operation instanceof Patch:
case $operation instanceof Put:
return $this->provideInput($operation, $uriVariables, $context);
case $operation instanceof Get:
return $this->provideItem($operation, $uriVariables, $context);
}
}
private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object
{
$paginator = $this->collectionProvider->provide($operation, $uriVariables, $context);
$items = new \ArrayObject();
foreach ($paginator->getIterator() as $item){
$items[] = new RemoteCalendarRuleOutput($item);
}
return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems());
}
public function provideItem(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
if (!$item) {
throw new NotFoundHttpException('RemoteCalendarRule not found');
}
return new RemoteCalendarRuleOutput($item);
}
public function provideInput(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
if (isset($uriVariables['uuid'])) {
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
return $item !== null ? new RemoteCalendarRuleInput($item) : null;
}
return new RemoteCalendarRuleInput();
}
}