JSONPathWrapper dynamically loads JSON Implementation
This commit is contained in:
parent
405129f37f
commit
5c1aee1c76
|
@ -0,0 +1,12 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.geoportal.common.JSONSerializationProvider;
|
||||
|
||||
public class JacksonProvider implements JSONSerializationProvider {
|
||||
|
||||
|
||||
@Override
|
||||
public void setJSONWrapperDefaults() {
|
||||
|
||||
}
|
||||
}
|
|
@ -54,6 +54,22 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- STORAGE -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-wrapper</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -72,18 +88,9 @@
|
|||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
</dependency>
|
||||
<!-- STORAGE -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-wrapper</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
package org.gcube.application.geoportal.common;
|
||||
|
||||
public interface JSONSerializationProvider {
|
||||
|
||||
public void setJSONWrapperDefaults();
|
||||
|
||||
}
|
|
@ -7,33 +7,37 @@ import com.jayway.jsonpath.spi.json.JsonProvider;
|
|||
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
|
||||
import com.jayway.jsonpath.spi.mapper.MappingProvider;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.geoportal.common.JSONSerializationProvider;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
public class JSONPathWrapper {
|
||||
|
||||
public static Configuration JSON_PATH_ALWAYS_LIST_CONFIG=null;
|
||||
public static Configuration JSON_PATH_PATHS_CONFIGURATION=null;
|
||||
|
||||
static {
|
||||
Configuration.setDefaults(new Configuration.Defaults() {
|
||||
private JsonProvider jacksonProvider = new JacksonJsonProvider();
|
||||
Reflections reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.forPackage("org.gcube.application")
|
||||
.filterInputsBy(new FilterBuilder().includePackage("org.gcube.application")));
|
||||
|
||||
private final MappingProvider mappingProvider = new JacksonMappingProvider();
|
||||
@Override
|
||||
public JsonProvider jsonProvider() {
|
||||
return jacksonProvider;
|
||||
reflections.getSubTypesOf(JSONSerializationProvider.class).iterator().forEachRemaining(providerClass->{
|
||||
if(!providerClass.isInterface()){
|
||||
try {
|
||||
log.warn("Loading JSON Provider {} ",providerClass);
|
||||
JSONSerializationProvider provider = providerClass.newInstance();
|
||||
provider.setJSONWrapperDefaults();
|
||||
}catch (Throwable t){
|
||||
log.error("Unable to instantiate provider "+providerClass,t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Option> options() {
|
||||
return EnumSet.noneOf(Option.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingProvider mappingProvider() {
|
||||
return mappingProvider;
|
||||
}
|
||||
});
|
||||
|
||||
JSON_PATH_ALWAYS_LIST_CONFIG= Configuration.builder().options(Option.ALWAYS_RETURN_LIST,Option.SUPPRESS_EXCEPTIONS,Option.DEFAULT_PATH_LEAF_TO_NULL).build();
|
||||
|
|
|
@ -368,6 +368,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
private static final RegisteredFileSet prepareRegisteredFileSet(ProfiledDocument doc, Profile profile,String destination,
|
||||
Document attributes,List<TempFile> files, StorageUtils storage,WorkspaceManager ws) throws StorageHubException, StorageException {
|
||||
log.debug("Preparing Registered FileSet..");
|
||||
|
||||
attributes.putIfAbsent(RegisteredFileSet.CREATION_INFO,UserUtils.getCurrent().asInfo());
|
||||
attributes.putIfAbsent(RegisteredFileSet.ACCESS,doc.getInfo().getAccess());
|
||||
FolderContainer base=ws.createFolder(new WorkspaceManager.FolderOptions(
|
||||
|
|
|
@ -2,6 +2,9 @@ package org.gcube.application.geoportal.service;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
||||
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
|
||||
import org.gcube.application.geoportal.service.engine.providers.StorageClientProvider;
|
||||
import org.gcube.application.geoportal.service.rest.GuardedMethod;
|
||||
import org.gcube.application.cms.Serialization;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
|
@ -19,8 +22,8 @@ public class BasicServiceTestUnit extends JerseyTest {
|
|||
return new GeoPortalService();
|
||||
}
|
||||
|
||||
protected static String scope="/gcube/devsec/devVRE";
|
||||
// protected static String scope="/pred4s/preprod/preVRE";
|
||||
// protected static String scope="/gcube/devsec/devVRE";
|
||||
protected static String scope="/pred4s/preprod/preVRE";
|
||||
// protected static String scope="/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype";
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
|
@ -32,7 +35,17 @@ public class BasicServiceTestUnit extends JerseyTest {
|
|||
TokenSetter.set(scope);
|
||||
}
|
||||
});
|
||||
|
||||
// ImplementationProvider.get().setStorageProvider(
|
||||
// new StorageClientProvider(){
|
||||
// @Override
|
||||
// public StorageUtils retrieveObject(){
|
||||
// new StorageUtils(){
|
||||
// @Override
|
||||
// getP
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,9 +3,11 @@ package org.gcube.application.geoportal.service;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.tests.TokenSetter;
|
||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||
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.Concessione;
|
||||
import org.gcube.application.geoportal.common.model.rest.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
|
@ -28,6 +30,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
||||
|
||||
|
@ -107,14 +110,24 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
|||
public void addFileSet() throws Exception {
|
||||
|
||||
ProfiledDocument doc = createNew();
|
||||
// Try set releazione scavo
|
||||
String fileSetPath="relazioneScavo";
|
||||
String fieldPath="relazioneScavo";
|
||||
String filename = "relazione.pdf";
|
||||
|
||||
doc = upload(
|
||||
new StorageUtils(),
|
||||
doc.get_id(),
|
||||
"relazioneScavo",
|
||||
"relazioneScavo",
|
||||
fileSetPath,
|
||||
fieldPath,
|
||||
Document.parse("{\"titolo\" : \"mio titolo\"}"),
|
||||
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
|
||||
"relazione.pdf");
|
||||
filename);
|
||||
assertTrue("Relazione exists",doc.getTheDocument().containsKey(fileSetPath));
|
||||
RegisteredFileSet set = Serialization.convert(doc.getTheDocument().get(fileSetPath), RegisteredFileSet.class);
|
||||
System.out.println(set);
|
||||
ProfiledConcessione.Relazione rel= Serialization.convert(doc.getTheDocument().get(fileSetPath), ProfiledConcessione.Relazione.class);
|
||||
System.out.println(rel);
|
||||
System.out.println(Serialization.write(doc));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue