diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs index f897a7f..ff7698f 100644 --- a/.settings/org.eclipse.m2e.core.prefs +++ b/.settings/org.eclipse.m2e.core.prefs @@ -1,4 +1,4 @@ activeProfiles= eclipse.preferences.version=1 -resolveWorkspaceProjects=true +resolveWorkspaceProjects=false version=1 diff --git a/pom.xml b/pom.xml index 1a923bd..1ee3fcf 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,18 @@ - - 4.0.0 - - org.gcube.tools - maven-parent - LATEST - - org.gcube.spatial.data - sdi-interface - 1.0.0-SNAPSHOT - SDI Interface - SDI Service interface and model - - + + 4.0.0 + + org.gcube.tools + maven-parent + LATEST + + org.gcube.spatial.data + sdi-interface + 1.0.0-SNAPSHOT + SDI Interface + SDI Service interface and model + + org.gcube.distribution @@ -22,10 +23,10 @@ - - - - + + + + junit junit @@ -34,15 +35,20 @@ - org.eclipse.persistence - org.eclipse.persistence.moxy - 2.6.0 + org.glassfish.jersey.media + jersey-media-json-jackson + 2.13 test - - - + + commons-collections + commons-collections + 3.0 + test + + + @@ -56,5 +62,5 @@ - + \ No newline at end of file diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/StringEntry.java b/src/main/java/org/gcube/spatial/data/sdi/model/StringEntry.java new file mode 100644 index 0000000..9871972 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/StringEntry.java @@ -0,0 +1,20 @@ +package org.gcube.spatial.data.sdi.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.Data; + +@XmlRootElement +@Data +@XmlAccessorType(XmlAccessType.NONE) +public class StringEntry { + + @XmlElement(name = "name") + private String name; + @XmlElement(name = "value") + private String value; + +} diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/faults/ErrorMessage.java b/src/main/java/org/gcube/spatial/data/sdi/model/faults/ErrorMessage.java index 5ef6d9e..a39533d 100644 --- a/src/main/java/org/gcube/spatial/data/sdi/model/faults/ErrorMessage.java +++ b/src/main/java/org/gcube/spatial/data/sdi/model/faults/ErrorMessage.java @@ -1,5 +1,7 @@ package org.gcube.spatial.data.sdi.model.faults; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -7,6 +9,7 @@ import lombok.Data; @XmlRootElement @Data +@XmlAccessorType(XmlAccessType.NONE) public class ErrorMessage { /** contains the same HTTP Status code returned by the server */ diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataReport.java b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataReport.java index 5b167dd..9ef9aa8 100644 --- a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataReport.java +++ b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/MetadataReport.java @@ -21,14 +21,16 @@ import lombok.ToString; @ToString @EqualsAndHashCode @XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) +@XmlAccessorType(XmlAccessType.NONE) public class MetadataReport { - + @XmlElement(name="publishedUUID") private String publishedUUID; + @XmlElement(name="publishedID") private Long publishedID; + @XmlElement(name="appliedTemplates") private Set appliedTemplates; } diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateApplicationRequest.java b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateApplicationRequest.java index 2653100..4006b8c 100644 --- a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateApplicationRequest.java +++ b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateApplicationRequest.java @@ -4,6 +4,7 @@ import java.util.HashSet; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; @@ -18,9 +19,10 @@ import lombok.ToString; @AllArgsConstructor @ToString @XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) +@XmlAccessorType(XmlAccessType.NONE) public class TemplateApplicationRequest { + @XmlElement(name="invocationSet") private HashSet invocationSet; @Override diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateCollection.java b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateCollection.java index b0dbfd1..954327f 100644 --- a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateCollection.java +++ b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateCollection.java @@ -5,6 +5,7 @@ import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; @@ -19,9 +20,10 @@ import lombok.ToString; @AllArgsConstructor @ToString @XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) +@XmlAccessorType(XmlAccessType.NONE) public class TemplateCollection { + @XmlElement(name="availableTemplates") private Set availableTemplates=new HashSet(); @Override diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateDescriptor.java b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateDescriptor.java index d837189..38598f9 100644 --- a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateDescriptor.java +++ b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateDescriptor.java @@ -6,6 +6,7 @@ import java.util.Map.Entry; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @@ -23,16 +24,22 @@ import lombok.ToString; @AllArgsConstructor @ToString @XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) +@XmlAccessorType(XmlAccessType.NONE) public class TemplateDescriptor { + @XmlElement(name="templateID") private String id; + @XmlElement(name="name") private String name; + @XmlElement(name="description") private String description; + @XmlElement(name="sourceURL") private String sourceURL; - @XmlAnyElement - @XmlJavaTypeAdapter(MapAdapter.class) +// @XmlAnyElement +// @XmlJavaTypeAdapter(MapAdapter.class) + + @XmlElement(name="parameters") private HashMap expectedParameters; @Override diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocation.java b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocation.java index 2c6e4e9..d4bbbe4 100644 --- a/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocation.java +++ b/src/main/java/org/gcube/spatial/data/sdi/model/metadata/TemplateInvocation.java @@ -5,11 +5,8 @@ import java.util.Map.Entry; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -import org.gcube.spatial.data.sdi.model.MapAdapter; import lombok.AllArgsConstructor; import lombok.Getter; @@ -23,13 +20,15 @@ import lombok.ToString; @AllArgsConstructor @ToString @XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) +@XmlAccessorType(XmlAccessType.NONE) public class TemplateInvocation { + @XmlElement(name="templateID") private String toInvokeTemplateID; - @XmlAnyElement - @XmlJavaTypeAdapter(MapAdapter.class) +// @XmlAnyElement +// @XmlJavaTypeAdapter(MapAdapter.class) + @XmlElement(name="parameters") private HashMap templateParameters; @Override diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/services/CatalogDefinition.java b/src/main/java/org/gcube/spatial/data/sdi/model/services/CatalogDefinition.java new file mode 100644 index 0000000..acd0949 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/services/CatalogDefinition.java @@ -0,0 +1,26 @@ +package org.gcube.spatial.data.sdi.model.services; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class CatalogDefinition { + + private String name; + +} diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoNetworkServiceDefinition.java b/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoNetworkServiceDefinition.java new file mode 100644 index 0000000..2671b9a --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoNetworkServiceDefinition.java @@ -0,0 +1,35 @@ +package org.gcube.spatial.data.sdi.model.services; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class GeoNetworkServiceDefinition extends ServiceDefinition { + + @XmlElement(name = "priority") + private int priority; + + @Override + public Type getType() { + return Type.GEONETWORK; + } + + + +} diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoServerDefinition.java b/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoServerDefinition.java new file mode 100644 index 0000000..8091a34 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/services/GeoServerDefinition.java @@ -0,0 +1,33 @@ +package org.gcube.spatial.data.sdi.model.services; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class GeoServerDefinition extends ServiceDefinition { + + @Override + public Type getType() { + return Type.GEOSERVER; + } + + private List workspaces; + +} diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/services/SdiStatusReport.java b/src/main/java/org/gcube/spatial/data/sdi/model/services/SdiStatusReport.java new file mode 100644 index 0000000..2e251ac --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/services/SdiStatusReport.java @@ -0,0 +1,10 @@ +package org.gcube.spatial.data.sdi.model.services; + +public class SdiStatusReport { + + + + + + +} diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/services/ServiceDefinition.java b/src/main/java/org/gcube/spatial/data/sdi/model/services/ServiceDefinition.java new file mode 100644 index 0000000..87234f7 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/services/ServiceDefinition.java @@ -0,0 +1,78 @@ +package org.gcube.spatial.data.sdi.model.services; + +import java.util.HashMap; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@RequiredArgsConstructor +public abstract class ServiceDefinition { + + public static enum Type{ + THREDDS,GEOSERVER,GEONETWORK + } + + + @XmlElement(name ="hostname") + @NonNull + private String hostname; + + @XmlElement(name ="majorVersion") + @NonNull + private Short majorVersion; + + @XmlElement(name ="minorVersion") + @NonNull + private Short minorVersion; + + @XmlElement(name ="releaseVersion") + private Short releaseVersion; + + @XmlElement(name ="type") + @NonNull + private Type type; + + @XmlElement(name ="adminPassword") + @NonNull + private String adminPassword; + + @XmlElement(name ="properties") + private HashMap properties; + + @XmlElement(name ="description") + private String description; + + @XmlElement(name ="name") + @NonNull + private String name; + + @Override + public String toString() { + return "ServiceDefinition [hostname=" + hostname + ", majorVersion=" + majorVersion + ", minorVersion=" + + minorVersion + ", releaseVersion=" + releaseVersion + ", type=" + type + ", properties=" + properties + + ", description=" + description + ", name=" + name + "]"; + } + + + + + + +} diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/services/ThreddsDefinition.java b/src/main/java/org/gcube/spatial/data/sdi/model/services/ThreddsDefinition.java new file mode 100644 index 0000000..c0297b3 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/services/ThreddsDefinition.java @@ -0,0 +1,34 @@ +package org.gcube.spatial.data.sdi.model.services; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class ThreddsDefinition extends ServiceDefinition { + + @Override + public Type getType() { + return Type.THREDDS; + } + + private List catalogs; + +} diff --git a/src/main/java/org/gcube/spatial/data/sdi/model/services/WorkspaceDefinition.java b/src/main/java/org/gcube/spatial/data/sdi/model/services/WorkspaceDefinition.java new file mode 100644 index 0000000..06e5847 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/sdi/model/services/WorkspaceDefinition.java @@ -0,0 +1,28 @@ +package org.gcube.spatial.data.sdi.model.services; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@Getter +@Setter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class WorkspaceDefinition { + + private String name; + + + +} diff --git a/src/main/resources/org/gcube/spatial/data/sdi/model/metadata/jaxb.properties b/src/main/resources/org/gcube/spatial/data/sdi/model/metadata/jaxb.properties deleted file mode 100644 index 5837a4c..0000000 --- a/src/main/resources/org/gcube/spatial/data/sdi/model/metadata/jaxb.properties +++ /dev/null @@ -1 +0,0 @@ -javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory \ No newline at end of file diff --git a/src/test/java/org/gcube/spatial/data/sdi/MarshallUnmarshallTest.java b/src/test/java/org/gcube/spatial/data/sdi/MarshallUnmarshallTest.java index 1967fab..eb02c73 100644 --- a/src/test/java/org/gcube/spatial/data/sdi/MarshallUnmarshallTest.java +++ b/src/test/java/org/gcube/spatial/data/sdi/MarshallUnmarshallTest.java @@ -2,204 +2,139 @@ package org.gcube.spatial.data.sdi; import static org.junit.Assert.assertTrue; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collection; -import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; +import org.apache.commons.collections.CollectionUtils; import org.gcube.spatial.data.sdi.model.faults.ErrorMessage; import org.gcube.spatial.data.sdi.model.metadata.MetadataReport; -import org.gcube.spatial.data.sdi.model.metadata.TemplateApplicationRequest; -import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection; import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor; -import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocationBuilder; +import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocation; import org.junit.BeforeClass; import org.junit.Test; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; + public class MarshallUnmarshallTest { -static JAXBContext ctx =null; + + + static ObjectMapper mapper=null; @BeforeClass public static void init() throws JAXBException{ - ctx = JAXBContext.newInstance( - MetadataReport.class, - TemplateApplicationRequest.class, - TemplateCollection.class, - ErrorMessage.class); + + mapper=new ObjectMapper(); + AnnotationIntrospector introspector=new JaxbAnnotationIntrospector(mapper.getTypeFactory()); + mapper.setAnnotationIntrospector(introspector); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + + + } - public static boolean roundTrip(Object obj){ + public static boolean roundTrip(Object obj) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException{ + Object roundTripResult=mapper.readValue(marshal(obj), obj.getClass()); - Object roundTripResult=unmarshal(obj.getClass(), new StringReader(marshal(obj,new StringWriter()).toString())); + if(obj instanceof Collection) { + return CollectionUtils.isEqualCollection((Collection)obj, (Collection)roundTripResult); + } return obj.equals(roundTripResult); } @Test - public void testHashAndEquals() { - assertTrue(getTemplateInvocations().equals(getTemplateInvocations())); - assertTrue(getTemplateInvocations().hashCode()==getTemplateInvocations().hashCode()); - assertTrue(getDescriptors().equals(getDescriptors())); - assertTrue(getDescriptors().hashCode()==getDescriptors().hashCode()); - assertTrue(getReport().equals(getReport())); - assertTrue(getReport().hashCode()==getReport().hashCode()); - assertTrue(getError().equals(getError())); - assertTrue(getError().hashCode()==getError().hashCode()); + public void testHashAndEquals() throws IOException { + assertTrue(loadObject(TemplateInvocation.class).equals(loadObject(TemplateInvocation.class))); + assertTrue(loadObject(TemplateInvocation.class).hashCode()==loadObject(TemplateInvocation.class).hashCode()); + assertTrue(loadObject(TemplateDescriptor.class).equals(loadObject(TemplateDescriptor.class))); + assertTrue(loadObject(TemplateDescriptor.class).hashCode()==loadObject(TemplateDescriptor.class).hashCode()); + assertTrue(loadObject(MetadataReport.class).equals(loadObject(MetadataReport.class))); + assertTrue(loadObject(MetadataReport.class).hashCode()==loadObject(MetadataReport.class).hashCode()); + assertTrue(loadObject(ErrorMessage.class).equals(loadObject(ErrorMessage.class))); + assertTrue(loadObject(ErrorMessage.class).hashCode()==loadObject(ErrorMessage.class).hashCode()); } @Test - public void Marshall(){ - print(getTemplateInvocations()); - print(getDescriptors()); - print(getReport()); - print(getError()); + public void Marshall() throws IOException{ + print(loadObject(TemplateInvocation.class)); + print(loadObject(TemplateDescriptor.class)); + print(loadObject(MetadataReport.class)); + print(loadObject(ErrorMessage.class)); } @Test - public void unMarshall(){ - assertTrue(roundTrip(getTemplateInvocations())); - assertTrue(roundTrip(getDescriptors())); - assertTrue(roundTrip(getReport())); - assertTrue(roundTrip(getError())); + public void unMarshall() throws JsonParseException, JsonMappingException, JsonProcessingException, IOException{ + assertTrue(roundTrip(loadObject(TemplateInvocation.class))); + assertTrue(roundTrip(loadObject(TemplateDescriptor.class))); + assertTrue(roundTrip(loadObject(MetadataReport.class))); + assertTrue(roundTrip(loadObject(ErrorMessage.class))); } @Test - public void toStringTest(){ - System.out.println(getTemplateInvocations()); - System.out.println(getDescriptors()); - System.out.println(getReport()); - System.out.println(getError()); - } - - /** - * Write the serialisation of a given resource to a {@link Result}. - * @param resource the resource - * @param stream the result - * @return the result in input - */ - public static T marshal(Object resource,T result) { - - try { - // OLD XML MARSHALLING -// JAXBContext context = ctx; -// Marshaller m = context.createMarshaller(); -// m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); -// -// m.marshal(resource,result); -// -// return result; - - - JAXBContext jaxbContext = ctx; - Marshaller marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty("eclipselink.media-type", "application/json"); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.marshal(resource, result); - return result; - } - catch(Exception e) { - throw new RuntimeException("serialisation error",e); - } - - - + public void toStringTest() throws IOException{ + System.out.println(loadObject(TemplateInvocation.class)); + System.out.println(loadObject(TemplateDescriptor.class)); + System.out.println(loadObject(MetadataReport.class)); + System.out.println(loadObject(ErrorMessage.class)); } - public static void print(Object resource) { - - marshal(resource,new OutputStreamWriter(System.out)); + public static String marshal(Object toSerialize) throws JsonProcessingException { + return mapper.writeValueAsString(toSerialize); } - /** - * Write the serialisation of a given resource to a given character stream. - * @param resource the resource - * @param stream the stream in input - */ - public static T marshal(Object resource,T stream) { - - marshal(resource,new StreamResult(stream)); - return stream; + public static void print(Object obj) throws JsonProcessingException { + System.out.println(marshal(obj)); } +// public static T unmarshal(Class resourceClass, String toRead) throws JsonParseException, JsonMappingException, IOException { +// return mapper.readValue(toRead, resourceClass); +// } - - /** - * Creates a resource of given class from its serialisation in a given {@link Reader}. - * @param resourceClass the class of the resource - * @param reader the reader - * @return the resource - */ - public static T unmarshal(Class resourceClass, Reader reader) { - return unmarshal(resourceClass,new StreamSource(reader)); - } - - /** - * Creates a resource of given class from its serialisation in a given {@link InputStream}. - * @param resourceClass the class of the resource - * @param stream the stream - * @return the resource - */ - public static T unmarshal(Class resourceClass, InputStream stream) { - return unmarshal(resourceClass,new StreamSource(stream)); - } - - /** - * Creates a resource of given class from its serialisation in a given {@link Source}. - * @param resourceClass the class of the resource - * @param source the source - * @return the resource - */ - public static T unmarshal(Class resourceClass,Source source) { - try { - Unmarshaller um = ctx.createUnmarshaller(); - um.setProperty("eclipselink.media-type", "application/json"); - return resourceClass.cast(um.unmarshal(source)); - } - catch(Exception e) { - throw new RuntimeException("deserialisation error",e); - } - } - - private TemplateApplicationRequest getTemplateInvocations(){ - return new TemplateApplicationRequest(new TemplateInvocationBuilder().threddsOnlineResources("localhost", "myDataset.nc", "my Catalog").get()); - } - - private TemplateCollection getDescriptors(){ - HashSet descriptors=new HashSet<>(); - descriptors.add(new TemplateDescriptor(TemplateInvocationBuilder.THREDDS_ONLINE.ID,"Thredds Online Resources","Online reousrce template for thredds resources","http://some.place.org/theTemplate", new HashMap())); - descriptors.add(new TemplateDescriptor(TemplateInvocationBuilder.THREDDS_ONLINE.ID,"Thredds Online Resources","Online reousrce template for thredds resources","http://some.place.org/theTemplate", new HashMap())); - return new TemplateCollection(descriptors); - } - - private MetadataReport getReport(){ - return new MetadataReport("theUUID", 12335l, Collections.singleton(TemplateInvocationBuilder.THREDDS_ONLINE.ID)); - } +// +// +// private TemplateApplicationRequest getTemplateInvocations(){ +// return new TemplateApplicationRequest(new TemplateInvocationBuilder().threddsOnlineResources("localhost", "myDataset.nc", "my Catalog").get()); +// } +// +// private TemplateCollection getDescriptors(){ +// HashSet descriptors=new HashSet<>(); +// descriptors.add(new TemplateDescriptor(TemplateInvocationBuilder.THREDDS_ONLINE.ID,"Thredds Online Resources","Online reousrce template for thredds resources","http://some.place.org/theTemplate", new HashMap())); +// descriptors.add(new TemplateDescriptor(TemplateInvocationBuilder.THREDDS_ONLINE.ID,"Thredds Online Resources","Online reousrce template for thredds resources","http://some.place.org/theTemplate", new HashMap())); +// return new TemplateCollection(descriptors); +// } +// +// private MetadataReport getReport(){ +// return new MetadataReport("theUUID", 12335l, Collections.singleton(TemplateInvocationBuilder.THREDDS_ONLINE.ID)); +// } +// +// +// private ErrorMessage getError(){ +// ErrorMessage error=new ErrorMessage(); +// error.setCode(500); +// error.setDeveloperMessage("Develop it better!"); +// error.setMessage("You didn't see anything"); +// error.setLink("www.sto.ca.z.z.o.org"); +// return error; +// } - private ErrorMessage getError(){ - ErrorMessage error=new ErrorMessage(); - error.setCode(500); - error.setDeveloperMessage("Develop it better!"); - error.setMessage("You didn't see anything"); - error.setLink("www.sto.ca.z.z.o.org"); - return error; + private T loadObject(Class objectClass) throws IOException { + byte[] encoded = Files.readAllBytes(Paths.get("src/test/resources/json/"+objectClass.getSimpleName()+".json")); + return mapper.readValue(encoded, objectClass); } + } diff --git a/src/test/resources/json/ErrorMessage.json b/src/test/resources/json/ErrorMessage.json new file mode 100644 index 0000000..2d87fdf --- /dev/null +++ b/src/test/resources/json/ErrorMessage.json @@ -0,0 +1,7 @@ +{ + "status" : 0, + "code" : 500, + "message" : "You didn't see anything", + "link" : "www.sto.ca.z.z.o.org", + "developerMessage" : "Develop it better!" +} \ No newline at end of file diff --git a/src/test/resources/json/MetadataReport.json b/src/test/resources/json/MetadataReport.json new file mode 100644 index 0000000..21b7e1e --- /dev/null +++ b/src/test/resources/json/MetadataReport.json @@ -0,0 +1,5 @@ +{ + "publishedUUID" : "theUUID", + "publishedID" : 12335, + "appliedTemplates" : [ "THREDDS_ONLINE_RESOURCES" ] +} \ No newline at end of file diff --git a/src/test/resources/json/TemplateDescriptor.json b/src/test/resources/json/TemplateDescriptor.json new file mode 100644 index 0000000..a262bc5 --- /dev/null +++ b/src/test/resources/json/TemplateDescriptor.json @@ -0,0 +1,11 @@ +{ + "templateID": "THREDDS_ONLINE_RESOURCES", + "name": "Thredds Online Resources", + "description": "Template for online resources exposed by thredds.", + "sourceURL": "http://sdi-d4s.d4science.org", + "parameters": { + "hostname" : "Thredds hostname", + "filename" : "The dataset's file name", + "catalog" : "The thredds catalog name" + } +} \ No newline at end of file diff --git a/src/test/resources/json/TemplateInvocation.json b/src/test/resources/json/TemplateInvocation.json new file mode 100644 index 0000000..c6c5ddf --- /dev/null +++ b/src/test/resources/json/TemplateInvocation.json @@ -0,0 +1,8 @@ +{ + "templateID" : "THREDDS_ONLINE_RESOURCES", + "parameters" : { + "hostname" : "localhost", + "filename" : "myDataset.nc", + "catalog" : "my Catalog" + } +} \ No newline at end of file