From a48c9d256d626ae5ce41c8ef634b33cd01db0b99 Mon Sep 17 00:00:00 2001 From: Maarten Plieger Date: Fri, 13 Sep 2024 12:50:38 +0200 Subject: [PATCH] Added --updatelayermetadata option to update layermetadata --- adagucserverEC/CDBFileScanner.cpp | 36 ++++- adagucserverEC/CDBFileScanner.h | 2 + adagucserverEC/CMakeLists.txt | 4 + adagucserverEC/CRequest.cpp | 154 ------------------- adagucserverEC/CRequest.h | 1 - adagucserverEC/Definitions.h | 1 - adagucserverEC/adagucserver.cpp | 125 +++++++-------- adagucserverEC/utils/ConfigurationUtils.cpp | 21 +++ adagucserverEC/utils/ConfigurationUtils.h | 12 ++ adagucserverEC/utils/UpdateLayerMetadata.cpp | 58 +++++++ adagucserverEC/utils/UpdateLayerMetadata.h | 9 ++ 11 files changed, 191 insertions(+), 232 deletions(-) create mode 100644 adagucserverEC/utils/ConfigurationUtils.cpp create mode 100644 adagucserverEC/utils/ConfigurationUtils.h create mode 100644 adagucserverEC/utils/UpdateLayerMetadata.cpp create mode 100644 adagucserverEC/utils/UpdateLayerMetadata.h diff --git a/adagucserverEC/CDBFileScanner.cpp b/adagucserverEC/CDBFileScanner.cpp index 988ea299a..f3f59f123 100644 --- a/adagucserverEC/CDBFileScanner.cpp +++ b/adagucserverEC/CDBFileScanner.cpp @@ -32,6 +32,7 @@ #include "CCreateTiles.h" #include #include "utils/LayerMetadataStore.h" +#include "utils/ConfigurationUtils.h" const char *CDBFileScanner::className = "CDBFileScanner"; std::vector CDBFileScanner::tableNamesDone; // #define CDBFILESCANNER_DEBUG @@ -951,7 +952,34 @@ int CDBFileScanner::updatedb(CDataSource *dataSource, CT::string *_tailPath, CT: if (fileToUpdate.length() == 0) { // No file specified, just scan the directory for matching filenames. try { - fileList = searchFileNames(dataSource->cfgLayer->FilePath[0]->value.c_str(), filter.c_str(), tailPath.c_str()); + if (scanFlags & CDBFILESCANNER_UPDATEDB_ONLYFILEFROMDEFAULTQUERY) { + if (checkIfPathIsFile(dataSource->cfgLayer->FilePath[0]->value.c_str())) { + fileList.push_back(dataSource->cfgLayer->FilePath[0]->value.c_str()); + CDBDebug("Obtained filename from layer configuration [%s]", dataSource->cfgLayer->FilePath[0]->value.c_str()); + } else { + CDBDebug("CDBFILESCANNER_UPDATEDB_ONLYFILEFROMDEFAULTQUERY"); + int status = CRequest::setDimValuesForDataSource(dataSource, dataSource->srvParams); + if (status != 0) { + CDBError("setDimValuesForDataSource"); + return 1; + } + status = CRequest::fillDimValuesForDataSource(dataSource, dataSource->srvParams); + if (status != 0) { + CDBError("fillDimValuesForDataSource"); + return 1; + } + status = CRequest::queryDimValuesForDataSource(dataSource, dataSource->srvParams); + if (status != 0) { + CDBError("queryDimValuesForDataSource"); + return 1; + } + fileList.push_back(dataSource->getFileName()); + CDBDebug("Queried file from database with filename [%s]", dataSource->getFileName()); + } + } else { + fileList = searchFileNames(dataSource->cfgLayer->FilePath[0]->value.c_str(), filter.c_str(), tailPath.c_str()); + } + } catch (int linenr) { CDBDebug("Exception in searchFileNames [%s] [%s]", dataSource->cfgLayer->FilePath[0]->value.c_str(), filter.c_str(), tailPath.c_str()); return 0; @@ -1089,10 +1117,8 @@ std::vector CDBFileScanner::searchFileNames(const char *path, CT::s } } } - // CDBDebug("Checking if this is a file: [%s]", filePath.c_str()); - if (filePath.endsWith(".nc") || filePath.endsWith(".h5") || filePath.endsWith(".hdf5") || filePath.endsWith(".he5") || filePath.endsWith(".png") || filePath.endsWith(".csv") || - filePath.endsWith(".geojson") || filePath.endsWith(".json") || filePath.startsWith("http://") || filePath.startsWith("https://") || filePath.startsWith("dodsc://")) { - // Add single file or opendap URL. + + if (checkIfPathIsFile(filePath)) { std::vector fileList; fileList.push_back(filePath.c_str()); // CDBDebug("%s is a file",filePath.c_str()); diff --git a/adagucserverEC/CDBFileScanner.h b/adagucserverEC/CDBFileScanner.h index 316024310..157efb038 100644 --- a/adagucserverEC/CDBFileScanner.h +++ b/adagucserverEC/CDBFileScanner.h @@ -42,6 +42,8 @@ #define CDBFILESCANNER_RECREATETABLES 32 #define CDBFILESCANNER_CLEANFILES 64 #define CDBFILESCANNER_DONOTTILE 128 +#define CDBUPDATE_LAYER_METADATA 256 +#define CDBFILESCANNER_UPDATEDB_ONLYFILEFROMDEFAULTQUERY 512 // Return type to indicate nothing was found. #define CDBFILESCANNER_RETURN_FILEDOESNOTMATCH 100 diff --git a/adagucserverEC/CMakeLists.txt b/adagucserverEC/CMakeLists.txt index 5dd9b9d62..69b234c70 100644 --- a/adagucserverEC/CMakeLists.txt +++ b/adagucserverEC/CMakeLists.txt @@ -77,6 +77,10 @@ add_library( utils/LayerUtils.cpp utils/LayerMetadataToJson.h utils/LayerMetadataToJson.cpp + utils/UpdateLayerMetadata.h + utils/UpdateLayerMetadata.cpp + utils/ConfigurationUtils.h + utils/ConfigurationUtils.cpp Types/LayerMetadataType.h CDataPostProcessors/CDataPostProcessor_AddFeatures.cpp CDataPostProcessors/CDataPostProcessor_AddFeatures.h diff --git a/adagucserverEC/CRequest.cpp b/adagucserverEC/CRequest.cpp index 2c2086e1c..ab16cc12a 100644 --- a/adagucserverEC/CRequest.cpp +++ b/adagucserverEC/CRequest.cpp @@ -414,151 +414,6 @@ int CRequest::generateGetReferenceTimesDoc(CT::string *result, CDataSource *data return 0; } -int CRequest::process_wms_getstyles_request() { - // int status; - // if(srvParam->serviceType==SERVICE_WMS){ - // if(srvParam->Geo->dWidth>MAX_IMAGE_WIDTH){ - // CDBError("Parameter WIDTH must be smaller than %d",MAX_IMAGE_WIDTH); - // return 1; - // } - // if(srvParam->Geo->dHeight>MAX_IMAGE_HEIGHT){ - // CDBError("Parameter HEIGHT must be smaller than %d",MAX_IMAGE_HEIGHT); - // return 1; - // } - // } - // CDrawImage plotCanvas; - // plotCanvas.setTrueColor(true); - // plotCanvas.createImage(int(srvParam->Geo->dWidth),int(srvParam->Geo->dHeight)); - // plotCanvas.create685Palette(); - // - // CImageDataWriter imageDataWriter; - // - // CDataSource * dataSource = new CDataSource(); - // //dataSource->setCFGLayer(srvParam,srvParam->configObj->Configuration[0],srvParam->cfg->Layer[0],"prediction",0); - // dataSource->addStep("",NULL); - // dataSource->getCDFDims()->addDimension("time","0",0); - // dataSource->setTimeStep(0); - // dataSource->srvParams=srvParam; - // dataSource->cfg=srvParam->configObj->Configuration[0]; - // dataSource->cfgLayer=srvParam->cfg->Layer[0]; - // CDataSource::DataObject *newDataObject = new CDataSource::DataObject(); - // newDataObject->variableName.copy("test"); - // dataSource->getDataObjectsVector()->push_back(newDataObject); - // dataSource->dLayerType=CConfigReaderLayerTypeStyled; - // - // - // - // - // plotCanvas.rectangle(0,0,plotCanvas.Geo->dWidth,plotCanvas.Geo->dHeight,CColor(255,255,255,255),CColor(255,255,255,255)); - // - // int legendWidth = 200; - // int legendHeight = 600; - // - // - // - // - // - // - // int posX=0; - // int posY=0; - // - // bool errorOccured = false; - // - // bool legendOnlyMode = true; - // try{ - // - // for(size_t j=0;jcfg->Style.size();j++){ - // CServerConfig::XMLE_Style* style = srvParam->cfg->Style[j]; - // CDBDebug("style %s",style->attr.name.c_str()); - // - // CT::PointerList *legendList = NULL; - // - // if(legendOnlyMode == false){ - // legendList = CServerParams::getLegendNames(style->Legend); - // }else{ - // legendList = new CT::PointerList(); - // for(size_t j=0;jcfg->Legend.size();j++){ - // - // legendList->push_back(new CT::string(srvParam->cfg->Legend[j]->attr.name.c_str())); - // - // } - // } - // - // CDBDebug("Found %d legends",legendList->size()); - // for(size_t i=0;isize();i++){ - // CDBDebug("legend %s",(*legendList)[i]->c_str()); - // - // int legendIndex = - // CImageDataWriter::getServerLegendIndexByName((*legendList)[i]->c_str(),srvParam->cfg->Legend); - // if(legendIndex == -1){ - // CDBError("Legend %s is not configured"); - // delete legendList; - // throw (__LINE__); - // } - // CDBDebug("Found legend index %d",legendIndex); - // - // CT::PointerList *renderMethodList = - // CImageDataWriter::getRenderMethodListForDataSource(dataSource,style); - // - // CDBDebug("Found %d rendermethods",renderMethodList->size()); - // // for(size_t r=0;rsize();r++){ - // // CDBDebug("Using - // %s->%s->%s",style->attr.name.c_str(),(*legendList)[i]->c_str(),(*renderMethodList)[r]->c_str()); - // // CT::string styleName; - // // styleName.print("%s/%s",style->attr.name.c_str(),(*renderMethodList)[r]->c_str()); - // // if(legendOnlyMode){ - // // styleName.print("%s",(*legendList)[i]->c_str()); - // // } - // // - // // - // // - // CImageDataWriter::makeStyleConfig(dataSource->styleConfiguration,dataSource);//,style->attr.name.c_str(),(*legendList)[i]->c_str(),(*renderMethodList)[r]->c_str()); - // // - // // CDrawImage legendImage; - // // legendImage.enableTransparency(true); - // // legendImage.createImage(&plotCanvas,legendWidth,legendHeight); - // // status = legendImage.createGDPalette(srvParam->cfg->Legend[legendIndex]);if(status != - // 0)throw(__LINE__); - // // - // // - // // - // legendImage.rectangle(0,0,legendImage.Geo->dWidth-1,legendImage.Geo->dHeight-1,CColor(255,255,255,255),CColor(0,0,255,255)); - // // status = imageDataWriter.createLegend(dataSource,&legendImage);if(status != 0)throw(__LINE__); - // // //posX = (legendNr++)*legendWidth; - // // - // // plotCanvas.draw(posX,posY,0,0,&legendImage); - // // - // plotCanvas.drawText(posX+4,posY+legendHeight-4,srvParam->cfg->WMS[0]->SubTitleFont[0]->attr.location.c_str(),8,0,styleName.c_str(),CColor(0,0,0,255),textBGColor); - // // - // // posX+=legendWidth; - // // if(posX>plotCanvas.Geo->dWidth){ - // // posX=0; - // // posY+=legendHeight; - // // } - // // if(legendOnlyMode)break; - // // } - // delete renderMethodList; - // } - // delete legendList; - // if(legendOnlyMode)break; - // } - // }catch(int e){ - // errorOccured = true; - // } - // - // - // - // - // delete dataSource; - // - // if(errorOccured){ - // return 1; - // } - // printf("%s%c%c\n","Content-Type:image/png",13,10); - // plotCanvas.printImagePng(); - return 0; -} - int CRequest::process_wms_getlegendgraphic_request() { if (srvParam->WMSLayers != NULL) for (size_t j = 0; j < srvParam->WMSLayers->count; j++) { @@ -2935,8 +2790,6 @@ int CRequest::process_querystring() { srvParam->requestType = REQUEST_WMS_GETLEGENDGRAPHIC; else if (REQUEST.equals("GETMETADATA")) srvParam->requestType = REQUEST_WMS_GETMETADATA; - else if (REQUEST.equals("GETSTYLES")) - srvParam->requestType = REQUEST_WMS_GETSTYLES; else if (REQUEST.equals("GETREFERENCETIMES")) srvParam->requestType = REQUEST_WMS_GETREFERENCETIMES; else { @@ -3061,13 +2914,6 @@ int CRequest::process_querystring() { // WMS Service if (dErrorOccured == 0 && srvParam->serviceType == SERVICE_WMS) { // CDBDebug("Entering WMS service"); - - if (srvParam->requestType == REQUEST_WMS_GETSTYLES) { - - if (process_wms_getstyles_request() != 0) return 1; - return 0; - } - if (srvParam->requestType == REQUEST_WMS_GETREFERENCETIMES) { int status = process_wms_getreferencetimes_request(); if (status != 0) { diff --git a/adagucserverEC/CRequest.h b/adagucserverEC/CRequest.h index 57b264958..a6f47e13a 100644 --- a/adagucserverEC/CRequest.h +++ b/adagucserverEC/CRequest.h @@ -200,7 +200,6 @@ class CRequest { int process_wms_getmap_request(); int process_wms_getmetadata_request(); int process_wms_getfeatureinfo_request(); - int process_wms_getstyles_request(); int process_wms_getlegendgraphic_request(); int process_wcs_getcap_request(); int process_wcs_describecov_request(); diff --git a/adagucserverEC/Definitions.h b/adagucserverEC/Definitions.h index 041475aa1..714d2f574 100755 --- a/adagucserverEC/Definitions.h +++ b/adagucserverEC/Definitions.h @@ -53,7 +53,6 @@ #define REQUEST_WCS_DESCRIBECOVERAGE 6 #define REQUEST_WCS_GETCOVERAGE 7 #define REQUEST_WMS_GETMETADATA 8 -#define REQUEST_WMS_GETSTYLES 9 #define REQUEST_WMS_GETPOINTVALUE 10 #define REQUEST_WMS_GETREFERENCETIMES 11 #define REQUEST_WMS_GETHISTOGRAM 12 diff --git a/adagucserverEC/adagucserver.cpp b/adagucserverEC/adagucserver.cpp index 3568bd98d..94b60e05b 100644 --- a/adagucserverEC/adagucserver.cpp +++ b/adagucserverEC/adagucserver.cpp @@ -30,6 +30,10 @@ #include #include "ProjCache.h" +#include "adagucserver.h" +#include "Types/ProjectionStore.h" +#include "utils/UpdateLayerMetadata.h" +#include "utils/ConfigurationUtils.h" DEF_ERRORMAIN(); @@ -78,35 +82,6 @@ void serverWarningFunction(const char *msg) { void serverLogFunctionCMDLine(const char *msg) { printf("%s", msg); } -#include "adagucserver.h" -#include "Types/ProjectionStore.h" - -void serverLogFunctionNothing(const char *) {} - -/* Set config file from environment variable ADAGUC_CONFIG */ -int setCRequestConfigFromEnvironment(CRequest *request, const char *additionalDataset = nullptr) { - char *configfile = getenv("ADAGUC_CONFIG"); - if (configfile != NULL) { - CT::string configWithAdditionalDataset = configfile; - if (additionalDataset != nullptr && strlen(additionalDataset) > 0) { - configWithAdditionalDataset.concat(","); - configWithAdditionalDataset.concat(additionalDataset); - } - int status = request->setConfigFile(configWithAdditionalDataset.c_str()); - - /* Check logging level */ - if (request->getServerParams()->isDebugLoggingEnabled() == false) { - setDebugFunction(serverLogFunctionNothing); - } - - return status; - } else { - CDBError("No configuration file is set. Please set ADAGUC_CONFIG environment variable accordingly."); - return 1; - } - return 0; -} - /** * @param layerPathToScan: the provided file to scan */ @@ -128,49 +103,42 @@ std::set findDataSetsToScan(CT::string layerPathToScan, bool verbos CDBDebug("directoryOfFileToScan = [%s]", directoryOfFileToScan.c_str()); } srvParam->verbose = false; - std::vector listOfDatasets; - for (size_t j = 0; j < srvParam->cfg->Dataset.size(); j++) { - if (srvParam->cfg->Dataset[j]->attr.enabled.equals("true") && srvParam->cfg->Dataset[j]->attr.location.empty() == false) { - if (verbose) { - CDBDebug("Dataset locations %s", srvParam->cfg->Dataset[j]->attr.location.c_str()); - } - auto files = CDirReader::listDir(srvParam->cfg->Dataset[j]->attr.location.c_str(), false, "^.*\\.xml$"); - for (auto &dataset : files) { - if (verbose) { - CDBDebug("Testing dataset %s", dataset.c_str()); - } - CRequest configParser; - auto configSrvParam = configParser.getServerParams(); - configSrvParam->verbose = false; - setCRequestConfigFromEnvironment(&configParser, dataset.c_str()); - - if (configSrvParam && configSrvParam->cfg) { - auto layers = configSrvParam->cfg->Layer; - for (size_t j = 0; j < layers.size(); j++) { - if (layers[j]->attr.type.equals("database")) { - if (layers[j]->FilePath.size() > 0) { - CT::string filePath = CDirReader::makeCleanPath(layers[j]->FilePath[0]->value); - // Directories need to end with a / - CT::string filePathWithTrailingSlash = filePath + "/"; - CT::string filter = layers[j]->FilePath[0]->attr.filter; - // CDBDebug(" %s %s", directoryOfFileToScan.c_str(), directoryOfFileToScan.c_str()); - // When the FilePath in the Layer configuration is exactly the same as the file to scan, give a Match - if (layerPathToScan.equals(filePath)) { - if (verbose) { - CDBDebug("Exactly matching: %s", filePath.c_str()); - } - datasetsToScan.insert(dataset.c_str()); - break; - // When the directory of the file to scan matches the FilePath and the filter matches, give a Match - } else if (directoryOfFileToScan.startsWith(filePathWithTrailingSlash)) { - if (CDirReader::testRegEx(layerPathToScan.basename(), filter.c_str()) == 1) { - if (verbose) { - CDBDebug("Directories Matching: %s / %s", filePath.c_str(), filter.c_str()); - } - datasetsToScan.insert(dataset.c_str()); - break; - } + auto datasetList = getEnabledDatasetsConfigurations(srvParam); + + for (auto &dataset : datasetList) { + if (verbose) { + CDBDebug("Testing dataset %s", dataset.c_str()); + } + CRequest configParser; + auto configSrvParam = configParser.getServerParams(); + configSrvParam->verbose = false; + setCRequestConfigFromEnvironment(&configParser, dataset.c_str()); + + if (configSrvParam && configSrvParam->cfg) { + auto layers = configSrvParam->cfg->Layer; + for (size_t j = 0; j < layers.size(); j++) { + if (layers[j]->attr.type.equals("database")) { + if (layers[j]->FilePath.size() > 0) { + CT::string filePath = CDirReader::makeCleanPath(layers[j]->FilePath[0]->value); + // Directories need to end with a / + CT::string filePathWithTrailingSlash = filePath + "/"; + CT::string filter = layers[j]->FilePath[0]->attr.filter; + // CDBDebug(" %s %s", directoryOfFileToScan.c_str(), directoryOfFileToScan.c_str()); + // When the FilePath in the Layer configuration is exactly the same as the file to scan, give a Match + if (layerPathToScan.equals(filePath)) { + if (verbose) { + CDBDebug("Exactly matching: %s", filePath.c_str()); + } + datasetsToScan.insert(dataset.c_str()); + break; + // When the directory of the file to scan matches the FilePath and the filter matches, give a Match + } else if (directoryOfFileToScan.startsWith(filePathWithTrailingSlash)) { + if (CDirReader::testRegEx(layerPathToScan.basename(), filter.c_str()) == 1) { + if (verbose) { + CDBDebug("Directories Matching: %s / %s", filePath.c_str(), filter.c_str()); } + datasetsToScan.insert(dataset.c_str()); + break; } } } @@ -178,6 +146,7 @@ std::set findDataSetsToScan(CT::string layerPathToScan, bool verbos } } } + return datasetsToScan; } @@ -218,6 +187,7 @@ int _main(int argc, char **argv, char **) { static struct option long_options[] = {{"updatedb", no_argument, 0, 0}, {"config", required_argument, 0, 0}, {"createtiles", no_argument, 0, 0}, + {"updatelayermetadata", no_argument, 0, 0}, {"tailpath", required_argument, 0, 0}, {"path", required_argument, 0, 0}, {"rescan", no_argument, 0, 0}, @@ -246,6 +216,10 @@ int _main(int argc, char **argv, char **) { automaticallyFindMatchingDataset = true; } + if (strncmp(long_options[opt_idx].name, "updatelayermetadata", 19) == 0) { + scanFlags += CDBUPDATE_LAYER_METADATA; + } + if (strncmp(long_options[opt_idx].name, "test", 4) == 0) { CDBDebug("Test"); CProj4ToCF proj4ToCF; @@ -345,6 +319,15 @@ int _main(int argc, char **argv, char **) { } readyerror(); return status; + } else if (scanFlags & CDBUPDATE_LAYER_METADATA) { + CRequest baseRequest; + int status = setCRequestConfigFromEnvironment(&baseRequest); + if (status != 0) { + CDBError("setCRequestConfigFromEnvironment failed"); + return 1; + } + status = updateLayerMetadata(baseRequest); + return status; } /* Check if layers need to be obtained. */ diff --git a/adagucserverEC/utils/ConfigurationUtils.cpp b/adagucserverEC/utils/ConfigurationUtils.cpp new file mode 100644 index 000000000..90ff9c5ba --- /dev/null +++ b/adagucserverEC/utils/ConfigurationUtils.cpp @@ -0,0 +1,21 @@ +#include "./ConfigurationUtils.h" + +std::vector getEnabledDatasetsConfigurations(CServerParams *srvParam) { + std::vector datasetList; + for (auto dataset : srvParam->cfg->Dataset) { + if (dataset->attr.enabled.equals("true") && dataset->attr.location.empty() == false) { + if (srvParam->verbose) { + CDBDebug("Dataset locations %s", dataset->attr.location.c_str()); + } + auto files = CDirReader::listDir(dataset->attr.location.c_str(), false, "^.*\\.xml$"); + datasetList.insert(datasetList.end(), files.begin(), files.end()); + } + } + return datasetList; +} + +// TODO: configure a list of possible extensions for adaguc at a central place +bool checkIfPathIsFile(CT::string filePath) { + return (filePath.endsWith(".nc") || filePath.endsWith(".h5") || filePath.endsWith(".hdf5") || filePath.endsWith(".he5") || filePath.endsWith(".png") || filePath.endsWith(".csv") || + filePath.endsWith(".geojson") || filePath.endsWith(".json") || filePath.startsWith("http://") || filePath.startsWith("https://") || filePath.startsWith("dodsc://")); +} diff --git a/adagucserverEC/utils/ConfigurationUtils.h b/adagucserverEC/utils/ConfigurationUtils.h new file mode 100644 index 000000000..3d8656008 --- /dev/null +++ b/adagucserverEC/utils/ConfigurationUtils.h @@ -0,0 +1,12 @@ +#ifndef CONFIGURATIONUTILS_H +#define CONFIGURATIONUTILS_H + +#include +#include +#include + +std::vector getEnabledDatasetsConfigurations(CServerParams *srvParam); + +bool checkIfPathIsFile(CT::string filePath); + +#endif diff --git a/adagucserverEC/utils/UpdateLayerMetadata.cpp b/adagucserverEC/utils/UpdateLayerMetadata.cpp new file mode 100644 index 000000000..58d83e8cc --- /dev/null +++ b/adagucserverEC/utils/UpdateLayerMetadata.cpp @@ -0,0 +1,58 @@ +#include "UpdateLayerMetadata.h" +#include +#include +#include "ConfigurationUtils.h" + +void serverLogFunctionNothing(const char *) {} + +/* Set config file from environment variable ADAGUC_CONFIG */ +int setCRequestConfigFromEnvironment(CRequest *request, const char *additionalDataset) { + char *configfile = getenv("ADAGUC_CONFIG"); + if (configfile != NULL) { + CT::string configWithAdditionalDataset = configfile; + if (additionalDataset != nullptr && strlen(additionalDataset) > 0) { + configWithAdditionalDataset.concat(","); + configWithAdditionalDataset.concat(additionalDataset); + } + int status = request->setConfigFile(configWithAdditionalDataset.c_str()); + + /* Check logging level */ + if (request->getServerParams()->isDebugLoggingEnabled() == false) { + setDebugFunction(serverLogFunctionNothing); + } + + return status; + } else { + CDBError("No configuration file is set. Please set ADAGUC_CONFIG environment variable accordingly."); + return 1; + } + return 0; +} + +int updateLayerMetadata(CRequest &request) { + CServerParams *srvParam = request.getServerParams(); + + auto datasetList = getEnabledDatasetsConfigurations(srvParam); + // TODO: Remove datasets in metadatable which don't have a matching configuration + // TODO: Remove dimension tables which don't have a matching configuration + + for (auto &dataset : datasetList) { + if (dataset.length() > 0) { + CDBDebug("***** Scanning dataset [%s]", dataset.c_str()); + } + CRequest requestPerDataset; + // dataset = "/data/adaguc-datasets/test.uwcw_ha43_dini_5p5km_10x8.xml"; + // dataset = "/data/adaguc-datasets/testdata.xml"; + int status = setCRequestConfigFromEnvironment(&requestPerDataset, dataset.c_str()); + if (status != 0) { + CDBError("Unable to read configuration file"); + return 1; + } + status = requestPerDataset.updatedb(nullptr, nullptr, CDBFILESCANNER_UPDATEDB | CDBFILESCANNER_DONTREMOVEDATAFROMDB | CDBFILESCANNER_UPDATEDB_ONLYFILEFROMDEFAULTQUERY, ""); + if (status != 0) { + CDBError("Error occured in updating the database"); + } + // return 0; + } + return 0; +} diff --git a/adagucserverEC/utils/UpdateLayerMetadata.h b/adagucserverEC/utils/UpdateLayerMetadata.h new file mode 100644 index 000000000..b07be6342 --- /dev/null +++ b/adagucserverEC/utils/UpdateLayerMetadata.h @@ -0,0 +1,9 @@ +#ifndef UPDATELAYERMETADATA_H +#define UPDATELAYERMETADATA_H +#include + +int setCRequestConfigFromEnvironment(CRequest *request, const char *additionalDataset = nullptr); + +int updateLayerMetadata(CRequest &request); + +#endif \ No newline at end of file