in progress on migration to UCD

This commit is contained in:
Francesco Mangiacrapa 2022-03-17 16:03:32 +01:00
parent f1cec8071a
commit 9f3bd01da0
13 changed files with 515 additions and 373 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.application.geoportalcommon; package org.gcube.application.geoportalcommon;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -27,6 +28,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorD
import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV; 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.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -134,7 +136,7 @@ public class ConvertToDataValueObjectModel {
* *
* @param ucd the ucd * @param ucd the ucd
* @param handlersIds the handlers ids. If not null only returns (so filtering * @param handlersIds the handlers ids. If not null only returns (so filtering
* for) handler ids. Otherwise returns all handlers * for) the handler ids. Otherwise returns all handlers
* @return the document config DV * @return the document config DV
* @throws Exception the exception * @throws Exception the exception
*/ */
@ -162,9 +164,15 @@ public class ConvertToDataValueObjectModel {
List<HandlerDeclaration> listHandlerDeclaration = handlersMapByID.get(handlersId); List<HandlerDeclaration> listHandlerDeclaration = handlersMapByID.get(handlersId);
for (HandlerDeclaration handlerDeclaration : listHandlerDeclaration) { for (HandlerDeclaration handlerDeclaration : listHandlerDeclaration) {
LOG.debug("converting handler {}", handlerDeclaration); LOG.debug("converting handler {}", handlerDeclaration);
HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration); HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration, ucd.getName());
LOG.debug("handler converted to {}", hdDV); if (hdDV != null) {
listHandlersDV.add(hdDV); LOG.debug("handler converted to {}", hdDV);
listHandlersDV.add(hdDV);
} else {
LOG.info("Skipping {} as null for {}", HandlerDeclarationDV.class.getSimpleName(),
handlerDeclaration);
}
} }
} }
} }
@ -172,9 +180,14 @@ public class ConvertToDataValueObjectModel {
List<HandlerDeclaration> listHandlerDeclaration = ucd.getHandlers(); List<HandlerDeclaration> listHandlerDeclaration = ucd.getHandlers();
for (HandlerDeclaration handlerDeclaration : listHandlerDeclaration) { for (HandlerDeclaration handlerDeclaration : listHandlerDeclaration) {
LOG.debug("converting handler {}", handlerDeclaration); LOG.debug("converting handler {}", handlerDeclaration);
HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration); HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration, ucd.getName());
LOG.debug("handler converted to {}", hdDV); if (hdDV != null) {
listHandlersDV.add(hdDV); LOG.debug("handler converted to {}", hdDV);
listHandlersDV.add(hdDV);
} else {
LOG.info("Skipping {} as null for {}", HandlerDeclarationDV.class.getSimpleName(),
handlerDeclaration);
}
} }
} }
@ -205,7 +218,8 @@ public class ConvertToDataValueObjectModel {
* @return the handler declaration DV * @return the handler declaration DV
* @throws Exception the exception * @throws Exception the exception
*/ */
public static HandlerDeclarationDV toHandlerDeclarationDV(HandlerDeclaration handlerDeclaration) throws Exception { public static HandlerDeclarationDV toHandlerDeclarationDV(HandlerDeclaration handlerDeclaration, String profileName)
throws Exception {
if (handlerDeclaration == null) { if (handlerDeclaration == null) {
LOG.warn(HandlerDeclaration.class.getSimpleName() + " is null"); LOG.warn(HandlerDeclaration.class.getSimpleName() + " is null");
@ -217,40 +231,61 @@ public class ConvertToDataValueObjectModel {
HandlerDeclarationDV hdDV = new HandlerDeclarationDV(); HandlerDeclarationDV hdDV = new HandlerDeclarationDV();
hdDV.setId(handlerDeclaration.getId()); hdDV.setId(handlerDeclaration.getId());
hdDV.setType(handlerDeclaration.getType()); hdDV.setType(handlerDeclaration.getType());
hdDV.setHandlerType(to_GEOPORTAL_DATA_HANDLER(handlerDeclaration.getId())); hdDV.setItemType(profileName);
hdDV.setDataHandlerType(to_GEOPORTAL_DATA_HANDLER(handlerDeclaration.getId()));
if (configuration == null) { if (configuration == null) {
LOG.warn("Configuration is null"); LOG.warn("Configuration is null in the handler with id: " + handlerDeclaration.getId());
return null; return null;
} }
try { try {
GEOPORTAL_CONFIGURATION_TYPE foundConfig = null; GEOPORTAL_CONFIGURATION_TYPE geoportalConfigType = null;
ArrayList<String> configurations = null; ArrayList<JSONObject> configurations = null;
for (GEOPORTAL_CONFIGURATION_TYPE configManaged : GEOPORTAL_CONFIGURATION_TYPE.values()) { for (GEOPORTAL_CONFIGURATION_TYPE configManaged : GEOPORTAL_CONFIGURATION_TYPE.values()) {
try { try {
configurations = configuration.get(configManaged.getId(), ArrayList.class); LOG.debug("searching '" + configManaged.getId() + "' in the configuration " + configuration);
foundConfig = configManaged; LOG.trace("contains " + configManaged.getId() + ": "
break; + configuration.containsKey(configManaged.getId()));
ArrayList<LinkedHashMap<String, Object>> hashMapConfig = configuration.get(configManaged.getId(),
ArrayList.class);
LOG.debug("hashMapConfig found is: {}", hashMapConfig);
if (hashMapConfig != null) {
configurations = new ArrayList<JSONObject>();
for (LinkedHashMap<String, Object> config : hashMapConfig) {
LOG.debug("config is: {}", config.toString());
configurations.add(new JSONObject(config.toString()));
}
LOG.debug("configurations found are: {}", configurations);
geoportalConfigType = configManaged;
break;
}
} catch (Exception e) { } catch (Exception e) {
LOG.info(configManaged.getId() + "not found in the handler"); LOG.info(configManaged.getId() + " not found in the configuration of the handler "
+ handlerDeclaration.getId(), e);
} }
} }
if (configurations == null) { if (configurations == null) {
String error = "No managed configurations as '" + GEOPORTAL_CONFIGURATION_TYPE.values() String error = "No managed configurations as '"
+ "' found in the handler"; + Arrays.asList(GEOPORTAL_CONFIGURATION_TYPE.values()).toString() + "' found in the handler "
+ handlerDeclaration.getId();
LOG.warn(error); LOG.warn(error);
throw new Exception(error); return null;
} }
switch (foundConfig) { switch (geoportalConfigType) {
case gcube_profiles: { case gcube_profiles: {
List<GcubeProfileDV> listGcubeProfiles = new ArrayList<GcubeProfileDV>(configurations.size()); List<GcubeProfileDV> listGcubeProfiles = new ArrayList<GcubeProfileDV>(configurations.size());
int i = 0; int i = 0;
for (String gCubeProfile : configurations) { for (JSONObject gCubeProfile : configurations) {
LOG.debug(i++ + ") the gCubeProfile is: " + gCubeProfile); String asJSONString = gCubeProfile.toString();
GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization.read(gCubeProfile, LOG.debug(++i + ") the gCubeProfile is: " + asJSONString);
GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization.read(asJSONString,
GcubeProfile.class); GcubeProfile.class);
listGcubeProfiles.add(toGcubeProfileDV(profile)); listGcubeProfiles.add(toGcubeProfileDV(profile));
} }
@ -268,9 +303,10 @@ public class ConvertToDataValueObjectModel {
List<ItemFieldDV> listItemFields = new ArrayList<ItemFieldDV>(configurations.size()); List<ItemFieldDV> listItemFields = new ArrayList<ItemFieldDV>(configurations.size());
int i = 0; int i = 0;
for (String itemField : configurations) { for (JSONObject itemField : configurations) {
LOG.debug(i++ + ") the itemField is: " + itemField); String asJSONString = itemField.toString();
ItemField profile = org.gcube.application.geoportal.client.utils.Serialization.read(itemField, LOG.debug(++i + ") the itemField is: " + asJSONString);
ItemField profile = org.gcube.application.geoportal.client.utils.Serialization.read(asJSONString,
ItemField.class); ItemField.class);
listItemFields.add(toItemFieldDV(profile)); listItemFields.add(toItemFieldDV(profile));
} }
@ -408,6 +444,9 @@ public class ConvertToDataValueObjectModel {
theProject.setProfileVersion( theProject.setProfileVersion(
project.getProfileVersion() != null ? project.getProfileVersion().getValue() : ""); project.getProfileVersion() != null ? project.getProfileVersion().getValue() : "");
theProject.setTheDocument(toDocumentDV(project.getTheDocument(), DocumentDV.class,
projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap()));
Relationship[] relations = project.getRelationships(); Relationship[] relations = project.getRelationships();
if (relations != null && projectReader.isIncludeRelationships()) { if (relations != null && projectReader.isIncludeRelationships()) {
@ -434,12 +473,14 @@ public class ConvertToDataValueObjectModel {
// if (theProject.getValidationReport() != null) // if (theProject.getValidationReport() != null)
// theProject.setValidationStatus(theConcessione.getValidationReport().getStatus()); // theProject.setValidationStatus(theConcessione.getValidationReport().getStatus());
// } // }
// //
// LOG.info("Returning concessioneDV with id: " + theConcessione.getItemId()); // LOG.info("Returning concessioneDV with id: " + theConcessione.getItemId());
// //
// if (LOG.isTraceEnabled()) if (LOG.isDebugEnabled())
// LOG.trace("Returning: " + theConcessione); LOG.trace("Returning: " + theProject);
LOG.info("Returning project with id: " + theProject.getId());
return theProject; return theProject;
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error on converting project: " + project, e); LOG.error("Error on converting project: " + project, e);

View File

@ -4,53 +4,160 @@
//import java.nio.file.Files; //import java.nio.file.Files;
//import java.nio.file.Paths; //import java.nio.file.Paths;
//import java.util.ArrayList; //import java.util.ArrayList;
//import java.util.LinkedHashMap;
//import java.util.List; //import java.util.List;
// //
//import org.bson.Document;
//import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
//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.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.UseCaseDescriptorDV;
//import org.gcube.application.geoportalcommon.shared.geoportal.config.DocumentConfigDV; //import org.gcube.application.geoportalcommon.shared.geoportal.config.DocumentConfigDV;
//import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
//import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
// //
//public class MockDocumentConfigurationReader { //public class MockDocumentConfigurationReader {
// // private static final Logger LOG = LoggerFactory.getLogger(MockDocumentConfigurationReader.class);
//
// private List<DocumentConfigDV> listDocumentConfigsDV = new ArrayList<DocumentConfigDV>(); // private List<DocumentConfigDV> listDocumentConfigsDV = new ArrayList<DocumentConfigDV>();
// //
// public MockDocumentConfigurationReader() { // public MockDocumentConfigurationReader() {
// try { // try {
// //loadDocumentConfiguration(); // //loadConfigurations();
// } catch (Exception e) { // } catch (Exception e) {
// // TODO Auto-generated catch block // // TODO Auto-generated catch block
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
//
// private void loadConfigurations() {
//
// List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>();
// UseCaseDescriptorDV usecaseDescriptorDV = new UseCaseDescriptorDV("theId","version","listConcessioni", null);
// List<HandlerDeclarationDV> handlers = new ArrayList<HandlerDeclarationDV>();
//
//
// //
//// //THIS IS A MOCK // HandlerDeclarationDV hdDV = new HandlerDeclarationDV();
//// private void loadDocumentConfiguration() throws Exception { // hdDV.setId(handlerDeclaration.getId());
//// System.out.println("loadDocumentConfiguration called"); // hdDV.setType(handlerDeclaration.getType());
//// String filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config.json"; // hdDV.setItemType("MISSING ITEM TYPE IN THE SERVICE MODEL");
//// // hdDV.setDataHandlerType(to_GEOPORTAL_DATA_HANDLER(handlerDeclaration.getId()));
//// DocumentConfigDV dc = getDocumentConfigVO(filePath); //
//// listDocumentConfigsDV.add(dc); //// List<GcubeProfileDV> gcubeProfiles = new ArrayList<GcubeProfileDV>();
//// //// GcubeProfileDV profile = new GcubeProfileDV();
//// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config2.json"; //// profile.setGcubeName("GcubeName");
//// dc = getDocumentConfigVO(filePath); //// profile.setGcubeSecondaryType("GcubeSecondaryType");
//// listDocumentConfigsDV.add(dc); //// gcubeProfiles.add(profile);
////
//// ConfigurationDV<List<GcubeProfileDV>> configuration = new ConfigurationDV<List<GcubeProfileDV>>(gcubeProfiles);
//// HandlerDeclarationDV handler = new HandlerDeclarationDV(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getType(), "Concessioni", configuration,GEOPORTAL_DATA_HANDLER.geoportal_data_entry);
//// ////
//// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config3.json"; //// handlers.add(handler);
//// dc = getDocumentConfigVO(filePath); //// usecaseDescriptorDV.setHandlers(handlers);
//// listDocumentConfigsDV.add(dc); //// listUCDDV.add(usecaseDescriptorDV);
//// //
//// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config4.json"; //
//// dc = getDocumentConfigVO(filePath); // try {
//// listDocumentConfigsDV.add(dc); // GEOPORTAL_CONFIGURATION_TYPE geoportalConfigType = null;
//// } //
//// // String jsonConfig = readFile(
//// private DocumentConfigDV getDocumentConfigVO(String filePath) throws JsonProcessingException, IOException { // "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config5.json");
//// String theFile = readFile(filePath); //
//// System.out.println("the file is: " + theFile); // Document document = org.gcube.application.geoportal.client.utils.Serialization.read(jsonConfig, Document.class);
//// DocumentConfig dc = org.gcube.application.geoportal.client.utils.Serialization.read(theFile, //
//// DocumentConfig.class); // LinkedHashMap<String, String> configuration = (LinkedHashMap<String, String>) document.get("_configuration");
//// System.out.println(dc); //
//// //
//// return ConvertToDataValueObjectModel.toDocumentConfigDV(dc); // List<String> configurations = new ArrayList<String>(configuration.values());
//// } //
// switch (geoportalConfigType) {
// case gcube_profiles: {
//
// List<GcubeProfileDV> listGcubeProfiles = new ArrayList<GcubeProfileDV>(configurations.size());
//
// int i = 0;
// for (String gCubeProfile : configurations) {
// LOG.debug(i++ + ") the gCubeProfile is: " + gCubeProfile);
// GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization.read(gCubeProfile,
// GcubeProfile.class);
// listGcubeProfiles.add(ConvertToDataValueObjectModel.toGcubeProfileDV(profile));
// }
//
// ConfigurationDV<List<GcubeProfileDV>> dDV = new ConfigurationDV<List<GcubeProfileDV>>(
// listGcubeProfiles);
// dDV.setConfiguration(listGcubeProfiles);
// dDV.setConfigurationType(GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles);
// hdDV.setConfiguration(dDV);
// LOG.info("returning {}", hdDV);
// return hdDV;
// }
// case item_fields: {
//
// List<ItemFieldDV> listItemFields = new ArrayList<ItemFieldDV>(configurations.size());
//
// int i = 0;
// for (String itemField : configurations) {
// LOG.debug(i++ + ") the itemField is: " + itemField);
// ItemField profile = org.gcube.application.geoportal.client.utils.Serialization.read(itemField,
// ItemField.class);
// listItemFields.add(ConvertToDataValueObjectModel.toItemFieldDV(profile));
// }
//
// ConfigurationDV<List<ItemFieldDV>> dDV = new ConfigurationDV<List<ItemFieldDV>>(listItemFields);
// dDV.setConfiguration(listItemFields);
// dDV.setConfigurationType(GEOPORTAL_CONFIGURATION_TYPE.item_fields);
// hdDV.setConfiguration(dDV);
// LOG.info("returning {}", hdDV);
// return hdDV;
// }
//
// default:
// break;
// }
//
// } catch (Exception e) {
// LOG.error("Error on getting " + HandlerDeclaration.class.getSimpleName(), e);
// throw e;
// }
// }
//
// //THIS IS A MOCK
// private void loadDocumentConfiguration() throws Exception {
// System.out.println("loadDocumentConfiguration called");
// String filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config.json";
//
// DocumentConfigDV dc = getDocumentConfigVO(filePath);
// listDocumentConfigsDV.add(dc);
//
// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config2.json";
// dc = getDocumentConfigVO(filePath);
// listDocumentConfigsDV.add(dc);
//
// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config3.json";
// dc = getDocumentConfigVO(filePath);
// listDocumentConfigsDV.add(dc);
//
// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config4.json";
// dc = getDocumentConfigVO(filePath);
// listDocumentConfigsDV.add(dc);
// }
//
// private DocumentConfigDV getDocumentConfigVO(String filePath) throws JsonProcessingException, IOException {
// String theFile = readFile(filePath);
// System.out.println("the file is: " + theFile);
// DocumentConfig dc = org.gcube.application.geoportal.client.utils.Serialization.read(theFile,
// DocumentConfig.class);
// System.out.println(dc);
//
// return ConvertToDataValueObjectModel.toDocumentConfigDV(dc);
// }
// //
// public static String readFile(String filePath) { // public static String readFile(String filePath) {
// String content = ""; // String content = "";

View File

@ -39,15 +39,36 @@ import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder; import com.mongodb.BasicDBObjectBuilder;
/**
* The Class ProjectsCaller.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 17, 2022
*/
public class ProjectsCaller { public class ProjectsCaller {
private static Logger LOG = LoggerFactory.getLogger(GeoportalClientCaller.class); private static Logger LOG = LoggerFactory.getLogger(GeoportalClientCaller.class);
/**
* Gets the client.
*
* @param profileID the profile ID
* @return the client
*/
public Projects<Project> getClient(String profileID) { public Projects<Project> getClient(String profileID) {
LOG.info("getClient called for profileID={}", profileID); LOG.info("getClient called for profileID={}", profileID);
return projects(profileID).build(); return projects(profileID).build();
} }
/**
* Creates the new.
*
* @param profileID the profile ID
* @param jsonDocument the json document
* @return the project
* @throws RemoteException the remote exception
*/
public Project createNew(String profileID, String jsonDocument) throws RemoteException { public Project createNew(String profileID, String jsonDocument) throws RemoteException {
LOG.info("createNew called on profileID={}", profileID); LOG.info("createNew called on profileID={}", profileID);
Document myDocument = Document.parse(jsonDocument); Document myDocument = Document.parse(jsonDocument);
@ -56,6 +77,20 @@ public class ProjectsCaller {
return project; return project;
} }
/**
* Register file set.
*
* @param profileID the profile ID
* @param project the project
* @param theFile the the file
* @param parentPath the parent path
* @param fieldName the field name
* @param fieldDefinition the field definition
* @return the project
* @throws RemoteException the remote exception
* @throws FileNotFoundException the file not found exception
* @throws JsonProcessingException the json processing exception
*/
public Project registerFileSet(String profileID, Project project, File theFile, String parentPath, String fieldName, public Project registerFileSet(String profileID, Project project, File theFile, String parentPath, String fieldName,
String fieldDefinition) throws RemoteException, FileNotFoundException, JsonProcessingException { String fieldDefinition) throws RemoteException, FileNotFoundException, JsonProcessingException {
LOG.info( LOG.info(
@ -73,6 +108,13 @@ public class ProjectsCaller {
return project; return project;
} }
/**
* Gets the list for profile ID.
*
* @param profileID the profile ID
* @return the list for profile ID
* @throws Exception the exception
*/
public List<Project> getListForProfileID(String profileID) throws Exception { public List<Project> getListForProfileID(String profileID) throws Exception {
LOG.info("getListForProfileID called for profileID: {}", profileID); LOG.info("getListForProfileID called for profileID: {}", profileID);
Projects<Project> client = (Projects<Project>) getClient(profileID); Projects<Project> client = (Projects<Project>) getClient(profileID);
@ -88,6 +130,13 @@ public class ProjectsCaller {
return listProjects; return listProjects;
} }
/**
* Gets the configuration.
*
* @param profileID the profile ID
* @return the configuration
* @throws Exception the exception
*/
public Configuration getConfiguration(String profileID) throws Exception { public Configuration getConfiguration(String profileID) throws Exception {
LOG.info("getConfiguration called for profileID: {} ", profileID); LOG.info("getConfiguration called for profileID: {} ", profileID);
Projects<Project> client = (Projects<Project>) getClient(profileID); Projects<Project> client = (Projects<Project>) getClient(profileID);
@ -99,15 +148,17 @@ public class ProjectsCaller {
/** /**
* Query on mongo. * Query on mongo.
* *
* @param offset the offset * @param profileID the profile ID
* @param limit the limit * @param totalItems the total items
* @param filter the filter * @param offset the offset
* @param recordType the record type * @param limit the limit
* @param filter the filter
* @param projectDVBuilder the project DV builder
* @return the result set paginated data * @return the result set paginated data
* @throws Exception the exception * @throws Exception the exception
*/ */
public ResultSetPaginatedData queryOnMongo(String profileID, Integer totalItems, Integer offset, Integer limit, public ResultSetPaginatedData queryOnMongo(String profileID, Integer totalItems, Integer offset, Integer limit,
SearchingFilter filter, String recordType, ProjectDVBuilder projectDVBuilder) throws Exception { SearchingFilter filter, ProjectDVBuilder projectDVBuilder) throws Exception {
LOG.info("queryOnMongo called"); LOG.info("queryOnMongo called");
try { try {

View File

@ -35,12 +35,12 @@ public class UseCaseDescriptorCaller {
listUCD.add(prg); listUCD.add(prg);
} }
LOG.info("returning %d {}", listUCD.size(), UseCaseDescriptor.class.getName()); LOG.info("returning {} {}", listUCD.size(), UseCaseDescriptor.class.getName());
return listUCD; return listUCD;
} }
public List<UseCaseDescriptor> getListForHandlerIds(List<String> listHandlersIds) throws Exception { public List<UseCaseDescriptor> getListForHandlerIds(List<String> listHandlersIds) throws Exception {
LOG.info("getListForHandlerId called"); LOG.info("getListForHandlerIds called");
return getListForJSONPath("_handlers._id", listHandlersIds); return getListForJSONPath("_handlers._id", listHandlersIds);
} }
@ -67,7 +67,7 @@ public class UseCaseDescriptorCaller {
QueryRequest queryRequest = new QueryRequest(); QueryRequest queryRequest = new QueryRequest();
Document queryDoc = new Document(); Document queryDoc = new Document();
queryDoc.put("$eq", list); queryDoc.put("$and", list);
LOG.debug("Performing query: {}", queryDoc.toJson()); LOG.debug("Performing query: {}", queryDoc.toJson());
queryRequest.setFilter(queryDoc); queryRequest.setFilter(queryDoc);
@ -85,7 +85,7 @@ public class UseCaseDescriptorCaller {
listUCD.add(prg); listUCD.add(prg);
} }
LOG.info("returning %d {}", listUCD.size(), UseCaseDescriptor.class.getName()); LOG.info("returning {} {}", listUCD.size(), UseCaseDescriptor.class.getName());
return listUCD; return listUCD;
} }

View File

@ -1,17 +0,0 @@
//package org.gcube.application.geoportalcommon.geoportal.config;
//
//import java.util.List;
//
//import javax.xml.bind.annotation.XmlRootElement;
//
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//
//@Data
//@XmlRootElement(name = "_configuration")
//@Slf4j
//public class Configuration<T>{
//
// private List<T> listConfigs;
//
//}

View File

@ -1,19 +0,0 @@
//package org.gcube.application.geoportalcommon.geoportal.config;
//
//import java.util.List;
//
//import javax.xml.bind.annotation.XmlRootElement;
//
//import com.fasterxml.jackson.annotation.JsonProperty;
//
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//
//@Data
//@XmlRootElement(name = "_configuration")
//@Slf4j
//public class ConfigurationGCubeProfile {
//
// @JsonProperty(value = "gcubeProfiles")
// private List<GcubeProfile> listConfigs;
//}

View File

@ -1,27 +0,0 @@
//package org.gcube.application.geoportalcommon.geoportal.config;
//
//import javax.xml.bind.annotation.XmlRootElement;
//
//import com.fasterxml.jackson.annotation.JsonProperty;
//
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//
//@Data
//@XmlRootElement
//@Slf4j
//public class DocumentConfig<T> {
//
// @JsonProperty
// private String _id;
//
// @JsonProperty
// private String _type;
//
// @JsonProperty
// private String _item_type;
//
// @JsonProperty
// private Configuration<T> _configuration;
//
//}

View File

@ -2,61 +2,147 @@ package org.gcube.application.geoportalcommon.shared.geoportal;
import java.io.Serializable; import java.io.Serializable;
/**
* The Class HandlerDeclarationDV.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 17, 2022
*/
public class HandlerDeclarationDV implements Serializable { public class HandlerDeclarationDV implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 9095207023666383038L; private static final long serialVersionUID = 3664650151266716354L;
private String id; private String id;
private String type; private String type;
private String itemType; // This is the use case (e.g. Concessioni)
private ConfigurationDV<?> configuration; private ConfigurationDV<?> configuration;
private GEOPORTAL_DATA_HANDLER dataHandlerType; private GEOPORTAL_DATA_HANDLER dataHandlerType;
/**
* Instantiates a new handler declaration DV.
*/
public HandlerDeclarationDV() { public HandlerDeclarationDV() {
} }
public HandlerDeclarationDV(String id, String type, ConfigurationDV<?> configuration, /**
* Instantiates a new handler declaration DV.
*
* @param id the id
* @param type the type
* @param itemType the item type
* @param configuration the configuration
* @param dataHandlerType the data handler type
*/
public HandlerDeclarationDV(String id, String type, String itemType,
ConfigurationDV<?> configuration,
GEOPORTAL_DATA_HANDLER dataHandlerType) { GEOPORTAL_DATA_HANDLER dataHandlerType) {
super();
this.id = id; this.id = id;
this.type = type; this.type = type;
this.itemType = itemType;
this.configuration = configuration; this.configuration = configuration;
this.dataHandlerType = dataHandlerType; this.dataHandlerType = dataHandlerType;
} }
/**
* Gets the id.
*
* @return the id
*/
public String getId() { public String getId() {
return id; return id;
} }
/**
* Gets the type.
*
* @return the type
*/
public String getType() { public String getType() {
return type; return type;
} }
/**
* Gets the item type.
*
* @return the item type
*/
public String getItemType() {
return itemType;
}
/**
* Gets the configuration.
*
* @return the configuration
*/
public ConfigurationDV<?> getConfiguration() { public ConfigurationDV<?> getConfiguration() {
return configuration; return configuration;
} }
public void setId(String id) { /**
this.id = id; * Gets the data handler type.
} *
* @return the data handler type
public void setType(String type) { */
this.type = type;
}
public void setConfiguration(ConfigurationDV<?> configuration) {
this.configuration = configuration;
}
public void setHandlerType(GEOPORTAL_DATA_HANDLER dataHandlerType) {
this.dataHandlerType = dataHandlerType;
}
public GEOPORTAL_DATA_HANDLER getDataHandlerType() { public GEOPORTAL_DATA_HANDLER getDataHandlerType() {
return dataHandlerType; return dataHandlerType;
} }
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(String id) {
this.id = id;
}
/**
* Sets the type.
*
* @param type the new type
*/
public void setType(String type) {
this.type = type;
}
/**
* Sets the item type.
*
* @param itemType the new item type
*/
public void setItemType(String itemType) {
this.itemType = itemType;
}
/**
* Sets the configuration.
*
* @param configuration the new configuration
*/
public void setConfiguration(ConfigurationDV<?> configuration) {
this.configuration = configuration;
}
/**
* Sets the data handler type.
*
* @param dataHandlerType the new data handler type
*/
public void setDataHandlerType(GEOPORTAL_DATA_HANDLER dataHandlerType) {
this.dataHandlerType = dataHandlerType;
}
/**
* To string.
*
* @return the string
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -64,6 +150,8 @@ public class HandlerDeclarationDV implements Serializable {
builder.append(id); builder.append(id);
builder.append(", type="); builder.append(", type=");
builder.append(type); builder.append(type);
builder.append(", itemType=");
builder.append(itemType);
builder.append(", configuration="); builder.append(", configuration=");
builder.append(configuration); builder.append(configuration);
builder.append(", dataHandlerType="); builder.append(", dataHandlerType=");
@ -72,4 +160,6 @@ public class HandlerDeclarationDV implements Serializable {
return builder.toString(); return builder.toString();
} }
} }

View File

@ -1,35 +0,0 @@
//package org.gcube.application.geoportalcommon.shared.geoportal.config;
//
//import java.io.Serializable;
//import java.util.List;
//
//public class ConfigGcubeProfileDV implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 372838411789432170L;
//
// private List<GcubeProfileDV> gcubeProfiles;
//
// public ConfigGcubeProfileDV() {
// }
//
// public List<GcubeProfileDV> getGcubeProfiles() {
// return gcubeProfiles;
// }
//
// public void setGcubeProfiles(List<GcubeProfileDV> gcubeProfiles) {
// this.gcubeProfiles = gcubeProfiles;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ConfigGcubeProfileDV [gcubeProfiles=");
// builder.append(gcubeProfiles);
// builder.append("]");
// return builder.toString();
// }
//
//}

View File

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

View File

@ -5,4 +5,5 @@ public interface GeoportalConfigurationID {
String getID(); String getID();
void setID(String configID); void setID(String configID);
} }

View File

@ -1,129 +1,131 @@
//package org.gcube.application; package org.gcube.application;
//
//import java.io.IOException; import java.io.IOException;
//import java.nio.file.Files; import java.nio.file.Files;
//import java.nio.file.Paths; import java.nio.file.Paths;
//import java.util.ArrayList; import java.util.ArrayList;
//import java.util.LinkedHashMap; import java.util.LinkedHashMap;
//import java.util.List; import java.util.List;
//
//import org.bson.Document; import org.bson.Document;
//import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
//import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
//import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile; import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile;
//import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
//import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV; import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
//import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
//import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
//import org.junit.Test; import org.junit.Test;
//import org.slf4j.Logger; import org.slf4j.Logger;
//import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
//
//public class LoadDocumentConfiguration { public class LoadDocumentConfiguration {
//
// private static String TOKEN = ""; private static String TOKEN = "";
// private static String CONTEXT = "/gcube/devsec/devVRE"; private static String CONTEXT = "/gcube/devsec/devVRE";
// private static String USERNAME = "francesco.mangiacrapa"; private static String USERNAME = "francesco.mangiacrapa";
// private static Logger LOG = LoggerFactory.getLogger(LoadDocumentConfiguration.class); private static Logger LOG = LoggerFactory.getLogger(LoadDocumentConfiguration.class);
//
// // @Before // @Before
// public void init() { public void init() {
// ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
// } }
//
// @Test @Test
// public void loadDocumentConfiguration() throws Exception { public void loadDocumentConfiguration() throws Exception {
//
//// MockDocumentConfigurationReader mock = new MockDocumentConfigurationReader(); // MockDocumentConfigurationReader mock = new MockDocumentConfigurationReader();
//// System.out.println(mock.getListDocumentConfig()); // System.out.println(mock.getListDocumentConfig());
//
// toHandlerDeclarationDV(null); toHandlerDeclarationDV(null);
// } }
//
// private static String readFile(String filePath) { private static String readFile(String filePath) {
// String content = ""; String content = "";
//
// try { try {
// content = new String(Files.readAllBytes(Paths.get(filePath))); content = new String(Files.readAllBytes(Paths.get(filePath)));
// } catch (IOException e) { } catch (IOException e) {
// e.printStackTrace(); e.printStackTrace();
}
return content;
}
/**
* To handler declaration DV.
*
* @param <T> the generic type
* @param handlerDeclaration the handler declaration
* @return the handler declaration DV
* @throws Exception
*/
public static HandlerDeclarationDV toHandlerDeclarationDV(HandlerDeclaration handlerDeclaration) throws Exception {
// if (handlerDeclaration == null) {
// LOG.warn(HandlerDeclaration.class.getSimpleName() + " is null");
// return null;
// } // }
// Document configuration = handlerDeclaration.getConfiguration();
// //
// return content; // if (configuration == null) {
// } // LOG.warn("Configuration is null");
// // return null;
// /** // }
// * To handler declaration DV.
// * String jsonConfig = readFile(
// * @param <T> the generic type "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config5.json");
// * @param handlerDeclaration the handler declaration
// * @return the handler declaration DV LOG.debug("File as JSON: " + jsonConfig);
// * @throws Exception
// */ Document document = org.gcube.application.geoportal.client.utils.Serialization.read(jsonConfig, Document.class);
// public static HandlerDeclarationDV toHandlerDeclarationDV(HandlerDeclaration handlerDeclaration) throws Exception {
// LinkedHashMap<String, String> configuration = (LinkedHashMap<String, String>) document.get("_configuration");
//// if (handlerDeclaration == null) {
//// LOG.warn(HandlerDeclaration.class.getSimpleName() + " is null"); //configuration.values();
//// return null;
//// } try {
// List<String> gcubeProfiles = new ArrayList<String>(configuration.values());
//// Document configuration = handlerDeclaration.getConfiguration();
////
//// if (configuration == null) {
//// LOG.warn("Configuration is null");
//// return null;
//// }
//
// String jsonConfig = readFile(
// "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config5.json");
//
// LOG.debug("File as JSON: " + jsonConfig);
//
// Document document = org.gcube.application.geoportal.client.utils.Serialization.read(jsonConfig, Document.class);
//
// LinkedHashMap<String, String> configuration = (LinkedHashMap<String, String>) document.get("_configuration");
//
// try {
// List<String> gcubeProfiles = null;
// try { // try {
// gcubeProfiles = configuration.get("gcubeProfiles", ArrayList.class); // gcubeProfiles = configuration.get("gcubeProfiles", ArrayList.class);
// } catch (Exception e) { // } catch (Exception e) {
// LOG.info("gcubeProfiles not found in the handler"); // LOG.info("gcubeProfiles not found in the handler");
// return null; // return null;
// } // }
//
// // HANDLER OF "gcubeProfiles" configuration // HANDLER OF "gcubeProfiles" configuration
// if (gcubeProfiles != null) { if (gcubeProfiles != null) {
//
// List<GcubeProfileDV> listGcubeProfiles = new ArrayList<GcubeProfileDV>(gcubeProfiles.size()); List<GcubeProfileDV> listGcubeProfiles = new ArrayList<GcubeProfileDV>(gcubeProfiles.size());
//
// int i = 0; int i = 0;
// for (String gCubeProfile : gcubeProfiles) { for (String gCubeProfile : gcubeProfiles) {
// LOG.debug(i++ + ") the gCubeProfile is: " + gCubeProfile); LOG.debug(i++ + ") the gCubeProfile is: " + gCubeProfile);
// GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization.read(gCubeProfile, GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization.read(gCubeProfile,
// GcubeProfile.class); GcubeProfile.class);
// listGcubeProfiles.add(ConvertToDataValueObjectModel.toGcubeProfileDV(profile)); listGcubeProfiles.add(ConvertToDataValueObjectModel.toGcubeProfileDV(profile));
// } }
//
// HandlerDeclarationDV hdDV = new HandlerDeclarationDV(); HandlerDeclarationDV hdDV = new HandlerDeclarationDV();
// hdDV.setId(handlerDeclaration.getId()); hdDV.setId(handlerDeclaration.getId());
// hdDV.setType(handlerDeclaration.getType()); hdDV.setType(handlerDeclaration.getType());
//
// ConfigurationDV<List<GcubeProfileDV>> dDV = new ConfigurationDV<List<GcubeProfileDV>>( ConfigurationDV<List<GcubeProfileDV>> dDV = new ConfigurationDV<List<GcubeProfileDV>>(
// listGcubeProfiles); listGcubeProfiles);
// dDV.setConfiguration(listGcubeProfiles); dDV.setConfiguration(listGcubeProfiles);
// hdDV.setConfiguration(dDV); hdDV.setConfiguration(dDV);
//
// LOG.info("returning {}", hdDV); LOG.info("returning {}", hdDV);
// return hdDV; return hdDV;
// } }
// } catch (Exception e) { } catch (Exception e) {
// LOG.error("Error on getting " + HandlerDeclaration.class.getSimpleName(), e); LOG.error("Error on getting " + HandlerDeclaration.class.getSimpleName(), e);
// throw e; throw e;
// } }
//
// return null; return null;
//
// } }
//
//} }

View File

@ -1,11 +1,13 @@
package org.gcube.application; package org.gcube.application;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller; import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
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.Before;
@ -53,7 +55,7 @@ public class UCD_Tests {
} }
@Test //@Test
public void convertToDVObject() throws Exception { public void convertToDVObject() throws Exception {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN); SecurityTokenProvider.instance.set(TOKEN);
@ -65,5 +67,17 @@ public class UCD_Tests {
ConvertToDataValueObjectModel.toUseCaseDescriptorDV(useCaseDescriptor, null); ConvertToDataValueObjectModel.toUseCaseDescriptorDV(useCaseDescriptor, null);
} }
} }
@Test
public void getUCDForHandlerIds() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<UseCaseDescriptor> listOfUCD = client.getListForHandlerIds(Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId()));
int i = 0;
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
System.out.println(++i + ") " + useCaseDescriptor);
ConvertToDataValueObjectModel.toUseCaseDescriptorDV(useCaseDescriptor, null);
}
}
} }