Various refactoring
This commit is contained in:
parent
da12a4b1aa
commit
1cdf92ba1a
|
@ -2,5 +2,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for org.gcube.application.cms-plugin-framework
|
||||
|
||||
## [v1.0.1-SNAPSHOT] 2022-01-17
|
||||
- Serialization Features
|
||||
|
||||
## [v1.0.0] 2021-09-20
|
||||
- First release
|
|
@ -4,7 +4,7 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cms-plugin-framework</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
|
@ -38,6 +38,12 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,138 @@
|
|||
package org.gcube.application.cms;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.gcube.application.geoportal.common.model.document.ComparableVersion;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Iterator;
|
||||
|
||||
@Slf4j
|
||||
public class Serialization {
|
||||
|
||||
public static final DateTimeFormatter FULL_FORMATTER=DateTimeFormatter.ofPattern("uuuuMMdd_HH-mm-ss");
|
||||
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper=new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
|
||||
SimpleModule s=new SimpleModule();
|
||||
s.addDeserializer(ObjectId.class,new ObjectIdDeserializer());
|
||||
s.addSerializer(ObjectId.class,new ObjectIdSerializer());
|
||||
s.addDeserializer(ComparableVersion.class,new ComparableVersionDeserializer());
|
||||
s.addSerializer(ComparableVersion.class,new ComparableVersionSerializer());
|
||||
mapper.registerModule(s);
|
||||
}
|
||||
|
||||
public static <T> T read(String jsonString,Class<T> clazz) throws JsonProcessingException, IOException {
|
||||
return mapper.readerFor(clazz).readValue(jsonString);
|
||||
}
|
||||
|
||||
public static <T> Iterator<T> readCollection(String jsonString, Class<T> clazz) throws IOException {
|
||||
return mapper.readerFor(clazz).readValues(jsonString);
|
||||
}
|
||||
|
||||
|
||||
public static String write(Object toWrite) throws JsonProcessingException {
|
||||
String toReturn= mapper.writeValueAsString(toWrite);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static QueryRequest parseQuery(String queryString) throws IOException {
|
||||
log.debug("Parsing query Request {} ",queryString);
|
||||
Document queryDocument = Document.parse(queryString);
|
||||
log.debug("Document is ",queryDocument.toJson());
|
||||
QueryRequest req = new QueryRequest();
|
||||
if (queryDocument.getOrDefault("ordering",null)!=null)
|
||||
req.setOrdering(Serialization.read(((Document) queryDocument.get("ordering")).toJson(), QueryRequest.OrderedRequest.class));
|
||||
if (queryDocument.getOrDefault("paging",null)!=null)
|
||||
req.setPaging(Serialization.read(((Document) queryDocument.get("paging")).toJson(), QueryRequest.PagedRequest.class));
|
||||
req.setProjection(queryDocument.get("projection", Document.class));
|
||||
req.setFilter(queryDocument.get("filter", Document.class));
|
||||
return req;
|
||||
}
|
||||
|
||||
|
||||
//**** PROFILED DOCUMENTS
|
||||
|
||||
public static final <T> T convert(Object d,Class<T> clazz){
|
||||
return mapper.convertValue(d,clazz);
|
||||
}
|
||||
|
||||
public static final Document asDocument(Object obj) throws JsonProcessingException {
|
||||
return Document.parse(mapper.writeValueAsString(obj));
|
||||
}
|
||||
|
||||
// ***** Serialization Exceptions
|
||||
|
||||
// OBJECT ID
|
||||
private static class ObjectIdSerializer extends JsonSerializer<ObjectId> {
|
||||
@Override
|
||||
public void serialize(ObjectId objectId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
||||
if (objectId == null) jsonGenerator.writeNull();
|
||||
else jsonGenerator.writeString(objectId.toHexString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ObjectId> handledType() {
|
||||
return ObjectId.class;
|
||||
}
|
||||
}
|
||||
private static class ObjectIdDeserializer extends JsonDeserializer<ObjectId> {
|
||||
|
||||
@Override
|
||||
public ObjectId deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||
String value=jsonParser.getValueAsString();
|
||||
if(value==null || value.isEmpty() || value.equals("null"))
|
||||
return null;
|
||||
else return new ObjectId(value);
|
||||
}
|
||||
@Override
|
||||
public Class<ObjectId> handledType() {
|
||||
return ObjectId.class;
|
||||
}
|
||||
}
|
||||
|
||||
//Comparable Version
|
||||
private static class ComparableVersionSerializer extends JsonSerializer<ComparableVersion> {
|
||||
@Override
|
||||
public void serialize(ComparableVersion comparableVersion, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
||||
if (comparableVersion == null) jsonGenerator.writeNull();
|
||||
else jsonGenerator.writeString(comparableVersion.getCanonical());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ComparableVersion> handledType() {
|
||||
return ComparableVersion.class;
|
||||
}
|
||||
}
|
||||
private static class ComparableVersionDeserializer extends JsonDeserializer<ComparableVersion> {
|
||||
|
||||
@Override
|
||||
public ComparableVersion deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||
String value=jsonParser.getValueAsString();
|
||||
if(value==null || value.isEmpty() || value.equals("null"))
|
||||
return null;
|
||||
else return new ComparableVersion(value);
|
||||
}
|
||||
@Override
|
||||
public Class<ComparableVersion> handledType() {
|
||||
return ComparableVersion.class;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package org.gcube.application.cms.plugins.reports;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
|
@ -13,4 +14,10 @@ public class Report {
|
|||
|
||||
private Status status;
|
||||
private List<String> messages;
|
||||
|
||||
public Report putMessage(String msg){
|
||||
if(messages==null)messages=new ArrayList<>();
|
||||
messages.add(msg);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
This library contains custom extensions for the support of GNA "concessioni" use case
|
||||
|
||||
## [v1.0.1-SNAPSHOT] - 2022-01-17
|
||||
- Serialization adaptation
|
||||
|
||||
## [v1.0.0] - 2021-12-15
|
||||
- First release
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>concessioni-lifecycle</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1</version>
|
||||
<name>GNA Concessioni Lifecycle</name>
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.application.cms.concessioni.plugins;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.faults.InitializationException;
|
||||
|
@ -47,13 +48,14 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
ExecutionReport report=new ExecutionReport();
|
||||
report.setRequest(request);
|
||||
report.setStatus(Report.Status.OK);
|
||||
report.setResult(request.getDocument());
|
||||
try {
|
||||
switch (request.getStep()) {
|
||||
case StepExecutionRequest.Steps.ON_INIT_DOCUMENT:
|
||||
// Set Defaults as for on update
|
||||
case StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT: {
|
||||
ProfiledDocument doc = request.getDocument();
|
||||
|
||||
log.debug("Setting default values..");
|
||||
report.setResult(setDefaults(request.getDocument()));
|
||||
break;
|
||||
}
|
||||
case StepExecutionRequest.Steps.ON_MATERIALIZE_DOCUMENT: {
|
||||
|
@ -79,7 +81,7 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
}catch (Throwable t){
|
||||
log.error("Unable to perform step "+request.getStep(),t);
|
||||
report.setStatus(Report.Status.ERROR);
|
||||
report.getMessages().add("Unable to execute Step "+request.getStep()+". Error was "+t.getMessage());
|
||||
report.putMessage("Unable to execute Step "+request.getStep()+". Error was "+t.getMessage());
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
@ -93,7 +95,7 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
// STATIC ROUTINES
|
||||
|
||||
private static final ProfiledDocument setDefaults(ProfiledDocument document){
|
||||
ProfiledConcessione c =(ProfiledConcessione) document;
|
||||
ProfiledConcessione c=Serialization.convert(document,ProfiledConcessione.class);
|
||||
c.setDefaults();
|
||||
return c;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
This library contains custom BEANS for the support of GNA "concessioni" use case
|
||||
|
||||
## [v1.0.1-SNAPSHOT] - 2022-01-17
|
||||
- Defaults Evaluation
|
||||
|
||||
|
||||
## [v1.0.0] - 2021-12-15
|
||||
- First release
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>org.gcube.application.cms</groupId>
|
||||
<artifactId>concessioni-model</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<name>GNA Concessioni Model</name>
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.application.cms.custom.gna.concessioni.model;
|
||||
|
||||
|
||||
import org.bson.BsonDocument;
|
||||
import org.bson.BsonString;
|
||||
import org.bson.BsonValue;
|
||||
|
@ -8,8 +9,6 @@ import org.gcube.application.geoportal.common.model.document.Access;
|
|||
import org.gcube.application.geoportal.common.model.document.AccessPolicy;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.document.RegisteredFileSet;
|
||||
import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.report.Check;
|
||||
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -79,7 +78,8 @@ public class ProfiledConcessione extends ProfiledDocument {
|
|||
|
||||
|
||||
//RELAZIONE
|
||||
doc.putIfAbsent(RELAZIONE_SCAVO,new RegisteredFileSet());
|
||||
// TODO NB provare se object gia' presente sia usando Document che sub Object
|
||||
doc.putIfAbsent(RELAZIONE_SCAVO,new Document());
|
||||
Document rel=doc.get(RELAZIONE_SCAVO,Document.class);
|
||||
rel.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" relazione di scavo");
|
||||
rel.putIfAbsent(SOGGETTO,doc.get(SOGGETTO));
|
||||
|
@ -90,7 +90,7 @@ public class ProfiledConcessione extends ProfiledDocument {
|
|||
relAccess.setPolicy(ConstraintCheck.defaultFor(relAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
|
||||
|
||||
//ABSTRACT Relazione
|
||||
doc.putIfAbsent(ABSTRACT_RELAZIONE,new RegisteredFileSet());
|
||||
doc.putIfAbsent(ABSTRACT_RELAZIONE,new Document());
|
||||
Document abs=doc.get(ABSTRACT_RELAZIONE,Document.class);
|
||||
abs.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" abstract relazione di scavo");
|
||||
abs.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
|
||||
|
@ -99,20 +99,23 @@ public class ProfiledConcessione extends ProfiledDocument {
|
|||
absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
|
||||
absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
|
||||
|
||||
//TODO complete setDefaults
|
||||
//IMMAGINI RAPPRESENTATIVE
|
||||
|
||||
|
||||
// if(doc.containsKey(IMMAGINI_RAPPRESENTATIVE)) {
|
||||
// for (BsonValue bsonValue : doc.toBsonDocument(null, null).
|
||||
// getArray(IMMAGINI_RAPPRESENTATIVE)) {
|
||||
// BsonDocument imgDocument = bsonValue.asDocument();
|
||||
// imgDocument.putIfAbsent(SOGGETTO,new BsonString(doc.getString(SOGGETTO));
|
||||
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,new BsonDocument(this.getInfo().getCreationInfo());
|
||||
if(doc.containsKey(IMMAGINI_RAPPRESENTATIVE)) {
|
||||
for (BsonValue bsonValue : doc.toBsonDocument(null, null).
|
||||
getArray(IMMAGINI_RAPPRESENTATIVE)) {
|
||||
|
||||
BsonDocument imgDocument = bsonValue.asDocument();
|
||||
imgDocument.putIfAbsent(SOGGETTO,new BsonString(doc.getString(SOGGETTO)));
|
||||
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
|
||||
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,new BsonDocument(new Document()));
|
||||
// imgDocument.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
|
||||
// Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
|
||||
// absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
|
||||
// absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for org.gcube.application.geoportal-common
|
||||
|
||||
# [v1.0.9-SNAPSHOT] - 2022-01-17
|
||||
- Minor fixes in model
|
||||
|
||||
# [v1.0.8] - 2021-11-10
|
||||
- Fixes [#22369](https://support.d4science.org/issues/22369)
|
||||
- Fixes [#22338](https://support.d4science.org/issues/22338)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>geoportal-common</artifactId>
|
||||
<version>1.0.8</version>
|
||||
<version>1.0.9-SNAPSHOT</version>
|
||||
<name>Geoportal Common</name>
|
||||
|
||||
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package org.gcube.application.geoportal.common.faults;
|
||||
|
||||
public class JsonParseException extends Exception{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public JsonParseException() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JsonParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JsonParseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JsonParseException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JsonParseException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package org.gcube.application.geoportal.common.model.document;
|
|||
import com.mongodb.client.model.geojson.GeoJsonObjectType;
|
||||
import lombok.*;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -2,6 +2,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for org.gcube.application.geoportal-service
|
||||
|
||||
## [v1.0.9-SNAPSHOT] 2022-01-17
|
||||
- Plugin Management
|
||||
|
||||
## [v1.0.8] 2021-09-20
|
||||
- Logging
|
||||
- Fixes [#22193](https://support.d4science.org/issues/22193)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.application</groupId>
|
||||
<artifactId>geoportal-service</artifactId>
|
||||
<version>1.0.8</version>
|
||||
<version>1.0.9-SNAPSHOT</version>
|
||||
<name>Geoportal Service</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
|
@ -185,10 +185,7 @@
|
|||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.gcube.application.geoportal.service.rest.ConcessioniOverMongo;
|
|||
|
||||
import org.gcube.application.geoportal.service.rest.ProfiledDocuments;
|
||||
import org.gcube.application.geoportal.service.rest.Sections;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
|
|
|
@ -23,18 +23,15 @@ import org.gcube.application.geoportal.service.engine.WorkspaceManager.FileOptio
|
|||
import org.gcube.application.geoportal.service.engine.WorkspaceManager.FolderOptions;
|
||||
import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.*;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.gcube.application.geoportal.service.utils.UserUtils;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.data.transfer.library.faults.RemoteServiceException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.gcube.application.geoportal.service.engine.mongo;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import lombok.Synchronized;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
@ -13,15 +13,13 @@ import org.gcube.application.cms.plugins.reports.ExecutionReport;
|
|||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.*;
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
|
||||
import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
|
||||
import org.gcube.application.geoportal.service.engine.providers.PluginManager;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.gcube.application.geoportal.service.utils.UserUtils;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
|
@ -33,7 +31,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager.asConcessione;
|
||||
import static org.gcube.application.cms.Serialization.*;
|
||||
|
||||
@Slf4j
|
||||
public class ProfiledMongoManager extends MongoManager implements MongoManagerI<ProfiledDocument>{
|
||||
|
@ -42,7 +40,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
Profile profile;
|
||||
MongoDatabase db=null;
|
||||
|
||||
LifecycleManager lfManager;
|
||||
|
||||
|
||||
|
||||
public ProfiledMongoManager(String profileId) throws ConfigurationException {
|
||||
|
@ -58,25 +56,6 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
log.debug("Loaded Profile {} ",profile);
|
||||
|
||||
|
||||
|
||||
|
||||
//Getting Lifecycle Manager declaration from Profile
|
||||
List<HandlerDeclaration> handlerDeclarations= profile.getHandlersMap().get(PluginDescriptor.BaseTypes.LIFECYCLE_MANAGER);
|
||||
if(handlerDeclarations==null || handlerDeclarations.isEmpty()) throw new ConfigurationException("No Lifecycle Handler defined for profile ID "+profileId);
|
||||
if(handlerDeclarations.size()>1) throw new ConfigurationException("Too many Lifecycle Handlers defined ("+handlerDeclarations+") in profile ID "+profileId);
|
||||
|
||||
HandlerDeclaration lcHandlerDeclaration=handlerDeclarations.get(0);
|
||||
|
||||
// Loading Lifecycle Manager
|
||||
log.debug("Looking for handler {} ",lcHandlerDeclaration);
|
||||
try{
|
||||
lfManager=(LifecycleManager) ImplementationProvider.get().getPluginManager().getObject().get(lcHandlerDeclaration.getId());
|
||||
if(lfManager==null) throw new ConfigurationException("Unable to find Lifecycle Manager Plugin. ID "+lcHandlerDeclaration.getId());
|
||||
}catch(ClassCastException e){
|
||||
throw new ConfigurationException("Unable to use "+lcHandlerDeclaration.getId()+" as Lifecycle Manager");
|
||||
}
|
||||
|
||||
|
||||
// Connect to DB
|
||||
String toUseDB=super.client.getConnection().getDatabase();
|
||||
log.info("Connecting to DB {} ",toUseDB);
|
||||
|
@ -85,8 +64,30 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
db=client.getTheClient().getDatabase(toUseDB);
|
||||
}
|
||||
|
||||
@Getter(lazy = true)
|
||||
private final LifecycleManager manager=getLCManager();
|
||||
|
||||
private LifecycleManager getLCManager() {
|
||||
try{
|
||||
LifecycleManager toReturn=null;
|
||||
//Getting Lifecycle Manager declaration from Profile
|
||||
List<HandlerDeclaration> handlerDeclarations= profile.getHandlersMap().get(PluginDescriptor.BaseTypes.LIFECYCLE_MANAGER);
|
||||
if(handlerDeclarations==null || handlerDeclarations.isEmpty()) throw new ConfigurationException("No Lifecycle Handler defined for profile ID "+profile.getId());
|
||||
if(handlerDeclarations.size()>1) throw new ConfigurationException("Too many Lifecycle Handlers defined ("+handlerDeclarations+") in profile ID "+profile.getId());
|
||||
|
||||
HandlerDeclaration lcHandlerDeclaration=handlerDeclarations.get(0);
|
||||
|
||||
// Loading Lifecycle Manager
|
||||
log.debug("Looking for handler {} ",lcHandlerDeclaration);
|
||||
toReturn=(LifecycleManager) ImplementationProvider.get().getPluginManager().getObject().get(lcHandlerDeclaration.getId());
|
||||
if(toReturn==null) throw new ConfigurationException("Unable to find Lifecycle Manager Plugin. ID "+lcHandlerDeclaration.getId());
|
||||
|
||||
return toReturn;
|
||||
} catch(Throwable t){
|
||||
log.warn("Unable to load LC Manager ",t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ProfiledDocument onUpdate(ProfiledDocument updatedDocument) throws StepException {
|
||||
|
||||
|
@ -96,13 +97,13 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
return step(updatedDocument,StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT).getResult();
|
||||
}
|
||||
|
||||
private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
|
||||
return Document.parse(Serialization.write(d));
|
||||
}
|
||||
|
||||
private ProfiledDocument asProfiledDocument(Document d) throws IOException {
|
||||
return Serialization.read(d.toJson(),ProfiledDocument.class);
|
||||
}
|
||||
// private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
|
||||
// return Document.parse(Serialization.write(d));
|
||||
// }
|
||||
//
|
||||
// private ProfiledDocument asProfiledDocument(Document d) throws IOException {
|
||||
// return Serialization.read(d.toJson(),ProfiledDocument.class);
|
||||
// }
|
||||
|
||||
private String getCollectionName(){
|
||||
// TODO Profile can directly specify, use ID only as default
|
||||
|
@ -156,7 +157,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException, StepException {
|
||||
log.trace("Replacing {} ",toSet);
|
||||
toSet=onUpdate(toSet);
|
||||
return asProfiledDocument(replace(asDocument(toSet),getCollectionName()));
|
||||
return convert(replace(asDocument(toSet),getCollectionName()),ProfiledDocument.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -190,7 +191,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
|
||||
@Override
|
||||
public ProfiledDocument getByID(String id) throws IOException {
|
||||
return asProfiledDocument(super.getById(asId(id),getCollectionName()));
|
||||
return convert(super.getById(asId(id),getCollectionName()),ProfiledDocument.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -245,12 +246,15 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
|
||||
|
||||
private ExecutionReport step(ProfiledDocument theDocument,String step) throws StepException {
|
||||
log.info("[Profile {} ] Invoking Step {} on " ,profile.getId(),step,lfManager.getDescriptor());
|
||||
log.info("[Profile {} ] Invoking Step {} on " ,profile.getId(),step,getManager().getDescriptor());
|
||||
StepExecutionRequest request=new StepExecutionRequest();
|
||||
request.setDocument(theDocument);
|
||||
request.setProfile(profile);
|
||||
request.setStep(StepExecutionRequest.Steps.ON_INIT_DOCUMENT);
|
||||
log.debug("Requesting Step Execution {} ",request);
|
||||
return lfManager.performStep(request);
|
||||
ExecutionReport report= getManager().performStep(request);
|
||||
log.debug("Report is {}",report);
|
||||
if(report.getResult()==null) throw new StepException("Report result is null");
|
||||
return report;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.gcube.application.geoportal.service.model.internal.db.PostgisTable.Fi
|
|||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.PublishException;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.SDIInteractionException;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
|
|
@ -5,7 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
|||
import org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager;
|
||||
import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
|
|
|
@ -3,16 +3,12 @@ package org.gcube.application.geoportal.service.rest;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.gcube.application.geoportal.common.model.rest.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||
import org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager;
|
||||
import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager;
|
||||
import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.json.JSONArray;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package org.gcube.application.geoportal.service.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Iterator;
|
||||
|
||||
@Slf4j
|
||||
public class Serialization {
|
||||
|
||||
|
||||
public static final DateTimeFormatter FULL_FORMATTER=DateTimeFormatter.ofPattern("uuuuMMdd_HH-mm-ss");
|
||||
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper=new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
|
||||
}
|
||||
|
||||
public static <T> T read(String jsonString,Class<T> clazz) throws JsonProcessingException, IOException {
|
||||
return mapper.readerFor(clazz).readValue(jsonString);
|
||||
}
|
||||
|
||||
public static <T> Iterator<T> readCollection(String jsonString, Class<T> clazz) throws IOException {
|
||||
return mapper.readerFor(clazz).readValues(jsonString);
|
||||
}
|
||||
|
||||
|
||||
public static String write(Object toWrite) throws JsonProcessingException {
|
||||
String toReturn= mapper.writeValueAsString(toWrite);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static QueryRequest parseQuery(String queryString) throws IOException {
|
||||
log.debug("Parsing query Request {} ",queryString);
|
||||
Document queryDocument = Document.parse(queryString);
|
||||
log.debug("Document is ",queryDocument.toJson());
|
||||
QueryRequest req = new QueryRequest();
|
||||
if (queryDocument.getOrDefault("ordering",null)!=null)
|
||||
req.setOrdering(Serialization.read(((Document) queryDocument.get("ordering")).toJson(), QueryRequest.OrderedRequest.class));
|
||||
if (queryDocument.getOrDefault("paging",null)!=null)
|
||||
req.setPaging(Serialization.read(((Document) queryDocument.get("paging")).toJson(), QueryRequest.PagedRequest.class));
|
||||
req.setProjection(queryDocument.get("projection", Document.class));
|
||||
req.setFilter(queryDocument.get("filter", Document.class));
|
||||
return req;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ package org.gcube.application.geoportal.service;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.service.rest.GuardedMethod;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@ import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
|||
import org.gcube.application.geoportal.common.utils.FileSets;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.common.storagehub.model.query.Queries;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package org.gcube.application.geoportal.service;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -37,6 +40,20 @@ public class ProjectTests extends BasicServiceTestUnit{
|
|||
System.out.println(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getByID(){
|
||||
target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class).forEach(d ->{
|
||||
|
||||
try {
|
||||
check(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).path((Serialization.convert(d,ProfiledDocument.class)).get_id())
|
||||
.request(MediaType.APPLICATION_JSON).get(),ProfiledDocument.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerNew() {
|
||||
WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
||||
|
|
|
@ -8,13 +8,11 @@ import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
|||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.GeoServerContent;
|
||||
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.PersistedContent;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
import org.gcube.application.geoportal.service.engine.materialization.SDIManager;
|
||||
import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.SDIInteractionException;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
Loading…
Reference in New Issue