Commit cb4e61d6 authored by François Agneray's avatar François Agneray
Browse files

In progress... 18/07

parent 2d660877
......@@ -21,6 +21,8 @@ use App\Utils\ActionTrait;
use App\Entity\User;
/**
* Route: /login/activate-account
*
* With this action, the newly registered user be able
* to send the activation code of his new account. (GET)
*
......
......@@ -20,6 +20,8 @@ use Swift_Message;
use App\Utils\ActionTrait;
/**
* Route: /login/change-password
*
* With this action the anis user can change his password (POST)
*
* @author François Agneray <francois.agneray@lam.fr>
......
......@@ -19,6 +19,8 @@ use Swift_Mailer;
use App\Utils\ActionTrait;
/**
* Route: /login/new-password
*
* This action asks for a new password
*
* @author François Agneray <francois.agneray@lam.fr>
......
......@@ -21,6 +21,8 @@ use App\Utils\ActionTrait;
use App\Entity\User;
/**
* Route: /login/register
*
* An action to saves a new user Anis (POST)
*
* @author François Agneray <francois.agneray@lam.fr>
......
......@@ -21,6 +21,8 @@ use Lcobucci\JWT\Token;
use App\Utils\ActionTrait;
/**
* Route: /login/token
*
* Get a valid token (jwt) for a anis user (POST)
*
* @author François Agneray <francois.agneray@lam.fr>
......
......@@ -19,19 +19,56 @@ use App\Utils\ActionTrait;
use App\Entity\Dataset;
use App\Entity\DatasetFamily;
/**
* Route: /metadata/dataset/{name}
* {name}: Dataset name
*
* This action is used to manage one dataset
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatasetAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
/**
* `GET` Returns the dataset found
* `PUT` Full update the dataset and returns the new version
* `DELETE` Delete the dataset found and return a confirmation message
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Dataset action dispatched');
......@@ -40,8 +77,10 @@ final class DatasetAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct dataset with primary key
$dataset = $this->em->find('App\Entity\Dataset', $args['name']);
// If dataset is not found 404
if (is_null($dataset)) {
return $this->dispatchHttpError(
$response,
......@@ -57,7 +96,7 @@ final class DatasetAction
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'description', 'id_dataset_family', 'display', 'count', 'vo', 'data_path') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -68,7 +107,10 @@ final class DatasetAction
}
}
// Search the correct dataset family with primary key
$family = $this->em->find('App\Entity\DatasetFamily', $parsedBody['id_dataset_family']);
// Dataset family is mandatory. If is null 404
if (is_null($family)) {
return $this->dispatchHttpError(
$response,
......@@ -91,6 +133,13 @@ final class DatasetAction
return $newResponse;
}
/**
* Update dataset object with setters
*
* @param Dataset $dataset The dataset to update
* @param string[] $parsedBody Contains the new values ​​of the dataset sent by the user
* @param DatasetFamily $family Contains the dataset family doctrine object
*/
private function editDataset(Dataset $dataset, array $parsedBody, DatasetFamily $family): void
{
$dataset->setLabel($parsedBody['label']);
......
......@@ -21,22 +21,56 @@ use App\Entity\Dataset;
use App\Entity\Project;
use App\Entity\DatasetFamily;
/**
* Route: /metadata/dataset
*
* This action is used to:
* - Get all datasets
* - Add a new dataset
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatasetListAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Factory that provides a connection to the business database
*
* @var DBALConnectionFactory
*/
private $dcf;
/**
* The encryption key used by anis to encrypt and decrypt sensitive data like passwords
* This key is provided by configuration (see the config file)
* The key needed to decrypt the password of the database
*
* @var string
*/
private $encryptionKey;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
* @param DBALConnectionFactory $dcf
* @param string $encryptionKey
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, DBALConnectionFactory $dcf, string $encryptionKey)
{
$this->logger = $logger;
......@@ -45,6 +79,17 @@ final class DatasetListAction
$this->encryptionKey = $encryptionKey;
}
/**
* `GET` Returns the list of datasets
* `POST` Add a new dataset. The program will search the business database for
* the columns of the table (table_ref) to transform them into attributes
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Dataset list action dispatched');
......@@ -61,7 +106,7 @@ final class DatasetListAction
if ($request->isPost()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('name', 'table_ref', 'label', 'description', 'display', 'count', 'vo', 'data_path', 'project_name', 'id_dataset_family') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -97,6 +142,15 @@ final class DatasetListAction
return $newResponse;
}
/**
* Create a new dataset doctrine object and save it
*
* @param string[] $parsedBody Contains the values ​​of the new dataset sent by the user
* @param Project $project Contains the project doctrine object
* @param DatasetFamily $datasetFamily Contains the dataset family doctrine object
*
* @return Dataset
*/
private function postDataset(array $parsedBody, Project $project, DatasetFamily $family): Dataset
{
$dataset = new Dataset($parsedBody['name']);
......@@ -117,6 +171,12 @@ final class DatasetListAction
return $dataset;
}
/**
* Access to the business database dans get all the columns of the table (table_ref)
* and makes the corresponding doctrine attribute objects
*
* @param Dataset $dataset Contains the new dataset doctrine object
*/
private function postAttributes(Dataset $dataset): void
{
$database = $dataset->getProject()->getDatabase();
......
......@@ -19,19 +19,56 @@ use App\Utils\ActionTrait;
use App\Entity\OutputCategory;
use App\Entity\OutputFamily;
/**
* Route: /metadata/output-category/{id}
* {id}: Output category id
*
* This action is used to manage one output category
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class OutputCategoryAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
/**
* `GET` Returns the output category found
* `PUT` Full update the output category and returns the new version
* `DELETE` Delete the output category found and returns a confirmation message
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, $args): Response
{
$this->logger->info('Output category action dispatched');
......@@ -40,8 +77,10 @@ final class OutputCategoryAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct output category with primary key (id)
$outputCategory = $this->em->find('App\Entity\OutputCategory', $args['id']);
// If output category is not found 404
if (is_null($outputCategory)) {
return $this->dispatchHttpError(
$response,
......@@ -57,7 +96,7 @@ final class OutputCategoryAction
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'display', 'id_output_family') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -68,8 +107,10 @@ final class OutputCategoryAction
}
}
// Vérification de l'existence de la output family
// Search the correct output family with primary key
$outputFamily = $this->em->find('App\Entity\OutputFamily', $parsedBody['id_output_family']);
// Output family is mandatory. If is null 404
if (is_null($outputFamily)) {
return $this->dispatchHttpError(
$response,
......@@ -92,6 +133,13 @@ final class OutputCategoryAction
return $newResponse;
}
/**
* Update output category object with setters
*
* @param OutputCategory $outputCategory The output category to update
* @param string[] $parsedBody Contains the new values ​​of the output category sent by the user
* @param OutputFamily $outputFamily Contains the output family doctrine object to set to the output category
*/
private function editOutputCategory(OutputCategory $outputCategory, array $parsedBody, OutputFamily $outputFamily): void
{
$outputCategory->setLabel($parsedBody['label']);
......
......@@ -19,19 +19,56 @@ use App\Utils\ActionTrait;
use App\Entity\Project;
use App\Entity\Database;
/**
* Route: /metadata/project/{name}
* {name}: Project name
*
* This action is used to manage one project
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class ProjectAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
/**
* `GET` Returns the project found
* `PUT` Full update the project and returns the new version
* `DELETE` Delete the project found and return a confirmation message
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Project action dispatched');
......@@ -40,8 +77,10 @@ final class ProjectAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct project with primary key
$project = $this->em->find('App\Entity\Project', $args['name']);
// If project is not found 404
if (is_null($project)) {
return $this->dispatchHttpError(
$response,
......@@ -57,7 +96,7 @@ final class ProjectAction
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'description', 'link', 'manager', 'id_database') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -68,8 +107,10 @@ final class ProjectAction
}
}
// Vérification de l'existence de la database
// Search the correct database with primary key
$database = $this->em->find('App\Entity\Database', $parsedBody['id_database']);
// Database is mandatory. If is null 404
if (is_null($database)) {
return $this->dispatchHttpError(
$response,
......@@ -92,6 +133,13 @@ final class ProjectAction
return $newResponse;
}
/**
* Update project object with setters
*
* @param Project $project The project to update
* @param string[] $parsedBody Contains the new values ​​of the project sent by the user
* @param Database $database Contains the database doctrine object to set to the project
*/
private function editProject(Project $project, array $parsedBody, Database $database): void
{
$project->setLabel($parsedBody['label']);
......
......@@ -16,6 +16,8 @@ use Psr\Http\Message\ResponseInterface as Response;
use file_get_contents;
/**
* Route: /open-api
*
* This action returns the open api description for the anis service. (GET)
*
* @author François Agneray <francois.agneray@lam.fr>
......
......@@ -15,6 +15,8 @@ use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
/**
* Route: /
*
* With this action user can make sure that
* the service is responding. (GET)
*
......
......@@ -74,26 +74,51 @@ class Database implements \JsonSerializable
*/
protected $password;
/**
* Getter property id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Getter property label
*
* @return string
*/
public function getLabel()
{
return $this->label;
}
/**
* Setter property label
*
* @param string $label
*/
public function setLabel($label)
{
$this->label = $label;
}
/**
* Getter property dbname
*
* @return string
*/
public function getDbName()
{
return $this->dbname;
}
/**
* Setter property dbname
*
* @param string $dbname
*/
public function setDbName($dbname)
{
$this->dbname = $dbname;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment