Skip to content

Commit

Permalink
Add Processing entity (#41)
Browse files Browse the repository at this point in the history
* Add Processing entities 

* Update Folder and Pia models

* [CI] Downgrade codeception because of bug Codeception/Codeception#5092

* Add tests and update existing ones

* Replace paths with parameter '%api_pattern%' in fos_rest configuration (#43)
  • Loading branch information
PapsOu authored Aug 2, 2018
1 parent 4c66c6f commit 582bb30
Show file tree
Hide file tree
Showing 22 changed files with 1,247 additions and 238 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"white-october/pagerfanta-bundle": "^1.1"
},
"require-dev": {
"codeception/codeception": "^2.4",
"codeception/codeception": "2.4.0",
"flow/jsonpath": "^0.4.0",
"guzzlehttp/guzzle": "^6.3",
"symfony/phpunit-bridge": "^4.0",
Expand Down
355 changes: 178 additions & 177 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions config/packages/fos_rest.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
zone:
- { path: ^/pias }
- { path: ^/profile }
- { path: ^/pia-templates }
- { path: ^/folders }
- { path: ^/structures }
- { path: ^/users }
- { path: ^/portfolios }
- { path: '%api_pattern%' }
body_converter:
enabled: true
body_listener:
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Pia/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function deleteAction(Request $request, $id)
$folder = $this->getResource($id);
$this->canAccessResourceOr403($folder);

if (count($folder->getPias())) {
if (count($folder->getProcessings())) {
throw new NonEmptyFolderCannotBeDeletedException();
}

Expand Down
17 changes: 0 additions & 17 deletions src/Controller/Pia/PiaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use PiaApi\Entity\Pia\Pia;
use PiaApi\DataExchange\Transformer\JsonToEntityTransformer;
use PiaApi\Entity\Pia\PiaTemplate;
use PiaApi\Entity\Pia\Folder;
use Swagger\Annotations as Swg;
use Nelmio\ApiDocBundle\Annotation as Nelmio;
use PiaApi\DataHandler\RequestDataHandler;
Expand Down Expand Up @@ -125,14 +124,6 @@ public function showAction(Request $request, $id)
public function createAction(Request $request)
{
$pia = $this->newFromRequest($request);

if ($request->get('folder') !== null) {
$folderId = $request->get('folder')['id'];
$folder = $this->getResource($folderId, Folder::class);
} else {
$folder = $this->getUser()->getStructure() ? $this->getUser()->getStructure()->getRootFolder() : null;
}
$pia->setFolder($folder);
$pia->setStructure($this->getUser()->getStructure());
$this->persist($pia);

Expand Down Expand Up @@ -168,12 +159,6 @@ public function createFromTemplateAction(Request $request, $id)
}

$pia = $this->jsonToEntityTransformer->transform($piaTemplate->getData());
if (($folderId = $request->get('folder')) !== null) {
$folder = $this->getResource($request->get('folder')['id'], Folder::class);
} else {
$folder = $this->getUser()->getStructure() ? $this->getUser()->getStructure()->getRootFolder() : null;
}
$pia->setFolder($folder);
$pia->setName($request->get('name', $pia->getName()));
$pia->setAuthorName($request->get('author_name', $pia->getAuthorName()));
$pia->setEvaluatorName($request->get('evaluator_name', $pia->getEvaluatorName()));
Expand Down Expand Up @@ -214,7 +199,6 @@ public function updateAction(Request $request, $id)
'author_name' => RequestDataHandler::TYPE_STRING,
'evaluator_name' => RequestDataHandler::TYPE_STRING,
'validator_name' => RequestDataHandler::TYPE_STRING,
'folder' => Folder::class,
'dpo_status' => RequestDataHandler::TYPE_INT,
'concerned_people_status' => RequestDataHandler::TYPE_INT,
'status' => RequestDataHandler::TYPE_INT,
Expand Down Expand Up @@ -286,7 +270,6 @@ public function importAction(Request $request)

$pia = $this->jsonToEntityTransformer->transform($importData);
$pia->setStructure($this->getUser()->getStructure());
$pia->setFolder($this->getUser()->getStructure()->getRootFolder());
$this->persist($pia);

return $this->view($pia, Response::HTTP_OK);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Pia/StructureFolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function deleteAction(Request $request, $structureId, $id)
$folder = $this->getRepository()->findOneBy(['structure' => $structureId, 'id' => $id]);
$this->canAccessResourceOr403($folder);

if (count($folder->getPias())) {
if (count($folder->getProcessings())) {
throw new NonEmptyFolderCannotBeDeletedException();
}

Expand Down
44 changes: 38 additions & 6 deletions src/Entity/Pia/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Gedmo\Timestampable\Timestampable;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use JMS\Serializer\Annotation as JMS;
use PiaApi\Entity\Pia\Traits\HasManyPiasTrait;
use PiaApi\Entity\Pia\Traits\ResourceTrait;

/**
Expand All @@ -29,7 +28,6 @@
class Folder implements Timestampable
{
use ResourceTrait,
HasManyPiasTrait,
TimestampableEntity;

/**
Expand Down Expand Up @@ -99,13 +97,13 @@ class Folder implements Timestampable
private $children;

/**
* @ORM\OneToMany(targetEntity="Pia", mappedBy="folder",cascade={"remove"})
* @ORM\OneToMany(targetEntity="Processing", mappedBy="folder",cascade={"remove"})
* @JMS\Groups({"Default", "Export"})
* @JMS\MaxDepth(2)
*
* @var Collection
* @var Collection|Processing[]
*/
protected $pias;
protected $processings;

/**
* @ORM\ManyToOne(targetEntity="Structure", inversedBy="folders").
Expand All @@ -124,8 +122,8 @@ public function __construct(string $name, ?Structure $structure = null)
$structure->getFolders()->add($this);
}

$this->pias = new ArrayCollection();
$this->children = new ArrayCollection();
$this->processings = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -303,4 +301,38 @@ public function getHierarchy(): array

return $ancestorHierarchy;
}

/**
* @return array|Processing[]
*/
public function getProcessings(): array
{
return $this->processings->getValues();
}

/**
* @param Processing $processing
*
* @throws \InvalidArgumentException
*/
public function addProcessing(Processing $processing): void
{
if ($this->processings->contains($processing)) {
throw new \InvalidArgumentException(sprintf('Processing « %s » is already in Folder « #%d »', $processing, $this->getId()));
}
$this->processings->add($processing);
}

/**
* @param Processing $processing
*
* @throws \InvalidArgumentException
*/
public function removeProcessing(Processing $processing): void
{
if (!$this->processings->contains($processing)) {
throw new \InvalidArgumentException(sprintf('Processing « %s » is not in Folder « #%d »', $processing, $this->getId()));
}
$this->processings->removeElement($processing);
}
}
49 changes: 24 additions & 25 deletions src/Entity/Pia/Pia.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,6 @@ class Pia implements Timestampable
*/
protected $template;

/**
* @ORM\ManyToOne(targetEntity="Folder", inversedBy="pias")
* @JMS\Groups({"Default", "Export"})
* @JMS\MaxDepth(1)
*
* @var Folder
*/
protected $folder;

/**
* @ORM\Column(type="string")
* @JMS\Groups({"Default", "Full"})
Expand All @@ -221,6 +212,14 @@ class Pia implements Timestampable
*/
protected $type = self::TYPE_ADVANCED;

/**
* @ORM\ManyToOne(targetEntity="Processing", inversedBy="pias")
* @JMS\Groups({"Full"})
*
* @var Processing
*/
protected $processing;

public function __construct()
{
$this->answers = new ArrayCollection();
Expand Down Expand Up @@ -428,22 +427,6 @@ public function setValidatorName(string $validatorName): void
$this->validatorName = $validatorName;
}

/**
* @return Folder
*/
public function getFolder(): ?Folder
{
return $this->folder;
}

/**
* @param Folder $folder
*/
public function setFolder(?Folder $folder): void
{
$this->folder = $folder;
}

/**
* @param int $dpoStatus
*/
Expand Down Expand Up @@ -539,4 +522,20 @@ public function setType(?string $type): void
{
$this->type = $type;
}

/**
* @return Processing
*/
public function getProcessing(): Processing
{
return $this->processing;
}

/**
* @param Processing $processing
*/
public function setProcessing(Processing $processing): void
{
$this->processing = $processing;
}
}
Loading

0 comments on commit 582bb30

Please sign in to comment.