Skip to content

Commit

Permalink
Merge pull request #372 from jjrom/develop
Browse files Browse the repository at this point in the history
Support of input start_datetime and end_datetime
  • Loading branch information
jjrom authored Apr 25, 2023
2 parents e2f0745 + 7a0c7e6 commit 64a4f22
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/resto/core/RestoConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RestoConstants
// [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class

// resto version
const VERSION = '7.0.0';
const VERSION = '7.0.1';

/* ============================================================
* NEVER EVER TOUCH THESE VALUES
Expand Down
3 changes: 3 additions & 0 deletions app/resto/core/RestoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class RestoContext
// True to automatically validate user on activation
'userAutoActivation' => false,

// True to split geometries that cross the -180/180 dateline
'splitGeometryOnDateLine' => true,

// Sendmail configuration
'sendmail' => array(
'senderName' => 'admin',
Expand Down
8 changes: 8 additions & 0 deletions app/resto/core/RestoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,14 @@ private function prepareFeatureArray($collection, $data, $params = array())
}
unset($properties['datetime']);
}
if (isset($properties['start_datetime'])) {
$properties['startDate'] = $properties['start_datetime'];
unset($properties['start_datetime']);
}
if (isset($properties['end_datetime'])) {
$properties['completionDate'] = $properties['end_datetime'];
unset($properties['end_datetime']);
}

/*
* Add collection to $properties to initialize facet counts on collection
Expand Down
13 changes: 8 additions & 5 deletions app/resto/core/addons/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,27 +382,30 @@ private function keywordsFromFacets($properties, $facetCategory, $model)
*/
private function getDateKeywords($properties, $model)
{

$startDate = $properties[$model->searchFilters['time:start']['key']];

/*
* startDate property is not present
* No startDate property or both startDate and completionDate are presents => range is not supported
*/
if (! isset($properties[$model->searchFilters['time:start']['key']])) {
if (! isset($startDate) || (isset($startDate) && isset($properties['completionDate']))) {
return array();
}

/*
* Year
*/
$year = substr($properties[$model->searchFilters['time:start']['key']], 0, 4);
$year = substr($startDate, 0, 4);

/*
* Month
*/
$month = substr($properties[$model->searchFilters['time:start']['key']], 5, 2);
$month = substr($startDate, 5, 2);

/*
* Day
*/
$day = substr($properties[$model->searchFilters['time:start']['key']], 8, 2);
$day = substr($startDate, 8, 2);

return array(
array(
Expand Down
4 changes: 2 additions & 2 deletions app/resto/core/api/CollectionsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public function deleteCollection($params)
* in="query",
* style="form",
* required=false,
* description="Set to false to not split geometry during feature insertion. Default is true",
* description="Superseed the SPLIT_GEOMETRY_ON_DATELINE configuration i.e. set to true to split geometry during feature insertion - false otherwise. Default is set to SPLIT_GEOMETRY_ON_DATELINE",
* @OA\Schema(
* type="boolean"
* )
Expand Down Expand Up @@ -685,7 +685,7 @@ public function insertFeatures($params, $body)
* Insert feature(s) within database
*/
$result = $collection->addFeatures($body, array(
'_splitGeom' => isset($params['_splitGeom']) && filter_var($params['_splitGeom'], FILTER_VALIDATE_BOOLEAN) === false ? false : true,
'_splitGeom' => isset($params['_splitGeom']) && filter_var($params['_splitGeom'], FILTER_VALIDATE_BOOLEAN) === false ? false : $this->context->core["splitGeometryOnDateLine"],
'tolerance' => isset($params['tolerance']) && is_numeric($params['tolerance']) ? (float) $params['tolerance'] : null,
'maxpoints' => isset($params['maxpoints']) && ctype_digit($params['maxpoints']) ? (integer) $params['maxpoints'] : null
));
Expand Down
4 changes: 2 additions & 2 deletions app/resto/core/api/FeaturesAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ public function updateFeature($params, $body)
}

// Specifically set splitGeometry
$params['_splitGeom'] = isset($params['_splitGeom']) && filter_var($params['_splitGeom'], FILTER_VALIDATE_BOOLEAN) === false ? false : true;
$params['_splitGeom'] = isset($params['_splitGeom']) && filter_var($params['_splitGeom'], FILTER_VALIDATE_BOOLEAN) === false ? false : $this->context->core["splitGeometryOnDateLine"];

return $collection->model->updateFeature($feature, $collection, $body, $params);
}

Expand Down
3 changes: 2 additions & 1 deletion app/resto/core/dbfunctions/FacetsFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ public function getFacetsFromKeywords($keywords, $facetCategories, $collectionId
'parentId' => $keywords[$i]['parentId'] ?? 'root',
'value' => $keywords[$i]['name'] ?? null,
'type' => $keywords[$i]['type'],
'collection' => $collectionId,
// [IMPORTANT] catalog facet are always attached to all collections
'collection' => $keywords[$i]['type'] === 'catalog' ? '*' : $collectionId,
'isLeaf' => $facetCategory['isLeaf']
);
}
Expand Down
6 changes: 4 additions & 2 deletions app/resto/core/dbfunctions/FeaturesFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ public function updateFeature($feature, $collection, $newFeatureArray)
/*'likes' => $oldFeatureArray['properties']['likes'],
'comments' => $oldFeatureArray['properties']['comments'],*/
'metadata' => array(),
'updated' => isset($newFeatureArray['properties']) && isset($newFeatureArray['properties']['updated']) ? $newFeatureArray['properties']['updated'] : 'now()'
'updated' => isset($newFeatureArray['properties']) && isset($newFeatureArray['properties']['updated']) ? $newFeatureArray['properties']['updated'] : 'now()',
'geometry' => $newFeatureArray['topologyAnalysis']['geometry'] ?? null,
'centroid' => $newFeatureArray['topologyAnalysis']['centroid'] ?? null,
'geom' => $newFeatureArray['topologyAnalysis']['geom'] ?? null
),
array(
'title',
Expand All @@ -437,7 +440,6 @@ public function updateFeature($feature, $collection, $newFeatureArray)
)
);


try {
/*
* Begin transaction
Expand Down
15 changes: 9 additions & 6 deletions app/resto/core/utils/RestoFeatureUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,19 @@ private function formatRawFeatureArray($rawFeatureArray, $collection)

switch ($key) {
case 'collection':
break;

case 'completionDate':
$featureArray['properties']['end_datetime'] = $rawFeatureArray[$key];
break;

case 'startDate':
/* [STAC][1.0.0] datetime is no more a range
$featureArray['properties']['datetime'] = $rawFeatureArray[$key] . (isset($rawFeatureArray['completionDate']) ? '/' . $rawFeatureArray['completionDate'] : '');
*/
$featureArray['properties']['datetime'] = $rawFeatureArray[$key];
$featureArray['properties']['start_datetime'] = $rawFeatureArray[$key];
$featureArray['properties']['end_datetime'] = $rawFeatureArray['completionDate'] ?? $rawFeatureArray[$key];
if (isset($rawFeatureArray['completionDate'])) {
$featureArray['properties']['start_datetime'] = $rawFeatureArray[$key];
}
else {
$featureArray['properties']['datetime'] = $rawFeatureArray[$key];
}
break;

case 'assets':
Expand Down
1 change: 1 addition & 0 deletions build/resto/config.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ return array(
'tokenDuration' => ${JWT_DURATION:-8640000},
'userAutoValidation' => ${USER_AUTOVALIDATION:-true},
'userAutoActivation' => ${USER_AUTOACTIVATION:-true},
'splitGeometryOnDateLine' => ${SPLIT_GEOMETRY_ON_DATELINE:-true},
'useCache' => ${USE_CACHE:-false},
'corsWhiteList' => array(${CORS_WHITELIST}),
'htmlSearchEndpoint' => '${SEARCH_OPENSEARCH_HTML_ENDPOINT}',
Expand Down
4 changes: 4 additions & 0 deletions config.env
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ DATABASE_USER_PASSWORD=resto
### True to use geometry_part table instead of feature to compute geometrical intersection
#USE_GEOMETRY_PART=false

### True to split input geometries that crosses -180/180
### [IMPORTANT] Set to false for geometries larger than half the earth globe - typically global product for instance
#SPLIT_GEOMETRY_ON_DATELINE=true

### =====================================================================
### Security configuration
### =====================================================================
Expand Down

0 comments on commit 64a4f22

Please sign in to comment.