diff --git a/src/main/java/org/gcube/informationsystem/impl/AccessPolicyImpl.java b/src/main/java/org/gcube/informationsystem/impl/AccessPolicyImpl.java new file mode 100644 index 0000000..899ef61 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/impl/AccessPolicyImpl.java @@ -0,0 +1,40 @@ +/** + * + */ +package org.gcube.informationsystem.impl; + +import org.gcube.informationsystem.model.AccessPolicy; +import org.gcube.informationsystem.model.ValueSchema; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + */ +public class AccessPolicyImpl implements AccessPolicy { + + @JsonDeserialize(as = ValueSchemaImpl.class) + protected ValueSchema policy; + protected String note; + + @Override + public ValueSchema getPolicy() { + return this.policy; + } + + @Override + public void setPolicy(ValueSchema policy) { + this.policy = policy; + } + + @Override + public String getNote() { + return this.note; + } + + @Override + public void setNote(String note) { + this.note = note; + } + +} diff --git a/src/main/java/org/gcube/informationsystem/impl/ValueSchemaImpl.java b/src/main/java/org/gcube/informationsystem/impl/ValueSchemaImpl.java new file mode 100644 index 0000000..4468636 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/impl/ValueSchemaImpl.java @@ -0,0 +1,39 @@ +/** + * + */ +package org.gcube.informationsystem.impl; + +import java.net.URI; + +import org.gcube.informationsystem.model.ValueSchema; + +/** + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + * + */ +public class ValueSchemaImpl implements ValueSchema { + + protected String value; + protected URI schema; + + @Override + public String getValue() { + return this.value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + + @Override + public URI getSchema() { + return this.schema; + } + + @Override + public void setSchema(URI schema) { + this.schema = schema; + } + +} diff --git a/src/main/java/org/gcube/informationsystem/impl/utils/Entities.java b/src/main/java/org/gcube/informationsystem/impl/utils/Entities.java new file mode 100644 index 0000000..56ff665 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/impl/utils/Entities.java @@ -0,0 +1,67 @@ +package org.gcube.informationsystem.impl.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + */ +public class Entities { + + protected static final ObjectMapper mapper = new ObjectMapper(); + + /** + * Write the serialisation of a given resource to a given stream. + * @param resource the resource + * @param stream the stream in input + * @throws IOException + * @throws JsonMappingException + * @throws JsonGenerationException + */ + public static T marshal(Object resource,T stream) throws JsonGenerationException, JsonMappingException, IOException { + mapper.writeValue(stream, resource); + return stream; + } + + /** + * Write the serialisation of a given resource to a given character stream. + * @param resource the resource + * @param stream the stream in input + * @throws IOException + * @throws JsonMappingException + * @throws JsonGenerationException + */ + public static T marshal(Object resource,T stream) throws JsonGenerationException, JsonMappingException, IOException { + mapper.writeValue(stream, resource); + return stream; + } + + + + public static T unmarshal(Class resourceClass, Reader reader) throws JsonParseException, JsonMappingException, IOException { + return mapper.readValue(reader, resourceClass); + } + + /** + * 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 + * @throws IOException + * @throws JsonMappingException + * @throws JsonParseException + */ + public static T unmarshal(Class resourceClass, InputStream stream) throws JsonParseException, JsonMappingException, IOException { + return mapper.readValue(stream, resourceClass); + } + + +}