migration in progress

This commit is contained in:
Francesco Mangiacrapa 2022-08-31 12:43:41 +02:00
parent 5c8c2a342d
commit 310817e425
4 changed files with 183 additions and 58 deletions

View File

@ -1,5 +1,7 @@
package org.gcube.application.geoportalcommon; package org.gcube.application.geoportalcommon;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
@ -45,6 +47,15 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescrip
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
/** /**
* The Class ConvertToDataValueObjectModel. * The Class ConvertToDataValueObjectModel.
* *
@ -63,6 +74,10 @@ public class ConvertToDataValueObjectModel {
public static final String HOURS_MINUTES_SEPARATOR = ":"; public static final String HOURS_MINUTES_SEPARATOR = ":";
public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm"; public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm";
public static List<String> KEYSET_POSSIBLE_DATE = Arrays.asList("start", "end", "created", "updated", "inizio",
"fine", "creato", "aggiornato");
/** /**
* To use case descriptor DV. * To use case descriptor DV.
* *
@ -129,6 +144,12 @@ public class ConvertToDataValueObjectModel {
} }
/**
* To GEOPORTA L DAT A HANDLER.
*
* @param id the id
* @return the geoportal data handler
*/
public static GEOPORTAL_DATA_HANDLER to_GEOPORTAL_DATA_HANDLER(String id) { public static GEOPORTAL_DATA_HANDLER to_GEOPORTAL_DATA_HANDLER(String id) {
if (id == null) if (id == null)
@ -364,7 +385,6 @@ public class ConvertToDataValueObjectModel {
* @param project the project * @param project the project
* @param projectReader the project reader * @param projectReader the project reader
* @return the project DV * @return the project DV
* @throws Exception the exception
*/ */
public static ProjectDV toProjectDV(Project project, ProjectDVBuilder projectReader) { public static ProjectDV toProjectDV(Project project, ProjectDVBuilder projectReader) {
LOG.info("toProjectDV called"); LOG.info("toProjectDV called");
@ -385,7 +405,7 @@ public class ConvertToDataValueObjectModel {
project.getProfileVersion() != null ? project.getProfileVersion().getValue() : ""); project.getProfileVersion() != null ? project.getProfileVersion().getValue() : "");
theProject.setVersion(project.getVersion() != null ? project.getVersion().getValue() : ""); theProject.setVersion(project.getVersion() != null ? project.getVersion().getValue() : "");
theProject.setTheDocument(toDocumentDV(project.getTheDocument(), DocumentDV.class, theProject.setTheDocument(toGenericDocumentDV(project.getTheDocument(), DocumentDV.class,
projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap())); projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap()));
List<Relationship> relations = project.getRelationships(); List<Relationship> relations = project.getRelationships();
@ -451,7 +471,6 @@ public class ConvertToDataValueObjectModel {
* *
* @param project the project * @param project the project
* @return the result document DV * @return the result document DV
* @throws Exception the exception
*/ */
public static ResultDocumentDV toResultDocumentDV(Project project) { public static ResultDocumentDV toResultDocumentDV(Project project) {
LOG.info("toResultDocumentDV called"); LOG.info("toResultDocumentDV called");
@ -465,8 +484,8 @@ public class ConvertToDataValueObjectModel {
try { try {
ResultDocumentDV rd = (ResultDocumentDV) toDocumentDV(project.getTheDocument(), ResultDocumentDV.class, ResultDocumentDV rd = (ResultDocumentDV) toGenericDocumentDV(project.getTheDocument(),
null, true); ResultDocumentDV.class, null, true);
rd.setId(project.getId()); rd.setId(project.getId());
rd.setProfileID(project.getProfileID()); rd.setProfileID(project.getProfileID());
@ -492,6 +511,12 @@ public class ConvertToDataValueObjectModel {
} }
/**
* To publication info DV.
*
* @param info the info
* @return the publication info DV
*/
private static PublicationInfoDV toPublicationInfoDV(PublicationInfo info) { private static PublicationInfoDV toPublicationInfoDV(PublicationInfo info) {
if (info == null) if (info == null)
return null; return null;
@ -505,6 +530,12 @@ public class ConvertToDataValueObjectModel {
} }
/**
* To access DV.
*
* @param access the access
* @return the access DV
*/
private static AccessDV toAccessDV(Access access) { private static AccessDV toAccessDV(Access access) {
if (access == null) if (access == null)
return null; return null;
@ -516,6 +547,12 @@ public class ConvertToDataValueObjectModel {
return acDV; return acDV;
} }
/**
* To accounting info DV.
*
* @param creationInfo the creation info
* @return the accounting info DV
*/
private static AccountingInfoDV toAccountingInfoDV(AccountingInfo creationInfo) { private static AccountingInfoDV toAccountingInfoDV(AccountingInfo creationInfo) {
if (creationInfo == null) if (creationInfo == null)
return null; return null;
@ -531,12 +568,20 @@ public class ConvertToDataValueObjectModel {
return aidv; return aidv;
} }
/**
* To identification reference DV.
*
* @param identificationReference the identification reference
* @param listDocumentKeys the list document keys
* @param getFullMap the get full map
* @return the identification reference DV
*/
private static IdentificationReferenceDV toIdentificationReferenceDV( private static IdentificationReferenceDV toIdentificationReferenceDV(
IdentificationReference identificationReference, List<String> listDocumentKeys, boolean getFullMap) { IdentificationReference identificationReference, List<String> listDocumentKeys, boolean getFullMap) {
if (identificationReference == null) if (identificationReference == null)
return null; return null;
IdentificationReferenceDV idv = (IdentificationReferenceDV) toDocumentDV(identificationReference, IdentificationReferenceDV idv = (IdentificationReferenceDV) toGenericDocumentDV(identificationReference,
IdentificationReferenceDV.class, listDocumentKeys, getFullMap); IdentificationReferenceDV.class, listDocumentKeys, getFullMap);
idv.setType(identificationReference.getType()); idv.setType(identificationReference.getType());
@ -597,24 +642,24 @@ public class ConvertToDataValueObjectModel {
// } // }
/** /**
* To document DV. * To generic document DV.
* *
* @param <T> the generic type * @param <T> the generic type
* @param document the document * @param document the document
* @param toType the to type * @param targetClass the target class
* @param listDocumentKeys the list document keys * @param listDocumentKeys the list document keys
* @param getFullMap the get full map * @param getFullMap the get full map
* @return the t * @return the document DV
*/ */
public static <T extends DocumentDV> DocumentDV toDocumentDV(Document document, Class<T> targetClass, public static <T extends DocumentDV> DocumentDV toGenericDocumentDV(Document document, Class<T> targetClass,
List<String> listDocumentKeys, boolean getFullMap) { List<String> listDocumentKeys, boolean getFullMap) {
if (document == null) if (document == null)
return null; return null;
T documentDV; T documentDV;
if (targetClass == null) if (targetClass == null) {
documentDV = (T) new DocumentDV(); documentDV = (T) new DocumentDV();
else { } else {
try { try {
documentDV = targetClass.newInstance(); documentDV = targetClass.newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
@ -631,7 +676,8 @@ public class ConvertToDataValueObjectModel {
if (listDocumentKeys != null && !getFullMap) { if (listDocumentKeys != null && !getFullMap) {
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(listDocumentKeys.size()); LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(listDocumentKeys.size());
for (String key : listDocumentKeys) { for (String key : listDocumentKeys) {
documentAsMap.put(key, document.get(key));
documentAsMap = fillMapValue(document, key, documentAsMap);
} }
documentDV.setDocumentAsMap(documentAsMap); documentDV.setDocumentAsMap(documentAsMap);
} }
@ -640,7 +686,8 @@ public class ConvertToDataValueObjectModel {
Set<String> keySet = document.keySet(); Set<String> keySet = document.keySet();
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(keySet.size()); LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(keySet.size());
for (String key : keySet) { for (String key : keySet) {
documentAsMap.put(key, document.get(key)); // documentAsMap.put(key, document.get(key));
documentAsMap = fillMapValue(document, key, documentAsMap);
} }
documentDV.setDocumentAsMap(documentAsMap); documentDV.setDocumentAsMap(documentAsMap);
} }
@ -650,6 +697,95 @@ public class ConvertToDataValueObjectModel {
return documentDV; return documentDV;
} }
public static final DateTimeFormatter FULL_FORMATTER=DateTimeFormatter.ofPattern("uuuuMMdd_HH-mm-ss");
public static class MyLocalDateSerializer extends JsonSerializer<LocalDate> {
@Override
public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeString(value.format(FULL_FORMATTER));
}
}
public static class ParseDeserializer extends StdDeserializer<LocalDateTime> {
public ParseDeserializer() {
super(LocalDateTime.class);
}
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
return LocalDateTime.parse(p.getValueAsString()); // or overloaded with an appropriate format
}
}
public static class MyLocalDateDeserializer extends JsonDeserializer<LocalDate> {
@Override
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return LocalDate.parse(p.getValueAsString(),FULL_FORMATTER);
}
}
/**
* Fill map.
*
* @param document the document
* @param key the key
* @param documentAsMap the document as map
* @return the linked hash map
*/
public static LinkedHashMap<String, Object> fillMapValue(Document document, String key,
LinkedHashMap<String, Object> documentAsMap) {
Object value = document.get(key);
String keyLower = key.toLowerCase();
/*
ObjectMapper objectMapper = new ObjectMapper();
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addDeserializer(LocalDateTime.class, new ParseDeserializer());
// javaTimeModule.addSerializer(LocalDate.class, new MyLocalDateSerializer());
objectMapper.registerModule(javaTimeModule);
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
*/
//checking if the key is a Date
for (String possibleDate : KEYSET_POSSIBLE_DATE) {
if (keyLower.contains(possibleDate)) {
try {
LOG.debug("value "+value+" is instance of: "+value.getClass());
Document documentDate = new Document((Map) value);
String jsonValue = documentDate.toJson();
LOG.debug("jsonValue "+value);
//LocalDate asDate = objectMapper.readerFor(LocalDate.class).readValue(jsonValue);
LocalDateTime asDate = org.gcube.application.geoportal.client.utils.Serialization.read(jsonValue, LocalDateTime.class);
LOG.info("Casted as date: " + asDate);
value = asDate;
break;
} catch (Exception e) {
LOG.warn("### MUST BE FIXED ### the field {} with value {} is not a date", key, value);
}
}
}
documentAsMap.put(key, value);
return documentAsMap;
}
public class LocalDateDeserializer extends JsonDeserializer<LocalDate> {
@Override
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return LocalDate.parse(p.getValueAsString());
}
}
/** /**
* To relationship DV. * To relationship DV.
* *
@ -667,7 +803,7 @@ public class ConvertToDataValueObjectModel {
/** /**
* To validation report. * To validation report.
* *
* @param validationReport the validation report * @param li the li
* @return the validation report DV * @return the validation report DV
* @throws Exception the exception * @throws Exception the exception
*/ */
@ -689,6 +825,12 @@ public class ConvertToDataValueObjectModel {
return liDV; return liDV;
} }
/**
* To lifecycle information DV status.
*
* @param status the status
* @return the lifecycle information D v. status
*/
public static LifecycleInformationDV.Status toLifecycleInformationDVStatus(LifecycleInformation.Status status) { public static LifecycleInformationDV.Status toLifecycleInformationDVStatus(LifecycleInformation.Status status) {
if (status == null) if (status == null)

View File

@ -446,41 +446,13 @@ public class ProjectsCaller {
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex); LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
LOG.info("Direction: " + sDirection); LOG.info("Direction: " + sDirection);
LOG.info("Projection: " + projectionDocument); LOG.info("Projection: " + projectionDocument);
LOG.info("Order by Fields: " + orderingFields); LOG.info("Order by Fields: " + ordering);
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());
} }
return geoportalClient.query(request); return geoportalClient.query(request);
// int i = 0;
// while (projects.hasNext()) {
// Project project = projects.next();
// ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectDVBuilder);
// toReturnList.add(projectDV);
// i++;
// LOG.trace(i + ") converted: " + projectDV);
// }
// LOG.debug("read " + toReturnList + " project/s");
//
// searchedData.setData(toReturnList);
//
// // TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT
// // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE
// if (filter.getConditions() != null) {
// searchedData.setTotalItems(toReturnList.size());
// totalItems = toReturnList.size();
// }
//
// if (totalItems == limit || totalItems == 0) {
// LOG.debug("Page completed returning " + totalItems + " items");
// int newOffset = offsetIndex + limitIndex;
// searchedData.setServerSearchFinished(newOffset > totalItems || totalItems == 0);
// LOG.debug("is Search finished: " + searchedData.isServerSearchFinished());
//
// }
//
// return searchedData;
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error on loading paginated and filtered list of Project: ", e); LOG.error("Error on loading paginated and filtered list of Project: ", e);

View File

@ -4,8 +4,6 @@ import java.io.Serializable;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
/** /**
@ -99,16 +97,14 @@ public class SearchingFilter implements Serializable {
} }
private void addProjectionBaseInfo(Class<? extends DocumentDV> theClass) { private void addProjectionBaseInfo() {
if (projection != null) { if (projection != null) {
projection.put("_profileID", 1); projection.put("_profileID", 1);
projection.put("_profileVersion", 1); projection.put("_profileVersion", 1);
projection.put("_version", 1); projection.put("_version", 1);
if (theClass.isAssignableFrom(ResultDocumentDV.class)) {
projection.put("_lifecycleInformation", 1); projection.put("_lifecycleInformation", 1);
projection.put("_info", 1); projection.put("_info", 1);
}
} }
} }
@ -122,6 +118,8 @@ public class SearchingFilter implements Serializable {
public SearchingFilter(List<ItemFieldDV> orderByFields, ORDER order) { public SearchingFilter(List<ItemFieldDV> orderByFields, ORDER order) {
this.orderByFields = orderByFields; this.orderByFields = orderByFields;
this.order = order; this.order = order;
if (this.order == null)
order = ORDER.ASC;
} }
/** /**
@ -145,9 +143,9 @@ public class SearchingFilter implements Serializable {
this.conditions = conditions; this.conditions = conditions;
} }
public void setProjection(LinkedHashMap<String, Object> projection, Class<? extends DocumentDV> theClass) { public void setProjection(LinkedHashMap<String, Object> projection) {
this.projection = projection; this.projection = projection;
addProjectionBaseInfo(theClass); addProjectionBaseInfo();
} }
public LinkedHashMap<String, Object> getProjection() { public LinkedHashMap<String, Object> getProjection() {

View File

@ -3,6 +3,8 @@ 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.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -19,6 +21,17 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
public class LoadDocumentConfiguration { public class LoadDocumentConfiguration {
private static String TOKEN = ""; private static String TOKEN = "";
@ -83,7 +96,7 @@ public class LoadDocumentConfiguration {
LinkedHashMap<String, String> configuration = (LinkedHashMap<String, String>) document.get("_configuration"); LinkedHashMap<String, String> configuration = (LinkedHashMap<String, String>) document.get("_configuration");
//configuration.values(); // configuration.values();
try { try {
List<String> gcubeProfiles = new ArrayList<String>(configuration.values()); List<String> gcubeProfiles = new ArrayList<String>(configuration.values());