From 5c8c2a342d914fa2cdd288823168396e07a60c29 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 10 Aug 2022 17:07:28 +0200 Subject: [PATCH] added new data view models --- .../ConvertToDataValueObjectModel.java | 216 ++++++++++++++++-- .../ConvertToDataViewModel.java | 34 --- .../geoportal/ProjectsCaller.java | 95 ++++---- .../shared/ResultSetPaginatedData.java | 9 +- .../shared/SearchingFilter.java | 25 +- .../shared/geoportal/ExtendedDocumentDV.java | 35 --- .../shared/geoportal/ResultDocumentDV.java | 81 +++++++ .../shared/geoportal/project/AccessDV.java | 83 +++++++ .../geoportal/project/AccountingInfoDV.java | 108 +++++++++ .../project/BasicLifecycleInformationDV.java | 112 +++++++++ .../project/IdentificationReferenceDV.java | 14 +- .../project/LifecycleInformationDV.java | 39 +--- .../geoportal/project/PublicationInfoDV.java | 56 +++++ .../org/gcube/application/Project_Tests.java | 99 ++++---- 14 files changed, 774 insertions(+), 232 deletions(-) delete mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ExtendedDocumentDV.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccessDV.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccountingInfoDV.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/BasicLifecycleInformationDV.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/PublicationInfoDV.java diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java index fe07e63..5985b64 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java @@ -1,8 +1,11 @@ package org.gcube.application.geoportalcommon; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -10,6 +13,9 @@ import java.util.Set; import org.bson.Document; 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; +import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo; import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference; import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation; import org.gcube.application.geoportal.common.model.document.relationships.Relationship; @@ -20,12 +26,17 @@ import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile; import org.gcube.application.geoportalcommon.geoportal.config.ItemField; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; +import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.AccessDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.AccountingInfoDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.BasicLifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.IdentificationReferenceDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.PublicationInfoDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; @@ -45,6 +56,13 @@ public class ConvertToDataValueObjectModel { private static Logger LOG = LoggerFactory.getLogger(ConvertToDataValueObjectModel.class); + private static final String NO_TIME = "T00:00"; + + public static final String DATE_FORMAT = "dd-MM-yyyy"; + + public static final String HOURS_MINUTES_SEPARATOR = ":"; + + public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm"; /** * To use case descriptor DV. * @@ -348,7 +366,7 @@ public class ConvertToDataValueObjectModel { * @return the project DV * @throws Exception the exception */ - public static ProjectDV toProjectDV(Project project, ProjectDVBuilder projectReader) throws Exception { + public static ProjectDV toProjectDV(Project project, ProjectDVBuilder projectReader) { LOG.info("toProjectDV called"); if (project == null) @@ -363,11 +381,12 @@ public class ConvertToDataValueObjectModel { ProjectDV theProject = new ProjectDV(); theProject.setId(project.getId()); theProject.setProfileID(project.getProfileID()); - theProject.setProfileVersion(project.getProfileVersion() != null ? project.getProfileVersion().getValue() : ""); - theProject.setVersion(project.getVersion()!=null? project.getVersion().getValue():""); + theProject.setProfileVersion( + project.getProfileVersion() != null ? project.getProfileVersion().getValue() : ""); + theProject.setVersion(project.getVersion() != null ? project.getVersion().getValue() : ""); - theProject.setTheDocument(toDocumentDV(project.getTheDocument(), DocumentDV.class, projectReader.getListDocumentKeys(), - projectReader.isIncludeFullDocumentMap())); + theProject.setTheDocument(toDocumentDV(project.getTheDocument(), DocumentDV.class, + projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap())); List relations = project.getRelationships(); @@ -382,20 +401,21 @@ public class ConvertToDataValueObjectModel { List identificationReferences = project.getIdentificationReferences(); - if(identificationReferences!=null) { - - Map mapIdentReferenceDV = new HashMap(identificationReferences.size()); - + if (identificationReferences != null) { + + Map mapIdentReferenceDV = new HashMap( + identificationReferences.size()); + for (IdentificationReference identificationReference : identificationReferences) { - IdentificationReferenceDV idv = toIdentificationReferenceDV(identificationReference, projectReader.getListDocumentKeys(), - projectReader.isIncludeFullDocumentMap()); - + IdentificationReferenceDV idv = toIdentificationReferenceDV(identificationReference, + projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap()); + mapIdentReferenceDV.put(idv.getType(), idv); } - + theProject.setMapIdentReferenceDV(mapIdentReferenceDV); } - + if (projectReader.isIncludeLifecycleInformation()) { if (project.getLifecycleInformation() != null) theProject.setLifecycleInformationDV(toLifecycleInformationDV(project.getLifecycleInformation())); @@ -411,8 +431,6 @@ public class ConvertToDataValueObjectModel { // projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap())); // } - - // // LOG.info("Returning concessioneDV with id: " + theConcessione.getItemId()); // @@ -428,6 +446,91 @@ public class ConvertToDataValueObjectModel { } + /** + * To result document DV. + * + * @param project the project + * @return the result document DV + * @throws Exception the exception + */ + public static ResultDocumentDV toResultDocumentDV(Project project) { + LOG.info("toResultDocumentDV called"); + + if (project == null) + return null; + + LOG.info("toResultDocumentDV called for project id: {}", project.getId()); + if (LOG.isTraceEnabled()) + LOG.trace("Source project is: " + project); + + try { + + ResultDocumentDV rd = (ResultDocumentDV) toDocumentDV(project.getTheDocument(), ResultDocumentDV.class, + null, true); + rd.setId(project.getId()); + rd.setProfileID(project.getProfileID()); + + rd.setPublicationInfo(toPublicationInfoDV(project.getInfo())); + + if (project.getLifecycleInformation() != null) { + BasicLifecycleInformationDV bld = new BasicLifecycleInformationDV(); + bld.setPhase(project.getLifecycleInformation().getPhase()); + bld.setLastOperationStatus( + toLifecycleInformationDVStatus(project.getLifecycleInformation().getLastOperationStatus())); + rd.setLifecycleInfo(bld); + } + + if (LOG.isDebugEnabled()) + LOG.debug("Returning: " + rd); + + LOG.info("Returning " + ResultDocumentDV.class.getSimpleName() + " with id: " + rd.getId()); + return rd; + } catch (Exception e) { + LOG.error("Error on converting " + ResultDocumentDV.class.getSimpleName() + ": " + project, e); + return null; + } + + } + + private static PublicationInfoDV toPublicationInfoDV(PublicationInfo info) { + if (info == null) + return null; + + PublicationInfoDV pidv = new PublicationInfoDV(); + pidv.setCreationInfo(toAccountingInfoDV(info.getCreationInfo())); + pidv.setLastEditInfo(toAccountingInfoDV(info.getLastEditInfo())); + pidv.setAccess(toAccessDV(info.getAccess())); + + return pidv; + + } + + private static AccessDV toAccessDV(Access access) { + if (access == null) + return null; + + AccessDV acDV = new AccessDV(); + acDV.setLicense(access.getLicense()); + acDV.setPolicy(access.getPolicy() != null ? access.getPolicy().name() : null); + + return acDV; + } + + private static AccountingInfoDV toAccountingInfoDV(AccountingInfo creationInfo) { + if (creationInfo == null) + return null; + + AccountingInfoDV aidv = new AccountingInfoDV(); + aidv.setContext(creationInfo.getContext() != null ? creationInfo.getContext().getId() : null); + aidv.setLocalDate(toDateFormatString(creationInfo.getInstant())); + if (creationInfo.getUser() != null) { + aidv.setRoles(creationInfo.getUser().getRoles()); + aidv.setUsername(creationInfo.getUser().getUsername()); + } + + return aidv; + } + private static IdentificationReferenceDV toIdentificationReferenceDV( IdentificationReference identificationReference, List listDocumentKeys, boolean getFullMap) { if (identificationReference == null) @@ -439,6 +542,40 @@ public class ConvertToDataValueObjectModel { return idv; } + + /** + * To date format string. + * + * @param dateTime the date time + * @return the string + */ + public static String toDateFormatString(LocalDateTime dateTime) { + + if (dateTime == null) + return null; + + String time = dateTime.toString(); + DateTimeFormatter formatter = null; + try { + if (!time.endsWith(NO_TIME)) { + formatter = DateTimeFormatter.ofPattern(DATE_FORMAT + " " + TIME_FORMAT); + } else { + time = time.replace(NO_TIME, ""); + formatter = DateTimeFormatter.ofPattern(DATE_FORMAT); + } + } catch (Exception e) { + LOG.warn("Parsing error: ", e); + } + + try { + if (formatter != null) + return dateTime.format(formatter); + } catch (Exception e) { + LOG.warn("Date format error: ", e); + } + + return dateTime.toString(); + } // /** // * To temporal reference DV. @@ -565,6 +702,51 @@ public class ConvertToDataValueObjectModel { } } + /** + * To list project. + * + * @param projects the projects + * @param projectBuilder the project builder + * @return the list + */ + public static List toListProject(Iterator projects, ProjectDVBuilder projectBuilder) { + List toReturnList = new ArrayList(); + int i = 0; + while (projects.hasNext()) { + Project project = projects.next(); + ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder); + toReturnList.add(projectDV); + i++; + LOG.trace(i + ") converted: " + projectDV); + } + LOG.debug("read " + toReturnList + " project/s"); + + return toReturnList; + + } + + /** + * To list result document. + * + * @param projects the projects + * @return the list + */ + public static List toListResultDocument(Iterator projects) { + List toReturnList = new ArrayList(); + int i = 0; + while (projects.hasNext()) { + Project project = projects.next(); + ResultDocumentDV resultDV = ConvertToDataValueObjectModel.toResultDocumentDV(project); + toReturnList.add(resultDV); + i++; + LOG.trace(i + ") converted: " + resultDV); + } + LOG.debug("read " + toReturnList + " project/s"); + + return toReturnList; + + } + /** * To JSON. * @@ -576,7 +758,7 @@ public class ConvertToDataValueObjectModel { try { // if (theObj instanceof Serializable) { - return org.gcube.application.geoportal.client.utils.Serialization.write(theObj); + return org.gcube.application.geoportal.client.utils.Serialization.write(theObj); // } // throw new Exception("The input object is not serializable"); diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java index 626ee52..20b52a6 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java @@ -1,8 +1,6 @@ package org.gcube.application.geoportalcommon; import java.io.Serializable; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -330,39 +328,7 @@ public class ConvertToDataViewModel { } - /** - * To date format string. - * - * @param dateTime the date time - * @return the string - */ - public static String toDateFormatString(LocalDateTime dateTime) { - if (dateTime == null) - return null; - - String time = dateTime.toString(); - DateTimeFormatter formatter = null; - try { - if (!time.endsWith(NO_TIME)) { - formatter = DateTimeFormatter.ofPattern(DATE_FORMAT + " " + TIME_FORMAT); - } else { - time = time.replace(NO_TIME, ""); - formatter = DateTimeFormatter.ofPattern(DATE_FORMAT); - } - } catch (Exception e) { - LOG.warn("Parsing error: ", e); - } - - try { - if (formatter != null) - return dateTime.format(formatter); - } catch (Exception e) { - LOG.warn("Date format error: ", e); - } - - return dateTime.toString(); - } /** * To abstract relazione scavo. 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 31e7f40..44a5457 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java +++ b/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java @@ -26,16 +26,12 @@ import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportal.common.utils.FileSets; import org.gcube.application.geoportal.common.utils.StorageUtils; -import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; -import org.gcube.application.geoportalcommon.ProjectDVBuilder; -import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; import org.gcube.application.geoportalcommon.shared.WhereClause; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.PhaseDV; -import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.json.JSONArray; import org.json.JSONObject; @@ -237,6 +233,13 @@ public class ProjectsCaller { return null; } + /** + * Gets the phases. + * + * @param profileID the profile ID + * @return the phases + * @throws Exception the exception + */ public PhaseDV[] getPhases(String profileID) throws Exception { LOG.info("getPhases called for profileID: {}", profileID); Projects client = (Projects) getClient(profileID); @@ -264,20 +267,20 @@ public class ProjectsCaller { return null; } + /** * Query on mongo. * - * @param profileID the profile ID - * @param totalItems the total items - * @param offset the offset - * @param limit the limit - * @param filter the filter - * @param projectDVBuilder the project DV builder - * @return the result set paginated data + * @param profileID the profile ID + * @param totalItems the total items + * @param offset the offset + * @param limit the limit + * @param filter the filter + * @return the iterator * @throws Exception the exception */ - public ResultSetPaginatedData queryOnMongo(String profileID, Integer totalItems, Integer offset, Integer limit, - SearchingFilter filter, ProjectDVBuilder projectDVBuilder) throws Exception { + public Iterator queryOnMongo(String profileID, Integer totalItems, Integer offset, Integer limit, + SearchingFilter filter) throws Exception { LOG.info("queryOnMongo called"); try { @@ -301,10 +304,6 @@ public class ProjectsCaller { limitIndex = totalItems; } - ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false); - searchedData.setTotalItems(totalItems); - - List toReturnList = new ArrayList(); Direction sDirection = null; List orderingFields = new ArrayList(); @@ -429,6 +428,10 @@ public class ProjectsCaller { bsValid_Document.append("$exists", true); bsValid_Document.append("$ne", null); query.append("_theDocument", bsValid_Document); + + BasicDBObject bsValidLfc = new BasicDBObject(); + bsValidLfc.append("$ne", null); + query.append("_lifecycleInformation._phase", bsValidLfc); BasicDBObject bsDocumentExists = new BasicDBObject(); bsDocumentExists.append("$exists", false); @@ -449,35 +452,35 @@ public class ProjectsCaller { LOG.info("Search query to JSON: " + query.toJson()); } - Iterator projects = geoportalClient.query(request); - int i = 0; - while (projects.hasNext()) { - Project project = projects.next(); - ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectDVBuilder); - toReturnList.add(projectDV); - i++; - LOG.trace(i + ") converted: " + projectDV); - } - LOG.debug("read " + toReturnList + " project/s"); - - searchedData.setData(toReturnList); - - // TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT - // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE - if (filter.getConditions() != null) { - searchedData.setTotalItems(toReturnList.size()); - totalItems = toReturnList.size(); - } - - if (totalItems == limit || totalItems == 0) { - LOG.debug("Page completed returning " + totalItems + " items"); - int newOffset = offsetIndex + limitIndex; - searchedData.setServerSearchFinished(newOffset > totalItems || totalItems == 0); - LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); - - } - - return searchedData; + return geoportalClient.query(request); +// int i = 0; +// while (projects.hasNext()) { +// Project project = projects.next(); +// ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectDVBuilder); +// toReturnList.add(projectDV); +// i++; +// LOG.trace(i + ") converted: " + projectDV); +// } +// LOG.debug("read " + toReturnList + " project/s"); +// +// searchedData.setData(toReturnList); +// +// // TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT +// // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE +// if (filter.getConditions() != null) { +// searchedData.setTotalItems(toReturnList.size()); +// totalItems = toReturnList.size(); +// } +// +// if (totalItems == limit || totalItems == 0) { +// LOG.debug("Page completed returning " + totalItems + " items"); +// int newOffset = offsetIndex + limitIndex; +// searchedData.setServerSearchFinished(newOffset > totalItems || totalItems == 0); +// LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); +// +// } +// +// return searchedData; } catch (Exception e) { LOG.error("Error on loading paginated and filtered list of Project: ", e); diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java b/src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java index 78b57ad..bbf9a58 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java @@ -6,7 +6,8 @@ package org.gcube.application.geoportalcommon.shared; import java.io.Serializable; import java.util.List; -import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; +import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; +import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; /** * The Class ResultSetPaginatedData. @@ -21,7 +22,7 @@ public class ResultSetPaginatedData implements Serializable { * */ private static final long serialVersionUID = 6800997954077785719L; - private List data; + private List data; private int offset = 0; private int limit; private boolean isServerSearchFinished = false; @@ -52,7 +53,7 @@ public class ResultSetPaginatedData implements Serializable { * * @return the data */ - public List getData() { + public List getData() { return data; } @@ -88,7 +89,7 @@ public class ResultSetPaginatedData implements Serializable { * * @param data the new data */ - public void setData(List data) { + public void setData(List data) { this.data = data; } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java b/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java index ee0529b..e4a829a 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java @@ -1,9 +1,11 @@ package org.gcube.application.geoportalcommon.shared; import java.io.Serializable; +import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; +import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; +import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; /** @@ -88,7 +90,7 @@ public class SearchingFilter implements Serializable { private List conditions; - private Map projection; + private LinkedHashMap projection; /** * Instantiates a new sort filter. @@ -96,13 +98,18 @@ public class SearchingFilter implements Serializable { public SearchingFilter() { } - - private void addProjectionBaseInfo(){ - if(projection!=null) { -// projection.put("_id", 1); + + private void addProjectionBaseInfo(Class theClass) { + + if (projection != null) { projection.put("_profileID", 1); projection.put("_profileVersion", 1); projection.put("_version", 1); + if (theClass.isAssignableFrom(ResultDocumentDV.class)) { + projection.put("_lifecycleInformation", 1); + projection.put("_info", 1); + } + } } @@ -138,12 +145,12 @@ public class SearchingFilter implements Serializable { this.conditions = conditions; } - public void setProjection(Map projection) { + public void setProjection(LinkedHashMap projection, Class theClass) { this.projection = projection; - addProjectionBaseInfo(); + addProjectionBaseInfo(theClass); } - public Map getProjection() { + public LinkedHashMap getProjection() { return projection; } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ExtendedDocumentDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ExtendedDocumentDV.java deleted file mode 100644 index 1d9d450..0000000 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ExtendedDocumentDV.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.gcube.application.geoportalcommon.shared.geoportal; - -import java.util.LinkedHashMap; - -public class ExtendedDocumentDV extends DocumentDV { - - /** - * - */ - private static final long serialVersionUID = -7209592503036632772L; - - public ExtendedDocumentDV() { - - } - - public void addItemToMap(String property, Object value) { - - if (documentAsMap == null) - documentAsMap = new LinkedHashMap(); - - documentAsMap.put(property, value); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ExtendedDocumentDV [toString()="); - builder.append(super.toString()); - builder.append("]"); - return builder.toString(); - } - - - -} 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 new file mode 100644 index 0000000..2a1ee82 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java @@ -0,0 +1,81 @@ +package org.gcube.application.geoportalcommon.shared.geoportal; + +import java.io.Serializable; +import java.util.LinkedHashMap; + +import org.gcube.application.geoportalcommon.shared.geoportal.project.BasicLifecycleInformationDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.PublicationInfoDV; + +public class ResultDocumentDV extends DocumentDV implements Serializable{ + + private String id; + private String profileID; + private BasicLifecycleInformationDV lifecycleInfo; + private PublicationInfoDV publicationInfoDV; + + /** + * + */ + private static final long serialVersionUID = -7209592503036632772L; + + public ResultDocumentDV() { + + } + + public String getId() { + return id; + } + + public String getProfileID() { + return profileID; + } + + public void setId(String id) { + this.id = id; + } + + public void setProfileID(String profileID) { + this.profileID = profileID; + } + + public void addItemToMap(String property, Object value) { + + if (documentAsMap == null) + documentAsMap = new LinkedHashMap(); + + documentAsMap.put(property, value); + } + + public BasicLifecycleInformationDV getLifecycleInfo() { + return lifecycleInfo; + } + + public void setLifecycleInfo(BasicLifecycleInformationDV lifecycleInfo) { + this.lifecycleInfo = lifecycleInfo; + } + + public void setPublicationInfo(PublicationInfoDV publicationInfoDV) { + this.publicationInfoDV = publicationInfoDV; + + } + + public PublicationInfoDV getPublicationInfoDV() { + return publicationInfoDV; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ResultDocumentDV [id="); + builder.append(id); + builder.append(", profileID="); + builder.append(profileID); + builder.append(", lifecycleInfo="); + builder.append(lifecycleInfo); + builder.append(", publicationInfoDV="); + builder.append(publicationInfoDV); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccessDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccessDV.java new file mode 100644 index 0000000..4079f5a --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccessDV.java @@ -0,0 +1,83 @@ +package org.gcube.application.geoportalcommon.shared.geoportal.project; + +import java.io.Serializable; + + +/** + * The Class AccessDV. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Aug 10, 2022 + */ +public class AccessDV implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -8017931037814730958L; + + private String policy; + + private String license; + + /** + * Instantiates a new access DV. + */ + public AccessDV() { + + } + + /** + * Gets the policy. + * + * @return the policy + */ + public String getPolicy() { + return policy; + } + + /** + * Gets the license. + * + * @return the license + */ + public String getLicense() { + return license; + } + + /** + * Sets the policy. + * + * @param policy the new policy + */ + public void setPolicy(String policy) { + this.policy = policy; + } + + /** + * Sets the license. + * + * @param license the new license + */ + public void setLicense(String license) { + this.license = license; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AccessDV [policy="); + builder.append(policy); + builder.append(", license="); + builder.append(license); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccountingInfoDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccountingInfoDV.java new file mode 100644 index 0000000..05f840c --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/AccountingInfoDV.java @@ -0,0 +1,108 @@ +package org.gcube.application.geoportalcommon.shared.geoportal.project; + +import java.io.Serializable; +import java.util.Set; + +/** + * The Class AccountingInfoDV. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Aug 10, 2022 + */ +public class AccountingInfoDV implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -5676731760855130687L; + private String username; + private Set roles; + private String context; + private String localDate; + + /** + * Instantiates a new accounting info DV. + */ + public AccountingInfoDV() { + + } + + /** + * Gets the username. + * + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * Gets the roles. + * + * @return the roles + */ + public Set getRoles() { + return roles; + } + + /** + * Gets the context. + * + * @return the context + */ + public String getContext() { + return context; + } + + /** + * Sets the username. + * + * @param username the new username + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * Sets the roles. + * + * @param roles the new roles + */ + public void setRoles(Set roles) { + this.roles = roles; + } + + /** + * Sets the context. + * + * @param context the new context + */ + public void setContext(String context) { + this.context = context; + } + + public String getLocalDate() { + return localDate; + } + + public void setLocalDate(String localDate) { + this.localDate = localDate; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AccountingInfoDV [username="); + builder.append(username); + builder.append(", roles="); + builder.append(roles); + builder.append(", context="); + builder.append(context); + builder.append(", localDate="); + builder.append(localDate); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/BasicLifecycleInformationDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/BasicLifecycleInformationDV.java new file mode 100644 index 0000000..321b547 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/BasicLifecycleInformationDV.java @@ -0,0 +1,112 @@ +package org.gcube.application.geoportalcommon.shared.geoportal.project; + +import java.io.Serializable; + +/** + * The Class BasicLifecycleInformationDV. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Aug 10, 2022 + */ +public class BasicLifecycleInformationDV implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 2301238401365921132L; + + /** + * The Enum Status. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 21, 2022 + */ + public static enum Status { + OK("Success"), ERROR("Error"), WARNING("Warning"), NOT_SPECIFIED("Not specified"); + + private String label; + + /** + * Instantiates a new status. + * + * @param label the label + */ + private Status(String label) { + this.label = label; + } + + /** + * Gets the label. + * + * @return the label + */ + public String getLabel() { + return label; + } + } + + protected String phase; + protected Status lastOperationStatus; + + /** + * Instantiates a new basic lifecycle information DV. + */ + public BasicLifecycleInformationDV() { + + } + + /** + * Gets the phase. + * + * @return the phase + */ + public String getPhase() { + return phase; + } + + /** + * Gets the last operation status. + * + * @return the last operation status + */ + public Status getLastOperationStatus() { + return lastOperationStatus; + } + + /** + * Sets the phase. + * + * @param phase the new phase + */ + public void setPhase(String phase) { + this.phase = phase; + } + + /** + * Sets the last operation status. + * + * @param lastOperationStatus the new last operation status + */ + public void setLastOperationStatus(Status lastOperationStatus) { + this.lastOperationStatus = lastOperationStatus; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("BasicLifecycleInformationDV [phase="); + builder.append(phase); + builder.append(", lastOperationStatus="); + builder.append(lastOperationStatus); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java index 3af3754..dcec7b4 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java @@ -10,8 +10,8 @@ public class IdentificationReferenceDV extends DocumentDV implements Serializabl * */ private static final long serialVersionUID = -1940104535678320214L; - - String type; + + private String type; public IdentificationReferenceDV() { @@ -25,4 +25,14 @@ public class IdentificationReferenceDV extends DocumentDV implements Serializabl public String getType() { return type; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IdentificationReferenceDV [type="); + builder.append(type); + builder.append("]"); + return builder.toString(); + } + } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/LifecycleInformationDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/LifecycleInformationDV.java index 3c6db82..208b307 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/LifecycleInformationDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/LifecycleInformationDV.java @@ -1,6 +1,5 @@ package org.gcube.application.geoportalcommon.shared.geoportal.project; -import java.io.Serializable; import java.util.List; /** @@ -10,47 +9,13 @@ import java.util.List; * * Mar 21, 2022 */ -public class LifecycleInformationDV implements Serializable { +public class LifecycleInformationDV extends BasicLifecycleInformationDV { /** * */ - private static final long serialVersionUID = 453646810523938512L; - - /** - * The Enum Status. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Mar 21, 2022 - */ - public static enum Status { - OK("Success"), ERROR("Error"), WARNING("Warning"), NOT_SPECIFIED("Not specified"); - - private String label; - - /** - * Instantiates a new status. - * - * @param label the label - */ - private Status(String label) { - this.label = label; - } - - /** - * Gets the label. - * - * @return the label - */ - public String getLabel() { - return label; - } - } - - private String phase; + private static final long serialVersionUID = 3042285563158430778L; private String lastInvokedStep; - private Status lastOperationStatus; private List errorMessages; private List warningMessages; private String asJSONString; diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/PublicationInfoDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/PublicationInfoDV.java new file mode 100644 index 0000000..da0977b --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/PublicationInfoDV.java @@ -0,0 +1,56 @@ +package org.gcube.application.geoportalcommon.shared.geoportal.project; + +import java.io.Serializable; + +public class PublicationInfoDV implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -6381578837148417563L; + private AccountingInfoDV creationInfo; + private AccountingInfoDV lastEditInfo; + private AccessDV access; + + public PublicationInfoDV() { + + } + + public AccountingInfoDV getCreationInfo() { + return creationInfo; + } + + public AccountingInfoDV getLastEditInfo() { + return lastEditInfo; + } + + public AccessDV getAccess() { + return access; + } + + public void setCreationInfo(AccountingInfoDV creationInfo) { + this.creationInfo = creationInfo; + } + + public void setLastEditInfo(AccountingInfoDV lastEditInfo) { + this.lastEditInfo = lastEditInfo; + } + + public void setAccess(AccessDV access) { + this.access = access; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PublicationInfoDV [creationInfo="); + builder.append(creationInfo); + builder.append(", lastEditInfo="); + builder.append(lastEditInfo); + builder.append(", access="); + builder.append(access); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/test/java/org/gcube/application/Project_Tests.java b/src/test/java/org/gcube/application/Project_Tests.java index 234fb3e..58d516f 100644 --- a/src/test/java/org/gcube/application/Project_Tests.java +++ b/src/test/java/org/gcube/application/Project_Tests.java @@ -2,38 +2,30 @@ package org.gcube.application; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.bson.BsonDocument; -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.lifecycle.LifecycleInformation; -import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ProjectDVBuilder; import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller; -import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; +import org.gcube.application.geoportalcommon.shared.WhereClause; +import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.PhaseDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; -import org.gcube.application.geoportalcommon.shared.WhereClause; -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; -import org.json.JSONArray; -import org.json.JSONObject; import org.junit.Before; import org.junit.Test; -import com.jayway.jsonpath.DocumentContext; -import com.jayway.jsonpath.JsonPath; -import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; - public class Project_Tests { private ProjectsCaller client = null; @@ -53,7 +45,7 @@ public class Project_Tests { client = GeoportalClientCaller.projects(); } - //@Test + // @Test public void getList() throws Exception { List listOfProjects = client.getListForProfileID(PROFILE_ID); @@ -62,8 +54,8 @@ public class Project_Tests { System.out.println(++i + ") " + project); } } - - //@Test + + // @Test public void getByID() throws Exception { Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); @@ -71,7 +63,7 @@ public class Project_Tests { System.out.println(projectDV); } - //@Test + // @Test public void getListProjectsDV() throws Exception { List listOfProjects = client.getListForProfileID(PROFILE_ID); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); @@ -82,52 +74,63 @@ public class Project_Tests { } } - - //@Test + + @Test public void getListProjectsDVFiltered() throws Exception { - //List listOfProjects = client.getListForProfileID(PROFILE_ID); - + // List listOfProjects = client.getListForProfileID(PROFILE_ID); + SearchingFilter filter = new SearchingFilter(); - - //Where Clause + // Where Clause List conditions = new ArrayList(); Map searchInto = new HashMap(); - //searchInto.put("_id", "61f0299baf51592c36795f52"); - //searchInto.put("_theDocument.nome", "Test progetto con clustering di fileset"); + // searchInto.put("_id", "61f0299baf51592c36795f52"); + // searchInto.put("_theDocument.nome", "Test progetto con clustering di + // fileset"); WhereClause whereClause = new WhereClause(LOGICAL_OP.AND, searchInto); conditions.add(whereClause); filter.setConditions(conditions); - - Map projection = new HashMap(); - //default + + LinkedHashMap projection = new LinkedHashMap(); + // default + projection.put("_theDocument.nome", 1); projection.put("_profileID", 1); projection.put("_profileVersion", 1); projection.put("_version", 1); projection.put("_theDocument", 1); - + projection.put("_theDocument.paroleChiaveLibere", 1); projection.put("_theDocument.editore", 1); projection.put("_theDocument.paroleChiaveICCD", 1); - projection.put("_theDocument.nome", 1); projection.put("_theDocument.responsabile", 1); - projection.put("_theDocument.authors", 1); - - projection.put("_theDocument.nome", 1); + projection.put("_theDocument.introduzione", 1); projection.put("_theDocument.authors", 1); - filter.setProjection(projection); - - ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); - ResultSetPaginatedData results = client.queryOnMongo(PROFILE_ID, 300, 0, 10, filter, projectBuilder); + filter.setProjection(projection, ResultDocumentDV.class); + + Integer totalDocs = client.getTotalDocument(PROFILE_ID); + + Iterator projects = client.queryOnMongo(PROFILE_ID, totalDocs, 0, 10, filter); + + List results = ConvertToDataValueObjectModel.toListResultDocument(projects); int i = 0; - for (ProjectDV projectDV : results.getData()) { + for (ResultDocumentDV projectDV : results) { System.out.println(++i + ") " + projectDV); } + //TEST TO PROJECT DV + /* + ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); + + List listProjects = ConvertToDataValueObjectModel.toListProject(projects, projectBuilder); + i = 0; + for (ProjectDV projectDV : listProjects) { + System.out.println(++i + ") " + projectDV); + } + */ } - - //@Test + + // @Test public void getLifecycleForProjectId() throws Exception { Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID); LifecycleInformation lci = project.getLifecycleInformation(); @@ -135,29 +138,29 @@ public class Project_Tests { System.out.println(liDV); // } - - //@Test + + // @Test public void getConfiguration() throws Exception { Configuration config = client.getConfiguration(PROFILE_ID); System.out.println(config); } - - //@Test + + // @Test public void getTotalDocument() throws Exception { System.out.println(client.getTotalDocument(PROFILE_ID)); } - - //@Test + + // @Test public void getListPhases() throws Exception { - + List idsPhases = client.getIDsPhases(PROFILE_ID); System.out.println(idsPhases); - + PhaseDV[] phases = client.getPhases(PROFILE_ID); for (PhaseDV phaseDV : phases) { System.out.println(phaseDV); } - + } }