From e902fadce257d27aff3d4eb00bedbce799ec8275 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Mar 2023 15:44:27 +0200 Subject: [PATCH 01/14] #24859 Added new parameter 'flagInternalIndex' to BaseRequest --- default-lc-managers/CHANGELOG.md | 4 ++++ default-lc-managers/pom.xml | 2 +- .../cms/plugins/implementations/Default3PhaseManager.java | 1 + .../cms/plugins/implementations/SimpleLifeCycleManager.java | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/default-lc-managers/CHANGELOG.md b/default-lc-managers/CHANGELOG.md index 79974f2..bd9d68d 100644 --- a/default-lc-managers/CHANGELOG.md +++ b/default-lc-managers/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for org.gcube.application.cms.ckan-plugin +## [v1.2.0-SNAPSHOT] + +- Integrated the field 'geov_link' (Geoportal GisViewer link) in the centroid layer [#24859] + ## [v1.1.1] - 2023-03-06 - [#24570] Integrated the UnPublish operation diff --git a/default-lc-managers/pom.xml b/default-lc-managers/pom.xml index 316429e..e51199c 100644 --- a/default-lc-managers/pom.xml +++ b/default-lc-managers/pom.xml @@ -5,7 +5,7 @@ 4.0.0 default-lc-managers - 1.1.1 + 1.2.0-SNAPSHOT gCube CMS - Default LC Managers diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java index 57a5179..c6ec985 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java @@ -173,6 +173,7 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life callParameters.put("workspace", Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName())); callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName()+"_centroids")); + callParameters.put("flagInternalIndex", true); return callParameters; } diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java index f2beee8..d97e27e 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java @@ -95,6 +95,7 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements Document callParameters = new Document(); callParameters.put("workspace",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName())); callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName()+"_centroids")); + callParameters.put("flagInternalIndex", false); return callParameters; } -- 2.17.1 From 07730153ca3514b2d0077e03c8d1e4b6937a0e82 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Mar 2023 15:45:21 +0200 Subject: [PATCH 02/14] #24859 integrated the Geoportal Gis Link --- sdi-plugins/CHANGELOG.md | 4 + sdi-plugins/pom.xml | 9 +- .../cms/sdi/engine/DBConstants.java | 2 + .../cms/sdi/plugins/SDIIndexerPlugin.java | 553 +++++++++--------- 4 files changed, 293 insertions(+), 275 deletions(-) diff --git a/sdi-plugins/CHANGELOG.md b/sdi-plugins/CHANGELOG.md index c6f8674..9c1b001 100644 --- a/sdi-plugins/CHANGELOG.md +++ b/sdi-plugins/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for org.gcube.application.cms.sdi-plugins +## [v1.1.0-SNAPSHOT] + +- Integrated the field 'geov_link' (Geoportal GisViewer link) in the centroid layer [#24859] + ## [v1.0.4] - 2023-03-06 - Fixed the import from joda-time to java.time - [#24702] Fixed the default-lc-managers dependency diff --git a/sdi-plugins/pom.xml b/sdi-plugins/pom.xml index 651cbf0..d16c89b 100644 --- a/sdi-plugins/pom.xml +++ b/sdi-plugins/pom.xml @@ -5,7 +5,7 @@ 4.0.0 sdi-plugins - 1.0.4 + 1.1.0-SNAPSHOT gCube CMS - SDI Plugins @@ -85,12 +85,19 @@ 1.14 + + org.gcube.portlets.user + uri-resolver-manager + [1.0.0,2.0.0-SNAPSHOT) + + org.gcube.application.cms cms-test-commons test + diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java index 381d259..4617b41 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java @@ -18,6 +18,8 @@ public class DBConstants { public static final String PROJECT_ID="projectid"; public static final String DISPLAYED="displayed_project"; + + public static final String GEOVIEWER_LINK_FIELD="geov_link"; public static final String XCOORD_FIELD="xcoord"; diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java index 8987e04..414b5ff 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java @@ -33,6 +33,9 @@ import org.gcube.application.geoportal.common.model.plugins.IndexerPluginDescrip import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor; import org.gcube.application.geoportal.common.model.rest.ConfigurationException; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; +import org.gcube.portlets.user.uriresolvermanager.UriResolverManager; +import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder; +import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS; import org.geojson.Crs; import org.geojson.GeoJsonObject; import org.geojson.LngLatAlt; @@ -42,283 +45,285 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; @Slf4j public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPluginInterface { - - static final PluginDescriptor DESCRIPTOR=new PluginDescriptor(Constants.INDEXER_PLUGIN_ID, - IndexerPluginDescriptor.INDEXER); - - - - - static final ArrayList BBOX_EVALUATORS=new ArrayList<>(); - - static { - DESCRIPTOR.setDescription("SDI Indexer. " + - "Manage Centroids layers."); - DESCRIPTOR.setVersion(new Semver("1.0.0")); - - BBOX_EVALUATORS.add(new BBOXPathScanner()); - BBOX_EVALUATORS.add(new BBOXByCoordinatePaths()); - - - - } - - @Override - public PluginDescriptor getDescriptor() { - return DESCRIPTOR; - } - - - @Override - public InitializationReport initInContext() throws InitializationException { - InitializationReport report = new InitializationReport(); - report.setStatus(Report.Status.OK); - return report; - } - - /** - * Expected parameters : - * - indexName (unique) - * - workspace - * - centroidRecord (OPT) - * - * @param request - * @return - */ - - @Override - public IndexDocumentReport index(IndexDocumentRequest request) throws InvalidPluginRequestException { - - log.info("Indexer {} : Serving Index Request {} ",this.getDescriptor().getId(),request); - - Project project =request.getDocument(); - UseCaseDescriptor useCaseDescriptor = request.getUseCaseDescriptor(); - Document requestArguments=request.getCallParameters(); - - IndexDocumentReport report= new IndexDocumentReport(request); - - - - try{ - // ********* INIT INDEX - // TODO CACHE - PostgisIndexer indexer = getIndexer(useCaseDescriptor,requestArguments); - - Document profileConfiguration =getConfigurationFromProfile(useCaseDescriptor).getConfiguration(); - log.debug("UseCaseDescriptor Configuration is {} ",profileConfiguration); - - - // ************* PREPARE RECORD - - - JSONPathWrapper documentNavigator=new JSONPathWrapper(Serialization.write(project)); - - Document centroidDoc = new Document(); - if(requestArguments.containsKey("centroidRecord")) - centroidDoc.putAll(requestArguments.get("centroidRecords",Document.class)); - // DEFAULT VALUES - centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId()); - centroidDoc.put(DBConstants.Defaults.DISPLAYED,true); - - - - // ********************** EVALAUTE POSITION - log.debug("indexing UseCaseDescriptor {} : Evaluating Centroid... ", useCaseDescriptor.getId()); - SpatialReference reference =null; - List refs=project.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE); - if(!refs.isEmpty()){ - - // Use existing Reference - - reference = Serialization.convert(refs.get(0), SpatialReference.class); - - log.debug("Using already defined spatial reference " + reference); - - - GeoJsonObject object = Serialization.convert(reference.getGeoJson(), GeoJsonObject.class); - - GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.fromGeoJSON(object.getBbox()); - - log.info("Found declared BBOX {} ", bbox); - Double pointX = (bbox.getMaxX() + bbox.getMinX())/2; - Double pointY = (bbox.getMaxY() + bbox.getMinY())/2; - String wkt = String.format("POINT (%1$f %2$f) ", - pointX, pointY); - - - centroidDoc.put("geom", wkt); - - } else{ - // unable to use current Spatial reference, try evaluating it - log.debug("UseCaseDescriptor {} : Getting evaluation paths from useCaseDescriptor.. ", useCaseDescriptor.getId()); - - // for each configuration option try until found - GCubeSDILayer.BBOX toSet = null; - for(BBOXEvaluator evaluator : BBOX_EVALUATORS){ - log.trace("UCD {}, Project {}. Evaluating BBOX with {}",useCaseDescriptor.getId(),project.getId(),evaluator); - try{ - if(evaluator.isConfigured(profileConfiguration)){ - toSet=evaluator.evaluate(profileConfiguration,useCaseDescriptor,documentNavigator); - if(toSet!=null) { - log.info("UCD {}, Project {}. Evaluated BBOX {} with method {}", - useCaseDescriptor.getId(),project.getId(),toSet,evaluator); - break; - } - } - }catch (Throwable t){ - log.warn("UCD {}, Project {}. Exception with {}", - useCaseDescriptor.getId(),project.getId(),evaluator,t); - } - } - if(toSet== null) - throw new IndexingException("No BBOX has been evaluated from project"); - - Double pointX=(toSet.getMaxX()+toSet.getMinX())/2; - Double pointY = (toSet.getMaxY()+toSet.getMinY())/2; - log.info("Evaluated BBOX {} ",toSet); - String wkt = String .format("POINT (%1$f %2$f) ", - pointX, pointY); - //TODO support altitude - Double pointZ= 0d; - - - centroidDoc.put("geom",wkt); - - Point point = new Point(); - point.setCoordinates(new LngLatAlt(pointX,pointY,pointZ)); - point.setBbox(toSet.asGeoJSONArray()); - - //TODO Manage CRS - point.setCrs(new Crs()); - reference = new SpatialReference(Serialization.asDocument(point)); - log.info("UCD {} project {}, Setting Spatial Reference {} ",useCaseDescriptor.getId(),project.getId(),Serialization.write(reference)); - report.addIdentificationReference(reference); - } - - - - //*********** Additional Values from useCaseDescriptor - - log.info("Setting additional values to centroid from mappings .."); - for(MappingObject m : getMappings(useCaseDescriptor)){ - List foundValues = documentNavigator.getByPath(m.getPath()); - Object toSetValue=null; - if(!foundValues.isEmpty()) { - // NB CSV for multiple values - StringBuilder b=new StringBuilder(); - foundValues.forEach(o-> { - // Parser returns list of list - if (o instanceof Collection) ((Collection) o).forEach(v ->b.append(v + ",")); - else b.append(o+","); - }); - b.deleteCharAt(b.length()-1); - toSetValue = b.toString(); - } - log.trace("Setting {} = {} in centroid doc ",m.getName(),toSetValue); - centroidDoc.put(m.getName(),toSetValue); - } - - log.info("Inserting Centroid {} into {} ",Serialization.write(centroidDoc.toJson()),indexer); - indexer.insert(centroidDoc); - - // Support to HIDE AND DISPLAY as requested by invoker - if(requestArguments.containsKey("_toHideIds")){ - - List ids = Serialization.convert(requestArguments.get("_toHideIds"),List.class); - log.info("Requested to hide centroids {} ",ids); - indexer.updateIsVisible(false,ids); - } - - if(requestArguments.containsKey("_toDisplayIds")){ - List ids = Serialization.convert(requestArguments.get("_toDisplayIds"),List.class); - - log.info("Requested to display centroids {} ",ids); - indexer.updateIsVisible(true,ids); - } - - - - report.setStatus(Report.Status.OK); - }catch (SDIInteractionException e){ - log.error("Unable to index "+request,e); - report.setStatus(Report.Status.ERROR); - report.putMessage(e.getMessage()); - }catch (Throwable t){ - log.error("Unable to index "+request,t); - report.setStatus(Report.Status.ERROR); - report.putMessage(t.getMessage()); - }finally{ - return report; - } - } - - private List getMappings(UseCaseDescriptor useCaseDescriptor) throws InvalidProfileException { - return MappingObject.getMappingsFromUCD(useCaseDescriptor, getDescriptor().getId()); - } - - @Override - public IndexDocumentReport deindex(IndexDocumentRequest request) throws InvalidPluginRequestException { - log.info("Indexer {} : Serving Index Request {} ",this.getDescriptor().getId(),request); - IndexDocumentReport report= new IndexDocumentReport(request); - try{ - PostgisIndexer indexer = getIndexer(request.getUseCaseDescriptor(),request.getCallParameters()); - indexer.removeByFieldValue(PostgisIndexer.StandardFields.PROJECT_ID,request.getDocument().getId()); - }catch (SDIInteractionException e){ - log.error("Unable to index "+request,e); - report.setStatus(Report.Status.ERROR); - report.putMessage(e.getMessage()); - }catch (Throwable t){ - log.error("Unable to index "+request,t); - report.setStatus(Report.Status.ERROR); - report.putMessage(t.getMessage()); - }finally{ - return report; - } - } - - /** - * Expected parameters : - * workspace - * indexName - * - * @param request - * @return - * @throws ConfigurationException - */ - @Override - public Index getIndex(BaseRequest request) throws ConfigurationException { - try { - return getIndexer(request.getUseCaseDescriptor(), request.getCallParameters()).getIndexConfiguration(); - }catch(Throwable t ){ - throw new ConfigurationException("Unable to get Postgis index for ucd "+request.getUseCaseDescriptor().getId()+" in "+ request.getContext(),t); - } - } - - // Inits index - // TODO CACHE - private PostgisIndexer getIndexer(UseCaseDescriptor ucd,Document params) throws ConfigurationException, SQLException, InvalidProfileException, SDIInteractionException { - PostgisIndexer indexer = new PostgisIndexer(sdiCache.getObject(), ucd, postgisCache.getObject()); - - List mappingObjects = getMappings(ucd); - List fields = PostgisTable.Field.fromMappings(mappingObjects); - - indexer.initIndex(params.getString("indexName"), - fields, - params.getString("workspace"), - params.getString("indexName")); - return indexer; - } - - - - - - - - + static final PluginDescriptor DESCRIPTOR = new PluginDescriptor(Constants.INDEXER_PLUGIN_ID, + IndexerPluginDescriptor.INDEXER); + + static final ArrayList BBOX_EVALUATORS = new ArrayList<>(); + + static { + DESCRIPTOR.setDescription("SDI Indexer. " + "Manage Centroids layers."); + DESCRIPTOR.setVersion(new Semver("1.0.0")); + + BBOX_EVALUATORS.add(new BBOXPathScanner()); + BBOX_EVALUATORS.add(new BBOXByCoordinatePaths()); + + } + + @Override + public PluginDescriptor getDescriptor() { + return DESCRIPTOR; + } + + @Override + public InitializationReport initInContext() throws InitializationException { + InitializationReport report = new InitializationReport(); + report.setStatus(Report.Status.OK); + return report; + } + + /** + * Expected parameters : - indexName (unique) - workspace - flagInternalIndex: + * boolean - centroidRecord (OPT) + * + * @param request + * @return + */ + + @Override + public IndexDocumentReport index(IndexDocumentRequest request) throws InvalidPluginRequestException { + + log.info("Indexer {} : Serving Index Request {} ", this.getDescriptor().getId(), request); + + Project project = request.getDocument(); + UseCaseDescriptor useCaseDescriptor = request.getUseCaseDescriptor(); + Document requestArguments = request.getCallParameters(); + + IndexDocumentReport report = new IndexDocumentReport(request); + + try { + // ********* INIT INDEX + // TODO CACHE + PostgisIndexer indexer = getIndexer(useCaseDescriptor, requestArguments); + + Document profileConfiguration = getConfigurationFromProfile(useCaseDescriptor).getConfiguration(); + log.debug("UseCaseDescriptor Configuration is {} ", profileConfiguration); + + // ************* PREPARE RECORD + + JSONPathWrapper documentNavigator = new JSONPathWrapper(Serialization.write(project)); + + Document centroidDoc = new Document(); + if (requestArguments.containsKey("centroidRecord")) + centroidDoc.putAll(requestArguments.get("centroidRecords", Document.class)); + // DEFAULT VALUES + centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId()); + centroidDoc.put(DBConstants.Defaults.DISPLAYED, true); + + boolean isInternalIndex = false; + try { + isInternalIndex = requestArguments.getBoolean("flagInternalIndex"); + log.debug("flagInternalIndex read as {} ", isInternalIndex); + } catch (Exception e) { + // TODO: handle exception + } + log.info("flagInternalIndex is {} ", isInternalIndex); + + try { + log.debug("Trying to generate Geoportal Gis Link..."); + //Contacting the Geoportal-Resolver via UriResolverManager + UriResolverManager uriResolverManager = new UriResolverManager("GEO"); + GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder(project.getProfileID(),project.getId()); + builder.scope(request.getContext().getId()); + + if(isInternalIndex) { + builder.resolverAs(RESOLVE_AS.PRIVATE); + }else { + builder.resolverAs(RESOLVE_AS.PUBLIC); + } + Map params = builder.buildQueryParameters(); + String shortLink = uriResolverManager.getLink(params, true); + log.info("Geoportal GisViewer link is {} ", shortLink); + centroidDoc.put(DBConstants.Defaults.GEOVIEWER_LINK_FIELD, shortLink); + }catch (Exception e) { + // TODO: handle exception + } + + + // ********************** EVALAUTE POSITION + log.debug("indexing UseCaseDescriptor {} : Evaluating Centroid... ", useCaseDescriptor.getId()); + SpatialReference reference = null; + List refs = project + .getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE); + if (!refs.isEmpty()) { + + // Use existing Reference + + reference = Serialization.convert(refs.get(0), SpatialReference.class); + + log.debug("Using already defined spatial reference " + reference); + + GeoJsonObject object = Serialization.convert(reference.getGeoJson(), GeoJsonObject.class); + + GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.fromGeoJSON(object.getBbox()); + + log.info("Found declared BBOX {} ", bbox); + Double pointX = (bbox.getMaxX() + bbox.getMinX()) / 2; + Double pointY = (bbox.getMaxY() + bbox.getMinY()) / 2; + String wkt = String.format("POINT (%1$f %2$f) ", pointX, pointY); + + centroidDoc.put("geom", wkt); + + } else { + // unable to use current Spatial reference, try evaluating it + log.debug("UseCaseDescriptor {} : Getting evaluation paths from useCaseDescriptor.. ", + useCaseDescriptor.getId()); + + // for each configuration option try until found + GCubeSDILayer.BBOX toSet = null; + for (BBOXEvaluator evaluator : BBOX_EVALUATORS) { + log.trace("UCD {}, Project {}. Evaluating BBOX with {}", useCaseDescriptor.getId(), project.getId(), + evaluator); + try { + if (evaluator.isConfigured(profileConfiguration)) { + toSet = evaluator.evaluate(profileConfiguration, useCaseDescriptor, documentNavigator); + if (toSet != null) { + log.info("UCD {}, Project {}. Evaluated BBOX {} with method {}", + useCaseDescriptor.getId(), project.getId(), toSet, evaluator); + break; + } + } + } catch (Throwable t) { + log.warn("UCD {}, Project {}. Exception with {}", useCaseDescriptor.getId(), project.getId(), + evaluator, t); + } + } + if (toSet == null) + throw new IndexingException("No BBOX has been evaluated from project"); + + Double pointX = (toSet.getMaxX() + toSet.getMinX()) / 2; + Double pointY = (toSet.getMaxY() + toSet.getMinY()) / 2; + log.info("Evaluated BBOX {} ", toSet); + String wkt = String.format("POINT (%1$f %2$f) ", pointX, pointY); + // TODO support altitude + Double pointZ = 0d; + + centroidDoc.put("geom", wkt); + + Point point = new Point(); + point.setCoordinates(new LngLatAlt(pointX, pointY, pointZ)); + point.setBbox(toSet.asGeoJSONArray()); + + // TODO Manage CRS + point.setCrs(new Crs()); + reference = new SpatialReference(Serialization.asDocument(point)); + log.info("UCD {} project {}, Setting Spatial Reference {} ", useCaseDescriptor.getId(), project.getId(), + Serialization.write(reference)); + report.addIdentificationReference(reference); + } + + // *********** Additional Values from useCaseDescriptor + + log.info("Setting additional values to centroid from mappings .."); + for (MappingObject m : getMappings(useCaseDescriptor)) { + List foundValues = documentNavigator.getByPath(m.getPath()); + Object toSetValue = null; + if (!foundValues.isEmpty()) { + // NB CSV for multiple values + StringBuilder b = new StringBuilder(); + foundValues.forEach(o -> { + // Parser returns list of list + if (o instanceof Collection) + ((Collection) o).forEach(v -> b.append(v + ",")); + else + b.append(o + ","); + }); + b.deleteCharAt(b.length() - 1); + toSetValue = b.toString(); + } + log.trace("Setting {} = {} in centroid doc ", m.getName(), toSetValue); + centroidDoc.put(m.getName(), toSetValue); + } + + log.info("Inserting Centroid {} into {} ", Serialization.write(centroidDoc.toJson()), indexer); + indexer.insert(centroidDoc); + + // Support to HIDE AND DISPLAY as requested by invoker + if (requestArguments.containsKey("_toHideIds")) { + + List ids = Serialization.convert(requestArguments.get("_toHideIds"), List.class); + log.info("Requested to hide centroids {} ", ids); + indexer.updateIsVisible(false, ids); + } + + if (requestArguments.containsKey("_toDisplayIds")) { + List ids = Serialization.convert(requestArguments.get("_toDisplayIds"), List.class); + + log.info("Requested to display centroids {} ", ids); + indexer.updateIsVisible(true, ids); + } + + report.setStatus(Report.Status.OK); + } catch (SDIInteractionException e) { + log.error("Unable to index " + request, e); + report.setStatus(Report.Status.ERROR); + report.putMessage(e.getMessage()); + } catch (Throwable t) { + log.error("Unable to index " + request, t); + report.setStatus(Report.Status.ERROR); + report.putMessage(t.getMessage()); + } finally { + return report; + } + } + + private List getMappings(UseCaseDescriptor useCaseDescriptor) throws InvalidProfileException { + return MappingObject.getMappingsFromUCD(useCaseDescriptor, getDescriptor().getId()); + } + + @Override + public IndexDocumentReport deindex(IndexDocumentRequest request) throws InvalidPluginRequestException { + log.info("Indexer {} : Serving Index Request {} ", this.getDescriptor().getId(), request); + IndexDocumentReport report = new IndexDocumentReport(request); + try { + PostgisIndexer indexer = getIndexer(request.getUseCaseDescriptor(), request.getCallParameters()); + indexer.removeByFieldValue(PostgisIndexer.StandardFields.PROJECT_ID, request.getDocument().getId()); + } catch (SDIInteractionException e) { + log.error("Unable to index " + request, e); + report.setStatus(Report.Status.ERROR); + report.putMessage(e.getMessage()); + } catch (Throwable t) { + log.error("Unable to index " + request, t); + report.setStatus(Report.Status.ERROR); + report.putMessage(t.getMessage()); + } finally { + return report; + } + } + + /** + * Expected parameters : workspace indexName + * + * @param request + * @return + * @throws ConfigurationException + */ + @Override + public Index getIndex(BaseRequest request) throws ConfigurationException { + try { + return getIndexer(request.getUseCaseDescriptor(), request.getCallParameters()).getIndexConfiguration(); + } catch (Throwable t) { + throw new ConfigurationException("Unable to get Postgis index for ucd " + + request.getUseCaseDescriptor().getId() + " in " + request.getContext(), t); + } + } + + // Inits index + // TODO CACHE + private PostgisIndexer getIndexer(UseCaseDescriptor ucd, Document params) + throws ConfigurationException, SQLException, InvalidProfileException, SDIInteractionException { + PostgisIndexer indexer = new PostgisIndexer(sdiCache.getObject(), ucd, postgisCache.getObject()); + + List mappingObjects = getMappings(ucd); + List fields = PostgisTable.Field.fromMappings(mappingObjects); + + indexer.initIndex(params.getString("indexName"), fields, params.getString("workspace"), + params.getString("indexName")); + return indexer; + } } -- 2.17.1 From d083cae89ea9092ffe31920f0c8ed0c14b684081 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Mar 2023 16:09:25 +0200 Subject: [PATCH 03/14] Only fixed imports --- .../cms/sdi/engine/DBConstants.java | 4 +- .../cms/sdi/engine/PostgisDBManager.java | 9 ++-- .../cms/sdi/engine/PostgisIndexer.java | 22 +++++----- .../cms/sdi/engine/PostgisTable.java | 31 +++++++++----- .../cms/sdi/engine/SDIManager.java | 19 +++++---- .../cms/sdi/engine/SDIManagerWrapper.java | 42 ++++++++++--------- .../engine/bboxes/BBOXByCoordinatePaths.java | 9 ++-- .../cms/sdi/engine/bboxes/BBOXEvaluator.java | 9 ++-- .../sdi/engine/bboxes/BBOXPathScanner.java | 5 ++- .../cms/sdi/model/GCubeSDILayerBuilder.java | 13 +++--- .../cms/sdi/model/MappingObject.java | 9 ++-- .../cms/sdi/model/SDIConfiguration.java | 4 +- .../cms/sdi/model/SupportedFormat.java | 7 ++-- .../cms/sdi/plugins/SDIAbstractPlugin.java | 9 ++-- .../cms/sdi/plugins/SDIIndexerPlugin.java | 18 ++++---- .../sdi/plugins/SDIMaterializerPlugin.java | 19 +++++---- 16 files changed, 128 insertions(+), 101 deletions(-) diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java index 4617b41..d79f5f0 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/DBConstants.java @@ -2,7 +2,9 @@ package org.gcube.application.cms.sdi.engine; import java.util.ArrayList; -import static org.gcube.application.cms.sdi.engine.PostgisTable.*; +import org.gcube.application.cms.sdi.engine.PostgisTable.Field; +import org.gcube.application.cms.sdi.engine.PostgisTable.FieldType; +import org.gcube.application.cms.sdi.engine.PostgisTable.GeometryType; public class DBConstants { diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisDBManager.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisDBManager.java index 43fe74c..5c12f51 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisDBManager.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisDBManager.java @@ -1,9 +1,5 @@ package org.gcube.application.cms.sdi.engine; -import lombok.extern.slf4j.Slf4j; -import org.gcube.application.cms.sdi.faults.DataParsingException; -import org.gcube.application.geoportal.common.model.legacy.BBOX; - import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -11,6 +7,11 @@ import java.sql.SQLException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.gcube.application.cms.sdi.faults.DataParsingException; +import org.gcube.application.geoportal.common.model.legacy.BBOX; + +import lombok.extern.slf4j.Slf4j; + @Slf4j public class PostgisDBManager implements PostgisDBManagerI { diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java index 035a199..3dfec18 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java @@ -1,16 +1,5 @@ package org.gcube.application.cms.sdi.engine; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import org.bson.Document; -import org.gcube.application.cms.sdi.faults.SDIInteractionException; -import org.gcube.application.cms.sdi.model.CrossReferencedLayer; -import org.gcube.application.cms.sdi.plugins.SDIIndexerPlugin; -import org.gcube.application.geoportal.common.model.configuration.Index; -import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; -import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; -import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; - import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -18,6 +7,17 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.bson.Document; +import org.gcube.application.cms.sdi.faults.SDIInteractionException; +import org.gcube.application.cms.sdi.model.CrossReferencedLayer; +import org.gcube.application.geoportal.common.model.configuration.Index; +import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; +import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; + +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; + @Slf4j public class PostgisIndexer { diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java index fd20a07..90b24be 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java @@ -1,20 +1,29 @@ package org.gcube.application.cms.sdi.engine; -import lombok.*; -import lombok.extern.slf4j.Slf4j; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.gcube.application.cms.sdi.faults.DataParsingException; import org.gcube.application.cms.sdi.model.MappingObject; import org.gcube.application.geoportal.common.model.legacy.BBOX; -import java.sql.Array; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Types; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; @Slf4j @RequiredArgsConstructor diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManager.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManager.java index 62a4228..6b35b8a 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManager.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManager.java @@ -1,21 +1,22 @@ package org.gcube.application.cms.sdi.engine; -import it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.gcube.application.cms.sdi.faults.SDIInteractionException; -import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; -import org.gcube.data.transfer.library.DataTransferClient; -import org.gcube.spatial.data.gis.GISInterface; -import org.gcube.spatial.data.gis.is.AbstractGeoServerDescriptor; - import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.gcube.application.cms.sdi.faults.SDIInteractionException; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; +import org.gcube.data.transfer.library.DataTransferClient; +import org.gcube.spatial.data.gis.GISInterface; +import org.gcube.spatial.data.gis.is.AbstractGeoServerDescriptor; + +import it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + @Slf4j public class SDIManager { diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManagerWrapper.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManagerWrapper.java index d8460ec..86f974f 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManagerWrapper.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/SDIManagerWrapper.java @@ -1,13 +1,15 @@ package org.gcube.application.cms.sdi.engine; -import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; -import it.geosolutions.geoserver.rest.GeoServerRESTReader; -import it.geosolutions.geoserver.rest.decoder.RESTFeatureType; -import it.geosolutions.geoserver.rest.decoder.RESTLayer; -import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; -import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder; -import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; -import lombok.extern.slf4j.Slf4j; +import static it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy.REPROJECT_TO_DECLARED; +import static org.gcube.application.cms.sdi.model.GCubeSDILayerBuilder.EPSG_4326; +import static org.gcube.application.cms.sdi.model.GCubeSDILayerBuilder.WGS84_FULL; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + import org.bson.Document; import org.gcube.application.cms.plugins.requests.BaseExecutionRequest; import org.gcube.application.cms.sdi.faults.SDIInteractionException; @@ -21,23 +23,25 @@ import org.gcube.application.geoportal.common.model.document.filesets.sdi.GeoSer import org.gcube.application.geoportal.common.model.document.filesets.sdi.PlatformInfo; import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; import org.gcube.application.geoportal.common.utils.Files; -import org.gcube.data.transfer.library.DataTransferClient; import org.gcube.data.transfer.library.TransferResult; import org.gcube.data.transfer.library.client.Client; -import org.gcube.data.transfer.library.faults.*; +import org.gcube.data.transfer.library.faults.DestinationNotSetException; +import org.gcube.data.transfer.library.faults.FailedTransferException; +import org.gcube.data.transfer.library.faults.InitializationException; +import org.gcube.data.transfer.library.faults.InvalidDestinationException; +import org.gcube.data.transfer.library.faults.InvalidSourceException; +import org.gcube.data.transfer.library.faults.SourceNotSetException; import org.gcube.data.transfer.model.Destination; import org.gcube.data.transfer.model.DestinationClashPolicy; import org.gcube.spatial.data.gis.is.AbstractGeoServerDescriptor; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import static it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy.REPROJECT_TO_DECLARED; -import static org.gcube.application.cms.sdi.model.GCubeSDILayerBuilder.EPSG_4326; -import static org.gcube.application.cms.sdi.model.GCubeSDILayerBuilder.WGS84_FULL; +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; +import it.geosolutions.geoserver.rest.GeoServerRESTReader; +import it.geosolutions.geoserver.rest.decoder.RESTFeatureType; +import it.geosolutions.geoserver.rest.decoder.RESTLayer; +import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; +import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; +import lombok.extern.slf4j.Slf4j; @Slf4j public class SDIManagerWrapper extends SDIManager{ diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXByCoordinatePaths.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXByCoordinatePaths.java index efb037c..1d9f77a 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXByCoordinatePaths.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXByCoordinatePaths.java @@ -1,15 +1,16 @@ package org.gcube.application.cms.sdi.engine.bboxes; -import lombok.Data; -import lombok.ToString; -import lombok.extern.slf4j.Slf4j; +import java.util.List; + import org.bson.Document; import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.geoportal.common.model.JSONPathWrapper; import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; -import java.util.List; +import lombok.Data; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; @Slf4j public class BBOXByCoordinatePaths extends BBOXEvaluator{ diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXEvaluator.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXEvaluator.java index bdc8d0f..b0a1f48 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXEvaluator.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXEvaluator.java @@ -1,13 +1,14 @@ package org.gcube.application.cms.sdi.engine.bboxes; +import org.bson.Document; +import org.gcube.application.geoportal.common.model.JSONPathWrapper; +import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; +import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; + import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.ToString; import lombok.extern.slf4j.Slf4j; -import org.bson.Document; -import org.gcube.application.geoportal.common.model.JSONPathWrapper; -import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; -import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; @RequiredArgsConstructor @ToString diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXPathScanner.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXPathScanner.java index ef92b9c..005d366 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXPathScanner.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/bboxes/BBOXPathScanner.java @@ -1,13 +1,14 @@ package org.gcube.application.cms.sdi.engine.bboxes; -import lombok.extern.slf4j.Slf4j; +import java.util.List; + import org.bson.Document; import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.geoportal.common.model.JSONPathWrapper; import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; -import java.util.List; +import lombok.extern.slf4j.Slf4j; @Slf4j public class BBOXPathScanner extends BBOXEvaluator{ diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/GCubeSDILayerBuilder.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/GCubeSDILayerBuilder.java index 17f6161..7d33da5 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/GCubeSDILayerBuilder.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/GCubeSDILayerBuilder.java @@ -1,16 +1,17 @@ package org.gcube.application.cms.sdi.model; -import lombok.Getter; -import org.bson.Document; -import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; -import org.gcube.application.geoportal.common.model.document.filesets.sdi.GeoServerPlatform; -import org.gcube.application.geoportal.common.model.document.filesets.sdi.PlatformInfo; - import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bson.Document; +import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; +import org.gcube.application.geoportal.common.model.document.filesets.sdi.GeoServerPlatform; +import org.gcube.application.geoportal.common.model.document.filesets.sdi.PlatformInfo; + +import lombok.Getter; + public class GCubeSDILayerBuilder { public static enum OGC_TYPE{ diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/MappingObject.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/MappingObject.java index 01b2e28..6d39512 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/MappingObject.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/MappingObject.java @@ -1,15 +1,16 @@ package org.gcube.application.cms.sdi.model; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; +import java.util.List; + import org.bson.Document; import org.gcube.application.cms.plugins.faults.InvalidProfileException; import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; -import java.util.ArrayList; -import java.util.List; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; @Data @Slf4j diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SDIConfiguration.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SDIConfiguration.java index 3374a56..f2bb385 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SDIConfiguration.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SDIConfiguration.java @@ -1,10 +1,10 @@ package org.gcube.application.cms.sdi.model; -import org.bson.Document; - import java.util.HashMap; import java.util.Map; +import org.bson.Document; + public class SDIConfiguration { public static final String GEOSERVER_PLATFORM="GeoServer"; diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SupportedFormat.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SupportedFormat.java index 0015174..f60a7b4 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SupportedFormat.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/model/SupportedFormat.java @@ -1,11 +1,12 @@ package org.gcube.application.cms.sdi.model; +import java.util.ArrayList; + +import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFile; + import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFile; - -import java.util.ArrayList; @Getter @RequiredArgsConstructor public abstract class SupportedFormat { diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java index 00c6c1d..2a3aa34 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java @@ -1,7 +1,8 @@ package org.gcube.application.cms.sdi.plugins; -import lombok.Synchronized; -import lombok.extern.slf4j.Slf4j; +import java.time.Duration; +import java.time.temporal.ChronoUnit; + import org.gcube.application.cms.caches.AbstractScopedMap; import org.gcube.application.cms.implementations.ISInterface; import org.gcube.application.cms.implementations.ImplementationProvider; @@ -16,8 +17,8 @@ import org.gcube.application.cms.sdi.engine.SDIManagerWrapper; import org.gcube.application.geoportal.common.model.rest.ConfigurationException; import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; -import java.time.Duration; -import java.time.temporal.ChronoUnit; +import lombok.Synchronized; +import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class SDIAbstractPlugin extends AbstractPlugin implements InitializablePlugin { diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java index 414b5ff..1a8918e 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java @@ -1,7 +1,11 @@ package org.gcube.application.cms.sdi.plugins; -import com.vdurmont.semver4j.Semver; -import lombok.extern.slf4j.Slf4j; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + import org.bson.Document; import org.gcube.application.cms.plugins.IndexerPluginInterface; import org.gcube.application.cms.plugins.faults.IndexingException; @@ -41,11 +45,9 @@ import org.geojson.GeoJsonObject; import org.geojson.LngLatAlt; import org.geojson.Point; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import com.vdurmont.semver4j.Semver; + +import lombok.extern.slf4j.Slf4j; @Slf4j public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPluginInterface { @@ -140,7 +142,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin log.info("Geoportal GisViewer link is {} ", shortLink); centroidDoc.put(DBConstants.Defaults.GEOVIEWER_LINK_FIELD, shortLink); }catch (Exception e) { - // TODO: handle exception + log.error("Error on creating the Geoportal GisViewer link for project id {}", project.getId(), e); } diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIMaterializerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIMaterializerPlugin.java index e928aff..8c21815 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIMaterializerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIMaterializerPlugin.java @@ -1,9 +1,10 @@ package org.gcube.application.cms.sdi.plugins; -import com.vdurmont.semver4j.Semver; -import lombok.Data; -import lombok.Synchronized; -import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.bson.Document; import org.gcube.application.cms.implementations.utils.UserUtils; import org.gcube.application.cms.plugins.MaterializationPlugin; @@ -28,12 +29,12 @@ import org.gcube.application.geoportal.common.model.plugins.MaterializerPluginDe import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor; import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; -import org.gcube.application.geoportal.common.utils.ContextUtils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.vdurmont.semver4j.Semver; + +import lombok.Data; +import lombok.Synchronized; +import lombok.extern.slf4j.Slf4j; @Slf4j public class SDIMaterializerPlugin extends AbstractPlugin implements MaterializationPlugin { -- 2.17.1 From 18458b99f6f6d0155bdfe4f6585adfd628e5a001 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Mar 2023 17:02:17 +0200 Subject: [PATCH 04/14] setting flagInternalIndex as Boolean#TRUE/FALSE --- .../cms/plugins/implementations/Default3PhaseManager.java | 2 +- .../cms/plugins/implementations/SimpleLifeCycleManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java index c6ec985..019c490 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java @@ -173,7 +173,7 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life callParameters.put("workspace", Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName())); callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName()+"_centroids")); - callParameters.put("flagInternalIndex", true); + callParameters.put("flagInternalIndex", Boolean.TRUE); return callParameters; } diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java index d97e27e..8e49858 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java @@ -95,7 +95,7 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements Document callParameters = new Document(); callParameters.put("workspace",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName())); callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName()+"_centroids")); - callParameters.put("flagInternalIndex", false); + callParameters.put("flagInternalIndex", Boolean.FALSE); return callParameters; } -- 2.17.1 From 374544a28ade1a34de25d889db9a554efa00eaea Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Mar 2023 17:06:02 +0200 Subject: [PATCH 05/14] updated "flagInternalIndex" read --- .../cms/sdi/plugins/SDIIndexerPlugin.java | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java index 1a8918e..ecec027 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java @@ -95,6 +95,8 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin UseCaseDescriptor useCaseDescriptor = request.getUseCaseDescriptor(); Document requestArguments = request.getCallParameters(); + log.debug("requestArguments is {} ", requestArguments); + IndexDocumentReport report = new IndexDocumentReport(request); try { @@ -116,7 +118,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId()); centroidDoc.put(DBConstants.Defaults.DISPLAYED, true); - boolean isInternalIndex = false; + Boolean isInternalIndex = null; try { isInternalIndex = requestArguments.getBoolean("flagInternalIndex"); log.debug("flagInternalIndex read as {} ", isInternalIndex); @@ -124,27 +126,29 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin // TODO: handle exception } log.info("flagInternalIndex is {} ", isInternalIndex); - - try { - log.debug("Trying to generate Geoportal Gis Link..."); - //Contacting the Geoportal-Resolver via UriResolverManager - UriResolverManager uriResolverManager = new UriResolverManager("GEO"); - GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder(project.getProfileID(),project.getId()); - builder.scope(request.getContext().getId()); - - if(isInternalIndex) { - builder.resolverAs(RESOLVE_AS.PRIVATE); - }else { - builder.resolverAs(RESOLVE_AS.PUBLIC); + + if (isInternalIndex != null) { + try { + log.debug("Trying to generate Geoportal Gis Link..."); + // Contacting the Geoportal-Resolver via UriResolverManager + UriResolverManager uriResolverManager = new UriResolverManager("GEO"); + GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder( + project.getProfileID(), project.getId()); + builder.scope(request.getContext().getId()); + + if (isInternalIndex) { + builder.resolverAs(RESOLVE_AS.PRIVATE); + } else { + builder.resolverAs(RESOLVE_AS.PUBLIC); + } + Map params = builder.buildQueryParameters(); + String shortLink = uriResolverManager.getLink(params, true); + log.info("Geoportal GisViewer link is {} ", shortLink); + centroidDoc.put(DBConstants.Defaults.GEOVIEWER_LINK_FIELD, shortLink); + } catch (Exception e) { + log.error("Error on creating the Geoportal GisViewer link for project id {}", project.getId(), e); } - Map params = builder.buildQueryParameters(); - String shortLink = uriResolverManager.getLink(params, true); - log.info("Geoportal GisViewer link is {} ", shortLink); - centroidDoc.put(DBConstants.Defaults.GEOVIEWER_LINK_FIELD, shortLink); - }catch (Exception e) { - log.error("Error on creating the Geoportal GisViewer link for project id {}", project.getId(), e); } - // ********************** EVALAUTE POSITION log.debug("indexing UseCaseDescriptor {} : Evaluating Centroid... ", useCaseDescriptor.getId()); -- 2.17.1 From 42fc5e4acec15f5fbbf5bca9868dd5615d3541c8 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 10:24:04 +0200 Subject: [PATCH 06/14] Fixed deploying of multiple versions of the default-lc-managers [#24875] --- geoportal-service/CHANGELOG.md | 3 +++ geoportal-service/pom.xml | 10 +++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/geoportal-service/CHANGELOG.md b/geoportal-service/CHANGELOG.md index a44d845..f91a6e3 100644 --- a/geoportal-service/CHANGELOG.md +++ b/geoportal-service/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog for org.gcube.application.geoportal-service +## [v1.0.14-SNAPSHOT] + +- Fixed deploying of multiple versions of the default-lc-managers [#24875] ## [v1.0.13] - 2023-02-23 - Integrating new facilities and bug fixing released in the Plugins diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index 4f5d02f..eeb9cfb 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.gcube.application geoportal-service - 1.0.13 + 1.0.14-SNAPSHOT Geoportal Service war @@ -21,16 +21,12 @@ ${project.basedir}${file.separator}${project.artifactId}${file.separator}src${file.separator}main${file.separator}webapp${file.separator}WEB-INF - - scm:git:${gitBaseUrl}/gcube-cms-suite scm:git:${gitBaseUrl}/gcube-cms-suite ${gitBaseUrl}/gcube-cms-suite - - @@ -66,6 +62,7 @@ org.gcube.application.cms default-lc-managers + provided @@ -94,7 +91,6 @@ - com.webcohesion.enunciate @@ -173,7 +169,7 @@ - + kr.motd.maven sphinx-maven-plugin -- 2.17.1 From 9dd1b77b7381adf5a8a5b7211ccdcf471e0069d3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 10:51:09 +0200 Subject: [PATCH 07/14] reverted scope of default-lc-managers from 'provided' to 'compile', see #24875#note-3 --- geoportal-service/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index eeb9cfb..7ff7be0 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -62,7 +62,6 @@ org.gcube.application.cms default-lc-managers - provided -- 2.17.1 From c23245151f258d11fad7d82ba3290acb13e3d0d4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 11:48:41 +0200 Subject: [PATCH 08/14] Added default case (as String) in the `setObjectInPreparedStatement` --- .../cms/sdi/engine/PostgisTable.java | 517 +++++++++--------- .../cms/sdi/plugins/SDIIndexerPlugin.java | 1 + 2 files changed, 259 insertions(+), 259 deletions(-) diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java index 90b24be..5d8d2c1 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisTable.java @@ -31,315 +31,314 @@ import lombok.extern.slf4j.Slf4j; @ToString public class PostgisTable { + @Getter + @AllArgsConstructor + public static enum GeometryType { + MULTIPOINT("4326", "geometry (MULTIPOINT,4326)", "", ""), POINT("4326", "geometry (POINT,4326)", "", ""), + LINE("4326", "geometry (MULTILINESTRING,4326)", "", ""), + POLYGON("4326", "geometry (MULTIPOLYGON,4326)", "", ""); - @Getter - @AllArgsConstructor - public static enum GeometryType{ - MULTIPOINT("4326","geometry (MULTIPOINT,4326)","",""), - POINT("4326","geometry (POINT,4326)","",""), - LINE("4326","geometry (MULTILINESTRING,4326)","",""), - POLYGON("4326","geometry (MULTIPOLYGON,4326)","",""); - private final String SRID; - private final String definition; - private final String InsertWKT; - private final String insertWKB; + private final String SRID; + private final String definition; + private final String InsertWKT; + private final String insertWKB; + } - } + @RequiredArgsConstructor + @Getter + @Setter + @ToString + public static class Field { + @NonNull + private String name; + @NonNull + private FieldType type; + private Boolean isIndexed; + private Object constantValue; - @RequiredArgsConstructor - @Getter - @Setter - @ToString - public static class Field{ - @NonNull - private String name; - @NonNull - private FieldType type; - private Boolean isIndexed; - private Object constantValue; + public static final Field fromMapping(MappingObject m) { + return new PostgisTable.Field(m.getName(), PostgisTable.FieldType.valueOf(m.getType())); + } - public static final Field fromMapping(MappingObject m){ - return new PostgisTable.Field(m.getName(), PostgisTable.FieldType.valueOf(m.getType())); - } + public static final List fromMappings(Collection coll) { + ArrayList toReturn = new ArrayList<>(); + if (coll != null) + coll.forEach(m -> toReturn.add(fromMapping(m))); + return toReturn; + } + } - public static final List fromMappings (Collection coll){ - ArrayList toReturn = new ArrayList<>(); - if(coll!=null) - coll.forEach(m -> toReturn.add(fromMapping(m))); - return toReturn; - } - } + @Getter + @AllArgsConstructor + public enum FieldType { + INT("int", java.sql.Types.INTEGER), BOOLEAN("boolean", java.sql.Types.BOOLEAN), + TEXT("text", java.sql.Types.LONGVARCHAR), FLOAT("float", java.sql.Types.FLOAT), GEOMETRY("", 0), + AUTOINCREMENT("BIGSERIAL PRIMARY KEY", java.sql.Types.BIGINT); - @Getter - @AllArgsConstructor - public enum FieldType{ - INT("int",java.sql.Types.INTEGER), - BOOLEAN("boolean", java.sql.Types.BOOLEAN), - TEXT("text",java.sql.Types.LONGVARCHAR), - FLOAT("float",java.sql.Types.FLOAT), - GEOMETRY("",0), - AUTOINCREMENT("BIGSERIAL PRIMARY KEY",java.sql.Types.BIGINT); + private String definition; + private int sqlType; + } - private String definition; - private int sqlType; - } + @RequiredArgsConstructor + @Getter + @ToString + public static class POINT { + private static Pattern pattern = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)"); - @RequiredArgsConstructor - @Getter - @ToString - public static class POINT{ + public static POINT parsePOINT(String point) throws DataParsingException { + // POINT(8.30230113965909 44.8011688237011) + // x,y + try { + log.debug("Parsing POINT " + point); + Matcher m = pattern.matcher(point); - private static Pattern pattern = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)"); + if (!m.find()) + throw new DataParsingException("Unable to get x "); + Double x = Double.parseDouble(m.group(1)); - public static POINT parsePOINT(String point) throws DataParsingException { - //POINT(8.30230113965909 44.8011688237011) - // x,y - try { - log.debug("Parsing POINT "+point); - Matcher m=pattern.matcher(point); + if (!m.find()) + throw new DataParsingException("Unable to get y "); + Double y = Double.parseDouble(m.group(1)); - if(!m.find()) throw new DataParsingException("Unable to get x "); - Double x=Double.parseDouble(m.group(1)); + return new POINT(x, y); + } catch (Throwable t) { + throw new DataParsingException("Invalid POINT " + point, t); + } + } - if(!m.find()) throw new DataParsingException("Unable to get y "); - Double y=Double.parseDouble(m.group(1)); + @NonNull + private Double x; + @NonNull + private Double y; - return new POINT(x,y); - }catch(Throwable t) { - throw new DataParsingException("Invalid POINT "+point,t); - } - } + } - @NonNull - private Double x; - @NonNull - private Double y; + private static final NumberFormat DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US); - } + static { + ((DecimalFormat) DECIMAL_FORMAT).setGroupingUsed(false); + } + public String getGeometryColumn() { + for (Field f : fields) + if (f.getType().equals(FieldType.GEOMETRY)) + return f.getName(); + return null; + } - private static final NumberFormat DECIMAL_FORMAT=NumberFormat.getInstance(Locale.US); + @NonNull + private String tablename; - static { - ((DecimalFormat) DECIMAL_FORMAT).setGroupingUsed(false); - } + @NonNull + private List fields; + @NonNull + private GeometryType geometryColumnType; - public String getGeometryColumn() { - for(Field f:fields) - if(f.getType().equals(FieldType.GEOMETRY)) return f.getName(); - return null; - } + @Setter + private BBOX boundingBox = null; - @NonNull - private String tablename; + @Setter + private POINT centroid = null; - @NonNull - private List fields; + public void setTablename(String tablename) { + this.tablename = sanitizeFieldName(tablename); + } + public String getCreateStatement() { + StringBuilder stmt = new StringBuilder(); + stmt.append("CREATE TABLE IF NOT EXISTS " + tablename + "( "); + for (Field field : fields) { - @NonNull - private GeometryType geometryColumnType; + String fieldDefinition = field.getType().getDefinition(); + if (field.getType().equals(FieldType.GEOMETRY)) + fieldDefinition = this.getGeometryColumnType().definition; - @Setter - private BBOX boundingBox=null; + stmt.append(field.getName() + " " + fieldDefinition + ","); + } + stmt.deleteCharAt(stmt.lastIndexOf(",")); + stmt.append(")"); + return stmt.toString(); + } - @Setter - private POINT centroid=null; + public String getDeleteByFieldStatement(Field field) { + return "DELETE FROM " + tablename + " WHERE " + field.getName() + " = ? "; + } - public void setTablename(String tablename) { - this.tablename = sanitizeFieldName(tablename); - } + public String getInsertionStatement(boolean geometryText) { + StringBuilder fieldList = new StringBuilder(); + StringBuilder fieldInsertion = new StringBuilder(); - public String getCreateStatement() { - StringBuilder stmt=new StringBuilder(); - stmt.append("CREATE TABLE IF NOT EXISTS "+tablename+"( "); - for(Field field:fields){ + for (Field field : fields) { + switch (field.getType()) { + case AUTOINCREMENT: + break; + case GEOMETRY: { + fieldList.append(field.getName() + ","); + if (geometryText) + fieldInsertion.append("ST_GeomFromText(?, 4326),"); + else + fieldInsertion.append("ST_GeomFromWKB(?, 4326),"); + break; + } + default: { + fieldList.append(field.getName() + ","); + fieldInsertion.append("?,"); + } + } + } - String fieldDefinition=field.getType().getDefinition(); - if(field.getType().equals(FieldType.GEOMETRY)) - fieldDefinition=this.getGeometryColumnType().definition; + fieldList.deleteCharAt(fieldList.lastIndexOf(",")); + fieldInsertion.deleteCharAt(fieldInsertion.lastIndexOf(",")); - stmt.append(field.getName()+" "+fieldDefinition+","); - } - stmt.deleteCharAt(stmt.lastIndexOf(",")); - stmt.append(")"); - return stmt.toString(); - } + return "Insert into " + tablename + " (" + fieldList + ") VALUES (" + fieldInsertion + ")"; + } - public String getDeleteByFieldStatement(Field field) { - return "DELETE FROM "+tablename+" WHERE "+field.getName()+" = ? "; - } + public void fillObjectsPreparedStatement(Map row, PreparedStatement toFill) throws SQLException { + int psFieldIndex = 0; + HashMap rowValues = new HashMap(); + for (Map.Entry entry : row.entrySet()) + rowValues.put(sanitizeFieldName(entry.getKey()), entry.getValue()); + for (Field field : fields) { + if (!field.getType().equals(FieldType.AUTOINCREMENT)) { + psFieldIndex++; - public String getInsertionStatement(boolean geometryText) { - StringBuilder fieldList=new StringBuilder(); - StringBuilder fieldInsertion=new StringBuilder(); + Object value = rowValues.get(field.getName()); + setObjectInPreparedStatement(field, value, toFill, psFieldIndex); - for(Field field:fields) { - switch(field.getType()) { - case AUTOINCREMENT : break; - case GEOMETRY : { - fieldList.append(field.getName()+","); - if(geometryText) - fieldInsertion.append("ST_GeomFromText(?, 4326),"); - else - fieldInsertion.append("ST_GeomFromWKB(?, 4326),"); - break; - } - default : { - fieldList.append(field.getName()+","); - fieldInsertion.append("?,"); - } - } - } + } - fieldList.deleteCharAt(fieldList.lastIndexOf(",")); - fieldInsertion.deleteCharAt(fieldInsertion.lastIndexOf(",")); + } + } + public void setObjectInPreparedStatement(Field field, Object value, PreparedStatement toFill, int psFieldIndex) + throws SQLException { + if (value == null) { + try { + toFill.setNull(psFieldIndex, field.getType().sqlType); + } catch (SQLException e) { + log.error("Unable to set null for field " + field); + throw e; + } + } else { + switch (field.getType()) { + case FLOAT: { + toFill.setFloat(psFieldIndex, (Float) value); + break; + } + case INT: { + toFill.setInt(psFieldIndex, (Integer) value); + break; + } + case TEXT: { + toFill.setString(psFieldIndex, value.toString()); + break; + } + case GEOMETRY: { + if (value instanceof String) + toFill.setString(psFieldIndex, ((String) value)); + else + toFill.setBytes(psFieldIndex, (byte[]) value); + break; + } + case BOOLEAN: { + if (value instanceof String) + toFill.setBoolean(psFieldIndex, Boolean.parseBoolean(value.toString())); + if (value instanceof Boolean) + toFill.setBoolean(psFieldIndex, (Boolean) value); + break; + } + // Added by Francesco + default: { + if (value instanceof String) { + toFill.setString(psFieldIndex, ((String) value)); + } else { + try { + String toStringValue = value.toString(); + toFill.setString(psFieldIndex, toStringValue); + } catch (Exception e) { + // silence + } + } + } + } + } + } - return "Insert into "+tablename+" ("+fieldList+") VALUES ("+fieldInsertion+")"; - } + public void fillCSVPreparedStatament(Map row, PreparedStatement toFill, boolean explicitGeometry) + throws SQLException { + int psFieldIndex = 0; + HashMap rowValues = new HashMap(); + for (Map.Entry entry : row.entrySet()) + rowValues.put(sanitizeFieldName(entry.getKey()), entry.getValue()); - public void fillObjectsPreparedStatement(Map row, PreparedStatement toFill) throws SQLException { - int psFieldIndex=0; - HashMap rowValues=new HashMap(); - for(Map.Entry entry:row.entrySet()) - rowValues.put(sanitizeFieldName(entry.getKey()), entry.getValue()); + for (Field field : fields) { + if (!field.getType().equals(FieldType.AUTOINCREMENT)) { + psFieldIndex++; - for(Field field:fields) { - if(!field.getType().equals(FieldType.AUTOINCREMENT)) { - psFieldIndex++; - - Object value=rowValues.get(field.getName()); - setObjectInPreparedStatement(field,value,toFill,psFieldIndex); - - } - - - } - } - - - public void setObjectInPreparedStatement(Field field,Object value, PreparedStatement toFill, int psFieldIndex) throws SQLException { - if(value==null) { - try{ - toFill.setNull(psFieldIndex, field.getType().sqlType); - }catch(SQLException e) { - log.error("Unable to set null for field "+field); - throw e; - } - } - else - switch(field.getType()) { - case FLOAT :{ - toFill.setFloat(psFieldIndex, (Float)value); - break; - } - case INT : { - toFill.setInt(psFieldIndex, (Integer)value); - break; - } - case TEXT : { - toFill.setString(psFieldIndex, value.toString()); - break; - } - case GEOMETRY : { - if(value instanceof String) - toFill.setString(psFieldIndex, ((String) value)); - else toFill.setBytes(psFieldIndex, (byte[])value); - break; - } - case BOOLEAN: { - if(value instanceof String) - toFill.setBoolean(psFieldIndex,Boolean.parseBoolean(value.toString())); - if(value instanceof Boolean) - toFill.setBoolean(psFieldIndex,(Boolean) value); - break; - } - } - } - - public void fillCSVPreparedStatament(Map row, PreparedStatement toFill,boolean explicitGeometry) throws SQLException { - int psFieldIndex=0; - - HashMap rowValues=new HashMap(); - for(Map.Entry entry:row.entrySet()) - rowValues.put(sanitizeFieldName(entry.getKey()), entry.getValue()); - - for(Field field:fields) { - - - if(!field.getType().equals(FieldType.AUTOINCREMENT)) { - psFieldIndex++; - - String value=rowValues.get(field.getName()); + String value = rowValues.get(field.getName()); // if(value==null||value.equalsIgnoreCase("null")) toFill.setNull(psFieldIndex, field.getType().sqlType); // else - switch(field.getType()) { - case FLOAT :{ - try{ - toFill.setFloat(psFieldIndex, Float.parseFloat(value)); - }catch(NumberFormatException e) { - throw new SQLException(field+" cannot be null. CSV Row is "+rowValues,e); - } - break; - } - case INT : { - try{ - toFill.setInt(psFieldIndex, Integer.parseInt(value)); - }catch(NumberFormatException e) { - log.warn("Skipping value for "+field+" row was "+rowValues,e); - toFill.setNull(psFieldIndex, java.sql.Types.INTEGER); - } - break; - } - case TEXT : { - toFill.setString(psFieldIndex, value.toString()); - break; - } - case GEOMETRY : { - if(explicitGeometry) { - toFill.setString(psFieldIndex,value); - }else { - switch(geometryColumnType){ - case POINT: { - String xRepresentation=DECIMAL_FORMAT.format(Double.parseDouble(rowValues.get(DBConstants.Defaults.XCOORD_FIELD))); - String yRepresentation=DECIMAL_FORMAT.format(Double.parseDouble(rowValues.get(DBConstants.Defaults.YCOORD_FIELD))); + switch (field.getType()) { + case FLOAT: { + try { + toFill.setFloat(psFieldIndex, Float.parseFloat(value)); + } catch (NumberFormatException e) { + throw new SQLException(field + " cannot be null. CSV Row is " + rowValues, e); + } + break; + } + case INT: { + try { + toFill.setInt(psFieldIndex, Integer.parseInt(value)); + } catch (NumberFormatException e) { + log.warn("Skipping value for " + field + " row was " + rowValues, e); + toFill.setNull(psFieldIndex, java.sql.Types.INTEGER); + } + break; + } + case TEXT: { + toFill.setString(psFieldIndex, value.toString()); + break; + } + case GEOMETRY: { + if (explicitGeometry) { + toFill.setString(psFieldIndex, value); + } else { + switch (geometryColumnType) { + case POINT: { + String xRepresentation = DECIMAL_FORMAT + .format(Double.parseDouble(rowValues.get(DBConstants.Defaults.XCOORD_FIELD))); + String yRepresentation = DECIMAL_FORMAT + .format(Double.parseDouble(rowValues.get(DBConstants.Defaults.YCOORD_FIELD))); - toFill.setString(psFieldIndex, "POINT("+xRepresentation+" "+ - yRepresentation+")"); - break; - } - default :{ - toFill.setString(psFieldIndex,rowValues.get("wkt")); - break; - } - } - } - break; - } - } - } + toFill.setString(psFieldIndex, "POINT(" + xRepresentation + " " + yRepresentation + ")"); + break; + } + default: { + toFill.setString(psFieldIndex, rowValues.get("wkt")); + break; + } + } + } + break; + } + } + } + } + } - - - } - } - - public static String sanitizeFieldName(String fieldName) { + public static String sanitizeFieldName(String fieldName) { // return fieldName.toLowerCase().replaceAll(" ", "_").replaceAll("\\.", "").replaceAll("-", "_").replaceAll("////","_"); - return fieldName.toLowerCase().replaceAll("[^a-z0-9_\\\\]", "_"); - } - - - + return fieldName.toLowerCase().replaceAll("[^a-z0-9_\\\\]", "_"); + } } diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java index ecec027..e5d3771 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java @@ -118,6 +118,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId()); centroidDoc.put(DBConstants.Defaults.DISPLAYED, true); + //Added by Francesco. Creating Gis Viewer Link as public or private Boolean isInternalIndex = null; try { isInternalIndex = requestArguments.getBoolean("flagInternalIndex"); -- 2.17.1 From 292fe88107e5546dcc4c35f5950ecb1035bc5650 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 12:04:24 +0200 Subject: [PATCH 09/14] Added GEOV_LINK as PostgisTable.Field --- .../application/cms/sdi/engine/PostgisIndexer.java | 4 ++-- .../cms/sdi/plugins/SDIIndexerPlugin.java | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java index 3dfec18..da0a1d4 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/engine/PostgisIndexer.java @@ -39,8 +39,8 @@ public class PostgisIndexer { public static class StandardFields{ public static final PostgisTable.Field PROJECT_ID= new PostgisTable.Field(DBConstants.Defaults.PROJECT_ID, PostgisTable.FieldType.TEXT); public static final PostgisTable.Field GEOM= new PostgisTable.Field(DBConstants.Defaults.DEFAULT_GEOMETRY_COLUMN_NAME, PostgisTable.FieldType.GEOMETRY); - public static final PostgisTable.Field DISPLAY=new PostgisTable.Field(DBConstants.Defaults.DISPLAYED,PostgisTable.FieldType.BOOLEAN); + public static final PostgisTable.Field GEOV_LINK=new PostgisTable.Field(DBConstants.Defaults.GEOVIEWER_LINK_FIELD,PostgisTable.FieldType.TEXT); } @@ -85,10 +85,10 @@ public class PostgisIndexer { tableFields.add(StandardFields.GEOM); tableFields.add(StandardFields.PROJECT_ID); tableFields.add(StandardFields.DISPLAY); + tableFields.add(StandardFields.GEOV_LINK); tableFields.addAll(customFields); - table = new PostgisTable(indexName,tableFields, PostgisTable.GeometryType.POINT); log.trace("Index Postgis Table is {} ",table); log.debug("Create if missing.."); diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java index e5d3771..31b83e2 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java @@ -79,11 +79,15 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin } /** - * Expected parameters : - indexName (unique) - workspace - flagInternalIndex: - * boolean - centroidRecord (OPT) + * Expected parameters : + * - indexName (unique) + * - workspace + * - flagInternalIndex as Boolean; + * boolean - centroidRecord (OPT). * - * @param request - * @return + * @param request the request + * @return the index document report + * @throws InvalidPluginRequestException the invalid plugin request exception */ @Override -- 2.17.1 From 7fb96e75fe916ea6dd970bc66c62680273f36a9d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 14:38:10 +0200 Subject: [PATCH 10/14] Fixing "Draft" execution step executing dematerialization and de-indexing actions [#24877] --- default-lc-managers/CHANGELOG.md | 1 + .../implementations/Default3PhaseManager.java | 81 ++++++++++++------- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/default-lc-managers/CHANGELOG.md b/default-lc-managers/CHANGELOG.md index bd9d68d..aa6639e 100644 --- a/default-lc-managers/CHANGELOG.md +++ b/default-lc-managers/CHANGELOG.md @@ -3,6 +3,7 @@ ## [v1.2.0-SNAPSHOT] - Integrated the field 'geov_link' (Geoportal GisViewer link) in the centroid layer [#24859] +- Fixed Draft execution step executing dematerialization and de-indexing actions [#24877] ## [v1.1.1] - 2023-03-06 diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java index 019c490..c99e911 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java @@ -177,37 +177,62 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life return callParameters; } - protected StepExecutionReport executeSubmit(StepExecutionReport theReport) throws Exception { - // Materialize + protected StepExecutionReport executeSubmit(StepExecutionReport theReport) throws Exception { + log.info(STEPS.SUBMIT + " running..."); - for(MaterializationPlugin mat : getMaterializers(theReport.getTheRequest())) - theReport = materializeDocument(theReport,mat,getMaterializationParameters(theReport.getTheRequest())); - if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){ - // Index - for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest())) - theReport = index(theReport,indexer,getInternalIndexParams(theReport.getTheRequest())); - // setPhase - if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) - theReport.getToSetLifecycleInformation().setPhase(Phases.PENDING_APPROVAL); - } - return theReport; - } + // Materialize + for (MaterializationPlugin mat : getMaterializers(theReport.getTheRequest())) + theReport = materializeDocument(theReport, mat, getMaterializationParameters(theReport.getTheRequest())); + if (theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) { + // Index + for (IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest())) + theReport = index(theReport, indexer, getInternalIndexParams(theReport.getTheRequest())); + // setPhase + if (theReport.getToSetLifecycleInformation().getLastOperationStatus() + .equals(LifecycleInformation.Status.OK)) + theReport.getToSetLifecycleInformation().setPhase(Phases.PENDING_APPROVAL); + } + return theReport; + } - protected StepExecutionReport executeApprove(StepExecutionReport theReport) throws Exception { - // Index - for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest())) - theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest())); - // setPhase - if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) - theReport.getToSetLifecycleInformation().setPhase(Phases.PUBLISHED); - return theReport; - } + protected StepExecutionReport executeApprove(StepExecutionReport theReport) throws Exception { + log.info(STEPS.APPROVE + " running..."); - protected StepExecutionReport executeReject(StepExecutionReport theReport) throws Exception { - if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) - theReport.getToSetLifecycleInformation().setPhase(LifecycleInformation.CommonPhases.DRAFT_PHASE); - return theReport; - } + // Index + for (IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest())) + theReport = index(theReport, indexer, getPublicIndexParams(theReport.getTheRequest())); + // setPhase + if (theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) + theReport.getToSetLifecycleInformation().setPhase(Phases.PUBLISHED); + return theReport; + } + + protected StepExecutionReport executeReject(StepExecutionReport theReport) throws Exception { + log.info(STEPS.REJECT + " running..."); + + // DeMaterialize + JSONPathWrapper wrapper = new JSONPathWrapper( + theReport.getTheRequest().getDocument().getTheDocument().toJson()); + for (String s : wrapper.getMatchingPaths("$..[?(@." + RegisteredFileSet.PAYLOADS + ")]")) { + log.info("Requesting dematerialization for {} ", s); + for (MaterializationPlugin mat : getMaterializers(theReport.getTheRequest())) + theReport = deMaterialize(theReport, mat, new Document("fileSetPath", s)); + if (!theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) + break; + } + // DeIndexing + if (theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) { + for (IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest())) { + log.info("Requesting deindexing for {} ", indexer.getDescriptor()); + theReport = deIndex(theReport, indexer, getInternalIndexParams(theReport.getTheRequest())); + } + } + + if (theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) + theReport.getToSetLifecycleInformation().setPhase(LifecycleInformation.CommonPhases.DRAFT_PHASE); + + return theReport; + } } -- 2.17.1 From 17299c7dd19336c1687c7fed1d85d8801679702a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 16:21:00 +0200 Subject: [PATCH 11/14] Created and used the IndexConstants class --- .../implementations/AbstractLifeCycleManager.java | 2 +- .../implementations/Default3PhaseManager.java | 12 ++++++------ .../implementations/SimpleLifeCycleManager.java | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java index 551e70f..5ea2117 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java @@ -41,7 +41,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class AbstractLifeCycleManager extends AbstractPlugin implements LifecycleManager { - + protected static class Events{ public static final OperationDescriptor INIT=new OperationDescriptor(EventExecutionRequest.Events.ON_INIT_DOCUMENT,"Sets defaults and validate"); public static final OperationDescriptor UPDATE=new OperationDescriptor(EventExecutionRequest.Events.ON_UPDATE_DOCUMENT,"Sets defaults and validate"); diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java index c99e911..34ae9a5 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java @@ -29,7 +29,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class Default3PhaseManager extends SimpleLifeCycleManager implements LifecycleManager { - protected static class Phases { + protected static class Phases { public static final String PENDING_APPROVAL="Pending Approval"; public static final String PUBLISHED=SimpleLifeCycleManager.Phases.PUBLISHED; @@ -171,9 +171,10 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life protected Document getInternalIndexParams(BaseRequest req){ Document callParameters = new Document(); - callParameters.put("workspace", Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName())); - callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName()+"_centroids")); - callParameters.put("flagInternalIndex", Boolean.TRUE); + callParameters.put(IndexConstants.INDEX_PARAMETER_WORKSPACE, Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName())); + callParameters.put(IndexConstants.INDEX_PARAMETER_INDEXNAME,Files.fixFilename(req.getUseCaseDescriptor().getId()+"_internal_"+req.getContext().getName()+"_centroids")); + //Added by Francesco + callParameters.put(IndexConstants.INDEX_PARAMETER_FLAGINTERNALINDEX, Boolean.TRUE); return callParameters; } @@ -211,8 +212,7 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life log.info(STEPS.REJECT + " running..."); // DeMaterialize - JSONPathWrapper wrapper = new JSONPathWrapper( - theReport.getTheRequest().getDocument().getTheDocument().toJson()); + JSONPathWrapper wrapper = new JSONPathWrapper(theReport.getTheRequest().getDocument().getTheDocument().toJson()); for (String s : wrapper.getMatchingPaths("$..[?(@." + RegisteredFileSet.PAYLOADS + ")]")) { log.info("Requesting dematerialization for {} ", s); for (MaterializationPlugin mat : getMaterializers(theReport.getTheRequest())) diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java index 8e49858..de1833f 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/SimpleLifeCycleManager.java @@ -93,9 +93,9 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements protected Document getPublicIndexParams(BaseRequest req){ Document callParameters = new Document(); - callParameters.put("workspace",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName())); - callParameters.put("indexName",Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName()+"_centroids")); - callParameters.put("flagInternalIndex", Boolean.FALSE); + callParameters.put(IndexConstants.INDEX_PARAMETER_WORKSPACE,Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName())); + callParameters.put(IndexConstants.INDEX_PARAMETER_INDEXNAME,Files.fixFilename(req.getUseCaseDescriptor().getId()+req.getContext().getName()+"_centroids")); + callParameters.put(IndexConstants.INDEX_PARAMETER_FLAGINTERNALINDEX, Boolean.FALSE); return callParameters; } -- 2.17.1 From 7a7c79ef17c727db9dfcfbba1afb7efcbf8a2627 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 16:21:28 +0200 Subject: [PATCH 12/14] Added the IndexConstants class --- .../plugins/implementations/IndexConstants.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/IndexConstants.java diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/IndexConstants.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/IndexConstants.java new file mode 100644 index 0000000..3855ac4 --- /dev/null +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/IndexConstants.java @@ -0,0 +1,16 @@ +package org.gcube.application.cms.plugins.implementations; + +/** + * The Class IndexConstants. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 29, 2023 + */ +public class IndexConstants { + + public static final String INDEX_PARAMETER_FLAGINTERNALINDEX = "flagInternalIndex"; + public static final String INDEX_PARAMETER_INDEXNAME = "indexName"; + public static final String INDEX_PARAMETER_WORKSPACE = "workspace"; + +} -- 2.17.1 From b37bd0644003580b872e0bb56e48c096ceaafb68 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 16:21:57 +0200 Subject: [PATCH 13/14] Used the IndexConstants class --- .../cms/sdi/plugins/SDIIndexerPlugin.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java index 31b83e2..98ad5c5 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java @@ -12,6 +12,7 @@ import org.gcube.application.cms.plugins.faults.IndexingException; import org.gcube.application.cms.plugins.faults.InitializationException; import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException; import org.gcube.application.cms.plugins.faults.InvalidProfileException; +import org.gcube.application.cms.plugins.implementations.IndexConstants; import org.gcube.application.cms.plugins.reports.IndexDocumentReport; import org.gcube.application.cms.plugins.reports.InitializationReport; import org.gcube.application.cms.plugins.reports.Report; @@ -79,11 +80,8 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin } /** - * Expected parameters : - * - indexName (unique) - * - workspace - * - flagInternalIndex as Boolean; - * boolean - centroidRecord (OPT). + * Expected parameters : - indexName (unique) - workspace - flagInternalIndex as + * Boolean; boolean - centroidRecord (OPT). * * @param request the request * @return the index document report @@ -122,15 +120,16 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId()); centroidDoc.put(DBConstants.Defaults.DISPLAYED, true); - //Added by Francesco. Creating Gis Viewer Link as public or private + // Added by Francesco. Creating Gis Viewer Link as public or private Boolean isInternalIndex = null; try { - isInternalIndex = requestArguments.getBoolean("flagInternalIndex"); - log.debug("flagInternalIndex read as {} ", isInternalIndex); + isInternalIndex = requestArguments + .getBoolean(IndexConstants.INDEX_PARAMETER_FLAGINTERNALINDEX); + log.debug(IndexConstants.INDEX_PARAMETER_FLAGINTERNALINDEX + " read as {} ", isInternalIndex); } catch (Exception e) { // TODO: handle exception } - log.info("flagInternalIndex is {} ", isInternalIndex); + log.info(IndexConstants.INDEX_PARAMETER_FLAGINTERNALINDEX + " is {} ", isInternalIndex); if (isInternalIndex != null) { try { @@ -332,8 +331,9 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin List mappingObjects = getMappings(ucd); List fields = PostgisTable.Field.fromMappings(mappingObjects); - indexer.initIndex(params.getString("indexName"), fields, params.getString("workspace"), - params.getString("indexName")); + indexer.initIndex(params.getString(IndexConstants.INDEX_PARAMETER_INDEXNAME), fields, + params.getString(IndexConstants.INDEX_PARAMETER_WORKSPACE), + params.getString(IndexConstants.INDEX_PARAMETER_INDEXNAME)); return indexer; } -- 2.17.1 From 4964056fb49456535af03cc96a8dc281c0523b81 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 29 Mar 2023 16:27:19 +0200 Subject: [PATCH 14/14] Added comment --- .../cms/plugins/implementations/Default3PhaseManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java index 34ae9a5..5315e73 100644 --- a/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java +++ b/default-lc-managers/src/main/java/org/gcube/application/cms/plugins/implementations/Default3PhaseManager.java @@ -208,6 +208,7 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life return theReport; } + //Updated by Francesco, see #24877 protected StepExecutionReport executeReject(StepExecutionReport theReport) throws Exception { log.info(STEPS.REJECT + " running..."); -- 2.17.1