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

In progress...

parent 7edd5ecf
......@@ -73,7 +73,7 @@ final class ActivateAccountAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -110,7 +110,7 @@ final class ActivateAccountAction
$user = $this->em->find('\App\Entity\User', $queryParams['email']);
// Is the activation key is the good one
// Is the activation key is the good one ?
if ($user->getActivationKey() !== $queryParams['activation_key']) {
return $this->dispatchHttpError(
$response,
......@@ -123,7 +123,7 @@ final class ActivateAccountAction
$user->setActivated(true);
$this->em->flush();
// Send a email confirmation for the user and returns user modified
// Send an email confirmation for the user and returns user modified
$this->sendEmail($user->getEmail());
return $response->withJson($user);
}
......
......@@ -69,7 +69,7 @@ final class ChangePasswordAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -106,7 +106,7 @@ final class ChangePasswordAction
$user = $this->em->find('\App\Entity\User', $parsedBody['email']);
// Is the user account is activated
// Is the user account is activated ?
if (!$user->getActivated()) {
return $this->dispatchHttpError(
$response,
......
......@@ -69,7 +69,7 @@ final class NewPasswordAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -104,7 +104,7 @@ final class NewPasswordAction
$user = $this->em->find('App\Entity\User', $parsedBody['email']);
// Is the user account is activated
// Is the user account is activated ?
if (!$user->getActivated()) {
return $this->dispatchHttpError(
$response,
......
......@@ -73,7 +73,7 @@ final class RegisterAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......
......@@ -81,7 +81,7 @@ final class TokenAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -107,6 +107,7 @@ final class TokenAction
}
}
// Is the user exists ?
if (!$this->isExistUser($parsedBody['email'])) {
return $this->dispatchHttpError(
$response,
......@@ -117,6 +118,7 @@ final class TokenAction
$user = $this->em->find('\App\Entity\User', $parsedBody['email']);
// Is the user activated ?
if (!$user->getActivated()) {
return $this->dispatchHttpError(
$response,
......@@ -125,6 +127,7 @@ final class TokenAction
);
}
// Is the password is ok ?
if (!password_verify($parsedBody['password'], $user->getPassword())) {
return $this->dispatchHttpError(
$response,
......@@ -133,7 +136,7 @@ final class TokenAction
);
}
// JWT generation
// // It's all right. JWT generation
$token = $this->generateToken($user->getEmail());
$data = array('email' => $user->getEmail(), 'token' => (string) $token);
return $response->withJson($data);
......
......@@ -21,19 +21,56 @@ use App\Entity\Attribute;
use App\Entity\CriteriaFamily;
use App\Entity\OutputCategory;
/**
* Route: /metadata/dataset/{name}/attribute/{id}
* {name}: Dataset name
* {id}: Attribute id
*
* This action is used to manage one attribute
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class AttributeAction
{
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 attribute found
* `PUT` Full update an attribute and returns the new version
*
* @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('Attribute list action dispatched');
......@@ -42,8 +79,10 @@ final class AttributeAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, OPTIONS');
}
// Search the correct attribute with primary key
$attribute = $this->em->getRepository('App\Entity\Attribute')->findOneBy(array('dataset' => $args['name'], 'id' => $args['id']));
// If attribute is not found 404
if (is_null($attribute)) {
return $this->dispatchHttpError(
$response,
......@@ -57,20 +96,20 @@ final class AttributeAction
}
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
$criteriaFamily = is_null($parsedBody['id_criteria_family']) ? null : $this->em->find('App\Entity\CriteriaFamily', $parsedBody['id_criteria_family']);
$outputCategory = is_null($parsedBody['id_output_category']) ? null : $this->em->find('App\Entity\OutputCategory', $parsedBody['id_output_category']);
$this->editAttribute($attribute, $parsedBody, $criteriaFamily, $outputCategory);
$this->em->flush();
$this->editAttribute($attribute, $request->getParsedBody());
$newResponse = $response->withJson($attribute);
}
return $newResponse;
}
private function editAttribute(Attribute $attribute, array $parsedBody, CriteriaFamily $criteriaFamily = null, OutputCategory $outputCategory = null): void
/**
* Update attribute object with setters
*
* @param Attribute $attribute The attribute to update
* @param string[] $parsedBody Contains the new values ​​of the attribute sent by the user
*/
private function editAttribute(Attribute $attribute, array $parsedBody): void
{
$attribute->setLabel($parsedBody['label']);
$attribute->setFormLabel($parsedBody['form_label']);
......@@ -100,7 +139,10 @@ final class AttributeAction
$attribute->setVoDescription($parsedBody['vo_description']);
$attribute->setVoDatatype($parsedBody['vo_datatype']);
$attribute->setVoSize($parsedBody['vo_size']);
$criteriaFamily = (is_null($parsedBody['id_criteria_family'])) ? null : $this->em->find('App\Entity\CriteriaFamily', $parsedBody['id_criteria_family']);
$attribute->setCriteriaFamily($criteriaFamily);
$outputCategory = (is_null($parsedBody['id_output_category'])) ? null : $this->em->find('App\Entity\OutputCategory', $parsedBody['id_output_category']);
$attribute->setOutputCategory($outputCategory);
$this->em->flush();
}
}
......@@ -21,19 +21,54 @@ use App\Entity\Attribute;
use App\Entity\CriteriaFamily;
use App\Entity\OutputCategory;
/**
* Route: /metadata/dataset/{name}/attribute/
* {name}: Dataset name
*
* This action returns a list of all attributes in a dataset
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class AttributeListAction
{
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 all attributes in the dataset selected
*
* @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('Attribute list action dispatched');
......@@ -44,6 +79,7 @@ final class AttributeListAction
$dataset = $this->em->find('App\Entity\Dataset', $args['name']);
// Returns HTTP 404 if the dataset is not found
if (is_null($dataset)) {
return $this->dispatchHttpError(
$response,
......
......@@ -18,14 +18,47 @@ use Psr\Http\Message\ResponseInterface as Response;
use App\Utils\ActionTrait;
use App\Entity\Database;
/**
* Route: /metadata/database/{id}
* {id}: Database id
*
* This action is used to manage one database
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatabaseAction
{
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;
/**
* The key needed to encrypt 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 string $encryptionKey
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, string $encryptionKey)
{
$this->logger = $logger;
......@@ -33,6 +66,17 @@ final class DatabaseAction
$this->encryptionKey = $encryptionKey;
}
/**
* `GET` Returns the database found
* `PUT` Full update the database and returns the new version
* `DELETE` Delete the database 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('Database action dispatched');
......@@ -41,8 +85,10 @@ final class DatabaseAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct database with primary key
$database = $this->em->find('App\Entity\Database', $args['id']);
// If database is not found 404
if (is_null($database)) {
return $this->dispatchHttpError(
$response,
......@@ -58,7 +104,7 @@ final class DatabaseAction
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'dbname', 'dbtype', 'dbhost', 'dbport', 'dblogin', 'dbpassword') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -83,6 +129,12 @@ final class DatabaseAction
return $newResponse;
}
/**
* Update database object with setters
*
* @param Database $database The database to update
* @param string[] $parsedBody Contains the new values ​​of the database sent by the user
*/
private function editDatabase(Database $database, array $parsedBody): void
{
$database->setLabel($parsedBody['label']);
......
......@@ -18,14 +18,46 @@ use Psr\Http\Message\ResponseInterface as Response;
use App\Utils\ActionTrait;
use App\Entity\Database;
/**
* Route: /metadata/database
*
* This action returns a list of all databases listed in the metamodel database
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatabaseListAction
{
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;
/**
* The key needed to encrypt 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 string $encryptionKey
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, string $encryptionKey)
{
$this->logger = $logger;
......@@ -33,6 +65,16 @@ final class DatabaseListAction
$this->encryptionKey = $encryptionKey;
}
/**
* `GET` Returns a list of all databases listed in the metamodel database
* `POST` Add a new database
*
* @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('Database list action dispatched');
......@@ -49,7 +91,7 @@ final class DatabaseListAction
if ($request->isPost()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'dbname', 'dbtype', 'dbhost', 'dbport', 'dblogin', 'dbpassword') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -67,6 +109,11 @@ final class DatabaseListAction
return $newResponse;
}
/**
* Add a new database into the metamodel
*
* @param string[] $parsedBody Contains the values ​​of the new database sent by the user
*/
private function postDatabase(array $parsedBody): Database
{
$database = new Database();
......
......@@ -42,10 +42,11 @@ final class OpenApiAction
/**
* This action returns the open api description for the anis service
* The open API description is available at the root of the project (anis-server.yaml)
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......
......@@ -45,7 +45,7 @@ final class RootAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......
......@@ -97,7 +97,7 @@ final class SearchAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......
Supports Markdown
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