From 2f263dae4467955239245b7c82868ecc2c8eb6e4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 21 Sep 2022 10:52:31 +0200 Subject: [PATCH] Added createRelation method --- .../ConvertToDataValueObjectModel.java | 34 +++++++++++++++---- .../geoportal/ProjectsCaller.java | 27 +++++++++++++++ .../shared/geoportal/ResultDocumentDV.java | 15 +++++++- .../geoportal/project/RelationshipDV.java | 9 +++++ 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java index 869b426..60611be 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java @@ -15,6 +15,7 @@ import java.util.Map; import java.util.Set; import org.bson.Document; +import org.gcube.application.geoportal.client.utils.Serialization; 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.accounting.AccountingInfo; @@ -174,7 +175,7 @@ public class ConvertToDataValueObjectModel { * To handler declaration DV. * * @param handlerDeclaration the handler declaration - * @param profileName the profile name + * @param ucd the ucd * @param readConfigs the read configs * @return the handler declaration DV * @throws Exception the exception @@ -311,19 +312,20 @@ public class ConvertToDataValueObjectModel { List listActionsDef = new ArrayList( jsonConfigurations.size()); - - LOG.trace("Into " + GEOPORTAL_CONFIGURATION_TYPE.actions_definition + " handlers are: {}", ucd.getHandlers()); + + LOG.trace("Into " + GEOPORTAL_CONFIGURATION_TYPE.actions_definition + " handlers are: {}", + ucd.getHandlers()); List listHandlersLC = ucd .getHandlersByType(GEOPORTAL_DATA_HANDLER.gna_concessioni_lc.getType()); - + HandlerDeclaration handlerLC = null; if (listHandlersLC != null && listHandlersLC.size() > 0) { handlerLC = listHandlersLC.get(0); } LOG.debug("Into " + GEOPORTAL_CONFIGURATION_TYPE.actions_definition + " the handler " + GEOPORTAL_DATA_HANDLER.gna_concessioni_lc + " is: {}", handlerLC); - + int i = 0; for (String asJSONString : jsonConfigurations) { LOG.debug(++i + ") the ActionDefinition is: " + asJSONString); @@ -597,6 +599,15 @@ public class ConvertToDataValueObjectModel { rd.setLifecycleInfo(bld); } + if (project.getRelationships() != null) { + List listRelDV = new ArrayList(project.getRelationships().size()); + for (Relationship relationship : project.getRelationships()) { + RelationshipDV relDV = toRelationshipDV(relationship); + listRelDV.add(relDV); + } + rd.setListRelationship(listRelDV); + } + if (LOG.isDebugEnabled()) LOG.debug("Returning: " + rd); @@ -962,7 +973,18 @@ public class ConvertToDataValueObjectModel { if (relationship == null) return null; - return new RelationshipDV(relationship.getRelationshipName(), relationship.getTargetID()); + RelationshipDV rDV = new RelationshipDV(relationship.getRelationshipName(), relationship.getTargetID()); + String jsonDocument = null; + + try { + jsonDocument = Serialization.asDocument(relationship).toJson(); + } catch (Exception e) { + + } + + rDV.setAsJSON(jsonDocument); + + return rDV; } /** diff --git a/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java b/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java index e41c4b0..3b4dbfd 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java +++ b/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java @@ -18,6 +18,7 @@ import org.gcube.application.geoportal.common.faults.InvalidRequestException; import org.gcube.application.geoportal.common.model.configuration.Archive; import org.gcube.application.geoportal.common.model.configuration.Configuration; 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.rest.QueryRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; @@ -323,6 +324,32 @@ public class ProjectsCaller { return client.updateDocument(projectID, updatedDocument); } + /** + * Creates the relationship. + * + * @param fromProfileID the from profile ID + * @param fromProjectID the from project ID + * @param relationshipName the relationship name + * @param toProfileID the to profile ID + * @param toProjectID the to project ID + * @return the project + * @throws RemoteException the remote exception + */ + public Relationship createRelationship(String fromProfileID, String fromProjectID, String relationshipName, + String toProfileID, String toProjectID) throws RemoteException { + LOG.info("createRelationship called for fromProfileID {} and fromProjectID {}", fromProfileID, fromProjectID); + LOG.info("create relationshipName {}", relationshipName); + LOG.info("to toProfileID {} and toProjectID {}", toProfileID, toProjectID); + Projects client = (Projects) getClient(fromProfileID); + + //TODO MISSING CREATE RELATIONSHIP + + LOG.warn("\n\n\n\n CREATE Relationship MUST BE CALLED ON THE SERVICE \n\n\n"); + + return new Relationship(relationshipName, toProjectID, toProfileID); + + } + /** * Query on mongo. * diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java index 2a1ee82..3d619d2 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java @@ -2,16 +2,19 @@ package org.gcube.application.geoportalcommon.shared.geoportal; import java.io.Serializable; import java.util.LinkedHashMap; +import java.util.List; import org.gcube.application.geoportalcommon.shared.geoportal.project.BasicLifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.PublicationInfoDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV; -public class ResultDocumentDV extends DocumentDV implements Serializable{ +public class ResultDocumentDV extends DocumentDV implements Serializable { private String id; private String profileID; private BasicLifecycleInformationDV lifecycleInfo; private PublicationInfoDV publicationInfoDV; + private List listRelationshipDV; /** * @@ -54,6 +57,14 @@ public class ResultDocumentDV extends DocumentDV implements Serializable{ this.lifecycleInfo = lifecycleInfo; } + public void setListRelationship(List listRelationshipDV) { + this.listRelationshipDV = listRelationshipDV; + } + + public List getListRelationshipDV() { + return listRelationshipDV; + } + public void setPublicationInfo(PublicationInfoDV publicationInfoDV) { this.publicationInfoDV = publicationInfoDV; @@ -74,6 +85,8 @@ public class ResultDocumentDV extends DocumentDV implements Serializable{ builder.append(lifecycleInfo); builder.append(", publicationInfoDV="); builder.append(publicationInfoDV); + builder.append(", listRelationshipDV="); + builder.append(listRelationshipDV); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/RelationshipDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/RelationshipDV.java index 4857325..ff2a535 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/RelationshipDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/RelationshipDV.java @@ -10,6 +10,7 @@ public class RelationshipDV implements Serializable { private static final long serialVersionUID = 8295671124305773593L; private String relationshipName; private String targetID; + private String asJSON; public RelationshipDV() { @@ -36,6 +37,14 @@ public class RelationshipDV implements Serializable { this.relationshipName = relationshipName; } + public String getAsJSON() { + return asJSON; + } + + public void setAsJSON(String asJSON) { + this.asJSON = asJSON; + } + @Override public String toString() { StringBuilder builder = new StringBuilder();