Added createRelation method

This commit is contained in:
Francesco Mangiacrapa 2022-09-21 10:52:31 +02:00
parent 5c644e8c1e
commit 2f263dae44
4 changed files with 78 additions and 7 deletions

View File

@ -15,6 +15,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bson.Document; 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.Project;
import org.gcube.application.geoportal.common.model.document.access.Access; import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo; import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
@ -174,7 +175,7 @@ public class ConvertToDataValueObjectModel {
* To handler declaration DV. * To handler declaration DV.
* *
* @param handlerDeclaration the handler declaration * @param handlerDeclaration the handler declaration
* @param profileName the profile name * @param ucd the ucd
* @param readConfigs the read configs * @param readConfigs the read configs
* @return the handler declaration DV * @return the handler declaration DV
* @throws Exception the exception * @throws Exception the exception
@ -312,7 +313,8 @@ public class ConvertToDataValueObjectModel {
List<ActionDefinitionDV> listActionsDef = new ArrayList<ActionDefinitionDV>( List<ActionDefinitionDV> listActionsDef = new ArrayList<ActionDefinitionDV>(
jsonConfigurations.size()); 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<HandlerDeclaration> listHandlersLC = ucd List<HandlerDeclaration> listHandlersLC = ucd
.getHandlersByType(GEOPORTAL_DATA_HANDLER.gna_concessioni_lc.getType()); .getHandlersByType(GEOPORTAL_DATA_HANDLER.gna_concessioni_lc.getType());
@ -597,6 +599,15 @@ public class ConvertToDataValueObjectModel {
rd.setLifecycleInfo(bld); rd.setLifecycleInfo(bld);
} }
if (project.getRelationships() != null) {
List<RelationshipDV> listRelDV = new ArrayList<RelationshipDV>(project.getRelationships().size());
for (Relationship relationship : project.getRelationships()) {
RelationshipDV relDV = toRelationshipDV(relationship);
listRelDV.add(relDV);
}
rd.setListRelationship(listRelDV);
}
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Returning: " + rd); LOG.debug("Returning: " + rd);
@ -962,7 +973,18 @@ public class ConvertToDataValueObjectModel {
if (relationship == null) if (relationship == null)
return 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;
} }
/** /**

View File

@ -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.Archive;
import org.gcube.application.geoportal.common.model.configuration.Configuration; 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.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;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction;
@ -323,6 +324,32 @@ public class ProjectsCaller {
return client.updateDocument(projectID, updatedDocument); 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<Project> client = (Projects<Project>) 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. * Query on mongo.
* *

View File

@ -2,16 +2,19 @@ package org.gcube.application.geoportalcommon.shared.geoportal;
import java.io.Serializable; import java.io.Serializable;
import java.util.LinkedHashMap; 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.BasicLifecycleInformationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.project.PublicationInfoDV; 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 id;
private String profileID; private String profileID;
private BasicLifecycleInformationDV lifecycleInfo; private BasicLifecycleInformationDV lifecycleInfo;
private PublicationInfoDV publicationInfoDV; private PublicationInfoDV publicationInfoDV;
private List<RelationshipDV> listRelationshipDV;
/** /**
* *
@ -54,6 +57,14 @@ public class ResultDocumentDV extends DocumentDV implements Serializable{
this.lifecycleInfo = lifecycleInfo; this.lifecycleInfo = lifecycleInfo;
} }
public void setListRelationship(List<RelationshipDV> listRelationshipDV) {
this.listRelationshipDV = listRelationshipDV;
}
public List<RelationshipDV> getListRelationshipDV() {
return listRelationshipDV;
}
public void setPublicationInfo(PublicationInfoDV publicationInfoDV) { public void setPublicationInfo(PublicationInfoDV publicationInfoDV) {
this.publicationInfoDV = publicationInfoDV; this.publicationInfoDV = publicationInfoDV;
@ -74,6 +85,8 @@ public class ResultDocumentDV extends DocumentDV implements Serializable{
builder.append(lifecycleInfo); builder.append(lifecycleInfo);
builder.append(", publicationInfoDV="); builder.append(", publicationInfoDV=");
builder.append(publicationInfoDV); builder.append(publicationInfoDV);
builder.append(", listRelationshipDV=");
builder.append(listRelationshipDV);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }

View File

@ -10,6 +10,7 @@ public class RelationshipDV implements Serializable {
private static final long serialVersionUID = 8295671124305773593L; private static final long serialVersionUID = 8295671124305773593L;
private String relationshipName; private String relationshipName;
private String targetID; private String targetID;
private String asJSON;
public RelationshipDV() { public RelationshipDV() {
@ -36,6 +37,14 @@ public class RelationshipDV implements Serializable {
this.relationshipName = relationshipName; this.relationshipName = relationshipName;
} }
public String getAsJSON() {
return asJSON;
}
public void setAsJSON(String asJSON) {
this.asJSON = asJSON;
}
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();