Creating IS model refs #4023

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/information-system-model@128744 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-05-20 12:42:52 +00:00
parent fcd2a7bd93
commit da27ceb1f2
3 changed files with 146 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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 extends OutputStream> 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 extends Writer> T marshal(Object resource,T stream) throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(stream, resource);
return stream;
}
public static <T> T unmarshal(Class<T> 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> T unmarshal(Class<T> resourceClass, InputStream stream) throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(stream, resourceClass);
}
}