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

Ajout data observations + codage #8

parent 3cfd8b8a
AstroNomical Information System - Server API
Copyright @ François Agneray & Chrystel Moreau
Copyright: François Agneray & Chrystel Moreau 2012 - 2019
Address: Centre de donneeS Astrophysique de Marseille (CeSAM)
Laboratoire d'Astrophysique de Marseille
Ple de l'Etoile, site de Chteau-Gombert
38, rue Frdric Joliot-Curie
13388 Marseille cedex 13 France
CNRS U.M.R 7326
ANIS Server API is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
......
......@@ -8,4 +8,5 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E
GRANT ALL PRIVILEGES ON DATABASE anis_metamodel TO anis;
GRANT ALL PRIVILEGES ON DATABASE anis_test TO anis;
EOSQL
psql -v ON_ERROR_STOP=1 -f /sql/anis_test.sql --username "anis" --dbname "anis_test"
\ No newline at end of file
psql -v ON_ERROR_STOP=1 -f /sql/obs_cat.sql --username "anis" --dbname "anis_test"
psql -v ON_ERROR_STOP=1 -f /sql/observations_info.sql --username "anis" --dbname "anis_test"
\ No newline at end of file
This diff is collapsed.
......@@ -18,7 +18,7 @@ services:
MAILER_HOST: "mailer"
MAILER_PORT: 25
LOGGER_NAME: "anis-v3-server"
LOGGER_PATH: "php://stderr"
LOGGER_PATH: "php://stdout"
LOGGER_LEVEL: "debug"
ports:
- 8080:80
......@@ -36,7 +36,8 @@ services:
POSTGRES_PASSWORD: "postgres"
volumes:
- pgdata:/var/lib/postgresql/data
- ./conf-dev/anis_test.sql:/sql/anis_test.sql
- ./conf-dev/obs_cat.sql:/sql/obs_cat.sql
- ./conf-dev/observations_info.sql:/sql/observations_info.sql
- ./conf-dev/init-postgres.sh:/docker-entrypoint-initdb.d/init-postgres.sh
adminer:
image: adminer
......
<?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\Search\Operator;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
class Equal extends Operator
{
private $value;
public function __construct(ExpressionBuilder $expr, string $column, string $value)
{
parent::__construct($expr, $column);
if (is_numeric($value)) {
$this->value = (float) $value;
} if(is_string($value)) {
$this->value = $value;
}
}
public function getExpression()
{
$expr = $this->expr->eq($this->column, $this->value);
return $expr;
}
}
\ No newline at end of file
<?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\Search\Operator;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
class NotEqual extends Operator
{
private $value;
public function __construct(ExpressionBuilder $expr, string $column, string $value)
{
parent::__construct($expr, $column);
if (is_numeric($value)) {
$this->value = (float) $value;
} if(is_string($value)) {
$this->value = (string) $value;
}
}
public function getExpression()
{
return $this->expr->neq($this->column, $this->value);
}
}
\ No newline at end of file
......@@ -20,6 +20,12 @@ class OperatorFactory
case 'bw':
return new Between($expr, $column, (float) $parameters[0], (float) $parameters[1]);
case 'eq':
return new Equal($expr, $column, $parameters[0]);
case 'neq':
return new NotEqual($expr, $column, $parameters[0]);
case 'gt':
return new GreaterThan($expr, $column, (float) $parameters[0]);
......@@ -32,6 +38,9 @@ class OperatorFactory
case 'lte':
return new LessThanEqual($expr, $column, (float) $parameters[0]);
case 'lk':
return Like($expr, $column, $parameters);
default:
throw OperatorException::unknownOperator($type);
}
......
<?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\Search;
use Doctrine\DBAL\Query\QueryBuilder;
use App\Entity\Dataset;
class QueryBuilderAdapter
{
private $queryBuilder;
private $dataset;
public function __construct(QueryBuilder $queryBuilder, Dataset $dataset)
{
$this->queryBuilder = $queryBuilder->from($dataset->getTableRef());
$this->dataset = $dataset;
}
public function count()
{
$queryBuilder->select('COUNT(*) as nb');
}
public function where(array $criteria)
{
foreach ($criteria as $criterion) {
$params = $this->getCriterionParams($criterion);
$attribute = $this->getCriterionAttribute($params[0], $dataset);
$column = $attribute->getTableName() . '.' . $attribute->getName();
$values = explode('|', $params[2]);
$operator = OperatorFactory::create($params[1], $expr, $column, $values);
}
}
public function getSQL()
{
return $this->queryBuilder->getSQL();
}
public function fetchAll()
{
$stmt = $queryBuilder->execute();
$result = $stmt->fetchAll();
}
private function getCriterionParams(string $criterion): array
{
$params = explode(':', $criterion);
$numberOfParams = count($params);
if ($numberOfParams != 3) {
throw SearchException::numberOfCriterionParams($numberOfParams, $criterion);
}
return $params;
}
private function getCriterionAttribute(int $id, Dataset $dataset): Attribute
{
if (!MetaToolbox::checkOneAttributeId($dataset, $id)) {
throw SearchException::attributeNotFound($id, $dataset->getLabel());
}
return MetaToolbox::getAttributeById($dataset, $id);
}
}
\ No newline at end of file
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