Moving to Project ad UCD models..

This commit is contained in:
Francesco Mangiacrapa 2022-03-11 12:01:27 +01:00
parent e27a95cab2
commit 608039a4d5
27 changed files with 1474 additions and 349 deletions

View File

@ -1,16 +1,26 @@
package org.gcube.application.geoportalcommon; package org.gcube.application.geoportalcommon;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import org.gcube.application.geoportalcommon.geoportalconfig.Configuration; import org.bson.Document;
import org.gcube.application.geoportalcommon.geoportalconfig.DocumentConfig; import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportalcommon.geoportalconfig.FilePath; import org.gcube.application.geoportal.common.model.document.Relationship;
import org.gcube.application.geoportalcommon.geoportalconfig.GcubeProfile; import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.ConfigurationDV; import org.gcube.application.geoportalcommon.geoportal.config.Configuration;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV; import org.gcube.application.geoportalcommon.geoportal.config.DocumentConfig;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.FilePathDV; import org.gcube.application.geoportalcommon.geoportal.config.FilePath;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileDV; import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile;
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
import org.gcube.application.geoportalcommon.shared.geoportal.RelationshipDV;
import org.gcube.application.geoportalcommon.shared.geoportal.TemporalReferenceDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.DocumentConfigDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -128,4 +138,115 @@ public class ConvertToDataValueObjectModel {
return fpVO; return fpVO;
} }
public static ProjectDV toProjectDV(Project project, ProjectDVBuilder projectReader) throws Exception {
LOG.info("toProjectDV called");
if (project == null)
return null;
LOG.info("toProjectDV called for project id=%s with ", project.getId(), projectReader);
if (LOG.isTraceEnabled())
LOG.trace("Source project is: " + project);
try {
ProjectDV theProject = new ProjectDV();
theProject.setId(project.getId());
theProject.setProfileID(project.getProfileID());
theProject.setProfileVersion(
project.getProfileVersion() != null ? project.getProfileVersion().getValue() : "");
Relationship[] relations = project.getRelationships();
if (relations != null && projectReader.isIncludeRelationships()) {
List<RelationshipDV> listRelations = new ArrayList<RelationshipDV>(relations.length);
for (Relationship relationship : relations) {
listRelations.add(toRelationshipDV(relationship));
}
theProject.setRelationships(listRelations);
}
if (projectReader.isIncludeSpatialReference()) {
theProject.setSpatialReference(toDocumentDV(project.getSpatialReference(), DocumentDV.class,
projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap()));
}
if (projectReader.isIncludeTemporalReference()) {
theProject.setTemporalReference(toTemporalReferenceDV(project.getTemporalReference(),
projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap()));
}
// if (projectReader.isIncludeValidationReport()) {
// theProject.setValidationReport(toValidationReport(concessione.getReport()));
// if (theProject.getValidationReport() != null)
// theProject.setValidationStatus(theConcessione.getValidationReport().getStatus());
// }
//
// LOG.info("Returning concessioneDV with id: " + theConcessione.getItemId());
//
// if (LOG.isTraceEnabled())
// LOG.trace("Returning: " + theConcessione);
return theProject;
} catch (Exception e) {
LOG.error("Error on converting project: " + project, e);
return null;
}
}
public static TemporalReferenceDV toTemporalReferenceDV(TemporalReference temporalReference,
List<String> listDocumentKeys, boolean getFullMap) {
if (temporalReference == null)
return null;
TemporalReferenceDV trDV = toDocumentDV(temporalReference, TemporalReferenceDV.class, listDocumentKeys,
getFullMap);
trDV.setField(temporalReference.getField());
return trDV;
}
public static <T extends DocumentDV> T toDocumentDV(Document document, Class<T> toType,
List<String> listDocumentKeys, boolean getFullMap) {
if (document == null)
return null;
T documentDV;
if (toType == TemporalReferenceDV.class) {
documentDV = (T) new TemporalReferenceDV();
} else {
documentDV = (T) new DocumentDV();
}
if (listDocumentKeys != null && !getFullMap) {
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(listDocumentKeys.size());
for (String key : listDocumentKeys) {
documentAsMap.put(key, document.get(key));
}
documentDV.setDocumentAsMap(documentAsMap);
}
if (getFullMap) {
Set<String> keySet = document.keySet();
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(keySet.size());
for (String key : keySet) {
documentAsMap.put(key, document.get(key));
}
documentDV.setDocumentAsMap(documentAsMap);
}
documentDV.setDocumentAsJSON(document.toJson());
return documentDV;
}
public static RelationshipDV toRelationshipDV(Relationship relationship) {
if (relationship == null)
return null;
return new RelationshipDV(relationship.getRelationshipName(), relationship.getTargetID());
}
} }

View File

@ -54,6 +54,7 @@ public class ConvertToDataViewModel {
public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm"; public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm";
/** /**
* To concessione. * To concessione.
* *

View File

@ -6,8 +6,8 @@ import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.application.geoportalcommon.geoportalconfig.DocumentConfig; import org.gcube.application.geoportalcommon.geoportal.config.DocumentConfig;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.DocumentConfigDV;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;

View File

@ -1,266 +1,266 @@
package org.gcube.application.geoportalcommon; //package org.gcube.application.geoportalcommon;
//
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni; //import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.Arrays; //import java.util.Arrays;
import java.util.Iterator; //import java.util.Iterator;
import java.util.List; //import java.util.List;
import java.util.Map; //import java.util.Map;
//
import org.bson.Document; //import org.bson.Document;
import org.gcube.application.geoportal.common.model.legacy.Concessione; //import org.gcube.application.geoportal.common.model.legacy.Concessione;
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;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; //import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni; //import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportalcommon.shared.ItemField; //import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; //import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter; //import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; //import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; //import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
import org.gcube.application.geoportalcommon.shared.WhereClause; //import org.gcube.application.geoportalcommon.shared.WhereClause;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; //import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
//
import com.mongodb.BasicDBList; //import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject; //import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder; //import com.mongodb.BasicDBObjectBuilder;
//
/** ///**
* The Class MongoServiceCommon. // * The Class MongoServiceCommon.
* // *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it // * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* // *
* Dec 3, 2021 // * Dec 3, 2021
*/ // */
public class MongoServiceCommon { //public class MongoServiceCommon {
//
private static Logger LOG = LoggerFactory.getLogger(MongoServiceCommon.class); // private static Logger LOG = LoggerFactory.getLogger(MongoServiceCommon.class);
//
/** // /**
* Gets the instance mongo concessioni. // * Gets the instance mongo concessioni.
* // *
* @return the instance mongo concessioni // * @return the instance mongo concessioni
*/ // */
public MongoConcessioni getInstanceMongoConcessioni() { // public MongoConcessioni getInstanceMongoConcessioni() {
return mongoConcessioni().build(); // return mongoConcessioni().build();
} // }
//
/** // /**
* Gets the list of concessioni. // * Gets the list of concessioni.
* // *
* @param reloadFromService the reload from service // * @param reloadFromService the reload from service
* @return the list of concessioni // * @return the list of concessioni
* @throws Exception the exception // * @throws Exception the exception
*/ // */
public List<Concessione> getListOfConcessioni() throws Exception { // public List<Concessione> getListOfConcessioni() throws Exception {
LOG.info("called getListOfConcessioni"); // LOG.info("called getListOfConcessioni");
//
List<Concessione> listOfConcessioni = new ArrayList<Concessione>(); // List<Concessione> listOfConcessioni = new ArrayList<Concessione>();
LOG.info("Loading list of concessioni from client mongo"); // LOG.info("Loading list of concessioni from client mongo");
MongoConcessioni clientMongo = getInstanceMongoConcessioni(); // MongoConcessioni clientMongo = getInstanceMongoConcessioni();
//
Iterator<Concessione> concessioni = clientMongo.getList(); // Iterator<Concessione> concessioni = clientMongo.getList();
if (concessioni != null) { // if (concessioni != null) {
while (concessioni.hasNext()) { // while (concessioni.hasNext()) {
Concessione concessione = (Concessione) concessioni.next(); // Concessione concessione = (Concessione) concessioni.next();
listOfConcessioni.add(concessione); // listOfConcessioni.add(concessione);
//
} // }
} // }
//
LOG.info("read list of concessioni with size: " + listOfConcessioni.size()); // LOG.info("read list of concessioni with size: " + listOfConcessioni.size());
return listOfConcessioni; // return listOfConcessioni;
} // }
//
/** // /**
* Query on mongo. // * Query on mongo.
* // *
* @param offset the offset // * @param offset the offset
* @param limit the limit // * @param limit the limit
* @param filter the filter // * @param filter the filter
* @param recordType the record type // * @param recordType the record type
* @return the result set paginated data // * @return the result set paginated data
* @throws Exception the exception // * @throws Exception the exception
*/ // */
public ResultSetPaginatedData queryOnMongo(Integer totalItems, Integer offset, Integer limit, SearchingFilter filter, String recordType) throws Exception { // public ResultSetPaginatedData queryOnMongo(Integer totalItems, Integer offset, Integer limit, SearchingFilter filter, String recordType) throws Exception {
//
try { // try {
//
if (recordType.equalsIgnoreCase("concessione")) { // if (recordType.equalsIgnoreCase("concessione")) {
MongoConcessioni clientMongo = getInstanceMongoConcessioni(); // MongoConcessioni clientMongo = getInstanceMongoConcessioni();
//
if(totalItems==null || totalItems < 0) { // if(totalItems==null || totalItems < 0) {
// TODO MUST BE REPLACED BY COUNT // // TODO MUST BE REPLACED BY COUNT
List<Concessione> listOfConcessioni = getListOfConcessioni(); // List<Concessione> listOfConcessioni = getListOfConcessioni();
int listConcessioniSize = listOfConcessioni.size(); // int listConcessioniSize = listOfConcessioni.size();
totalItems = listConcessioniSize; // totalItems = listConcessioniSize;
} // }
//
Integer offsetIndex = offset; // Integer offsetIndex = offset;
Integer limitIndex = limit; // Integer limitIndex = limit;
//
if (offset == null || offset<0) { // if (offset == null || offset<0) {
offsetIndex = 0; // offsetIndex = 0;
} // }
if (limit == null || limit<0) { // if (limit == null || limit<0) {
limitIndex = totalItems; // limitIndex = totalItems;
} // }
//
ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false); // ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false);
searchedData.setTotalItems(totalItems); // searchedData.setTotalItems(totalItems);
//
List<ConcessioneDV> toReturnList = new ArrayList<ConcessioneDV>(); // List<ConcessioneDV> toReturnList = new ArrayList<ConcessioneDV>();
Direction sDirection = null; // Direction sDirection = null;
List<String> orderingFields = new ArrayList<String>(); // List<String> orderingFields = new ArrayList<String>();
//
if (filter == null) { // if (filter == null) {
LOG.info("No filter found, creating empty filter"); // LOG.info("No filter found, creating empty filter");
filter = new SearchingFilter(); // filter = new SearchingFilter();
} // }
//
ORDER order = filter.getOrder(); // ORDER order = filter.getOrder();
//
if (order == null) { // if (order == null) {
order = ORDER.ASC; // order = ORDER.ASC;
LOG.info("No direction/order found, using default: " + order); // LOG.info("No direction/order found, using default: " + order);
} // }
//
switch (order) { // switch (order) {
case ASC: // case ASC:
sDirection = Direction.ASCENDING; // sDirection = Direction.ASCENDING;
break; // break;
case DESC: // case DESC:
sDirection = Direction.DESCENDING; // sDirection = Direction.DESCENDING;
break; // break;
} // }
//
List<ItemField> orderByFields = filter.getOrderByFields(); // List<ItemField> orderByFields = filter.getOrderByFields();
//
if(orderByFields==null) { // if(orderByFields==null) {
orderByFields = new ArrayList<ItemField>(); // orderByFields = new ArrayList<ItemField>();
} // }
//
if(orderByFields.isEmpty()) { // if(orderByFields.isEmpty()) {
ItemField orderD = new ItemField("", Arrays.asList("name"), false, false, false); // ItemField orderD = new ItemField("", Arrays.asList("name"), false, false, false);
LOG.info("Order by is null, adding default: " + orderD); // LOG.info("Order by is null, adding default: " + orderD);
orderByFields.add(orderD); // orderByFields.add(orderD);
} // }
//
for (ItemField itemField : orderByFields) { // for (ItemField itemField : orderByFields) {
if (itemField.getJsonFields() != null) { // if (itemField.getJsonFields() != null) {
for (String field : itemField.getJsonFields()) { // for (String field : itemField.getJsonFields()) {
orderingFields.add(field); // orderingFields.add(field);
} // }
} // }
//
} // }
//
QueryRequest request = new QueryRequest(); // QueryRequest request = new QueryRequest();
PagedRequest paging = new PagedRequest(); // PagedRequest paging = new PagedRequest();
paging.setOffset(offsetIndex); // paging.setOffset(offsetIndex);
paging.setLimit(limitIndex); // paging.setLimit(limitIndex);
request.setPaging(paging); // request.setPaging(paging);
//
OrderedRequest ordering = new OrderedRequest(); // OrderedRequest ordering = new OrderedRequest();
ordering.setDirection(sDirection); // ordering.setDirection(sDirection);
ordering.setFields(orderingFields); // ordering.setFields(orderingFields);
//
request.setOrdering(ordering); // request.setOrdering(ordering);
//
Document query = new Document(); // Document query = new Document();
if(filter.getConditions()!=null) { // if(filter.getConditions()!=null) {
for (WhereClause whereClause : filter.getConditions()) { // for (WhereClause whereClause : filter.getConditions()) {
//
LOGICAL_OP searchWithOperator = whereClause.getOperator(); // LOGICAL_OP searchWithOperator = whereClause.getOperator();
if(searchWithOperator==null) { // if(searchWithOperator==null) {
searchWithOperator = LOGICAL_OP.OR; // searchWithOperator = LOGICAL_OP.OR;
} // }
//
if (whereClause.getSearchInto() != null) { // if (whereClause.getSearchInto() != null) {
Map<String, Object> searchFields = whereClause.getSearchInto(); // Map<String, Object> searchFields = whereClause.getSearchInto();
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); // BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
for (String key : searchFields.keySet()) { // for (String key : searchFields.keySet()) {
// using regex and case-insensitive // // using regex and case-insensitive
BasicDBObject bs = new BasicDBObject(); // BasicDBObject bs = new BasicDBObject();
bs.append("$regex", searchFields.get(key)); // bs.append("$regex", searchFields.get(key));
bs.append("$options", "i"); // bs.append("$options", "i");
builder.append(key, bs); // builder.append(key, bs);
//
//
} // }
//Building list of Document in OR clause // //Building list of Document in OR clause
BasicDBList list = new BasicDBList(); // BasicDBList list = new BasicDBList();
Map map = builder.get().toMap(); // Map map = builder.get().toMap();
for (Object key : map.keySet()) { // for (Object key : map.keySet()) {
//
BasicDBObject value = (BasicDBObject) map.get(key); // BasicDBObject value = (BasicDBObject) map.get(key);
Document doc = new Document((String) key, value); // Document doc = new Document((String) key, value);
list.add(doc); // list.add(doc);
} // }
//
//query = new Document(); // //query = new Document();
query.put(searchWithOperator.getOperator(), list); // query.put(searchWithOperator.getOperator(), list);
//
// BasicDBObject bs = new BasicDBObject(); //// BasicDBObject bs = new BasicDBObject();
// bs.append("$eq", "PASSED"); //// bs.append("$eq", "PASSED");
// query.put("report.status", bs); //// query.put("report.status", bs);
//
} // }
} // }
} // }
//
request.setFilter(query); // request.setFilter(query);
//
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex); // LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
LOG.info("Direction: " + sDirection); // LOG.info("Direction: " + sDirection);
LOG.info("Order by Fields: " + orderingFields); // LOG.info("Order by Fields: " + orderingFields);
LOG.info("Search for conditions: " + filter.getConditions()); // LOG.info("Search for conditions: " + filter.getConditions());
if (query != null) { // if (query != null) {
LOG.info("Search query to JSON: " + query.toJson()); // LOG.info("Search query to JSON: " + query.toJson());
} // }
//
Iterator<Concessione> concessioni = clientMongo.query(request); // Iterator<Concessione> concessioni = clientMongo.query(request);
int i = 0; // int i = 0;
while (concessioni.hasNext()) { // while (concessioni.hasNext()) {
Concessione concessione = concessioni.next(); // Concessione concessione = concessioni.next();
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); // ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
toReturnList.add(concessioneDV); // toReturnList.add(concessioneDV);
i++; // i++;
LOG.trace(i+") converted: " + concessioneDV); // LOG.trace(i+") converted: " + concessioneDV);
} // }
LOG.debug("read " + toReturnList + " project/s"); // LOG.debug("read " + toReturnList + " project/s");
//
searchedData.setData(toReturnList); // searchedData.setData(toReturnList);
//
// TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT // // TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT
// AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE // // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE
if (filter.getConditions() != null) { // if (filter.getConditions() != null) {
searchedData.setTotalItems(toReturnList.size()); // searchedData.setTotalItems(toReturnList.size());
totalItems = toReturnList.size(); // totalItems = toReturnList.size();
} // }
//
if (totalItems == limit || totalItems == 0) { // if (totalItems == limit || totalItems == 0) {
LOG.debug("Page completed returning " + totalItems + " items"); // LOG.debug("Page completed returning " + totalItems + " items");
int newOffset = offsetIndex + limitIndex; // int newOffset = offsetIndex + limitIndex;
searchedData.setServerSearchFinished(newOffset > totalItems || totalItems == 0); // searchedData.setServerSearchFinished(newOffset > totalItems || totalItems == 0);
LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); // LOG.debug("is Search finished: " + searchedData.isServerSearchFinished());
//
} // }
//
return searchedData; // return searchedData;
} // }
//
} catch (Exception e) { // } catch (Exception e) {
LOG.error("Error on loading paginated and filtered list of concessioni: ", e); // LOG.error("Error on loading paginated and filtered list of concessioni: ", e);
throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); // throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage());
} // }
//
return null; // return null;
//
} // }
//
} //}

View File

@ -0,0 +1,102 @@
package org.gcube.application.geoportalcommon;
import java.util.List;
/**
* The Class ProjectDVBuilder.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 10, 2022
*/
public class ProjectDVBuilder {
private boolean validationReport;
private boolean spatialReference;
private boolean temporalReference;
private boolean relationships;
private List<String> listDocumentKeys;
private boolean fullDocumentMap;
private ProjectDVBuilder() {
}
public static ProjectDVBuilder newBuilder() {
return new ProjectDVBuilder();
}
public boolean isIncludeValidationReport() {
return validationReport;
}
public boolean isIncludeSpatialReference() {
return spatialReference;
}
public boolean isIncludeTemporalReference() {
return temporalReference;
}
public boolean isIncludeRelationships() {
return relationships;
}
public List<String> getListDocumentKeys() {
return listDocumentKeys;
}
public boolean isIncludeFullDocumentMap() {
return fullDocumentMap;
}
public ProjectDVBuilder validationReport(boolean includeValidationReport) {
this.validationReport = includeValidationReport;
return this;
}
public ProjectDVBuilder spatialReference(boolean includeSpatialReference) {
this.spatialReference = includeSpatialReference;
return this;
}
public ProjectDVBuilder temporalReference(boolean includeTemporalReference) {
this.temporalReference = includeTemporalReference;
return this;
}
public ProjectDVBuilder relationships(boolean includeRelationships) {
this.relationships = includeRelationships;
return this;
}
public ProjectDVBuilder listDocumentKeys(List<String> listDocumentKeys) {
this.listDocumentKeys = listDocumentKeys;
return this;
}
public ProjectDVBuilder fullDocumentMap(boolean includeFullDocumentMap) {
this.fullDocumentMap = includeFullDocumentMap;
return this;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ProjectDVBuilder [validationReport=");
builder.append(validationReport);
builder.append(", spatialReference=");
builder.append(spatialReference);
builder.append(", temporalReference=");
builder.append(temporalReference);
builder.append(", relationships=");
builder.append(relationships);
builder.append(", listDocumentKeys=");
builder.append(listDocumentKeys);
builder.append(", fullDocumentMap=");
builder.append(fullDocumentMap);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,33 @@
package org.gcube.application.geoportalcommon.geoportal;
/**
* The Class GeoportalClientCaller
*
* Wrapping the geoportal Clients
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 11, 2022
*/
public class GeoportalClientCaller {
/**
* Use case descriptor client.
*
* @return the use case descriptor caller
*/
public static UseCaseDescriptorCaller useCaseDescriptors() {
return new UseCaseDescriptorCaller();
}
/**
* Projects client
*
* @return the projects caller
*/
public static ProjectsCaller projects() {
return new ProjectsCaller();
}
}

View File

@ -0,0 +1,281 @@
package org.gcube.application.geoportalcommon.geoportal;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
import java.io.File;
import java.io.FileNotFoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bson.Document;
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;
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.PagedRequest;
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.ItemField;
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.ProjectDV;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
public class ProjectsCaller {
private static Logger LOG = LoggerFactory.getLogger(GeoportalClientCaller.class);
public Projects<Project> getClient(String profileID) {
LOG.info("getProjectsClient called for profileID={}", profileID);
return projects(profileID).build();
}
public Project createNew(String profileID, String jsonDocument) throws RemoteException {
LOG.info("createNew called on profileID={}", profileID);
Document myDocument = Document.parse(jsonDocument);
Projects<Project> client = getClient(profileID);
Project project = client.createNew(myDocument);
return project;
}
public Project registerFileSet(String profileID, Project project, File theFile, String parentPath, String fieldName,
String fieldDefinition) throws RemoteException, FileNotFoundException, JsonProcessingException {
LOG.info(
"registerFileSet called with [profileID={}, projectID={}, theFile={}, parentPath={}, fieldName={}, fieldDefinition={}",
parentPath, project.getId(), theFile, parentPath, fieldName, fieldDefinition);
Projects<Project> client = getClient(profileID);
// Prepare request
RegisterFileSetRequest fsRequest = FileSets.prepareRequest(new StorageUtils(), parentPath, fieldName,
fieldDefinition, theFile);
project = client.registerFileSet(project.getId(), fsRequest);
LOG.trace("Resulting Project : " + project);
return project;
}
public List<Project> getListForProfileID(String profileID) throws Exception {
LOG.info("getlistOfProjectsForProfileID called for profileID: {}", profileID);
Projects<Project> client = (Projects<Project>) getClient(profileID);
List<Project> listProjects = new ArrayList<Project>();
Iterator<Project> projects = client.query(new QueryRequest());
for (Iterator<Project> iterator = projects; projects.hasNext();) {
Project prg = (Project) iterator.next();
listProjects.add(prg);
}
LOG.info("returning %d {}", listProjects.size(), Project.class.getName());
return listProjects;
}
public Configuration getConfiguration(String profileID) throws Exception {
LOG.info("getConfiguration called for profileID: {} ", profileID);
Projects<Project> client = (Projects<Project>) getClient(profileID);
Configuration config = client.getConfiguration();
LOG.debug("returning: {} ", config);
return config;
}
/**
* Query on mongo.
*
* @param offset the offset
* @param limit the limit
* @param filter the filter
* @param recordType the record type
* @return the result set paginated data
* @throws Exception the exception
*/
public ResultSetPaginatedData queryOnMongo(String profileID, Integer totalItems, Integer offset, Integer limit,
SearchingFilter filter, String recordType, ProjectDVBuilder projectDVBuilder) throws Exception {
try {
Projects<Project> geoportalClient = getClient(profileID);
if (totalItems == null || totalItems < 0) {
// TODO MUST BE REPLACED BY COUNT
List<Project> listOfProjects = getListForProfileID(profileID);
int listConcessioniSize = listOfProjects.size();
totalItems = listConcessioniSize;
}
Integer offsetIndex = offset;
Integer limitIndex = limit;
if (offset == null || offset < 0) {
offsetIndex = 0;
}
if (limit == null || limit < 0) {
limitIndex = totalItems;
}
ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false);
searchedData.setTotalItems(totalItems);
List<ProjectDV> toReturnList = new ArrayList<ProjectDV>();
Direction sDirection = null;
List<String> orderingFields = new ArrayList<String>();
if (filter == null) {
LOG.info("No filter found, creating empty filter");
filter = new SearchingFilter();
}
ORDER order = filter.getOrder();
if (order == null) {
order = ORDER.ASC;
LOG.info("No direction/order found, using default: " + order);
}
switch (order) {
case ASC:
sDirection = Direction.ASCENDING;
break;
case DESC:
sDirection = Direction.DESCENDING;
break;
}
List<ItemField> orderByFields = filter.getOrderByFields();
if (orderByFields == null) {
orderByFields = new ArrayList<ItemField>();
}
if (orderByFields.isEmpty()) {
ItemField orderD = new ItemField("", Arrays.asList("name"), false, false, false);
LOG.info("Order by is null, adding default: " + orderD);
orderByFields.add(orderD);
}
for (ItemField itemField : orderByFields) {
if (itemField.getJsonFields() != null) {
for (String field : itemField.getJsonFields()) {
orderingFields.add(field);
}
}
}
QueryRequest request = new QueryRequest();
PagedRequest paging = new PagedRequest();
paging.setOffset(offsetIndex);
paging.setLimit(limitIndex);
request.setPaging(paging);
OrderedRequest ordering = new OrderedRequest();
ordering.setDirection(sDirection);
ordering.setFields(orderingFields);
request.setOrdering(ordering);
Document query = new Document();
if (filter.getConditions() != null) {
for (WhereClause whereClause : filter.getConditions()) {
LOGICAL_OP searchWithOperator = whereClause.getOperator();
if (searchWithOperator == null) {
searchWithOperator = LOGICAL_OP.OR;
}
if (whereClause.getSearchInto() != null) {
Map<String, Object> searchFields = whereClause.getSearchInto();
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
for (String key : searchFields.keySet()) {
// using regex and case-insensitive
BasicDBObject bs = new BasicDBObject();
bs.append("$regex", searchFields.get(key));
bs.append("$options", "i");
builder.append(key, bs);
}
// Building list of Document in OR clause
BasicDBList list = new BasicDBList();
Map map = builder.get().toMap();
for (Object key : map.keySet()) {
BasicDBObject value = (BasicDBObject) map.get(key);
Document doc = new Document((String) key, value);
list.add(doc);
}
// query = new Document();
query.put(searchWithOperator.getOperator(), list);
// BasicDBObject bs = new BasicDBObject();
// bs.append("$eq", "PASSED");
// query.put("report.status", bs);
}
}
}
request.setFilter(query);
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
LOG.info("Direction: " + sDirection);
LOG.info("Order by Fields: " + orderingFields);
LOG.info("Search for conditions: " + filter.getConditions());
if (query != null) {
LOG.info("Search query to JSON: " + query.toJson());
}
Iterator<Project> 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;
} catch (Exception e) {
LOG.error("Error on loading paginated and filtered list of concessioni: ", e);
throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage());
}
}
}

View File

@ -0,0 +1,64 @@
package org.gcube.application.geoportalcommon.geoportal;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.rest.UseCaseDescriptorsI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mongodb.BasicDBObject;
public class UseCaseDescriptorCaller {
private static Logger LOG = LoggerFactory.getLogger(UseCaseDescriptorCaller.class);
public UseCaseDescriptorsI useCaseDescriptorsClient() {
LOG.info("useCaseDescriptorsClient called");
return useCaseDescriptors().build();
}
public List<UseCaseDescriptor> getList() throws Exception {
LOG.info("getlistOfUseCaseDescriptors called");
UseCaseDescriptorsI client = useCaseDescriptorsClient();
List<UseCaseDescriptor> listUCD = new ArrayList<UseCaseDescriptor>();
Iterator<UseCaseDescriptor> useCaseDescrs = client.query(new QueryRequest());
for (Iterator<UseCaseDescriptor> iterator = useCaseDescrs; useCaseDescrs.hasNext();) {
UseCaseDescriptor prg = (UseCaseDescriptor) iterator.next();
listUCD.add(prg);
}
LOG.info("returning %d {}", listUCD.size(), UseCaseDescriptor.class.getName());
return listUCD;
}
public UseCaseDescriptor geUCDForId(String profileID) throws Exception {
LOG.info("getUseCaseDescriptorForId called for profileID: {}", profileID);
UseCaseDescriptorsI client = useCaseDescriptorsClient();
QueryRequest queryRequest = new QueryRequest();
Document queryDoc = new Document();
BasicDBObject bs = new BasicDBObject();
bs.append("$eq", profileID);
queryDoc.put("_id", bs);
LOG.debug("Performing query: {}", queryDoc.toJson());
queryRequest.setFilter(queryDoc);
Iterator<UseCaseDescriptor> useCaseDescrs = client.query(queryRequest);
UseCaseDescriptor ucd = null;
if (useCaseDescrs.hasNext()) {
ucd = useCaseDescrs.next();
}
LOG.info("for profileID: {}, returning: {}", profileID, ucd);
return ucd;
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.geoportalconfig; package org.gcube.application.geoportalcommon.geoportal.config;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.geoportalconfig; package org.gcube.application.geoportalcommon.geoportal.config;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.geoportalconfig; package org.gcube.application.geoportalcommon.geoportal.config;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.geoportalconfig; package org.gcube.application.geoportalcommon.geoportal.config;
import java.util.List; import java.util.List;

View File

@ -6,7 +6,7 @@ package org.gcube.application.geoportalcommon.shared;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
/** /**
* The Class ResultSetPaginatedData. * The Class ResultSetPaginatedData.
@ -21,7 +21,7 @@ public class ResultSetPaginatedData implements Serializable {
* *
*/ */
private static final long serialVersionUID = 6800997954077785719L; private static final long serialVersionUID = 6800997954077785719L;
private List<ConcessioneDV> data; private List<ProjectDV> data;
private int offset = 0; private int offset = 0;
private int limit; private int limit;
private boolean isServerSearchFinished = false; private boolean isServerSearchFinished = false;
@ -52,7 +52,7 @@ public class ResultSetPaginatedData implements Serializable {
* *
* @return the data * @return the data
*/ */
public List<ConcessioneDV> getData() { public List<ProjectDV> getData() {
return data; return data;
} }
@ -88,7 +88,7 @@ public class ResultSetPaginatedData implements Serializable {
* *
* @param data the new data * @param data the new data
*/ */
public void setData(List<ConcessioneDV> data) { public void setData(List<ProjectDV> data) {
this.data = data; this.data = data;
} }

View File

@ -0,0 +1,51 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
import java.io.Serializable;
import java.util.LinkedHashMap;
public class DocumentDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = 4978517506036855883L;
private LinkedHashMap<String, Object> documentAsMap;
private String documentAsJSON;
public DocumentDV() {
}
public DocumentDV(LinkedHashMap<String, Object> documentAsMap, String documentAsJSON) {
super();
this.documentAsMap = documentAsMap;
this.documentAsJSON = documentAsJSON;
}
public LinkedHashMap<String, Object> getDocumentAsMap() {
return documentAsMap;
}
public String getDocumentAsJSON() {
return documentAsJSON;
}
public void setDocumentAsMap(LinkedHashMap<String, Object> documentAsMap) {
this.documentAsMap = documentAsMap;
}
public void setDocumentAsJSON(String documentAsJSON) {
this.documentAsJSON = documentAsJSON;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DocumentDV [documentAsMap=");
builder.append(documentAsMap);
builder.append(", documentAsJSON=");
builder.append(documentAsJSON);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,62 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
import java.io.Serializable;
public class HandlerDeclarationDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = 9095207023666383038L;
private String id;
private String type;
private DocumentDV configuration;
HandlerDeclarationDV() {
}
public HandlerDeclarationDV(String id, String type, DocumentDV configuration) {
super();
this.id = id;
this.type = type;
this.configuration = configuration;
}
public String getId() {
return id;
}
public String getType() {
return type;
}
public DocumentDV getConfiguration() {
return configuration;
}
public void setId(String id) {
this.id = id;
}
public void setType(String type) {
this.type = type;
}
public void setConfiguration(DocumentDV configuration) {
this.configuration = configuration;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("HandlerDeclarationDV [id=");
builder.append(id);
builder.append(", type=");
builder.append(type);
builder.append(", configuration=");
builder.append(configuration);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,113 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
import java.io.Serializable;
import java.util.List;
public class ProjectDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = 498764909635626624L;
private String id;
private String version;
// private PublicationInfo info;
private String profileID;
private String profileVersion;
private List<RelationshipDV> relationships;
private DocumentDV spatialReference;
private TemporalReferenceDV temporalReference;
private DocumentDV theDocument;
public ProjectDV() {
}
public String getId() {
return id;
}
public String getVersion() {
return version;
}
public String getProfileID() {
return profileID;
}
public String getProfileVersion() {
return profileVersion;
}
public List<RelationshipDV> getRelationships() {
return relationships;
}
public DocumentDV getSpatialReference() {
return spatialReference;
}
public TemporalReferenceDV getTemporalReference() {
return temporalReference;
}
public DocumentDV getTheDocument() {
return theDocument;
}
public void setId(String id) {
this.id = id;
}
public void setVersion(String version) {
this.version = version;
}
public void setProfileID(String profileID) {
this.profileID = profileID;
}
public void setProfileVersion(String profileVersion) {
this.profileVersion = profileVersion;
}
public void setRelationships(List<RelationshipDV> relationships) {
this.relationships = relationships;
}
public void setSpatialReference(DocumentDV spatialReference) {
this.spatialReference = spatialReference;
}
public void setTemporalReference(TemporalReferenceDV temporalReference) {
this.temporalReference = temporalReference;
}
public void setTheDocument(DocumentDV theDocument) {
this.theDocument = theDocument;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ProjectDV [id=");
builder.append(id);
builder.append(", version=");
builder.append(version);
builder.append(", profileID=");
builder.append(profileID);
builder.append(", profileVersion=");
builder.append(profileVersion);
builder.append(", relationships=");
builder.append(relationships);
builder.append(", spatialReference=");
builder.append(spatialReference);
builder.append(", temporalReference=");
builder.append(temporalReference);
builder.append(", theDocument=");
builder.append(theDocument);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,50 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
import java.io.Serializable;
public class RelationshipDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = 8295671124305773593L;
private String relationshipName;
private String targetID;
public RelationshipDV() {
}
public RelationshipDV(String relationshipName, String targetID) {
this.relationshipName = relationshipName;
this.targetID = targetID;
}
public String getTargetID() {
return targetID;
}
public void setTargetID(String targetID) {
this.targetID = targetID;
}
public String getRelationshipName() {
return relationshipName;
}
public void setRelationshipName(String relationshipName) {
this.relationshipName = relationshipName;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("RelationshipDV [relationshipName=");
builder.append(relationshipName);
builder.append(", targetID=");
builder.append(targetID);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,47 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
/**
* The Class TemporalReferenceDV.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 10, 2022
*/
public class TemporalReferenceDV extends DocumentDV {
/**
*
*/
private static final long serialVersionUID = -7990905553022863653L;
private String field;
/**
* Instantiates a new temporal reference DV.
*/
public TemporalReferenceDV() {
}
public TemporalReferenceDV(String field) {
super();
this.field = field;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TemporalReferenceDV [field=");
builder.append(field);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,114 @@
package org.gcube.application.geoportalcommon.shared.geoportal;
import java.io.Serializable;
import java.util.List;
public class UseCaseDescriptorDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = -2864888245002804887L;
private String id;
private String version;
private String name;
private String description;
private String fieldType;
private String fieldLabel;
private List<HandlerDeclarationDV> handlers;
UseCaseDescriptorDV() {
}
public UseCaseDescriptorDV(String id, String version, String name, String description, String fieldType,
String fieldLabel, List<HandlerDeclarationDV> handlers) {
super();
this.id = id;
this.version = version;
this.name = name;
this.description = description;
this.fieldType = fieldType;
this.fieldLabel = fieldLabel;
this.handlers = handlers;
}
public String getId() {
return id;
}
public String getVersion() {
return version;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getFieldType() {
return fieldType;
}
public String getFieldLabel() {
return fieldLabel;
}
public List<HandlerDeclarationDV> getHandlers() {
return handlers;
}
public void setId(String id) {
this.id = id;
}
public void setVersion(String version) {
this.version = version;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public void setFieldType(String fieldType) {
this.fieldType = fieldType;
}
public void setFieldLabel(String fieldLabel) {
this.fieldLabel = fieldLabel;
}
public void setHandlers(List<HandlerDeclarationDV> handlers) {
this.handlers = handlers;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("UseCaseDescriptorDV [id=");
builder.append(id);
builder.append(", version=");
builder.append(version);
builder.append(", name=");
builder.append(name);
builder.append(", description=");
builder.append(description);
builder.append(", fieldType=");
builder.append(fieldType);
builder.append(", fieldLabel=");
builder.append(fieldLabel);
builder.append(", handlers=");
builder.append(handlers);
builder.append("]");
return builder.toString();
}
}

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportalcommon.shared.geoportalconfig; package org.gcube.application.geoportalcommon.shared.geoportal.config;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -8,14 +8,14 @@ import java.util.List;
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Mar 7, 2022 * Mar 7, 2022
*/ */
public class GcubeProfileDV implements Serializable { public class GcubeProfileDV implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = -7910384776524845043L; private static final long serialVersionUID = -6177379075015880565L;
public static final int MIN_MAX_NOT_SPECIFIED = -1; public static final int MIN_MAX_NOT_SPECIFIED = -1;
@ -46,15 +46,6 @@ public class GcubeProfileDV implements Serializable {
public GcubeProfileDV() { public GcubeProfileDV() {
} }
/**
* Gets the serialversionuid.
*
* @return the serialversionuid
*/
public static long getSerialversionuid() {
return serialVersionUID;
}
/** /**
* Gets the gcube secondary type. * Gets the gcube secondary type.
* *
@ -91,9 +82,9 @@ public class GcubeProfileDV implements Serializable {
return sectionTitle; return sectionTitle;
} }
/** /**
* Gets the parent name. If is null or empty return the "" /(empty string) as default. * Gets the parent name. If is null or empty return the "" /(empty string) as
* default.
* *
* @return the parent name * @return the parent name
*/ */

View File

@ -5,7 +5,7 @@ import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import org.gcube.application.geoportalcommon.MockDocumentConfigurationReader; import org.gcube.application.geoportalcommon.MockDocumentConfigurationReader;
import org.gcube.application.geoportalcommon.geoportalconfig.DocumentConfig; import org.gcube.application.geoportalcommon.geoportal.config.DocumentConfig;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Test; import org.junit.Test;

View File

@ -0,0 +1,55 @@
package org.gcube.application;
import java.util.List;
import org.gcube.application.geoportal.common.model.document.Project;
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.geoportal.ProjectDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
public class Project_Tests {
private ProjectsCaller client = null;
// private static String CONTEXT = "/pred4s/preprod/preVRE";
// private static String TOKEN = ""; //preVRE
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni";
@Before
public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
client = GeoportalClientCaller.projects();
}
@Test
public void getList() throws Exception {
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
int i = 0;
for (Project project : listOfProjects) {
System.out.println(++i + ") " + project);
}
}
@Test
public void getListProjectsDV() throws Exception {
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
int i = 0;
for (Project project : listOfProjects) {
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
System.out.println(++i + ") " + projectDV);
}
}
}

View File

@ -1,26 +1,13 @@
package org.gcube.application; package org.gcube.application;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.GeoportalCommonConstants;
import org.gcube.application.geoportalcommon.MongoServiceCommon;
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.ItemField;
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.config.RoleRights; import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
public class TestGNACommon { public class TestGNACommon {
@ -57,40 +44,40 @@ public class TestGNACommon {
} }
// @Test // @Test
public void queryConcessioniTest() throws Exception { // public void queryConcessioniTest() throws Exception {
try { // try {
//
ScopeProvider.instance.set(CONTEXT); // ScopeProvider.instance.set(CONTEXT);
MongoServiceCommon msc = new MongoServiceCommon(); // MongoServiceCommon msc = new MongoServiceCommon();
SearchingFilter filter = new SearchingFilter(); // SearchingFilter filter = new SearchingFilter();
//
Map<String, Object> searchInto = new HashMap<String, Object>(); // Map<String, Object> searchInto = new HashMap<String, Object>();
searchInto.put("nome", "san"); // searchInto.put("nome", "san");
searchInto.put("authors", "silvia"); // searchInto.put("authors", "silvia");
// searchInto.put("report.status", "PASSED"); // // searchInto.put("report.status", "PASSED");
//
WhereClause where1 = new WhereClause(LOGICAL_OP.OR, searchInto); // WhereClause where1 = new WhereClause(LOGICAL_OP.OR, searchInto);
//
Map<String, Object> searchInto2 = new HashMap<String, Object>(); // Map<String, Object> searchInto2 = new HashMap<String, Object>();
searchInto2.put("report.status", "PASSED"); // searchInto2.put("report.status", "PASSED");
WhereClause where2 = new WhereClause(LOGICAL_OP.AND, searchInto2); // WhereClause where2 = new WhereClause(LOGICAL_OP.AND, searchInto2);
//
ArrayList<WhereClause> list = new ArrayList<WhereClause>(); // ArrayList<WhereClause> list = new ArrayList<WhereClause>();
list.add(where1); // list.add(where1);
// list.add(where2); // // list.add(where2);
filter.setConditions(list); // filter.setConditions(list);
ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione"); // ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione");
//
int i = 0; // int i = 0;
for (ConcessioneDV concessione : result.getData()) { // for (ConcessioneDV concessione : result.getData()) {
System.out.println(++i + ") " + concessione); // System.out.println(++i + ") " + concessione);
} // }
//
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
//
} // }
// @Test // @Test
public void readGNDataEntryConfigsFromIS() throws Exception { public void readGNDataEntryConfigsFromIS() throws Exception {

View File

@ -0,0 +1,53 @@
package org.gcube.application;
import java.util.List;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
public class UCD_Tests {
private UseCaseDescriptorCaller client = null;
// private static String CONTEXT = "/pred4s/preprod/preVRE";
// private static String TOKEN = ""; //preVRE
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni";
@Before
public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
client = GeoportalClientCaller.useCaseDescriptors();
}
// @Test
public void getList() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<UseCaseDescriptor> listOfUCD = client.getList();
int i = 0;
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
System.out.println(++i + ") " + useCaseDescriptor);
}
}
@Test
public void getItemByID() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
UseCaseDescriptor ucd = client.geUCDForId(PROFILE_ID);
System.out.println(ucd);
}
}