Refactored. Added getListPhases, getConfiguration, getTotalDocument

This commit is contained in:
Francesco Mangiacrapa 2022-08-10 12:29:03 +02:00
parent 83f6fb915c
commit 0d2fddce07
19 changed files with 257 additions and 44 deletions

View File

@ -20,17 +20,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.GEOPORTAL_CONFIGURATION_TYPE;
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.IdentificationReferenceDV;
import org.gcube.application.geoportalcommon.shared.geoportal.LifecycleInformationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
import org.gcube.application.geoportalcommon.shared.geoportal.RelationshipDV;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
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.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.RelationshipDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -6,13 +6,16 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bson.Document;
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.rest.QueryRequest;
@ -30,12 +33,18 @@ 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.ProjectDV;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
@ -75,7 +84,7 @@ public class ProjectsCaller {
Document myDocument = Document.parse(jsonDocument);
Projects<Project> client = getClient(profileID);
Project project = client.createNew(myDocument);
return project;
}
@ -166,6 +175,95 @@ public class ProjectsCaller {
return config;
}
/**
* Gets the total document.
*
* @param profileID the profile ID
* @return the total document
* @throws Exception the exception
*/
public Integer getTotalDocument(String profileID) throws Exception {
LOG.info("getTotalDocument called for profileID: {}", profileID);
Projects<Project> client = (Projects<Project>) getClient(profileID);
Configuration config = client.getConfiguration();
List<Archive> listArchives = config.getArchives();
for (Archive archive : listArchives) {
String theType = archive.getString("_type");
if (theType.equalsIgnoreCase("DOCUMENT-STORE-COLLECTION")) {
String totalDocumentAre = archive.get("count").toString();
int total = Integer.parseInt(totalDocumentAre);
LOG.info("total docs for profileID: {}, are: {}", profileID, total);
return total;
}
}
return null;
}
/**
* Gets the total document.
*
* @param profileID the profile ID
* @return the total document
* @throws Exception the exception
*/
public List<String> getIDsPhases(String profileID) throws Exception {
LOG.info("getIDsPhases called for profileID: {}", profileID);
Projects<Project> client = (Projects<Project>) getClient(profileID);
Configuration config = client.getConfiguration();
List<Archive> listArchives = config.getArchives();
for (Archive archive : listArchives) {
String theType = archive.getString("_type");
if (theType.equalsIgnoreCase("DOCUMENT-STORE-COLLECTION")) {
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
String toJSON = archive.toJson();
JSONObject jObject = new JSONObject(toJSON);
JsonPath jsonPath = JsonPath.compile("$.countByPhase[*]._id.phase");
JSONArray phases = jsonPath.read(jObject, configuration);
HashSet<String> listdata = new HashSet<String>(phases.length());
for (int i = 0; i < phases.length(); i++) {
listdata.add(phases.get(i).toString());
}
List<String> idsPhases = listdata.stream().collect(Collectors.toList());
LOG.info("getIDsPhases returning: {}", idsPhases);
return idsPhases;
}
}
LOG.info("getIDsPhases returning null");
return null;
}
public PhaseDV[] getPhases(String profileID) throws Exception {
LOG.info("getPhases called for profileID: {}", profileID);
Projects<Project> client = (Projects<Project>) getClient(profileID);
Configuration config = client.getConfiguration();
List<Archive> listArchives = config.getArchives();
for (Archive archive : listArchives) {
String theType = archive.getString("_type");
if (theType.equalsIgnoreCase("DOCUMENT-STORE-COLLECTION")) {
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
String toJSON = archive.toJson();
JSONObject jObject = new JSONObject(toJSON);
JsonPath jsonPath = JsonPath.compile("$.countByPhase[*]");
JSONArray phases = jsonPath.read(jObject, configuration);
final ObjectMapper objectMapper = new ObjectMapper();
PhaseDV[] phasesArr = objectMapper.readValue(phases.toString(), PhaseDV[].class);
LOG.info("getPhases returning {} PhaseDVs", phasesArr.length);
return phasesArr;
}
}
LOG.info("getPhases returning null");
return null;
}
/**
* Query on mongo.
*
@ -251,11 +349,11 @@ public class ProjectsCaller {
}
}
Map<String, Object> projection = filter.getProjection();
Document projectionDocument = null;
if(projection!=null && !projection.isEmpty()) {
if (projection != null && !projection.isEmpty()) {
projectionDocument = new Document(projection);
}
@ -264,7 +362,7 @@ public class ProjectsCaller {
paging.setOffset(offsetIndex);
paging.setLimit(limitIndex);
request.setPaging(paging);
OrderedRequest ordering = new OrderedRequest();
ordering.setDirection(sDirection);
ordering.setFields(orderingFields);
@ -311,28 +409,27 @@ public class ProjectsCaller {
}
}
}
if(projectionDocument!=null) {
if (projectionDocument != null) {
request.setProjection(projectionDocument);
//THE first field specified in the projection must be not null
// THE first field specified in the projection must be not null
BasicDBObject bsNotEqualEmpty = new BasicDBObject();
bsNotEqualEmpty.append("$ne", null);
Optional<String> firstKey = projection.keySet().stream().findFirst();
if (firstKey.isPresent()) {
String firstFieldPath = firstKey.get();
query.append(firstFieldPath, bsNotEqualEmpty);
String firstFieldPath = firstKey.get();
query.append(firstFieldPath, bsNotEqualEmpty);
}
}
BasicDBObject bsValid_Document = new BasicDBObject();
bsValid_Document.append("$exists", true);
bsValid_Document.append("$ne", null);
query.append("_theDocument", bsValid_Document);
BasicDBObject bsDocumentExists = new BasicDBObject();
bsDocumentExists.append("$exists", false);
query.append("theDocument", bsDocumentExists);
@ -340,12 +437,12 @@ public class ProjectsCaller {
// BasicDBObject bsNotEqualEmpty = new BasicDBObject();
// bsNotEqualEmpty.append("$ne", null);
// query.append("_theDocument.nome", bsNotEqualEmpty);
request.setFilter(query);
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
LOG.info("Direction: " + sDirection);
LOG.info("Projection: "+projectionDocument);
LOG.info("Projection: " + projectionDocument);
LOG.info("Order by Fields: " + orderingFields);
LOG.info("Search for conditions: " + filter.getConditions());
if (query != null) {

View File

@ -6,7 +6,7 @@ package org.gcube.application.geoportalcommon.shared;
import java.io.Serializable;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
/**
* The Class ResultSetPaginatedData.

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GeoportalConfigurationID;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE;
public class ConfigurationDV<T extends List<? extends GeoportalConfigurationID>> implements Serializable {

View File

@ -9,7 +9,7 @@ public class DocumentDV implements Serializable {
*
*/
private static final long serialVersionUID = 4978517506036855883L;
private LinkedHashMap<String, Object> documentAsMap;
protected LinkedHashMap<String, Object> documentAsMap;
private String documentAsJSON;
private ConfigurationDV<?> configuration;

View File

@ -0,0 +1,35 @@
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<String, Object>();
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();
}
}

View File

@ -1,7 +1,9 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.project;
import java.io.Serializable;
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
public class IdentificationReferenceDV extends DocumentDV implements Serializable {
/**

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.project;
import java.io.Serializable;
import java.util.List;

View File

@ -0,0 +1,35 @@
package org.gcube.application.geoportalcommon.shared.geoportal.project;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class PhaseDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1894531938705738017L;
private Integer count;
private Phase_Id _id;
public PhaseDV() {
}
@Data
@AllArgsConstructor
class Phase_Id {
String phase;
String status;
public Phase_Id() {
}
}
}

View File

@ -1,9 +1,11 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.project;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
public class ProjectDV implements Serializable {
/**

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.project;
import java.io.Serializable;

View File

@ -1,4 +1,6 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.project;
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
/**
* The Class TemporalReferenceDV.

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.ucd;
public enum GEOPORTAL_CONFIGURATION_TYPE {
item_fields("itemFields"), gcube_profiles("gcubeProfiles");

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.ucd;
public enum GEOPORTAL_DATA_HANDLER {

View File

@ -1,7 +1,9 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.ucd;
import java.io.Serializable;
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
/**
* The Class HandlerDeclarationDV.
*

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
package org.gcube.application.geoportalcommon.shared.geoportal.ucd;
import java.io.Serializable;
import java.util.List;

View File

@ -12,8 +12,8 @@ import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDec
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile;
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Test;
import org.slf4j.Logger;

View File

@ -5,8 +5,12 @@ import java.util.HashMap;
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;
@ -14,14 +18,22 @@ 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.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.application.geoportalcommon.shared.geoportal.LifecycleInformationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
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;
@ -71,7 +83,7 @@ public class Project_Tests {
}
@Test
//@Test
public void getListProjectsDVFiltered() throws Exception {
//List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
@ -123,4 +135,29 @@ public class Project_Tests {
System.out.println(liDV);
//
}
//@Test
public void getConfiguration() throws Exception {
Configuration config = client.getConfiguration(PROFILE_ID);
System.out.println(config);
}
//@Test
public void getTotalDocument() throws Exception {
System.out.println(client.getTotalDocument(PROFILE_ID));
}
//@Test
public void getListPhases() throws Exception {
List<String> idsPhases = client.getIDsPhases(PROFILE_ID);
System.out.println(idsPhases);
PhaseDV[] phases = client.getPhases(PROFILE_ID);
for (PhaseDV phaseDV : phases) {
System.out.println(phaseDV);
}
}
}

View File

@ -10,11 +10,11 @@ import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
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.ucd.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;