Skip to content

Commit

Permalink
Fix routes and processing creation from template (#78)
Browse files Browse the repository at this point in the history
* Fix routes and processing creation from template

* fix createFromTemplateAction

* fix creation of a processing from a new template forma
  • Loading branch information
GlennCavarle authored and RomainSanchez committed Nov 28, 2018
1 parent 0583135 commit 6b2ef29
Show file tree
Hide file tree
Showing 24 changed files with 371 additions and 111 deletions.
10 changes: 7 additions & 3 deletions src/Controller/Pia/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function showAction(Request $request, $id)
* type="object",
* required={"name"},
* @Swg\Property(property="name", type="string"),
* @Swg\Property(property="person_in_charge", type="string"),
* @Swg\Property(property="parent", type="object", @Swg\Property(property="id", type="number"))
* ),
* description="The Folder content"
Expand Down Expand Up @@ -173,7 +174,8 @@ public function createAction(Request $request)
$folder = $this->folderService->createFolder(
$request->get('name'),
$structure,
$parent
$parent,
$request->get('person_in_charge')
);

$this->persist($folder);
Expand Down Expand Up @@ -214,6 +216,7 @@ public function createAction(Request $request)
* @Swg\Schema(
* type="object",
* @Swg\Property(property="name", type="string"),
* @Swg\Property(property="person_in_charge", type="string"),
* @Swg\Property(property="parent", type="object", @Swg\Property(property="id", type="number"))
* ),
* description="The Folder content"
Expand All @@ -238,8 +241,9 @@ public function updateAction(Request $request, $id)
$this->canAccessResourceOr403($folder);

$updatableAttributes = [
'name' => RequestDataHandler::TYPE_STRING,
'parent' => Folder::class,
'name' => RequestDataHandler::TYPE_STRING,
'person_in_charge' => RequestDataHandler::TYPE_STRING,
'parent' => Folder::class,
];

$this->mergeFromRequest($folder, $updatableAttributes, $request);
Expand Down
69 changes: 0 additions & 69 deletions src/Controller/Pia/PiaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PiaApi\DataExchange\Transformer\PiaTransformer;
use PiaApi\DataHandler\RequestDataHandler;
use PiaApi\Entity\Pia\Pia;
use PiaApi\Entity\Pia\ProcessingTemplate;
use PiaApi\Entity\Pia\Processing;
use PiaApi\Exception\DataImportException;
use PiaApi\Entity\Pia\Answer;
Expand Down Expand Up @@ -218,74 +217,6 @@ public function createAction(Request $request)
return $this->view($pia, Response::HTTP_OK);
}

/**
* Creates a PIA from a template.
*
* @Swg\Tag(name="Pia")
*
* @FOSRest\Post("/pias/new-from-template/{id}")
*
* @Swg\Parameter(
* name="Authorization",
* in="header",
* type="string",
* required=true,
* description="The API token. e.g.: Bearer <TOKEN>"
* )
* @Swg\Parameter(
* name="id",
* in="path",
* type="string",
* required=true,
* description="The ID of the PIA's template"
* )
* @Swg\Parameter(
* name="PIA",
* in="body",
* required=true,
* @Swg\Schema(
* type="object",
* required={"author_name","evaluator_name","validator_name","processing"},
* @Swg\Property(property="author_name", type="string"),
* @Swg\Property(property="evaluator_name", type="string"),
* @Swg\Property(property="validator_name", type="string"),
* @Swg\Property(property="processing", type="object", required={"id"}, @Swg\Property(property="id", type="number"))
* ),
* description="The PIA content"
* )
*
* @Swg\Response(
* response=200,
* description="Returns the newly created PIA",
* @Swg\Schema(
* type="object",
* ref=@Nelmio\Model(type=Pia::class, groups={"Default"})
* )
* )
*
* @Security("is_granted('CAN_CREATE_PIA')")
*
* @return array
*/
public function createFromTemplateAction(Request $request, $id)
{
/** @var ProcessingTemplate $pTemplate */
$pTemplate = $this->getDoctrine()->getRepository(ProcessingTemplate::class)->find($id);
if ($pTemplate === null) {
return $this->view($pTemplate, Response::HTTP_NOT_FOUND);
}

$pia = $this->jsonToEntityTransformer->transform($pTemplate->getData());
$pia->setAuthorName($request->get('author_name', $pia->getAuthorName()));
$pia->setEvaluatorName($request->get('evaluator_name', $pia->getEvaluatorName()));
$pia->setValidatorName($request->get('validator_name', $pia->getValidatorName()));
$pia->setStructure($this->getUser()->getStructure());
$pia->setProcessing($this->getResource($request->get('processing', ['id' => -1])['id'], Processing::class));
$this->persist($pia);

return $this->view($pia, Response::HTTP_OK);
}

/**
* Updates a PIA.
*
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Pia/ProcessingCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace PiaApi\Controller\Pia;

use PiaApi\DataHandler\RequestDataHandler;
use PiaApi\Services\ProcessingCommentService;
use PiaApi\Entity\Pia\ProcessingComment;
use PiaApi\Entity\Pia\Processing;
use FOS\RestBundle\Controller\Annotations as FOSRest;
Expand All @@ -25,7 +24,8 @@

class ProcessingCommentController extends RestController
{
public function __construct(PropertyAccessorInterface $propertyAccessor) {
public function __construct(PropertyAccessorInterface $propertyAccessor)
{
parent::__construct($propertyAccessor);
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public function updateAction(Request $request, $id)
$this->canAccessResourceOr403($processingComment);

$updatableAttributes = [
'content' => RequestDataHandler::TYPE_STRING,
'content' => RequestDataHandler::TYPE_STRING,
'field' => RequestDataHandler::TYPE_STRING,
];

Expand Down
99 changes: 97 additions & 2 deletions src/Controller/Pia/ProcessingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use PiaApi\Services\ProcessingService;
use PiaApi\Entity\Pia\Processing;
use PiaApi\Entity\Pia\ProcessingTemplate;
use PiaApi\Entity\Pia\Folder;
use PiaApi\DataHandler\RequestDataHandler;
use PiaApi\Entity\Pia\ProcessingDataType;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function __construct(
SerializerInterface $serializer
) {
parent::__construct($propertyAccessor);

$this->processingService = $processingService;
$this->processingTransformer = $processingTransformer;
$this->serializer = $serializer;
Expand Down Expand Up @@ -177,6 +178,7 @@ public function showAction(Request $request, $id)
* @Swg\Property(property="controllers", type="string"),
* @Swg\Property(property="non_eu_transfer", type="string"),
* @Swg\Property(property="context_of_implementation", type="string"),
* @Swg\Property(property="concerned_people", type="string"),
* @Swg\Property(property="processing_data_types", type="array", @Swg\Items(
* ref=@Nelmio\Model(type=ProcessingDataType::class, groups={"Default"})
* )),
Expand Down Expand Up @@ -260,6 +262,7 @@ public function createAction(Request $request)
* @Swg\Property(property="rights_guarantee", type="string"),
* @Swg\Property(property="exactness", type="string"),
* @Swg\Property(property="consent", type="string"),
* @Swg\Property(property="concerned_people", type="string"),
* @Swg\Property(property="non_eu_transfer", type="string"),
* @Swg\Property(property="context_of_implementation", type="string"),
* @Swg\Property(property="processing_data_types", type="array", @Swg\Items(
Expand All @@ -268,7 +271,7 @@ public function createAction(Request $request)
* @Swg\Property(property="recipients", type="string"),
* @Swg\Property(property="evaluationComment", type="string"),
* @Swg\Property(property="evaluationState", type="integer"),
* @Swg\Property(property="folder", required={"id"}, type="object",
* @Swg\Property(property="folder", required={"id"}, type="object",
* @Swg\Property(property="id", type="number")),
* @Swg\Property(property="comments", type="array", @Swg\Items(
* ref=@Nelmio\Model(type=ProcessingComment::class, groups={"Default"})
Expand Down Expand Up @@ -320,6 +323,7 @@ public function updateAction(Request $request, $id)
'rights_guarantee' => RequestDataHandler::TYPE_STRING,
'exactness' => RequestDataHandler::TYPE_STRING,
'consent' => RequestDataHandler::TYPE_STRING,
'concerned_people' => RequestDataHandler::TYPE_STRING,
'status' => RequestDataHandler::TYPE_INT,
'evaluation_comment' => RequestDataHandler::TYPE_STRING,
'evaluation_state' => RequestDataHandler::TYPE_INT,
Expand Down Expand Up @@ -466,4 +470,95 @@ public function importAction(Request $request)

return $this->view($processing, Response::HTTP_OK);
}

/**
* Creates a PIA from a template.
*
* @Swg\Tag(name="Processing")
*
* @FOSRest\Post("/processings/new-from-template/{id}")
*
* @Swg\Parameter(
* name="Authorization",
* in="header",
* type="string",
* required=true,
* description="The API token. e.g.: Bearer <TOKEN>"
* )
* @Swg\Parameter(
* name="id",
* in="path",
* type="string",
* required=true,
* description="The ID of the Processing template"
* )
* @Swg\Parameter(
* name="Processing",
* in="body",
* required=true,
* description="The Processing content",
* @Swg\Schema(
* type="object",
* ref=@Nelmio\Model(type=Processing::class, groups={"Default"})
* )
* )
*
* @Swg\Response(
* response=200,
* description="Returns the newly created Processing",
* @Swg\Schema(
* type="object",
* ref=@Nelmio\Model(type=Processing::class, groups={"Default"})
* )
* )
*
* @Security("is_granted('CAN_CREATE_PROCESSING')")
*
* @return array
*/
public function createFromTemplateAction(Request $request, $id)
{
/** @var ProcessingTemplate $pTemplate */
$pTemplate = $this->getDoctrine()->getRepository(ProcessingTemplate::class)->find($id);
$folder = $this->getResource($request->get('folder', ['id' => -1])['id'], Folder::class);

if ($pTemplate === null || $folder === null) {
return $this->view($pTemplate, Response::HTTP_NOT_FOUND);
}

$this->processingTransformer->setFolder($folder);

try {
$tplData = json_decode($pTemplate->getData(), true);
$processing = $this->processingTransformer->jsonToProcessing($tplData);
$processing->setAuthor($request->get('author'));
$processing->setDesignatedController($request->get('designated_controller'));

$this->persist($processing);

$descriptor = $this->processingTransformer->fromJson($tplData, ProcessingDescriptor::class);

//only last PIA is used
if (count($descriptor->getPias()) > 0) {
$pias = $descriptor->getPias();
$pia = $this->processingTransformer->extractPia($processing, end($pias));
$processing->addPia($pia);
$pia->setProcessing($processing);
$pia->setStructure($folder->getStructure()); //@todo to be removed, a Pia do not need a structure
$this->persist($pia);
}

foreach ($descriptor->getProcessingDataTypes() as $types) {
$processing->addProcessingDataType($this->processingTransformer->extractDataType($processing, $types));
}

$processing->setTemplate($pTemplate);

$this->persist($processing);
} catch (DataImportException $ex) {
return $this->view(unserialize($ex->getMessage()), Response::HTTP_BAD_REQUEST);
}

return $this->view($processing, Response::HTTP_OK);
}
}
6 changes: 6 additions & 0 deletions src/Controller/Pia/StructureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ public function createAction(Request $request)
* @Swg\Property(property="siret", type="string"),
* @Swg\Property(property="vat_number", type="string"),
* @Swg\Property(property="activity_code", type="string"),
* @Swg\Property(property="executive", type="string"),
* @Swg\Property(property="backup", type="string"),
* @Swg\Property(property="dpo", type="string"),
* @Swg\Property(property="legal_form", type="string"),
* @Swg\Property(property="registration_date", type="string")
* ),
Expand Down Expand Up @@ -266,6 +269,9 @@ public function updateAction(Request $request, $id)
'siret' => RequestDataHandler::TYPE_STRING,
'vat_number' => RequestDataHandler::TYPE_STRING,
'activity_code' => RequestDataHandler::TYPE_STRING,
'executive' => RequestDataHandler::TYPE_STRING,
'backup' => RequestDataHandler::TYPE_STRING,
'dpo' => RequestDataHandler::TYPE_STRING,
'legal_form' => RequestDataHandler::TYPE_STRING,
'registration_date' => \DateTime::class,
];
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/Pia/StructureFolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function showAction(Request $request, $structureId, $id)
* type="object",
* required={"name"},
* @Swg\Property(property="name", type="string"),
* @Swg\Property(property="person_in_charge", type="string"),
* @Swg\Property(property="parent", type="object", @Swg\Property(property="id", type="number"))
* ),
* description="The Folder content"
Expand Down Expand Up @@ -194,7 +195,8 @@ public function createAction(Request $request, $structureId)
$folder = $this->folderService->createFolder(
$request->get('name'),
$structure,
$parent
$parent,
$request->get('person_in_charge')
);
$this->canAccessResourceOr403($folder);

Expand Down Expand Up @@ -243,6 +245,7 @@ public function createAction(Request $request, $structureId)
* @Swg\Schema(
* type="object",
* @Swg\Property(property="name", type="string"),
* @Swg\Property(property="person_in_charge", type="string"),
* @Swg\Property(property="parent", type="object", @Swg\Property(property="id", type="number"))
* ),
* description="The Folder content"
Expand Down Expand Up @@ -272,6 +275,7 @@ public function updateAction(Request $request, $structureId, $id)

$updatableAttributes = [
'name' => RequestDataHandler::TYPE_STRING,
'person_in_charge' => RequestDataHandler::TYPE_STRING,
'parent' => Folder::class,
];

Expand Down
15 changes: 7 additions & 8 deletions src/DataExchange/Descriptor/PiaDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class PiaDescriptor extends AbstractDescriptor
/**
* @JMS\Type("string")
* @JMS\Groups({"Default", "Export"})
* @Assert\NotBlank
*
* @var string
*/
Expand Down Expand Up @@ -195,15 +194,15 @@ public function __construct(
string $evaluator,
string $validator,
int $dpoStatus,
string $dpoOpinion,
string $concernedPeopleOpinion,
?string $dpoOpinion,
?string $concernedPeopleOpinion,
int $concernedPeopleStatus,
bool $concernedPeopleSearchedOpinion,
string $concernedPeopleSearchedContent,
string $rejectionReason,
string $appliedAdjustments,
string $dposNames,
string $peopleNames,
?string $concernedPeopleSearchedContent,
?string $rejectionReason,
?string $appliedAdjustments,
?string $dposNames,
?string $peopleNames,
bool $isExample,
\DateTime $createdAt,
\DateTime $updatedAt,
Expand Down
1 change: 0 additions & 1 deletion src/DataExchange/Descriptor/ProcessingDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ProcessingDescriptor extends AbstractDescriptor
/**
* @JMS\Type("string")
* @JMS\Groups({"Default", "Export"})
* @Assert\NotBlank
*
* @var string|null
*/
Expand Down
2 changes: 1 addition & 1 deletion src/DataExchange/Transformer/ProcessingTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function toProcessing(ProcessingDescriptor $descriptor): Processing
$processing->setLifeCycle($descriptor->getLifeCycle());
$processing->setStorage($descriptor->getStorage());
$processing->setStandards($descriptor->getStandards());
$processing->setStatus($descriptor->getStatus());
$processing->setStatus((int) $descriptor->getStatus());
$processing->setLawfulness($descriptor->getLawfulness());
$processing->setMinimization($descriptor->getMinimization());
$processing->setRightsGuarantee($descriptor->getRightsGuarantee());
Expand Down
Loading

0 comments on commit 6b2ef29

Please sign in to comment.