From 23dae96c830f50a706698961178d08bd27568768 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Mar 2023 15:25:57 +0100 Subject: [PATCH 1/7] #24754 first patched version --- concessioni-lifecycle/CHANGELOG.md | 3 + concessioni-lifecycle/pom.xml | 2 +- .../plugins/ConcessioniLifeCycleManager.java | 501 ++++++++++++------ .../plugins/ConcessioniPluginTests.java | 42 ++ 4 files changed, 380 insertions(+), 168 deletions(-) diff --git a/concessioni-lifecycle/CHANGELOG.md b/concessioni-lifecycle/CHANGELOG.md index df0576d..40e009a 100644 --- a/concessioni-lifecycle/CHANGELOG.md +++ b/concessioni-lifecycle/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog for org.gcube.application.cms.concessioni-lifecycle +## [v1.1.0-SNAPSHOT] - 2023-03-13 +- [#24754] Fixed hide/show project ids on the latest node of the relation chain + ## [v1.0.4] - 2023-03-06 - [#24702] Fixed the default-lc-managers dependency diff --git a/concessioni-lifecycle/pom.xml b/concessioni-lifecycle/pom.xml index 4d7409b..47e9ded 100644 --- a/concessioni-lifecycle/pom.xml +++ b/concessioni-lifecycle/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 concessioni-lifecycle - 1.0.4 + 1.1.0-SNAPSHOT GNA Concessioni Lifecycle diff --git a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java index 527438c..fbecea0 100644 --- a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java +++ b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java @@ -1,7 +1,11 @@ package org.gcube.application.cms.concessioni.plugins; -import com.vdurmont.semver4j.Semver; -import lombok.extern.slf4j.Slf4j; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + import org.bson.Document; import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione; import org.gcube.application.cms.implementations.ImplementationProvider; @@ -15,219 +19,382 @@ import org.gcube.application.cms.plugins.requests.IndexDocumentRequest; import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.geoportal.common.model.JSONPathWrapper; import org.gcube.application.geoportal.common.model.document.Project; -import org.gcube.application.geoportal.common.model.document.access.Access; -import org.gcube.application.geoportal.common.model.document.access.AccessPolicy; -import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet; +import org.gcube.application.geoportal.common.model.document.relationships.Relationship; import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import com.vdurmont.semver4j.Semver; + +import lombok.extern.slf4j.Slf4j; @Slf4j -/** Overrides 3 Phases lifecycle with override of default values +/** + * Overrides 3 Phases lifecycle with override of default values * */ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements LifecycleManager { + private static final String FOLLOWS = "follows"; + private static final String PRECEDES = "precedes"; - private static final String FOLLOWS="follows"; - private static final String PRECEDES="precedes"; + public ConcessioniLifeCycleManager() { + DESCRIPTOR.setId("GNA-CONCESSIONI-LC"); + DESCRIPTOR.setDescription( + "GNA Concessioni. This plugin supports custom lifecycle management for the GNA Concessioni UseCase."); + DESCRIPTOR.setVersion(new Semver("1.0.0")); + } + @Override + public EventExecutionReport setDefault(EventExecutionReport currentReport) { + EventExecutionReport report = super.setDefault(currentReport); + try { + report.setResultingDocument(setDefaults(report.getTheRequest().getDocument()).getTheDocument()); + } catch (Throwable t) { + log.error("Unable to evaluate defaults for concessione " + + currentReport.getTheRequest().getDocument().getId(), t); + log.debug("Object was {} ", report.getTheRequest().getDocument()); + report.setStatus(Report.Status.ERROR); + report.getMessages().add("Unable to evaluate defaults : " + t.getMessage()); + } + return report; + } - public ConcessioniLifeCycleManager() { - DESCRIPTOR.setId("GNA-CONCESSIONI-LC"); - DESCRIPTOR.setDescription("GNA Concessioni. This plugin supports custom lifecycle management for the GNA Concessioni UseCase."); - DESCRIPTOR.setVersion(new Semver("1.0.0")); - } + // STATIC ROUTINES - @Override - public EventExecutionReport setDefault(EventExecutionReport currentReport) { - EventExecutionReport report = super.setDefault(currentReport); - try{ - report.setResultingDocument(setDefaults(report.getTheRequest().getDocument()).getTheDocument()); - }catch (Throwable t){ - log.error("Unable to evaluate defaults for concessione "+currentReport.getTheRequest().getDocument().getId(),t); - log.debug("Object was {} ",report.getTheRequest().getDocument()); - report.setStatus(Report.Status.ERROR ); - report.getMessages().add("Unable to evaluate defaults : "+t.getMessage()); - } - return report; - } + static final Project setDefaults(Project document) throws IOException { + log.info("Concessione ID {}, setting defaults..", document.getId()); + log.debug("Full concessione is {}", document); + ProfiledConcessione c = Serialization.convert(document, ProfiledConcessione.class); + Document doc = c.getTheDocument(); + doc.putIfAbsent(ProfiledConcessione.SOGGETTO, new String[] { "Research Excavation", "Archaeology" }); + doc.putIfAbsent(ProfiledConcessione.DESCRIZIONE_CONTENUTO, + "Relazione di fine scavo e relativo abstract; selezione di immagini rappresentative;" + + " posizionamento topografico dell'area indagata, pianta di fine scavo."); - // STATIC ROUTINES + // Super Section + // TODO read from UCD + c.getInfo().getAccess() + .setLicense(ConstraintCheck.defaultFor(c.getInfo().getAccess().getLicense(), "CC0-1.0").evaluate()); - static final Project setDefaults(Project document) throws IOException { - log.info("Concessione ID {}, setting defaults..",document.getId()); - log.debug("Full concessione is {}",document); - ProfiledConcessione c=Serialization.convert(document,ProfiledConcessione.class); - Document doc=c.getTheDocument(); - doc.putIfAbsent(ProfiledConcessione.SOGGETTO,new String[]{"Research Excavation","Archaeology"}); + // RELAZIONE + Document rel = doc.containsKey(ProfiledConcessione.RELAZIONE_SCAVO) + ? Serialization.convert(doc.get(ProfiledConcessione.RELAZIONE_SCAVO), Document.class) + : new Document(); + log.debug("Concessione {}, managing relazione {}", document.getId(), rel); + rel.putIfAbsent(ProfiledConcessione.Sections.TITOLO, + doc.getString(ProfiledConcessione.NOME) + " relazione di scavo"); + rel.putIfAbsent(ProfiledConcessione.SOGGETTO, doc.get(ProfiledConcessione.SOGGETTO)); + doc.put(ProfiledConcessione.RELAZIONE_SCAVO, rel); - doc.putIfAbsent(ProfiledConcessione.DESCRIZIONE_CONTENUTO,"Relazione di fine scavo e relativo abstract; selezione di immagini rappresentative;" - + " posizionamento topografico dell'area indagata, pianta di fine scavo."); + // ABSTRACT Relazione + Document abs = doc.containsKey(ProfiledConcessione.ABSTRACT_RELAZIONE) + ? Serialization.convert(doc.get(ProfiledConcessione.ABSTRACT_RELAZIONE), Document.class) + : new Document(); + log.debug("Concessione {}, managing abstract relazione {}", document.getId(), abs); + abs.putIfAbsent(ProfiledConcessione.Sections.TITOLO, + doc.getString(ProfiledConcessione.NOME) + " abstract relazione di scavo"); + doc.put(ProfiledConcessione.ABSTRACT_RELAZIONE, abs); - // Super Section - // TODO read from UCD - c.getInfo().getAccess().setLicense( - ConstraintCheck.defaultFor(c.getInfo().getAccess().getLicense(), "CC0-1.0").evaluate()); + // Posizionamento scavo + if (doc.containsKey(ProfiledConcessione.POSIZIONAMENTO_SCAVO)) { + Document pos = Serialization.convert(doc.get(ProfiledConcessione.POSIZIONAMENTO_SCAVO), Document.class); + log.debug("Concessione {}, managing posizionamento scavo {}", document.getId(), pos); + pos.putIfAbsent(ProfiledConcessione.Sections.TITOLO, + doc.getString(ProfiledConcessione.NOME) + " posizionamento scavo"); + pos.putIfAbsent(ProfiledConcessione.Sections.ABSTRACT, + "Posizionamento topografico georeferenziato dell’area interessata dalle indagini"); + pos.putIfAbsent(ProfiledConcessione.Layers.TOPIC, "Society"); + pos.putIfAbsent(ProfiledConcessione.Layers.SUB_TOPIC, "Archeology"); + pos.putIfAbsent(ProfiledConcessione.PAROLE_CHIAVE_LIBERE, + doc.get(ProfiledConcessione.PAROLE_CHIAVE_LIBERE)); + pos.putIfAbsent(ProfiledConcessione.PAREOLE_CHIAVE_ICCD, doc.get(ProfiledConcessione.PAREOLE_CHIAVE_ICCD)); + // BBOX in registered filesets - //RELAZIONE - Document rel = doc.containsKey(ProfiledConcessione.RELAZIONE_SCAVO)? - Serialization.convert(doc.get(ProfiledConcessione.RELAZIONE_SCAVO), Document.class):new Document(); - log.debug("Concessione {}, managing relazione {}",document.getId(),rel); - rel.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" relazione di scavo"); - rel.putIfAbsent(ProfiledConcessione.SOGGETTO,doc.get(ProfiledConcessione.SOGGETTO)); - doc.put(ProfiledConcessione.RELAZIONE_SCAVO,rel); + pos.put(ProfiledConcessione.RESPONSABILE, doc.get(ProfiledConcessione.RESPONSABILE)); + doc.put(ProfiledConcessione.POSIZIONAMENTO_SCAVO, pos); + } + // IMMAGINI RAPPRESENTATIVE - //ABSTRACT Relazione - Document abs=doc.containsKey(ProfiledConcessione.ABSTRACT_RELAZIONE)? - Serialization.convert(doc.get(ProfiledConcessione.ABSTRACT_RELAZIONE), Document.class):new Document(); - log.debug("Concessione {}, managing abstract relazione {}",document.getId(),abs); - abs.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" abstract relazione di scavo"); - doc.put(ProfiledConcessione.ABSTRACT_RELAZIONE,abs); + JSONPathWrapper wrapper = new JSONPathWrapper(Serialization.write(doc)); + if (doc.containsKey(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE)) { + List imgs = wrapper.getByPath("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE, List.class).get(0); + log.debug("Concessione {}, found imgs {}", document.getId(), imgs.size()); + for (int i = 0; i < imgs.size(); i++) { + Document imgDoc = Serialization.asDocument(imgs.get(i)); + imgDoc.putIfAbsent(ProfiledConcessione.SOGGETTO, doc.get(ProfiledConcessione.SOGGETTO)); + wrapper.setElement("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE + "[" + i + "]", imgDoc); + } + } - //Posizionamento scavo - if(doc.containsKey(ProfiledConcessione.POSIZIONAMENTO_SCAVO)){ - Document pos = Serialization.convert(doc.get(ProfiledConcessione.POSIZIONAMENTO_SCAVO), Document.class); - log.debug("Concessione {}, managing posizionamento scavo {}",document.getId(),pos); - pos.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" posizionamento scavo"); - pos.putIfAbsent(ProfiledConcessione.Sections.ABSTRACT,"Posizionamento topografico georeferenziato dell’area interessata dalle indagini"); - pos.putIfAbsent(ProfiledConcessione.Layers.TOPIC,"Society"); - pos.putIfAbsent(ProfiledConcessione.Layers.SUB_TOPIC,"Archeology"); + // Layers + if (doc.containsKey(ProfiledConcessione.PIANTE_FINE_SCAVO)) { + List piante = wrapper.getByPath("$." + ProfiledConcessione.PIANTE_FINE_SCAVO, List.class).get(0); + log.debug("Concessione {}, found piante {}", document.getId(), piante.size()); + for (int i = 0; i < piante.size(); i++) { + Document piantaDoc = Serialization.asDocument(piante.get(i)); + log.debug("Concessione {}, managing pianta {}", document.getId(), piantaDoc); + piantaDoc.putIfAbsent(ProfiledConcessione.Sections.TITOLO, + doc.getString(ProfiledConcessione.NOME) + " pianta fine scavo"); + piantaDoc.putIfAbsent(ProfiledConcessione.Sections.ABSTRACT, + "Planimetria georeferenziata dell'area indagata al termine delle attività"); + piantaDoc.putIfAbsent(ProfiledConcessione.Layers.TOPIC, "Society"); + piantaDoc.putIfAbsent(ProfiledConcessione.Layers.SUB_TOPIC, "Archeology"); - pos.putIfAbsent(ProfiledConcessione.PAROLE_CHIAVE_LIBERE,doc.get(ProfiledConcessione.PAROLE_CHIAVE_LIBERE)); - pos.putIfAbsent(ProfiledConcessione.PAREOLE_CHIAVE_ICCD,doc.get(ProfiledConcessione.PAREOLE_CHIAVE_ICCD)); + piantaDoc.putIfAbsent(ProfiledConcessione.PAROLE_CHIAVE_LIBERE, + doc.get(ProfiledConcessione.PAROLE_CHIAVE_LIBERE)); + piantaDoc.putIfAbsent(ProfiledConcessione.PAREOLE_CHIAVE_ICCD, + doc.get(ProfiledConcessione.PAREOLE_CHIAVE_ICCD)); - // BBOX in registered filesets + // BBOX in registered filesets - pos.put(ProfiledConcessione.RESPONSABILE,doc.get(ProfiledConcessione.RESPONSABILE)); - doc.put(ProfiledConcessione.POSIZIONAMENTO_SCAVO,pos); - } + piantaDoc.put(ProfiledConcessione.RESPONSABILE, doc.get(ProfiledConcessione.RESPONSABILE)); - //IMMAGINI RAPPRESENTATIVE + wrapper.setElement("$." + ProfiledConcessione.PIANTE_FINE_SCAVO + "[" + i + "]", piantaDoc); + } + } - JSONPathWrapper wrapper=new JSONPathWrapper(Serialization.write(doc)); - if(doc.containsKey(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE)) { - List imgs=wrapper.getByPath("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE, List.class).get(0); - log.debug("Concessione {}, found imgs {}",document.getId(),imgs.size()); - for (int i = 0; i projects = new ArrayList<>(); + ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class); + // get Last ID in relation chain + projects.add(indexingProject); + if (!indexingProject.getRelationshipsByName(PRECEDES).isEmpty()) + scanRelation(projects, access + .getRelations(indexingProject.getProfileID(), indexingProject.getId(), PRECEDES, true).get(0), + false); + if (!indexingProject.getRelationshipsByName(FOLLOWS).isEmpty()) + scanRelation(projects, access + .getRelations(indexingProject.getProfileID(), indexingProject.getId(), FOLLOWS, true).get(0), + false); - piantaDoc.putIfAbsent(ProfiledConcessione.PAROLE_CHIAVE_LIBERE,doc.get(ProfiledConcessione.PAROLE_CHIAVE_LIBERE)); - piantaDoc.putIfAbsent(ProfiledConcessione.PAREOLE_CHIAVE_ICCD,doc.get(ProfiledConcessione.PAREOLE_CHIAVE_ICCD)); + log.debug("Produced full chain [size : {}] from {}, evaluating last available for PHASE {} ", + projects.size(), indexingProject.getId(), indexingProject.getLifecycleInformation().getPhase()); - // BBOX in registered filesets + List toDisplayId = new ArrayList<>(); + List toHideIds = new ArrayList<>(); - piantaDoc.put(ProfiledConcessione.RESPONSABILE,doc.get(ProfiledConcessione.RESPONSABILE)); + log.trace("Checking from LAST.. "); + // Projects is time -ordered so we scan from last + for (int i = projects.size() - 1; i >= 0; i--) { + Project p = projects.get(i); + log.debug("Currently checking {} : {}", p.getId(), p.getTheDocument().get("nome")); + if (!toDisplayId.isEmpty()) + toHideIds.add(p.getId()); + else { + // Still need to find candidate for displaying feature - wrapper.setElement("$."+ProfiledConcessione.PIANTE_FINE_SCAVO+"["+i+"]",piantaDoc); - } - } + // Our currently indexing project is always a good candidate + if (p.getId().equals(indexingProject.getId())) + toDisplayId.add(p.getId()); + // We check PHASE in order to skip projects not yet in the PHASE we are indexing + else + switch (indexingProject.getLifecycleInformation().getPhase()) { + case Phases.PENDING_APPROVAL: { + if ((p.getLifecycleInformation().getPhase().equals(Phases.PENDING_APPROVAL) + || p.getLifecycleInformation().getPhase().equals(Phases.PUBLISHED))) + toDisplayId.add(p.getId()); + break; + } + case Phases.PUBLISHED: { + if (p.getLifecycleInformation().getPhase().equals(Phases.PUBLISHED)) + toDisplayId.add(p.getId()); + break; + } + } - c.setTheDocument(Serialization.read(wrapper.getValueCTX().jsonString(),Document.class)); - return c; - } + if (!toDisplayId.isEmpty()) + log.debug("Found last concessioni candidate for displaying. ID {}, PHASE {} ", toDisplayId, + p.getLifecycleInformation().getPhase()); + else + toHideIds.add(p.getId()); // Still not found + } + } + toReturn.put("_toHideIds", toHideIds); + toReturn.put("_toDisplayIds", toDisplayId); - @Override - protected Document evaluateAdditionalIndexParameters(IndexDocumentRequest request) throws IndexingException { - Document toReturn = super.evaluateAdditionalIndexParameters(request); - if(toReturn == null) toReturn = new Document(); - Project indexingProject = request.getDocument(); + log.info("Indexing request for Concessione [ID {}] with to HIDE {} and toDisplay {} ", + indexingProject.getId(), toHideIds, toDisplayId); + return toReturn; + } catch (Exception e) { + log.error("Unable to evaluate to Hide and Display Ids ", e); + throw new IndexingException("Unable to evaluate chain ids to hide / display", e); + } - // Evaluate to display project IDs - log.info("Evaluating Last ID in relationship chain. Current Concessione ID is {}",indexingProject.getId()); - try { - ArrayList projects = new ArrayList<>(); - ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class); - // get Last ID in relation chain - projects.add(indexingProject); - if(!indexingProject.getRelationshipsByName(PRECEDES).isEmpty()) - scanRelation(projects,access.getRelations(indexingProject.getProfileID(), indexingProject.getId(), PRECEDES,true).get(0),false); - if(!indexingProject.getRelationshipsByName(FOLLOWS).isEmpty()) - scanRelation(projects,access.getRelations(indexingProject.getProfileID(), indexingProject.getId(), FOLLOWS,true).get(0),false); + } - log.debug("Produced full chain [size : {}] from {}, evaluating last available for PHASE {} ",projects.size(),indexingProject.getId(), - indexingProject.getLifecycleInformation().getPhase()); + /** + * New method implemented by Francesco + */ + @Override + protected Document evaluateAdditionalIndexParameters(IndexDocumentRequest request) throws IndexingException { + Document toReturn = super.evaluateAdditionalIndexParameters(request); + if (toReturn == null) + toReturn = new Document(); + Project indexingProject = request.getDocument(); - List toDisplayId = new ArrayList<>(); - List toHideIds = new ArrayList<>(); + // Evaluate to display project IDs + log.debug("Evaluating Last ID in relationship chain. Current Concessione ID is {}", indexingProject.getId()); + try { + ArrayList projects = new ArrayList<>(); + ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class); + // get Last ID in relation chain + projects.add(indexingProject); + if (!indexingProject.getRelationshipsByName(PRECEDES).isEmpty()) + scanRelation(projects, access + .getRelations(indexingProject.getProfileID(), indexingProject.getId(), PRECEDES, true).get(0), + false); + if (!indexingProject.getRelationshipsByName(FOLLOWS).isEmpty()) + scanRelation(projects, access + .getRelations(indexingProject.getProfileID(), indexingProject.getId(), FOLLOWS, true).get(0), + false); - log.trace("Checking from LAST.. "); - // Projects is time -ordered so we scan from last - for(int i = projects.size()-1;i>=0;i--) { - Project p = projects.get(i); - log.debug("Currently checking {} : {}",p.getId(),p.getTheDocument().get("nome")); - if(!toDisplayId.isEmpty()) - toHideIds.add(p.getId()); - else { - //Still need to find candidate for displaying feature + log.debug("Produced full chain [size : {}] from {}, evaluating last available for PHASE {} ", + projects.size(), indexingProject.getId(), indexingProject.getLifecycleInformation().getPhase()); - //Our currently indexing project is always a good candidate - if(p.getId().equals(indexingProject.getId())) - toDisplayId.add(p.getId()); - //We check PHASE in order to skip projects not yet in the PHASE we are indexing - else switch(indexingProject.getLifecycleInformation().getPhase()){ - case Phases.PENDING_APPROVAL:{ - if ((p.getLifecycleInformation().getPhase().equals(Phases.PENDING_APPROVAL)|| - p.getLifecycleInformation().getPhase().equals(Phases.PUBLISHED))) - toDisplayId.add(p.getId()); - break; - } - case Phases.PUBLISHED:{ - if (p.getLifecycleInformation().getPhase().equals(Phases.PUBLISHED)) - toDisplayId.add(p.getId()); - break; - } - } + log.info("projects are: " + projects.size()); - if(!toDisplayId.isEmpty()) - log.debug("Found last concessioni candidate for displaying. ID {}, PHASE {} ",toDisplayId,p.getLifecycleInformation().getPhase()); - else toHideIds.add(p.getId()); // Still not found - } - } + List toDisplayId = new ArrayList<>(); + List toHideIds = new ArrayList<>(); - toReturn.put("_toHideIds",toHideIds); - toReturn.put("_toDisplayIds",toDisplayId); + // Reverse Order means from the last FOLLOW to the first one (temporal reverse + // order) + Collections.sort(projects, Collections.reverseOrder(new ProjectRelationComparator())); + if (log.isDebugEnabled()) { + int j = 0; + log.debug("Printing project reverse order...."); + for (Project theProject : projects) { + log.debug(++j + ") " + theProject.getId() + " data inizio: " + + theProject.getTheDocument().get("dataInizioProgetto")); + } + } - log.info("Indexing request for Concessione [ID {}] with to HIDE {} and toDisplay {} ",indexingProject.getId(),toHideIds,toDisplayId); - return toReturn; - } catch (Exception e) { - log.error("Unable to evaluate to Hide and Display Ids ",e); - throw new IndexingException("Unable to evaluate chain ids to hide / display",e); - } + log.trace("Checking from LAST.. "); - } + for (int i = 0; i < projects.size(); i++) { - private static void scanRelation(ArrayList chain,RelationshipNavigationObject obj, boolean putBefore){ - if(putBefore)chain.add(0,obj.getTarget()); - else chain.add(obj.getTarget()); - if(obj.getChildren()!=null) - obj.getChildren().forEach(r-> scanRelation(chain,r,putBefore)); - } + Project p = projects.get(i); + String phase = p.getLifecycleInformation().getPhase(); + + // IS TO DISPLAY EMPTY? Step into only once + if (toDisplayId.isEmpty()) { + // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding toDisplayId + if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) { + toDisplayId.add(p.getId()); + } + } else { + + // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding (the remaining) toHideIds + switch (phase) { + case Phases.PENDING_APPROVAL: + case Phases.PUBLISHED: { + toHideIds.add(p.getId()); + break; + } + } + } + } + + toReturn.put("_toHideIds", toHideIds); + toReturn.put("_toDisplayIds", toDisplayId); + + log.info("Indexing request for Concessione [ID {}] with to HIDE {} and toDisplay {} ", + indexingProject.getId(), toHideIds, toDisplayId); + return toReturn; + } catch (Exception e) { + log.error("Unable to evaluate to Hide and Display Ids ", e); + throw new IndexingException("Unable to evaluate chain ids to hide / display", e); + } + + } + + private static void scanRelation(ArrayList chain, RelationshipNavigationObject obj, boolean putBefore) { + if (putBefore) + chain.add(0, obj.getTarget()); + else + chain.add(obj.getTarget()); + if (obj.getChildren() != null) + obj.getChildren().forEach(r -> scanRelation(chain, r, putBefore)); + } + + public static class ProjectRelationComparator implements Comparator { + @Override + public int compare(Project p1, Project p2) { + + if (p1 == null) + return 1; + if (p2 == null) + return -1; + + Integer compareResult = null; + compareResult = compareProjectAgainstRelations(p1, p2); + log.trace("p1 & p2, comparator result: {}", compareResult); + if (compareResult == null) { + log.debug("No relations beetween p1 & p2, checking inverted relations"); + compareResult = compareProjectAgainstRelations(p2, p1); + log.trace("p2 & p1, comparator result: {}", compareResult); + + if (compareResult == null) { + log.trace("p1 & p2, are not comparable, returning 0"); + compareResult = 0; + } + } + + log.debug("p1 & p2, comparator result, returns: {}", compareResult); + return compareResult; + } + } + + public static Integer compareProjectAgainstRelations(Project source, Project target) { + log.debug("comparing source {} and target {}", source.getId(), target.getId()); + List listRel = source.getRelationships(); + log.debug("relationships of {} are : {}", source.getId(), listRel); + if (listRel != null) { + String targetId = target.getId(); + for (Relationship relationship : listRel) { + String relTargetId = relationship.getTargetID(); + if (targetId.compareTo(relTargetId) == 0) { + String relationName = relationship.getRelationshipName(); + if (relationName.equals(PRECEDES)) { + log.debug("source {} [rel {} ] target {}, so source < target ", source.getId(), PRECEDES, + target.getId()); + // source < target + return -1; + } else if (relationName.equals(FOLLOWS)) { + log.debug("source {} [rel {} ] target {}, so source > target ", source.getId(), FOLLOWS, + target.getId()); + // source > target + return 1; + } + } + } + } + log.debug("No relations beetween a & b"); + return null; + } } diff --git a/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java b/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java index ac26185..abe50b7 100644 --- a/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java +++ b/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java @@ -2,12 +2,18 @@ package org.gcube.application.cms.concessioni.plugins; import org.bson.Document; import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione; +import org.gcube.application.cms.plugins.faults.IndexingException; +import org.gcube.application.cms.plugins.requests.IndexDocumentRequest; +import org.gcube.application.cms.plugins.requests.StepExecutionRequest; import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.cms.tests.TestDocuments; import org.gcube.application.cms.tests.plugins.BasicPluginTest; import org.gcube.application.geoportal.common.model.JSONPathWrapper; import org.gcube.application.geoportal.common.model.document.Project; +import org.gcube.application.geoportal.common.model.document.accounting.Context; +import org.gcube.application.geoportal.common.model.document.accounting.User; import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet; +import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.junit.Assert; import org.junit.Test; @@ -18,6 +24,10 @@ import java.util.List; import static junit.framework.TestCase.*; public class ConcessioniPluginTests extends BasicPluginTest { + + public static final String SCOPE_TEST = "/gcube/devsec/devVRE"; + public static final String USERNAME = "francesco.mangiacrapa"; + public static final String UCD_ID = "concessioni-estere"; @Test public void testLoad(){ @@ -104,4 +114,36 @@ public class ConcessioniPluginTests extends BasicPluginTest { }); } + + @Test + public void testEvaluateAdditionalIndexParameters() throws IOException { + UseCaseDescriptor ucd = getUCD(); + ucd.setId(UCD_ID); + + User user = getCurrentUser(); + user.setUsername(USERNAME); + + Context context = getContextObject(); + context.setId(SCOPE_TEST); + context.setName(SCOPE_TEST); + + +// Project document = TestDocuments.documentMap.get("dummy.json"); +// +// +// StepExecutionRequest req = new StepExecutionRequest(ucd, user, context,document, "PUBLISH"); +// +// IndexDocumentRequest indexRequest = new IndexDocumentRequest( +// req.getUseCaseDescriptor(),req.getCaller(), req.getContext(),req.getDocument()); +// +// ConcessioniLifeCycleManager clfM = new ConcessioniLifeCycleManager(); +// +// try { +// clfM.evaluateAdditionalIndexParameters(indexRequest); +// } catch (IndexingException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } + + } } -- 2.17.1 From 7ea671953485b8768c04165ff60e39cb26482dfb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Mar 2023 16:14:38 +0100 Subject: [PATCH 2/7] added more logs --- .../plugins/ConcessioniLifeCycleManager.java | 10 +++--- .../plugins/ConcessioniPluginTests.java | 32 ------------------- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java index fbecea0..0c01284 100644 --- a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java +++ b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java @@ -258,7 +258,7 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements Project indexingProject = request.getDocument(); // Evaluate to display project IDs - log.debug("Evaluating Last ID in relationship chain. Current Concessione ID is {}", indexingProject.getId()); + log.info("Evaluating Last ID in relationship chain. Current ID is {}", indexingProject.getId()); try { ArrayList projects = new ArrayList<>(); ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class); @@ -285,11 +285,11 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements // order) Collections.sort(projects, Collections.reverseOrder(new ProjectRelationComparator())); - if (log.isDebugEnabled()) { + if (log.isInfoEnabled()) { int j = 0; - log.debug("Printing project reverse order...."); + log.info("Printing project reverse order...."); for (Project theProject : projects) { - log.debug(++j + ") " + theProject.getId() + " data inizio: " + log.info(++j + ") " + theProject.getId() + " data inizio: " + theProject.getTheDocument().get("dataInizioProgetto")); } } @@ -323,7 +323,7 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements toReturn.put("_toHideIds", toHideIds); toReturn.put("_toDisplayIds", toDisplayId); - log.info("Indexing request for Concessione [ID {}] with to HIDE {} and toDisplay {} ", + log.info("Indexing request for "+indexingProject.getProfileID()+" [ID {}] with to _toHideIds {} and _toDisplayIds {} ", indexingProject.getId(), toHideIds, toDisplayId); return toReturn; } catch (Exception e) { diff --git a/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java b/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java index abe50b7..86b4649 100644 --- a/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java +++ b/concessioni-lifecycle/src/test/java/org/gcube/application/cms/concessioni/plugins/ConcessioniPluginTests.java @@ -114,36 +114,4 @@ public class ConcessioniPluginTests extends BasicPluginTest { }); } - - @Test - public void testEvaluateAdditionalIndexParameters() throws IOException { - UseCaseDescriptor ucd = getUCD(); - ucd.setId(UCD_ID); - - User user = getCurrentUser(); - user.setUsername(USERNAME); - - Context context = getContextObject(); - context.setId(SCOPE_TEST); - context.setName(SCOPE_TEST); - - -// Project document = TestDocuments.documentMap.get("dummy.json"); -// -// -// StepExecutionRequest req = new StepExecutionRequest(ucd, user, context,document, "PUBLISH"); -// -// IndexDocumentRequest indexRequest = new IndexDocumentRequest( -// req.getUseCaseDescriptor(),req.getCaller(), req.getContext(),req.getDocument()); -// -// ConcessioniLifeCycleManager clfM = new ConcessioniLifeCycleManager(); -// -// try { -// clfM.evaluateAdditionalIndexParameters(indexRequest); -// } catch (IndexingException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } - - } } -- 2.17.1 From 1b0a93d91c42844b65857a58ced1138beacf42ca Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Mar 2023 16:32:45 +0100 Subject: [PATCH 3/7] Fixed log --- sdi-plugins/CHANGELOG.md | 3 ++- .../gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sdi-plugins/CHANGELOG.md b/sdi-plugins/CHANGELOG.md index f746439..c6f8674 100644 --- a/sdi-plugins/CHANGELOG.md +++ b/sdi-plugins/CHANGELOG.md @@ -2,7 +2,8 @@ ## [v1.0.4] - 2023-03-06 - Fixed the import from joda-time to java.time -- [#24702] Fixed the default-lc-managers dependency +- [#24702] Fixed the default-lc-managers dependency +- Fixed log ## [v1.0.3] - 2023-01-24 - Fixes [#24476](https://support.d4science.org/issues/24476) 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 fa80841..8987e04 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 @@ -236,7 +236,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin if(requestArguments.containsKey("_toDisplayIds")){ List ids = Serialization.convert(requestArguments.get("_toDisplayIds"),List.class); - log.info("Requested to hide centroids {} ",ids); + log.info("Requested to display centroids {} ",ids); indexer.updateIsVisible(true,ids); } -- 2.17.1 From 2797ae5d767d63ce0df1a5d716a57e8e3f050467 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Mar 2023 16:46:32 +0100 Subject: [PATCH 4/7] ignoring phases --- .../plugins/ConcessioniLifeCycleManager.java | 112 +++--------------- 1 file changed, 16 insertions(+), 96 deletions(-) diff --git a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java index 0c01284..c83eb39 100644 --- a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java +++ b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java @@ -162,91 +162,6 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements return c; } - /** - * OLD METHOD - * - * @param request - * @return - * @throws IndexingException - */ - protected Document evaluateAdditionalIndexParameters2(IndexDocumentRequest request) throws IndexingException { - Document toReturn = super.evaluateAdditionalIndexParameters(request); - if (toReturn == null) - toReturn = new Document(); - Project indexingProject = request.getDocument(); - - // Evaluate to display project IDs - log.info("Evaluating Last ID in relationship chain. Current Concessione ID is {}", indexingProject.getId()); - try { - ArrayList projects = new ArrayList<>(); - ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class); - // get Last ID in relation chain - projects.add(indexingProject); - if (!indexingProject.getRelationshipsByName(PRECEDES).isEmpty()) - scanRelation(projects, access - .getRelations(indexingProject.getProfileID(), indexingProject.getId(), PRECEDES, true).get(0), - false); - if (!indexingProject.getRelationshipsByName(FOLLOWS).isEmpty()) - scanRelation(projects, access - .getRelations(indexingProject.getProfileID(), indexingProject.getId(), FOLLOWS, true).get(0), - false); - - log.debug("Produced full chain [size : {}] from {}, evaluating last available for PHASE {} ", - projects.size(), indexingProject.getId(), indexingProject.getLifecycleInformation().getPhase()); - - List toDisplayId = new ArrayList<>(); - List toHideIds = new ArrayList<>(); - - log.trace("Checking from LAST.. "); - // Projects is time -ordered so we scan from last - for (int i = projects.size() - 1; i >= 0; i--) { - Project p = projects.get(i); - log.debug("Currently checking {} : {}", p.getId(), p.getTheDocument().get("nome")); - if (!toDisplayId.isEmpty()) - toHideIds.add(p.getId()); - else { - // Still need to find candidate for displaying feature - - // Our currently indexing project is always a good candidate - if (p.getId().equals(indexingProject.getId())) - toDisplayId.add(p.getId()); - // We check PHASE in order to skip projects not yet in the PHASE we are indexing - else - switch (indexingProject.getLifecycleInformation().getPhase()) { - case Phases.PENDING_APPROVAL: { - if ((p.getLifecycleInformation().getPhase().equals(Phases.PENDING_APPROVAL) - || p.getLifecycleInformation().getPhase().equals(Phases.PUBLISHED))) - toDisplayId.add(p.getId()); - break; - } - case Phases.PUBLISHED: { - if (p.getLifecycleInformation().getPhase().equals(Phases.PUBLISHED)) - toDisplayId.add(p.getId()); - break; - } - } - - if (!toDisplayId.isEmpty()) - log.debug("Found last concessioni candidate for displaying. ID {}, PHASE {} ", toDisplayId, - p.getLifecycleInformation().getPhase()); - else - toHideIds.add(p.getId()); // Still not found - } - } - - toReturn.put("_toHideIds", toHideIds); - toReturn.put("_toDisplayIds", toDisplayId); - - log.info("Indexing request for Concessione [ID {}] with to HIDE {} and toDisplay {} ", - indexingProject.getId(), toHideIds, toDisplayId); - return toReturn; - } catch (Exception e) { - log.error("Unable to evaluate to Hide and Display Ids ", e); - throw new IndexingException("Unable to evaluate chain ids to hide / display", e); - } - - } - /** * New method implemented by Francesco */ @@ -299,24 +214,29 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements for (int i = 0; i < projects.size(); i++) { Project p = projects.get(i); - String phase = p.getLifecycleInformation().getPhase(); + //String phase = p.getLifecycleInformation().getPhase(); // IS TO DISPLAY EMPTY? Step into only once if (toDisplayId.isEmpty()) { // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding toDisplayId - if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) { - toDisplayId.add(p.getId()); - } +// if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) { +// toDisplayId.add(p.getId()); +// } + + toDisplayId.add(p.getId()); + } else { + + toHideIds.add(p.getId()); // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding (the remaining) toHideIds - switch (phase) { - case Phases.PENDING_APPROVAL: - case Phases.PUBLISHED: { - toHideIds.add(p.getId()); - break; - } - } +// switch (phase) { +// case Phases.PENDING_APPROVAL: +// case Phases.PUBLISHED: { +// toHideIds.add(p.getId()); +// break; +// } +// } } } -- 2.17.1 From b2f93e2167c28aea3d8cfc43bab30ddfe01acec2 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Mar 2023 17:14:07 +0100 Subject: [PATCH 5/7] updated behaviour --- .../plugins/ConcessioniLifeCycleManager.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java index c83eb39..fc5d7ba 100644 --- a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java +++ b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java @@ -210,20 +210,23 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements } log.trace("Checking from LAST.. "); + + //I'm ignoring the phase, this code is called on + // SUBMIT (DRAFT-> PENDING_APPROVAL) + // APPROVE (PENDING_APPROVAL -> PUBLISH + // for (int i = 0; i < projects.size(); i++) { Project p = projects.get(i); - //String phase = p.getLifecycleInformation().getPhase(); + String phase = p.getLifecycleInformation().getPhase(); - // IS TO DISPLAY EMPTY? Step into only once + // IS TO DISPLAY EMPTY? Step into only once. Indexing the first project that is in PENDING APPROVAL or PUBLISHED if (toDisplayId.isEmpty()) { // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding toDisplayId -// if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) { -// toDisplayId.add(p.getId()); -// } - - toDisplayId.add(p.getId()); + if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) { + toDisplayId.add(p.getId()); + } } else { -- 2.17.1 From 0dcdd2bf32ecd0fa853dff5f3d0397ba308f4167 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Mar 2023 17:42:47 +0100 Subject: [PATCH 6/7] updated behaviour --- .../cms/concessioni/plugins/ConcessioniLifeCycleManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java index fc5d7ba..f3801fe 100644 --- a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java +++ b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java @@ -215,6 +215,8 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements // SUBMIT (DRAFT-> PENDING_APPROVAL) // APPROVE (PENDING_APPROVAL -> PUBLISH // + + //Operation (go to PENDING APPROVAL or PUBLISHED) called on the indexingProject for (int i = 0; i < projects.size(); i++) { @@ -226,6 +228,9 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding toDisplayId if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) { toDisplayId.add(p.getId()); + }else if(p.getId().compareTo(indexingProject.getId())==0) { + //Means that the operation is is called on indexing project from DRAFT phase to PENDING_APPROVAL or PUBLISH + toDisplayId.add(p.getId()); } } else { -- 2.17.1 From 2bc5d3a192d8a23e9492b01bdce7445bd4250a41 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 14 Mar 2023 10:51:02 +0100 Subject: [PATCH 7/7] #24754 Fixed --- .../plugins/ConcessioniLifeCycleManager.java | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java index f3801fe..5604293 100644 --- a/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java +++ b/concessioni-lifecycle/src/main/java/org/gcube/application/cms/concessioni/plugins/ConcessioniLifeCycleManager.java @@ -173,7 +173,7 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements Project indexingProject = request.getDocument(); // Evaluate to display project IDs - log.info("Evaluating Last ID in relationship chain. Current ID is {}", indexingProject.getId()); + log.info("Evaluating relationship chain. Current ID is {}", indexingProject.getId()); try { ArrayList projects = new ArrayList<>(); ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class); @@ -210,48 +210,36 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements } log.trace("Checking from LAST.. "); - - //I'm ignoring the phase, this code is called on - // SUBMIT (DRAFT-> PENDING_APPROVAL) - // APPROVE (PENDING_APPROVAL -> PUBLISH - // - - //Operation (go to PENDING APPROVAL or PUBLISHED) called on the indexingProject - for (int i = 0; i < projects.size(); i++) { Project p = projects.get(i); String phase = p.getLifecycleInformation().getPhase(); - // IS TO DISPLAY EMPTY? Step into only once. Indexing the first project that is in PENDING APPROVAL or PUBLISHED + // IS TO DISPLAY EMPTY? Step into only once. + // Indexing the first project that is in PENDING APPROVAL or PUBLISHED or + // updating the phase of the indexing (selected) project if (toDisplayId.isEmpty()) { // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding toDisplayId if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) { toDisplayId.add(p.getId()); - }else if(p.getId().compareTo(indexingProject.getId())==0) { - //Means that the operation is is called on indexing project from DRAFT phase to PENDING_APPROVAL or PUBLISH + } else if (p.getId().compareTo(indexingProject.getId()) == 0) { + // Means that the operation has been called on the indexing project from DRAFT + // phase to PENDING_APPROVAL or PUBLISH toDisplayId.add(p.getId()); } - - } else { - - toHideIds.add(p.getId()); - // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding (the remaining) toHideIds -// switch (phase) { -// case Phases.PENDING_APPROVAL: -// case Phases.PUBLISHED: { -// toHideIds.add(p.getId()); -// break; -// } -// } + } else { + // Hides the centroid regardless of project phase + toHideIds.add(p.getId()); } } toReturn.put("_toHideIds", toHideIds); toReturn.put("_toDisplayIds", toDisplayId); - log.info("Indexing request for "+indexingProject.getProfileID()+" [ID {}] with to _toHideIds {} and _toDisplayIds {} ", + log.info( + "Indexing request for " + indexingProject.getProfileID() + + " [ID {}] with to _toHideIds {} and _toDisplayIds {} ", indexingProject.getId(), toHideIds, toDisplayId); return toReturn; } catch (Exception e) { -- 2.17.1