Commit 80c9fdcf authored by François Agneray's avatar François Agneray

Merge anis-settings with anis-server

parent ea834ebc
......@@ -56,6 +56,22 @@ $container->set('App\Action\RootAction', function () {
return new App\Action\RootAction();
});
$container->set('App\Action\SelectListAction', function (ContainerInterface $c) {
return new App\Action\SelectListAction($c->get('em'));
});
$container->set('App\Action\SelectAction', function (ContainerInterface $c) {
return new App\Action\SelectAction($c->get('em'));
});
$container->set('App\Action\OptionListAction', function (ContainerInterface $c) {
return new App\Action\OptionListAction($c->get('em'));
});
$container->set('App\Action\OptionAction', function (ContainerInterface $c) {
return new App\Action\OptionAction($c->get('em'));
});
$container->set('App\Action\DatabaseListAction', function (ContainerInterface $c) {
return new App\Action\DatabaseListAction($c->get('em'));
});
......
......@@ -15,6 +15,10 @@ use Slim\Routing\RouteCollectorProxy;
$app->get('/', App\Action\RootAction::class);
$app->group('', function (RouteCollectorProxy $group) {
$group->map([OPTIONS, GET, POST], '/select', App\Action\SelectListAction::class);
$group->map([OPTIONS, GET, PUT, DELETE], '/select/{name}', App\Action\SelectAction::class);
$group->map([OPTIONS, GET, POST], '/option', App\Action\OptionListAction::class);
$group->map([OPTIONS, GET, PUT, DELETE], '/option/{id}', App\Action\OptionAction::class);
$group->map([OPTIONS, GET, POST], '/database', App\Action\DatabaseListAction::class);
$group->map([OPTIONS, GET, PUT, DELETE], '/database/{id}', App\Action\DatabaseAction::class);
$group->map([OPTIONS, GET], '/database/{id}/table', App\Action\TableListAction::class);
......
FROM php:7.3-apache
FROM php:7.4-apache
# Install modules
RUN apt-get update \
......
......@@ -7,6 +7,57 @@ admin_token=$(curl --location --request POST 'http://keycloak:8180/auth/realms/a
# Create the settings database (only tables)
./vendor/bin/doctrine orm:schema-tool:create
# Add settings for anis-admin GUI
curl -d '{"name":"search_flag","label":"Search flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/select
curl -d '{"name":"search_type","label":"Search Type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/select
curl -d '{"name":"operator","label":"Operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/select
curl -d '{"name":"renderer","label":"Renderer"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/select
curl -d '{"name":"renderer_detail","label":"Renderer detail"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/select
curl -d '{"label":"ID","value":"ID","display":10,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"RA","value":"RA","display":20,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"DEC","value":"DEC","display":30,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Z","value":"Z","display":40,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Z_FLAG","value":"Z_FLAG","display":50,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"SPECTRUM_1D","value":"SPECTRUM_1D","display":60,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"SPECTRUM_1D_NOISE","value":"SPECTRUM_1D_NOISE","display":70,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"SPECTRUM_1D_SKY","value":"SPECTRUM_1D_SKY","display":80,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"SPECTRUM_2D","value":"SPECTRUM_2D","display":90,"select_name":"search_flag"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Field","value":"field","display":10,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Between","value":"between","display":20,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Select","value":"select","display":30,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Select multiple","value":"select-multiple","display":40,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Datalist","value":"datalist","display":50,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"List","value":"list","display":60,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Radio","value":"radio","display":70,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Checkbox","value":"checkbox","display":80,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Between date","value":"between-date","display":90,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Date","value":"date","display":100,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Time","value":"time","display":110,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Date time","value":"date-time","display":120,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"JSON","value":"json","display":130,"select_name":"search_type"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"=","value":"eq","display":10,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"≠","value":"neq","display":20,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":">","value":"gt","display":30,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":">=","value":"gte","display":40,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"<","value":"lt","display":50,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"<=","value":"lte","display":60,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"like","value":"lk","display":70,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"not like","value":"nlk","display":80,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"in","value":"in","display":90,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"not in","value":"nin","display":100,"select_name":"operator"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Detail page","value":"detail","display":10,"select_name":"renderer"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Download file","value":"download","display":20,"select_name":"renderer"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Link (file, web page...)","value":"link","display":30,"select_name":"renderer"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Display image (png, jpg...)","value":"image","display":40,"select_name":"renderer"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Display json","value":"json","display":50,"select_name":"renderer"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Image","value":"img","display":10,"select_name":"renderer_detail"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
curl -d '{"label":"Spectra graph","value":"spectra_graph","display":20,"select_name":"renderer_detail"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/option
# Add database
curl -d '{"label":"Test","dbname":"anis_test","dbtype":"pdo_pgsql","dbhost":"db","dbport":5432,"dblogin":"anis","dbpassword":"anis"}' --header 'Content-Type: application/json' --header "Authorization: Bearer $admin_token" -X POST http://localhost/database
......
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqmfw644EhXO2QURqqnLucM0qS8iE7l1fgAF44HaE+8NKeM+VaWUmPM5j0hCN9ujcsP9XOynU7t4c06T70f7csrzLVd36EUw35Z5vdLL5gEloW4eOvZYCRhybJSB3ED8qFSn0SvO01GdhUkyzFhqkfjCg0HInnTn+2PPj0x2TNsjPYWJfl9Hf9HZHc0GEZrqjV688Vjo4QlSDzdc0kDg+E7esAQE8125eca1HI6pJXF/eDL+Lg32m7+P9NxO6h3Qppqov+iSSXLF9HO6RnunFRNQgtof0wye4RU4HP9+irPR85vvLMom4THILBD95B8FyHZ8VMBr7KjfKoo7Kt4VBYQIDAQAB
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj2lDSbVhNIgJl6C91sgQuVPWWo9DN5c4a89i1scqizMutt0Vre+C9c0Zxko/DnkThnFZBAaE5e7gL7mwRWFY8yQAZWi1e03nZfL+zr8Z7ppLyUdDo4pGT6D62LdVglwDGgBvRtobI8CvRLQO0TQr+I09j/hFAHUnmRMvL9ZvyIBmC8Cje5AANelObInto8oBLXaptMr7BcTFtd/0PFuXEUMH9qlQ+FWNGyryVPExW3pqYRcaFwBs0clF52q6iBE3m6vzA5sSv+tO/tPOnSghvAtD9zSyQ9OHldgh070vSJM4t0I6feMYJkOn0SOa2ZcLxkop5gwe852hctGo/UCatwIDAQAB
-----END PUBLIC KEY-----
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Action;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Exception\HttpNotFoundException;
use Slim\Exception\HttpBadRequestException;
use App\Entity\Option;
/**
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action
*/
final class OptionAction extends AbstractAction
{
/**
* `GET` Returns one option by ID
* `PUT` Edit one option
* `DELETE` Delete one option
*
* @param ServerRequestInterface $request PSR-7 This object represents the HTTP request
* @param ResponseInterface $response PSR-7 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
{
if ($request->getMethod() === OPTIONS) {
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct option with primary key (ID)
$option = $this->em->find('App\Entity\Option', $args['id']);
// If option is not found 404
if (is_null($option)) {
throw new HttpNotFoundException(
$request,
'Option with id ' . $args['id'] . ' is not found'
);
}
if ($request->getMethod() === GET) {
$payload = json_encode($option);
}
if ($request->getMethod() === PUT) {
$parsedBody = $request->getParsedBody();
// If mandatories empty fields 400
foreach (array('label', 'value', 'display') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
throw new HttpBadRequestException(
$request,
'Param ' . $a . ' needed to edit the option'
);
}
}
$this->editOption($option, $parsedBody);
$payload = json_encode($option);
}
if ($request->getMethod() === DELETE) {
$id = $option->getId();
$this->em->remove($option);
$this->em->flush();
$payload = json_encode(array('message' => 'Option with id ' . $id . ' is removed!'));
}
$response->getBody()->write($payload);
return $response;
}
/**
* Update option object with setters
*
* @param Option $option The option object to update
* @param array $parsedBody Contains the new values ​​of the option sent by the user
*/
private function editOption(Option $option, array $parsedBody): void
{
$option->setLabel($parsedBody['label']);
$option->setValue($parsedBody['value']);
$option->setDisplay($parsedBody['display']);
$this->em->flush();
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Action;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Exception\HttpNotFoundException;
use Slim\Exception\HttpBadRequestException;
use App\Entity\Select;
use App\Entity\Option;
/**
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action
*/
final class OptionListAction extends AbstractAction
{
/**
* `GET` Returns a list of all option available for one select
* `POST` Add a new option for a select
*
* @param ServerRequestInterface $request PSR-7 This object represents the HTTP request
* @param ResponseInterface $response PSR-7 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
{
if ($request->getMethod() === OPTIONS) {
return $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
}
if ($request->getMethod() === GET) {
$optionList = $this->em->getRepository('App\Entity\Option')->findAll();
$payload = json_encode($optionList);
}
if ($request->getMethod() === POST) {
$parsedBody = $request->getParsedBody();
// To work this action needs user information to update
foreach (array('label', 'value', 'display', 'select_name') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
throw new HttpBadRequestException(
$request,
'Param ' . $a . ' needed to add a new option'
);
}
}
// Search the correct select with primary key (name)
$select = $this->em->find('App\Entity\Select', $parsedBody['select_name']);
// If select is not found 404
if (is_null($select)) {
throw new HttpNotFoundException(
$request,
'Select with name ' . $parsedBody['select_name'] . ' is not found'
);
}
$option = $this->postOption($select, $parsedBody);
$payload = json_encode($option);
$response = $response->withStatus(201);
}
$response->getBody()->write($payload);
return $response;
}
private function postOption(Select $select, array $parsedBody): Option
{
$option = new Option($select);
$option->setLabel($parsedBody['label']);
$option->setValue($parsedBody['value']);
$option->setDisplay($parsedBody['display']);
$this->em->persist($option);
$this->em->flush();
return $option;
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Action;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Exception\HttpNotFoundException;
use Slim\Exception\HttpBadRequestException;
use App\Entity\Select;
/**
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action
*/
final class SelectAction extends AbstractAction
{
/**
* `GET` Returns one select by ID
* `PUT` Edit one select
* `DELETE` Delete one select
*
* @param ServerRequestInterface $request PSR-7 This object represents the HTTP request
* @param ResponseInterface $response PSR-7 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
{
if ($request->getMethod() === OPTIONS) {
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct select with primary key (name)
$select = $this->em->find('App\Entity\Select', $args['name']);
// If select is not found 404
if (is_null($select)) {
throw new HttpNotFoundException(
$request,
'Select with name ' . $args['name'] . ' is not found'
);
}
if ($request->getMethod() === GET) {
$payload = json_encode($select);
}
if ($request->getMethod() === PUT) {
$parsedBody = $request->getParsedBody();
// If mandatories empty fields 400
foreach (array('label') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
throw new HttpBadRequestException(
$request,
'Param ' . $a . ' needed to edit the select'
);
}
}
$this->editSelect($select, $parsedBody);
$payload = json_encode($select);
}
if ($request->getMethod() === DELETE) {
$name = $select->getName();
$this->em->remove($select);
$this->em->flush();
$payload = json_encode(array('message' => 'Select with name ' . $name . ' is removed!'));
}
$response->getBody()->write($payload);
return $response;
}
/**
* Update select object with setters
*
* @param Select $select The select object to update
* @param array $parsedBody Contains the new values ​​of the select sent by the user
*/
private function editSelect(Select $select, array $parsedBody): void
{
$select->setLabel($parsedBody['label']);
$this->em->flush();
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Action;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Exception\HttpBadRequestException;
use App\Entity\Select;
/**
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action
*/
final class SelectListAction extends AbstractAction
{
/**
* `GET` Returns a list of all select listed in the metamodel database
* `POST` Add a new select
*
* @param ServerRequestInterface $request PSR-7 This object represents the HTTP request
* @param ResponseInterface $response PSR-7 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
{
if ($request->getMethod() === OPTIONS) {
return $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
}
if ($request->getMethod() === GET) {
$selectList = $this->em->getRepository('App\Entity\Select')->findAll();
$payload = json_encode($selectList);
}
if ($request->getMethod() === POST) {
$parsedBody = $request->getParsedBody();
// To work this action needs user information to update
foreach (array('name', 'label') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
throw new HttpBadRequestException(
$request,
'Param ' . $a . ' needed to add a new select'
);
}
}
$select = $this->postSelect($parsedBody);
$payload = json_encode($select);
$response = $response->withStatus(201);
}
$response->getBody()->write($payload);
return $response;
}
/**
* Add a new select into the settings database
*
* @param array $parsedBody Contains the values ​​of the new select
*/
private function postSelect(array $parsedBody): Select
{
$select = new Select($parsedBody['name']);
$select->setLabel($parsedBody['label']);
$this->em->persist($select);
$this->em->flush();
return $select;
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Entity;
/**
* @Entity
* @Table(name="settings_option")
*/
class Option implements \JsonSerializable
{
/**
* @var integer
*
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue
*/
protected $id;
/**
* @var string
*
* @Column(type="string", nullable=false)
*/
protected $label;
/**
* @var string
*
* @Column(type="string", nullable=false)
*/
protected $value;
/**
* @var integer
*
* @Column(type="integer", nullable=false)
*/
protected $display;
/**
* @var Anis\Entity\Select
*
* @ManyToOne(targetEntity="Select", inversedBy="options")
* @JoinColumn(name="select_name", referencedColumnName="name", nullable=false)
*/
protected $select;
public function __construct(Select $select)
{
$this->select = $select;
}
public function getId(): int
{
return $this->id;
}
public function getLabel(): string
{
return $this->label;
}
public function setLabel(string $label): void
{
$this->label = $label;
}
public function getValue(): string
{
return $this->value;
}
public function setValue(string $value): void
{
$this->value = $value;
}
public function getDisplay(): int
{
return $this->display;
}
public function setDisplay(int $display): void
{
$this->display = (int) $display;
}
public function getSelect(): Select
{
return $this->select;
}
public function jsonSerialize()
{
return [
'id' => $this->getId(),
'label' => $this->getLabel(),
'value' => $this->getValue(),
'display' => $this->getDisplay(),
'select_name' => $this->getSelect()->getName()
];
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/