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

Suppression actions datasetcriteria, datasetoutput

parent 995676e9
<?php declare(strict_types=1);
/*
* This file is part of ANIS SERVER API.
*
* (c) François Agneray <francois.agneray@lam.fr>
* (c) Chrystel Moreau <chrystel.moreau@lam.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Action\Meta;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use App\Utils\ActionTrait;
final class DatasetCriteriaListAction
{
use ActionTrait;
private $logger;
private $em;
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Dataset criteria list action dispatched');
if ($request->isOptions()) {
return $response->withHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
}
$dataset = $this->em->find('App\Entity\Dataset', $args['name']);
if (is_null($dataset)) {
return $this->dispatchHttpError(
$response,
'Invalid request',
'Dataset with name ' . $args['name'] . ' is not found'
)->withStatus(404);
}
if ($request->isGet()) {
$criteria = array();
$attributes = $dataset->getAttributes();
foreach ($attributes as $attribute) {
$criteriaFamily = $attribute->getCriteriaFamily();
if (!empty($criteriaFamily)) {
$idCriteriaFamily = $criteriaFamily->getId();
$criteria[$idCriteriaFamily][] = $attribute->getId();
}
}
$newResponse = $response->withJson($criteria);
}
return $newResponse;
}
}
<?php declare(strict_types=1);
/*
* This file is part of ANIS SERVER API.
*
* (c) François Agneray <francois.agneray@lam.fr>
* (c) Chrystel Moreau <chrystel.moreau@lam.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Action\Meta;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use App\Utils\ActionTrait;
final class DatasetOutputListAction
{
use ActionTrait;
private $logger;
private $em;
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Dataset output list action dispatched');
if ($request->isOptions()) {
return $response->withHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
}
$dataset = $this->em->find('App\Entity\Dataset', $args['name']);
if (is_null($dataset)) {
return $this->dispatchHttpError(
$response,
'Invalid request',
'Dataset with name ' . $args['name'] . ' is not found'
)->withStatus(404);
}
if ($request->isGet()) {
$output = array();
$attributes = $dataset->getAttributes();
foreach ($attributes as $attribute) {
$outputCategory = $attribute->getOutputCategory();
if (!empty($outputCategory)) {
$idOutputFamily = $outputCategory->getOutputFamily()->getId();
$idOutputCategory = $outputCategory->getId();
$criteria[$idOutputFamily][$idOutputCategory][] = $attribute->getId();
}
}
$newResponse = $response->withJson($output);
}
return $newResponse;
}
}
......@@ -180,18 +180,6 @@ $container['App\Action\Meta\AttributeListAction'] = function ($c) {
return new App\Action\Meta\AttributeListAction($c->get('logger'), $c->get('em'));
};
$container['App\Action\Meta\DatasetCriteriaListAction'] = function ($c) {
return new App\Action\Meta\DatasetCriteriaListAction($c->get('logger'), $c->get('em'));
};
$container['App\Action\Meta\DatasetOutputListAction'] = function ($c) {
return new App\Action\Meta\DatasetOutputListAction($c->get('logger'), $c->get('em'));
};
$container['App\Action\Meta\OptionListAction'] = function ($c) {
return new App\Action\Meta\OptionListAction($c->get('logger'), $c->get('em'));
};
$container['App\Action\Meta\FileProxyAction'] = function ($c) {
return new App\Action\Meta\FileProxyAction($c->get('em'));
};
......
......@@ -37,8 +37,6 @@ $app->map(['OPTIONS', 'GET', 'POST'], '/metadata/dataset', App\Action\Meta\Datas
$app->map(['OPTIONS', 'GET', 'PUT', 'DELETE'], '/metadata/dataset/{name}', App\Action\Meta\DatasetAction::class);
$app->map(['OPTIONS', 'GET'], '/metadata/dataset/{name}/attribute', App\Action\Meta\AttributeListAction::class);
$app->map(['OPTIONS', 'GET', 'PUT'], '/metadata/dataset/{name}/attribute/{id}', App\Action\Meta\AttributeAction::class);
$app->map(['OPTIONS', 'GET'], '/metadata/dataset/{name}/criteria', App\Action\Meta\DatasetCriteriaListAction::class);
$app->map(['OPTIONS', 'GET'], '/metadata/dataset/{name}/output', App\Action\Meta\DatasetOutputListAction::class);
$app->map(['OPTIONS', 'GET'], '/metadata/dataset/{name}/get-file/{path}', App\Action\Meta\FileProxyAction::class);
$app->map(['OPTIONS', 'GET', 'POST'], '/metadata/dataset/{name}/file', App\Action\Meta\FileListAction::class);
$app->map(['OPTIONS', 'GET', 'PUT', 'DELETE'], '/metadata/file/{id}', App\Action\Meta\FileAction::class);
......
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