Merge pull request 'bug_24754' (#12) from bug_24754 into master

Reviewed-on: #12
This commit is contained in:
Francesco Mangiacrapa 2023-03-14 11:23:05 +01:00
commit a499c5e151
6 changed files with 267 additions and 170 deletions

View File

@ -1,5 +1,8 @@
# Changelog for org.gcube.application.cms.concessioni-lifecycle # 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 ## [v1.0.4] - 2023-03-06
- [#24702] Fixed the default-lc-managers dependency - [#24702] Fixed the default-lc-managers dependency

View File

@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>concessioni-lifecycle</artifactId> <artifactId>concessioni-lifecycle</artifactId>
<version>1.0.4</version> <version>1.1.0-SNAPSHOT</version>
<name>GNA Concessioni Lifecycle</name> <name>GNA Concessioni Lifecycle</name>

View File

@ -1,7 +1,11 @@
package org.gcube.application.cms.concessioni.plugins; package org.gcube.application.cms.concessioni.plugins;
import com.vdurmont.semver4j.Semver; import java.io.IOException;
import lombok.extern.slf4j.Slf4j; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.bson.Document; import org.bson.Document;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione; import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
import org.gcube.application.cms.implementations.ImplementationProvider; import org.gcube.application.cms.implementations.ImplementationProvider;
@ -15,219 +19,298 @@ import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.JSONPathWrapper; 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.Project;
import org.gcube.application.geoportal.common.model.document.access.Access; import org.gcube.application.geoportal.common.model.document.relationships.Relationship;
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.RelationshipNavigationObject; import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject;
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck; import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
import java.io.IOException; import com.vdurmont.semver4j.Semver;
import java.util.ArrayList;
import java.util.List; import lombok.extern.slf4j.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 { 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"; public ConcessioniLifeCycleManager() {
private static final String PRECEDES="precedes"; 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() { // STATIC ROUTINES
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 static final Project setDefaults(Project document) throws IOException {
public EventExecutionReport setDefault(EventExecutionReport currentReport) { log.info("Concessione ID {}, setting defaults..", document.getId());
EventExecutionReport report = super.setDefault(currentReport); log.debug("Full concessione is {}", document);
try{ ProfiledConcessione c = Serialization.convert(document, ProfiledConcessione.class);
report.setResultingDocument(setDefaults(report.getTheRequest().getDocument()).getTheDocument()); Document doc = c.getTheDocument();
}catch (Throwable t){ doc.putIfAbsent(ProfiledConcessione.SOGGETTO, new String[] { "Research Excavation", "Archaeology" });
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;
}
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 { // RELAZIONE
log.info("Concessione ID {}, setting defaults..",document.getId()); Document rel = doc.containsKey(ProfiledConcessione.RELAZIONE_SCAVO)
log.debug("Full concessione is {}",document); ? Serialization.convert(doc.get(ProfiledConcessione.RELAZIONE_SCAVO), Document.class)
ProfiledConcessione c=Serialization.convert(document,ProfiledConcessione.class); : new Document();
Document doc=c.getTheDocument(); log.debug("Concessione {}, managing relazione {}", document.getId(), rel);
doc.putIfAbsent(ProfiledConcessione.SOGGETTO,new String[]{"Research Excavation","Archaeology"}); 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;" // ABSTRACT Relazione
+ " posizionamento topografico dell'area indagata, pianta di fine scavo."); 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 // Posizionamento scavo
// TODO read from UCD if (doc.containsKey(ProfiledConcessione.POSIZIONAMENTO_SCAVO)) {
c.getInfo().getAccess().setLicense( Document pos = Serialization.convert(doc.get(ProfiledConcessione.POSIZIONAMENTO_SCAVO), Document.class);
ConstraintCheck.defaultFor(c.getInfo().getAccess().getLicense(), "CC0-1.0").evaluate()); 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 dellarea 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 pos.put(ProfiledConcessione.RESPONSABILE, doc.get(ProfiledConcessione.RESPONSABILE));
Document rel = doc.containsKey(ProfiledConcessione.RELAZIONE_SCAVO)? doc.put(ProfiledConcessione.POSIZIONAMENTO_SCAVO, pos);
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);
// IMMAGINI RAPPRESENTATIVE
//ABSTRACT Relazione JSONPathWrapper wrapper = new JSONPathWrapper(Serialization.write(doc));
Document abs=doc.containsKey(ProfiledConcessione.ABSTRACT_RELAZIONE)? if (doc.containsKey(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE)) {
Serialization.convert(doc.get(ProfiledConcessione.ABSTRACT_RELAZIONE), Document.class):new Document(); List imgs = wrapper.getByPath("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE, List.class).get(0);
log.debug("Concessione {}, managing abstract relazione {}",document.getId(),abs); log.debug("Concessione {}, found imgs {}", document.getId(), imgs.size());
abs.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" abstract relazione di scavo"); for (int i = 0; i < imgs.size(); i++) {
doc.put(ProfiledConcessione.ABSTRACT_RELAZIONE,abs); Document imgDoc = Serialization.asDocument(imgs.get(i));
imgDoc.putIfAbsent(ProfiledConcessione.SOGGETTO, doc.get(ProfiledConcessione.SOGGETTO));
wrapper.setElement("$." + ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE + "[" + i + "]", imgDoc);
}
}
//Posizionamento scavo // Layers
if(doc.containsKey(ProfiledConcessione.POSIZIONAMENTO_SCAVO)){ if (doc.containsKey(ProfiledConcessione.PIANTE_FINE_SCAVO)) {
Document pos = Serialization.convert(doc.get(ProfiledConcessione.POSIZIONAMENTO_SCAVO), Document.class); List piante = wrapper.getByPath("$." + ProfiledConcessione.PIANTE_FINE_SCAVO, List.class).get(0);
log.debug("Concessione {}, managing posizionamento scavo {}",document.getId(),pos); log.debug("Concessione {}, found piante {}", document.getId(), piante.size());
pos.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" posizionamento scavo"); for (int i = 0; i < piante.size(); i++) {
pos.putIfAbsent(ProfiledConcessione.Sections.ABSTRACT,"Posizionamento topografico georeferenziato dellarea interessata dalle indagini"); Document piantaDoc = Serialization.asDocument(piante.get(i));
pos.putIfAbsent(ProfiledConcessione.Layers.TOPIC,"Society"); log.debug("Concessione {}, managing pianta {}", document.getId(), piantaDoc);
pos.putIfAbsent(ProfiledConcessione.Layers.SUB_TOPIC,"Archeology"); 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)); piantaDoc.putIfAbsent(ProfiledConcessione.PAROLE_CHIAVE_LIBERE,
pos.putIfAbsent(ProfiledConcessione.PAREOLE_CHIAVE_ICCD,doc.get(ProfiledConcessione.PAREOLE_CHIAVE_ICCD)); 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)); piantaDoc.put(ProfiledConcessione.RESPONSABILE, doc.get(ProfiledConcessione.RESPONSABILE));
doc.put(ProfiledConcessione.POSIZIONAMENTO_SCAVO,pos);
}
//IMMAGINI RAPPRESENTATIVE wrapper.setElement("$." + ProfiledConcessione.PIANTE_FINE_SCAVO + "[" + i + "]", piantaDoc);
}
}
JSONPathWrapper wrapper=new JSONPathWrapper(Serialization.write(doc)); c.setTheDocument(Serialization.read(wrapper.getValueCTX().jsonString(), Document.class));
if(doc.containsKey(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE)) { return c;
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); /**
} * 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();
// Layers // Evaluate to display project IDs
if(doc.containsKey(ProfiledConcessione.PIANTE_FINE_SCAVO)) { log.info("Evaluating relationship chain. Current ID is {}", indexingProject.getId());
List piante=wrapper.getByPath("$." + ProfiledConcessione.PIANTE_FINE_SCAVO, List.class).get(0); try {
log.debug("Concessione {}, found piante {}",document.getId(),piante.size()); ArrayList<Project> projects = new ArrayList<>();
for (int i = 0; i <piante.size() ; i++) { ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class);
Document piantaDoc=Serialization.asDocument(piante.get(i)); // get Last ID in relation chain
log.debug("Concessione {}, managing pianta {}",document.getId(),piantaDoc); projects.add(indexingProject);
piantaDoc.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" pianta fine scavo"); if (!indexingProject.getRelationshipsByName(PRECEDES).isEmpty())
piantaDoc.putIfAbsent(ProfiledConcessione.Sections.ABSTRACT,"Planimetria georeferenziata dell'area indagata al termine delle attività"); scanRelation(projects, access
piantaDoc.putIfAbsent(ProfiledConcessione.Layers.TOPIC,"Society"); .getRelations(indexingProject.getProfileID(), indexingProject.getId(), PRECEDES, true).get(0),
piantaDoc.putIfAbsent(ProfiledConcessione.Layers.SUB_TOPIC,"Archeology"); 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)); log.debug("Produced full chain [size : {}] from {}, evaluating last available for PHASE {} ",
piantaDoc.putIfAbsent(ProfiledConcessione.PAREOLE_CHIAVE_ICCD,doc.get(ProfiledConcessione.PAREOLE_CHIAVE_ICCD)); projects.size(), indexingProject.getId(), indexingProject.getLifecycleInformation().getPhase());
// BBOX in registered filesets log.info("projects are: " + projects.size());
piantaDoc.put(ProfiledConcessione.RESPONSABILE,doc.get(ProfiledConcessione.RESPONSABILE)); List<String> toDisplayId = new ArrayList<>();
List<String> toHideIds = new ArrayList<>();
wrapper.setElement("$."+ProfiledConcessione.PIANTE_FINE_SCAVO+"["+i+"]",piantaDoc); // Reverse Order means from the last FOLLOW to the first one (temporal reverse
} // order)
} Collections.sort(projects, Collections.reverseOrder(new ProjectRelationComparator()));
c.setTheDocument(Serialization.read(wrapper.getValueCTX().jsonString(),Document.class)); if (log.isInfoEnabled()) {
return c; int j = 0;
} log.info("Printing project reverse order....");
for (Project theProject : projects) {
log.info(++j + ") " + theProject.getId() + " data inizio: "
+ theProject.getTheDocument().get("dataInizioProgetto"));
}
}
log.trace("Checking from LAST.. ");
for (int i = 0; i < projects.size(); i++) {
@Override Project p = projects.get(i);
protected Document evaluateAdditionalIndexParameters(IndexDocumentRequest request) throws IndexingException { String phase = p.getLifecycleInformation().getPhase();
Document toReturn = super.evaluateAdditionalIndexParameters(request);
if(toReturn == null) toReturn = new Document();
Project indexingProject = request.getDocument();
// Evaluate to display project IDs // IS TO DISPLAY EMPTY? Step into only once.
log.info("Evaluating Last ID in relationship chain. Current Concessione ID is {}",indexingProject.getId()); // Indexing the first project that is in PENDING APPROVAL or PUBLISHED or
try { // updating the phase of the indexing (selected) project
ArrayList<Project> projects = new ArrayList<>(); if (toDisplayId.isEmpty()) {
ProjectAccess access = ImplementationProvider.get().getProvidedObjectByClass(ProjectAccess.class); // IF PHASE IS PENDING APPROVAL OR PUBLISHED adding toDisplayId
// get Last ID in relation chain if ((phase.equals(Phases.PENDING_APPROVAL) || phase.equals(Phases.PUBLISHED))) {
projects.add(indexingProject); toDisplayId.add(p.getId());
if(!indexingProject.getRelationshipsByName(PRECEDES).isEmpty()) } else if (p.getId().compareTo(indexingProject.getId()) == 0) {
scanRelation(projects,access.getRelations(indexingProject.getProfileID(), indexingProject.getId(), PRECEDES,true).get(0),false); // Means that the operation has been called on the indexing project from DRAFT
if(!indexingProject.getRelationshipsByName(FOLLOWS).isEmpty()) // phase to PENDING_APPROVAL or PUBLISH
scanRelation(projects,access.getRelations(indexingProject.getProfileID(), indexingProject.getId(), FOLLOWS,true).get(0),false); toDisplayId.add(p.getId());
}
log.debug("Produced full chain [size : {}] from {}, evaluating last available for PHASE {} ",projects.size(),indexingProject.getId(), } else {
indexingProject.getLifecycleInformation().getPhase()); // Hides the centroid regardless of project phase
toHideIds.add(p.getId());
}
}
List<String> toDisplayId = new ArrayList<>(); toReturn.put("_toHideIds", toHideIds);
List<String> toHideIds = new ArrayList<>(); toReturn.put("_toDisplayIds", toDisplayId);
log.trace("Checking from LAST.. "); log.info(
// Projects is time -ordered so we scan from last "Indexing request for " + indexingProject.getProfileID()
for(int i = projects.size()-1;i>=0;i--) { + " [ID {}] with to _toHideIds {} and _toDisplayIds {} ",
Project p = projects.get(i); indexingProject.getId(), toHideIds, toDisplayId);
log.debug("Currently checking {} : {}",p.getId(),p.getTheDocument().get("nome")); return toReturn;
if(!toDisplayId.isEmpty()) } catch (Exception e) {
toHideIds.add(p.getId()); log.error("Unable to evaluate to Hide and Display Ids ", e);
else { throw new IndexingException("Unable to evaluate chain ids to hide / display", e);
//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()) private static void scanRelation(ArrayList chain, RelationshipNavigationObject obj, boolean putBefore) {
log.debug("Found last concessioni candidate for displaying. ID {}, PHASE {} ",toDisplayId,p.getLifecycleInformation().getPhase()); if (putBefore)
else toHideIds.add(p.getId()); // Still not found chain.add(0, obj.getTarget());
} else
} chain.add(obj.getTarget());
if (obj.getChildren() != null)
obj.getChildren().forEach(r -> scanRelation(chain, r, putBefore));
}
toReturn.put("_toHideIds",toHideIds); public static class ProjectRelationComparator implements Comparator<Project> {
toReturn.put("_toDisplayIds",toDisplayId); @Override
public int compare(Project p1, Project p2) {
if (p1 == null)
return 1;
if (p2 == null)
return -1;
log.info("Indexing request for Concessione [ID {}] with to HIDE {} and toDisplay {} ",indexingProject.getId(),toHideIds,toDisplayId); Integer compareResult = null;
return toReturn; compareResult = compareProjectAgainstRelations(p1, p2);
} catch (Exception e) { log.trace("p1 & p2, comparator result: {}", compareResult);
log.error("Unable to evaluate to Hide and Display Ids ",e); if (compareResult == null) {
throw new IndexingException("Unable to evaluate chain ids to hide / display",e); 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;
}
}
private static void scanRelation(ArrayList chain,RelationshipNavigationObject obj, boolean putBefore){ log.debug("p1 & p2, comparator result, returns: {}", compareResult);
if(putBefore)chain.add(0,obj.getTarget()); return compareResult;
else chain.add(obj.getTarget()); }
if(obj.getChildren()!=null) }
obj.getChildren().forEach(r-> scanRelation(chain,r,putBefore));
} public static Integer compareProjectAgainstRelations(Project source, Project target) {
log.debug("comparing source {} and target {}", source.getId(), target.getId());
List<Relationship> 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;
}
} }

View File

@ -2,12 +2,18 @@ package org.gcube.application.cms.concessioni.plugins;
import org.bson.Document; import org.bson.Document;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione; 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.serialization.Serialization;
import org.gcube.application.cms.tests.TestDocuments; import org.gcube.application.cms.tests.TestDocuments;
import org.gcube.application.cms.tests.plugins.BasicPluginTest; import org.gcube.application.cms.tests.plugins.BasicPluginTest;
import org.gcube.application.geoportal.common.model.JSONPathWrapper; 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.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.document.filesets.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -18,6 +24,10 @@ import java.util.List;
import static junit.framework.TestCase.*; import static junit.framework.TestCase.*;
public class ConcessioniPluginTests extends BasicPluginTest { 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 @Test
public void testLoad(){ public void testLoad(){

View File

@ -2,7 +2,8 @@
## [v1.0.4] - 2023-03-06 ## [v1.0.4] - 2023-03-06
- Fixed the import from joda-time to java.time - 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 ## [v1.0.3] - 2023-01-24
- Fixes [#24476](https://support.d4science.org/issues/24476) - Fixes [#24476](https://support.d4science.org/issues/24476)

View File

@ -236,7 +236,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
if(requestArguments.containsKey("_toDisplayIds")){ if(requestArguments.containsKey("_toDisplayIds")){
List<String> ids = Serialization.convert(requestArguments.get("_toDisplayIds"),List.class); List<String> 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); indexer.updateIsVisible(true,ids);
} }