Commit bdc5dc5d authored by François Agneray's avatar François Agneray

Merge branch 'develop' into 'master'

Develop

See merge request !48
parents 00b7856b 45330495
......@@ -6,7 +6,7 @@ stages:
- deploy
variables:
VERSION: "3.1"
VERSION: "3.3"
SONARQUBE_URL: https://sonarqube.lam.fr
CONTAINER_IMAGE: portus.lam.fr/anis/anis-server
......
......@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [3.3.0]
### Added
- #54: Added search by cone-search
## [3.2.1]
### Fixed
- #55: Fixed bug json in json when only one column is selected
......
3.2.1
\ No newline at end of file
3.3.0
\ No newline at end of file
openapi: "3.0.0"
info:
version: 3.1.0
version: 3.3.0
title: Anis Server
description: 'AstroNomical Information System is a generic web tool that aims to facilitate the provision of data (Astrophysics), accessible from a database, to a community of scientists.'
contact:
......
......@@ -17,9 +17,9 @@ curl -d '{"name":"colibri","label":"Colibri Project Test","description":"Project
# Add default dataset family and ANIS datasets
curl -d '{"label":"Default dataset family","display":10}' -H "Content-Type: application/json" -X POST http://localhost/instance/default/dataset-family
curl -d '{"name":"obs_cat","table_ref":"obs_cat","label":"ObsCat dataset","description":"ObsCat","display":10,"count":10000,"vo":false,"data_path":"/mnt/mount","selectable_row":true,"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset
curl -d '{"name":"observations","table_ref":"observations_info","label":"Observations dataset","description":"Observations","display":20,"count":177454,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset
curl -d '{"name":"vipers_dr2_w1","table_ref":"aspic_vipers_dr2_w1","label":"VIPERS-W1 (DR2)","description":"VIPERS W1 dataset","display":30,"count":1000,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset
curl -d '{"name":"obs_cat","table_ref":"obs_cat","label":"ObsCat dataset","description":"ObsCat","display":10,"count":10000,"vo":false,"data_path":"/mnt/mount","selectable_row":true,"config":{"cone_search":{"enabled":true,"column_ra":2,"column_dec":3}},"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset
curl -d '{"name":"observations","table_ref":"observations_info","label":"Observations dataset","description":"Observations","display":20,"count":177454,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"config":{},"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset
curl -d '{"name":"vipers_dr2_w1","table_ref":"aspic_vipers_dr2_w1","label":"VIPERS-W1 (DR2)","description":"VIPERS W1 dataset","display":30,"count":1000,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"config":{},"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset
# Add ANIS obs_cat default criteria family, default output family and default output category
curl -d '{"label":"Default criteria family","display":10}' -H "Content-Type: application/json" -X POST http://localhost/dataset/obs_cat/criteria-family
......@@ -28,9 +28,9 @@ curl -d '{"label":"Default output category","display":10}' -H "Content-Type: app
# Add SVOM dataset family and SVOM datasets
curl -d '{"label":"Svom dataset family","display":20}' -H "Content-Type: application/json" -X POST http://localhost/instance/default/dataset-family
curl -d '{"name":"l1","table_ref":"public.v_rawproducts","label":"L0 & L1","description":"L0 & L1 products list","display":10,"count":0,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset
curl -d '{"name":"products","table_ref":"public.v_products","label":"Scientific Products","description":"SR3 & SR4 products list","display":20,"count":0,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset
curl -d '{"name":"sp_cards","table_ref":"sp_cards","label":"SP Metadata","description":"Contains metadata of scientific products (Core Program & General Program)","display":30,"count":100,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset
curl -d '{"name":"l1","table_ref":"public.v_rawproducts","label":"L0 & L1","description":"L0 & L1 products list","display":10,"count":0,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"config":{},"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset
curl -d '{"name":"products","table_ref":"public.v_products","label":"Scientific Products","description":"SR3 & SR4 products list","display":20,"count":0,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"config":{},"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset
curl -d '{"name":"sp_cards","table_ref":"sp_cards","label":"SP Metadata","description":"Contains metadata of scientific products (Core Program & General Program)","display":30,"count":100,"vo":false,"data_path":"/mnt/mount","selectable_row":false,"config":{},"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset
# Add SVOM l1 criteria families, default output family and default output category
curl -d '{"label":"Obs","display":10}' -H "Content-Type: application/json" -X POST http://localhost/dataset/l1/criteria-family
......@@ -99,7 +99,7 @@ curl -d '{"id":9,"name":"json_schema_uploaded","table_name":"sp_cards","label":"
# Add COLIBRI dataset family and COLIBRI dataset
curl -d '{"label":"Colibri dataset family","display":30}' -H "Content-Type: application/json" -X POST http://localhost/instance/default/dataset-family
curl -d '{"name":"anis_observation","table_ref":"anis_observation","label":"COLIBRI OBS","description":"colibri observations","display":10,"count":0,"vo":true,"data_path":"/mnt/mount","selectable_row":true,"project_name":"colibri"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/3/dataset
curl -d '{"name":"anis_observation","table_ref":"anis_observation","label":"COLIBRI OBS","description":"colibri observations","display":10,"count":0,"vo":true,"data_path":"/mnt/mount","selectable_row":true,"config":{},"project_name":"colibri"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/3/dataset
# Add COLIBRI anis_observation default criteria family, output families and output categories
curl -d '{"label":"Default criteria family","display":10}' -H "Content-Type: application/json" -X POST http://localhost/dataset/anis_observation/criteria-family
......
......@@ -103,6 +103,11 @@ final class SearchAction extends AbstractAction
$attributes = $this->select($queryBuilder, $dataset, explode(';', $queryParams['a']));
}
// The special parameter cs is not mandatory and represents the Cone Search
if (array_key_exists('cs', $queryParams)) {
$this->coneSearch($queryBuilder, $dataset, $queryParams['cs']);
}
// The parameter c is not mandatory and represents the SQL where clause
if (array_key_exists('c', $queryParams)) {
$this->where($queryBuilder, $dataset, explode(';', $queryParams['c']));
......@@ -156,6 +161,67 @@ final class SearchAction extends AbstractAction
return $attributes;
}
/**
* Adds the cone search clause to the request
*
* @param QueryBuilder $queryBuilder Represents the query being built
* @param Dataset $dataset Represents the requested dataset
* @param string $param The substring of the url (parameter cs)
*/
private function coneSearch(QueryBuilder $queryBuilder, Dataset $dataset, string $param): void
{
if (count(explode(':', $param)) < 3) {
throw SearchException::badNumberOfParamsForConeSearch();
}
list($ra, $dec, $radius) = explode(':', $param);
$coneSearchConfig = $dataset->getConfig()['cone_search'];
if ($coneSearchConfig['enabled'] !== true) {
throw SearchException::coneSearchUnavailable();
}
$attributeRa = $this->getAttribute($dataset, $coneSearchConfig['column_ra']);
$attributeDec = $this->getAttribute($dataset, $coneSearchConfig['column_dec']);
$columnRa = $dataset->getTableRef() . '.' . $attributeRa->getName();
$columnDec = $dataset->getTableRef() . '.' . $attributeDec->getName();
$cdcl2 = pow(cos($dec * (M_PI * 2) / 360), 2);
if ($radius == 0) {
$radius = 1 / 1000000;
}
$radius2 = pow($radius, 2);
$raddeg = $radius / 3600;
$decmin = $dec - $raddeg;
$decmax = $dec + $raddeg;
if ($decmin < -90 || $decmax > 90) {
$ramin = 0;
$ramax = 360;
} else {
$ra_corrected_radius = $raddeg / cos(deg2rad(abs($dec) + $raddeg));
$ramin = $ra - $ra_corrected_radius;
$ramax = $ra + $ra_corrected_radius;
}
$coneSearchValue = '(' . $cdcl2 . ' * (' . $ra . ' - ' . $columnRa . ') * (' . $ra . ' - ' . $columnRa . '))';
$coneSearchValue .= ' + ((' . $dec . ' - ' . $columnDec . ') * (' . $dec . ' - ' . $columnDec . '))';
$coneSearchCriterion = $queryBuilder->expr()->lte($coneSearchValue, $radius2);
$raCriterion = (new CompositeExpression(CompositeExpression::TYPE_AND, [
$queryBuilder->expr()->gte($columnRa, $ramin),
$queryBuilder->expr()->lte($columnRa, $ramax)
]));
$decCriterion = (new CompositeExpression(CompositeExpression::TYPE_AND, [
$queryBuilder->expr()->gte($columnDec, $decmin),
$queryBuilder->expr()->lte($columnDec, $decmax)
]));
$queryBuilder->where(new CompositeExpression(CompositeExpression::TYPE_AND, [
$coneSearchCriterion,
$raCriterion,
$decCriterion
]));
}
/**
* Adds the where clause to the request
*
......@@ -185,7 +251,7 @@ final class SearchAction extends AbstractAction
);
$expressions[] = $operator->getExpression();
}
$queryBuilder->where(new CompositeExpression(CompositeExpression::TYPE_AND, $expressions));
$queryBuilder->andWhere(new CompositeExpression(CompositeExpression::TYPE_AND, $expressions));
}
/**
......
......@@ -49,7 +49,7 @@ class LessThanEqual extends Operator
*
* @return string
*/
public function getExpression() : string
public function getExpression(): string
{
return $this->expr->lte($this->column, $this->getSqlValue($this->value));
}
......
......@@ -87,6 +87,22 @@ class SearchException extends Exception
return new self("Limit (p) needs 2 params to work");
}
/**
* @return SearchException
*/
public static function badNumberOfParamsForConeSearch(): SearchException
{
return new self("Cone search (cs) needs 3 params to work");
}
/**
* @return SearchException
*/
public static function coneSearchUnavailable(): SearchException
{
return new self("The cone search is unavailable for this dataset");
}
/**
* @return SearchException
*/
......
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