Project Access Provider

This commit is contained in:
Fabio Sinibaldi 2022-10-27 16:03:38 +02:00
parent b8a0e8db4c
commit 0efb397af9
24 changed files with 193 additions and 173 deletions

View File

@ -0,0 +1,23 @@
package org.gcube.application.cms.implementations;
import org.bson.Document;
import org.gcube.application.cms.implementations.faults.InvalidUserRoleException;
import org.gcube.application.cms.implementations.faults.ProjectNotFoundException;
import org.gcube.application.cms.implementations.faults.RegistrationException;
import org.gcube.application.cms.implementations.faults.UnauthorizedAccess;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import java.util.List;
public interface ProjectAccess {
public Project getById(String ucid,String id) throws RegistrationException, ConfigurationException, InvalidUserRoleException, ProjectNotFoundException, UnauthorizedAccess;
public Iterable<Document> query(String ucid, QueryRequest query) throws RegistrationException, ConfigurationException, InvalidUserRoleException;
public List<RelationshipNavigationObject> getRelations(String ucid, String id, String relation) throws InvalidUserRoleException, RegistrationException, ProjectNotFoundException, ConfigurationException, UnauthorizedAccess;
}

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class DataParsingException extends Exception {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class DeletionException extends Exception {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class InvalidLockException extends Exception{
public InvalidLockException() {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class InvalidStateException extends Exception {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class InvalidUserRoleException extends Exception {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class ProjectLockedException extends Exception{
public ProjectLockedException() {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class ProjectNotFoundException extends Exception {
public ProjectNotFoundException() {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class RegistrationException extends Exception {

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.service.model.internal.faults;
package org.gcube.application.cms.implementations.faults;
public class UnauthorizedAccess extends Exception {

View File

@ -2,6 +2,7 @@ package org.gcube.application.cms.plugins.implementations;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.implementations.ProjectAccess;
import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.PluginManagerInterface;
import org.gcube.application.cms.plugins.faults.*;
@ -41,6 +42,10 @@ public abstract class AbstractLifeCycleManager extends AbstractPlugin implements
@Setter
protected PluginManagerInterface pluginManager;
@Setter
protected ProjectAccess projectAccess;
private Map<String, GuardedStepExecution> registeredSteps=new HashMap<>();
private Map<String, GuardedEventManager> registeredEvent=new HashMap<>();

View File

@ -10,9 +10,11 @@ import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.plugins.faults.MaterializationException;
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
import org.gcube.application.cms.plugins.requests.BaseRequest;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.configuration.Configuration;
import org.gcube.application.geoportal.common.model.configuration.Index;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
@ -77,42 +79,19 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
setStep(new GuardedStepExecution(STEPS.SUBMIT) {
@Override
protected StepExecutionReport run() throws Exception {
// 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;
return executeSubmit(theReport);
}
});
setStep(new GuardedStepExecution(STEPS.APPROVE) {
@Override
protected StepExecutionReport run() 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;
return executeApprove(theReport);
}
});
setStep(new GuardedStepExecution(STEPS.REJECT) {
@Override
protected StepExecutionReport run() throws Exception {
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
theReport.getToSetLifecycleInformation().setPhase(LifecycleInformation.CommonPhases.DRAFT_PHASE);
return theReport;
return executeReject(theReport);
}
});
}
@ -125,104 +104,6 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
}
// @Override
// public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException, InvalidProfileException, ConfigurationException, InsufficientPrivileges {
// StepExecutionReport report = super.performStep(request);
// LifecycleInformation info=report.getToSetLifecycleInformation();
// try {
// if(!canInvokeStep(request.getStep(),request.getCaller(),getConfigurationFromProfile(request.getUseCaseDescriptor())))
// throw new InsufficientPrivileges("Insufficient privileges for executing step "+request.getStep());
//
// MaterializationPlugin plugin;
// IndexerPluginInterface indexerPlugin;
// plugin= (MaterializationPlugin) pluginManager.getById("SDI-Default-Materializer");
// indexerPlugin = (IndexerPluginInterface) pluginManager.getById("SDI-Indexer-Plugin");
//
//
//
// switch (request.getStep()) {
// case STEPS.SUBMIT:{
// //TODO validation
//
// if(!request.getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE))
// throw new StepException("Document is not in "+LifecycleInformation.CommonPhases.DRAFT_PHASE+" phase");
// //Materialize layers
// MaterializationRequest matReq = new MaterializationRequest(request.getUseCaseDescriptor(),request.getCaller(), request.getContext(), request.getDocument());
//
// matReq.setDocument(request.getDocument());
// matReq.setUseCaseDescriptor(request.getUseCaseDescriptor());
// Document params = new Document();
// String workspace = request.getUseCaseDescriptor().getId() + request.getContext().getId();
// params.put("workspace", Files.fixFilename(workspace));
//
//
// matReq.setCallParameters(params);
// MaterializationReport matRep = plugin.materialize(matReq);
//
//
// report.setResultingDocument(matRep.getResultingDocument());
//
//
// switch(matRep.getStatus()){
// case OK : {
// index(report,indexerPlugin);
// //TODO Optional Notifications
// break;
// }
// case ERROR : {
// info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
// matRep.getMessages().forEach(s -> info.addErrorMessage(s));
// break;
// }
// case WARNING : {
// info.setLastOperationStatus(LifecycleInformation.Status.WARNING);
// matRep.getMessages().forEach(s -> info.addWarningMessage(s));
// break;
// }
// }
//
// }
// break;
// case STEPS.REJECT:{
// if(!request.getDocument().getLifecycleInformation().getPhase().equals(Phases.PENDING_APPROVAL))
// throw new StepException("Document is not in "+Phases.PENDING_APPROVAL+" phase");
// // TODO OPTIONAL Notification
//
// info.setPhase(Phases.PENDING_APPROVAL);
// if(request.getCallParameters()!=null&&request.getCallParameters().containsKey(PARAMETERS.NOTES))
// info.setNotes(request.getCallParameters().getString(PARAMETERS.NOTES));
// break;
// }
//
// case STEPS.APPROVE:{
// // Index-published
// if(!request.getDocument().getLifecycleInformation().getPhase()
// .equals(Phases.PENDING_APPROVAL))
// throw new StepException("Document is not in "+Phases.PENDING_APPROVAL+" phase");
//
// index(report,indexerPlugin);
// break;
// }
//
// default:
// throw new StepException("Invalid Step " + request.getStep());
// }
// }catch (StepException e){
// throw e;
// }catch (Throwable t){
// log.error("Unable to perform step "+request.getStep(),t);
// String msg = "Unable to execute Step "+request.getStep()+". Error was "+t.getMessage();
// report.setStatus(Report.Status.ERROR);
// report.putMessage(msg);
// info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
// info.addErrorMessage(msg);
// }
// return report;
// }
@Override
public Configuration getCurrentConfiguration(BaseRequest req) throws ConfigurationException {
Configuration toReturn = super.getCurrentConfiguration(req);
@ -244,11 +125,45 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
return toReturn;
}
private Document getInternalIndexParams(BaseRequest req){
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"));
return callParameters;
}
protected StepExecutionReport executeSubmit(StepExecutionReport theReport) throws Exception {
// 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 executeReject(StepExecutionReport theReport) throws Exception {
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
theReport.getToSetLifecycleInformation().setPhase(LifecycleInformation.CommonPhases.DRAFT_PHASE);
return theReport;
}
}

View File

@ -4,14 +4,12 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.caches.Engine;
import org.gcube.application.cms.implementations.ImplementationProvider;
import org.gcube.application.cms.implementations.ProjectAccess;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportal.service.engine.mongo.UCDManagerI;
import org.gcube.application.geoportal.service.engine.providers.ConfigurationCache;
import org.gcube.application.geoportal.service.engine.providers.MongoClientProvider;
import org.gcube.application.geoportal.service.engine.providers.PluginManager;
import org.gcube.application.geoportal.service.engine.providers.StorageClientProvider;
import org.gcube.application.geoportal.service.engine.providers.*;
import org.gcube.application.geoportal.service.engine.providers.ucd.ProfileMap;
import org.gcube.application.geoportal.service.engine.providers.ucd.SingleISResourceUCDProvider;
import org.gcube.application.geoportal.service.engine.providers.ucd.UCDManager;
@ -54,6 +52,7 @@ public class GeoPortalService extends ResourceConfig{
log.info("Setting implementations .. ");
ImplementationProvider.get().setEngine(new MongoClientProvider(), Mongo.class);
ImplementationProvider.get().setEngine(new ProjectAccessProvider(), ProjectAccess.class);
ImplementationProvider.get().setEngine(new StorageClientProvider(), StorageUtils.class);
ImplementationProvider.get().setEngine(new SingleISResourceUCDProvider(), ProfileMap.class);
ImplementationProvider.get().setEngine(new PluginManager(), PluginManager.PluginMap.class);

View File

@ -2,6 +2,7 @@ package org.gcube.application.geoportal.service.engine.mongo;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.bson.Document;
import org.gcube.application.cms.implementations.faults.*;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
import org.gcube.application.cms.plugins.faults.StepException;

View File

@ -13,6 +13,7 @@ import org.bson.Document;
import org.bson.types.ObjectId;
import org.gcube.application.cms.implementations.ImplementationProvider;
import org.gcube.application.cms.implementations.WorkspaceManager;
import org.gcube.application.cms.implementations.faults.*;
import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;

View File

@ -3,7 +3,7 @@ package org.gcube.application.geoportal.service.engine.mongo;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
import org.gcube.application.cms.implementations.faults.RegistrationException;
public interface UCDManagerI {

View File

@ -12,7 +12,7 @@ import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.utils.ContextUtils;
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
import org.gcube.application.cms.implementations.faults.RegistrationException;
import javax.ws.rs.WebApplicationException;
import java.util.NoSuchElementException;

View File

@ -0,0 +1,70 @@
package org.gcube.application.geoportal.service.engine.providers;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.gcube.application.cms.implementations.ProjectAccess;
import org.gcube.application.cms.implementations.faults.InvalidUserRoleException;
import org.gcube.application.cms.implementations.faults.ProjectNotFoundException;
import org.gcube.application.cms.implementations.faults.RegistrationException;
import org.gcube.application.cms.implementations.faults.UnauthorizedAccess;
import org.gcube.application.geoportal.common.model.document.Project;
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.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class ProjectAccessImpl implements ProjectAccess {
@Override
public Project getById(String ucid, String id) throws RegistrationException, ConfigurationException, InvalidUserRoleException, ProjectNotFoundException, UnauthorizedAccess {
return new ProfiledMongoManager(ucid).getByID(id);
}
@Override
public Iterable<Document> query(String ucid, QueryRequest query) throws RegistrationException, ConfigurationException, InvalidUserRoleException {
return new ProfiledMongoManager(ucid).query(query);
}
@Override
public List<RelationshipNavigationObject> getRelations(String ucid, String id, String relation) throws InvalidUserRoleException, RegistrationException, ProjectNotFoundException, ConfigurationException, UnauthorizedAccess {
return getRelationshipChain(ucid,id,relation,true);
}
public static List<RelationshipNavigationObject> getRelationshipChain(String ucid, String id, String relationshipId, Boolean deep) throws RegistrationException, ConfigurationException, InvalidUserRoleException, ProjectNotFoundException, UnauthorizedAccess {
// recursive
ProfiledMongoManager manager = new ProfiledMongoManager(ucid);
log.info("UCD {} : Getting Relationships List for {} [rel : {}, recurse {}]",
manager.getUseCaseDescriptor().getId(), id, relationshipId, deep);
Project current = manager.getByID(id);
long startTime = System.currentTimeMillis();
List<RelationshipNavigationObject> toReturn = getLinked(current, relationshipId, deep);
log.info("Got {} relationship elements in {}ms", toReturn.size(), (System.currentTimeMillis() - startTime));
return toReturn;
}
private static List<RelationshipNavigationObject> getLinked(Project current, String relationName, Boolean recurse) {
log.debug("Getting Relationships Lists for {} [rel : {}, recurse {}]", current.getId(), relationName, recurse);
ArrayList<RelationshipNavigationObject> toReturn = new ArrayList<>();
List<Relationship> existing = current.getRelationshipsByName(relationName);
for (Relationship relationship : existing) {
try {
log.trace("Navigating from {} : {} to[rel {} ] {} : {}", relationship.getTargetUCD(),
relationship.getTargetID(), relationship.getRelationshipName(), current.getProfileID(), current.getId());
RelationshipNavigationObject linkedProject = new RelationshipNavigationObject();
linkedProject.setTarget(new ProfiledMongoManager(relationship.getTargetUCD()).getByID(relationship.getTargetID()));
if (recurse) linkedProject.setChildren(getLinked(linkedProject.getTarget(), relationName, recurse));
toReturn.add(linkedProject);
} catch (Exception e) {
log.warn("Unable to navigate from {} : {} to[rel {} ] {} : {}", relationship.getTargetUCD(),
relationship.getTargetID(), relationship.getRelationshipName(), current.getProfileID(), current.getId(), e);
}
}
return toReturn;
}
}

View File

@ -0,0 +1,26 @@
package org.gcube.application.geoportal.service.engine.providers;
import org.gcube.application.cms.caches.Engine;
import org.gcube.application.cms.implementations.ProjectAccess;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
public class ProjectAccessProvider implements Engine<ProjectAccess> {
@Override
public void init() {
}
@Override
public void shutdown() {
}
@Override
public ProjectAccess getObject() throws ConfigurationException {
return new ProjectAccessImpl();
}
}

View File

@ -13,7 +13,7 @@ import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDes
import org.gcube.application.geoportal.common.utils.ContextUtils;
import org.gcube.application.geoportal.service.engine.mongo.UCDManagerI;
import org.gcube.application.geoportal.service.engine.mongo.UCDMongoManager;
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
import org.gcube.application.cms.implementations.faults.RegistrationException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

View File

@ -3,7 +3,7 @@ package org.gcube.application.geoportal.service.model.internal.db;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.geoportal.common.model.legacy.BBOX;
import org.gcube.application.geoportal.service.model.internal.faults.DataParsingException;
import org.gcube.application.cms.implementations.faults.DataParsingException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

View File

@ -4,10 +4,10 @@ import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
import org.gcube.application.cms.plugins.faults.UnrecognizedStepException;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.service.model.internal.faults.InvalidLockException;
import org.gcube.application.geoportal.service.model.internal.faults.InvalidUserRoleException;
import org.gcube.application.geoportal.service.model.internal.faults.ProjectLockedException;
import org.gcube.application.geoportal.service.model.internal.faults.ProjectNotFoundException;
import org.gcube.application.cms.implementations.faults.InvalidLockException;
import org.gcube.application.cms.implementations.faults.InvalidUserRoleException;
import org.gcube.application.cms.implementations.faults.ProjectLockedException;
import org.gcube.application.cms.implementations.faults.ProjectNotFoundException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;

View File

@ -18,6 +18,7 @@ import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager;
import org.gcube.application.geoportal.service.engine.providers.ConfigurationCache;
import org.gcube.application.geoportal.service.engine.providers.ProjectAccessImpl;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@ -262,14 +263,10 @@ public class ProfiledDocuments {
return new GuardedMethod<String>(){
@Override
protected String run() throws Exception, WebApplicationException {
// recursive
log.info("UCD {} : Getting Relationships List for {} [rel : {}, recurse {}]",
manager.getUseCaseDescriptor().getId(),id,relationshipId,deep);
Project current = manager.getByID(id);
long startTime=System.currentTimeMillis();
List<RelationshipNavigationObject> toReturn = getLinked(current,relationshipId,deep);
log.info("Got {} relationship elements in {}ms",toReturn.size(),(System.currentTimeMillis()-startTime));
return Serialization.write(toReturn);
return Serialization.write(ProjectAccessImpl.getRelationshipChain(
manager.getUseCaseDescriptor().getId(),
id, relationshipId,deep
));
}
}.execute().getResult();
}
@ -319,23 +316,5 @@ public class ProfiledDocuments {
private static List<RelationshipNavigationObject> getLinked(Project current, String relationName, Boolean recurse)throws Exception{
log.debug("Getting Relationships Lists for {} [rel : {}, recurse {}]",current.getId(),relationName,recurse);
ArrayList<RelationshipNavigationObject> toReturn = new ArrayList<>();
List<Relationship> existing = current.getRelationshipsByName(relationName);
for (Relationship relationship : existing) {
try{
log.trace("Navigating from {} : {} to[rel {} ] {} : {}",relationship.getTargetUCD(),
relationship.getTargetID(),relationship.getRelationshipName(),current.getProfileID(),current.getId());
RelationshipNavigationObject linkedProject = new RelationshipNavigationObject();
linkedProject.setTarget(new ProfiledMongoManager(relationship.getTargetUCD()).getByID(relationship.getTargetID()));
if(recurse) linkedProject.setChildren(getLinked(linkedProject.getTarget(),relationName,recurse));
toReturn.add(linkedProject);
} catch (Exception e) {
log.warn("Unable to navigate from {} : {} to[rel {} ] {} : {}",relationship.getTargetUCD(),
relationship.getTargetID(),relationship.getRelationshipName(),current.getProfileID(),current.getId(),e);
}
}
return toReturn;
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.application.geoportal.service.engine.mongo;
import org.bson.Document;
import org.gcube.application.cms.implementations.faults.*;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
import org.gcube.application.cms.plugins.faults.StepException;