Added facility class for Context
This commit is contained in:
parent
b084b8695b
commit
2d5c9247cc
|
@ -0,0 +1,182 @@
|
||||||
|
package org.gcube.resourcemanagement.contexts.impl.entities;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
|
import org.gcube.informationsystem.contexts.impl.entities.ContextImpl;
|
||||||
|
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.Event;
|
||||||
|
import org.gcube.resourcemanagement.contexts.impl.properties.BasicInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
@JsonTypeName(value=Context.NAME)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class GCubeContext extends ContextImpl {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generated Serial Version UID
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -8929392680534884169L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The events occurred to the Contexts.
|
||||||
|
* creation, renaming, parent change.
|
||||||
|
* Some of the event are managed by the resource-registry.
|
||||||
|
* Others can be added by an authorized client.
|
||||||
|
* This create a sort of journal. See #27707
|
||||||
|
*/
|
||||||
|
public static final String EVENTS_PROPERTY = "events";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It contains the basic information for the context
|
||||||
|
*/
|
||||||
|
public static final String INFORMATION_PROPERTY = "information";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This information is provided to allowed user only (by role)
|
||||||
|
* The symmetric key for the context
|
||||||
|
*/
|
||||||
|
public static final String KEY_PROPERTY = "key";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* ...
|
||||||
|
* "availableAt" : [
|
||||||
|
* "https://i-marine.d4science.org/group/alienandinvasivespecies",
|
||||||
|
* "https://services.d4science.org/group/alienandinvasivespecies"
|
||||||
|
* ]
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* For non VRE context this field could be null or could have multiple value.
|
||||||
|
* For VRE it is normally one value only (but some exception could exists)
|
||||||
|
*/
|
||||||
|
public static final String AVAILABLE_AT_PROPERTY = "availableAt";
|
||||||
|
|
||||||
|
protected SortedSet<Event> events;
|
||||||
|
protected BasicInformation information;
|
||||||
|
protected String key;
|
||||||
|
protected List<String> availableAt;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public GCubeContext(Context c) {
|
||||||
|
this.uuid = c.getID();
|
||||||
|
this.metadata = c.getMetadata();
|
||||||
|
|
||||||
|
this.name = c.getName();
|
||||||
|
|
||||||
|
this.parent = c.getParent();
|
||||||
|
this.children = c.getChildren();
|
||||||
|
|
||||||
|
this.state = c.getState();
|
||||||
|
|
||||||
|
this.additionalProperties = new HashMap<>();
|
||||||
|
Map<String, Object> ap = c.getAdditionalProperties();
|
||||||
|
for(String key : ap.keySet()) {
|
||||||
|
Object obj = ap.get(key);
|
||||||
|
switch (key) {
|
||||||
|
case EVENTS_PROPERTY:
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
SortedSet<Event> events = (SortedSet<Event>) obj;
|
||||||
|
setEvents(events);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_PROPERTY:
|
||||||
|
setKey((String) obj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INFORMATION_PROPERTY:
|
||||||
|
setInformation((BasicInformation) obj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AVAILABLE_AT_PROPERTY:
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> availableAt = (List<String>) obj;
|
||||||
|
setAvailableAt(availableAt);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
this.additionalProperties.put(key, obj);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GCubeContext() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GCubeContext(UUID uuid) {
|
||||||
|
this(null, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GCubeContext(String name) {
|
||||||
|
this(name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GCubeContext(String name, UUID uuid) {
|
||||||
|
super(name, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonGetter(EVENTS_PROPERTY)
|
||||||
|
public SortedSet<Event> getEvents() {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSetter(EVENTS_PROPERTY)
|
||||||
|
public void setEvents(SortedSet<Event> events) {
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public void addEvent(Event event) {
|
||||||
|
if(this.events==null) {
|
||||||
|
this.events = new TreeSet<>();
|
||||||
|
}
|
||||||
|
this.events.add(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonGetter(INFORMATION_PROPERTY)
|
||||||
|
public BasicInformation getInformation() {
|
||||||
|
return information;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSetter(INFORMATION_PROPERTY)
|
||||||
|
public void setInformation(BasicInformation information) {
|
||||||
|
this.information = information;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonGetter(KEY_PROPERTY)
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSetter(KEY_PROPERTY)
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonGetter(AVAILABLE_AT_PROPERTY)
|
||||||
|
public List<String> getAvailableAt() {
|
||||||
|
return availableAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSetter(AVAILABLE_AT_PROPERTY)
|
||||||
|
public void setAvailableAt(List<String> availableAt) {
|
||||||
|
this.availableAt = availableAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package org.gcube.resourcemanagement.contexts.impl.properties;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public class BasicInformation {
|
||||||
|
|
||||||
|
protected String description;
|
||||||
|
protected Set<String> designers;
|
||||||
|
protected Set<String> managers;
|
||||||
|
protected Date from;
|
||||||
|
/**
|
||||||
|
* Can be null. It means no end date defined.
|
||||||
|
*/
|
||||||
|
protected Date to;
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getDesigners() {
|
||||||
|
return designers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesigners(Set<String> designers) {
|
||||||
|
this.designers = designers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDesigner(String designer) {
|
||||||
|
if(this.designers==null) {
|
||||||
|
this.designers = new HashSet<>();
|
||||||
|
}
|
||||||
|
this.designers.add(designer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getManagers() {
|
||||||
|
return managers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManagers(Set<String> managers) {
|
||||||
|
this.managers = managers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addManager(String manager) {
|
||||||
|
if(this.managers==null) {
|
||||||
|
this.managers = new HashSet<>();
|
||||||
|
}
|
||||||
|
this.managers.add(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
|
||||||
|
public Date getFrom() {
|
||||||
|
return from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFrom(Date from) {
|
||||||
|
this.from = from;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
|
||||||
|
public Date getTo() {
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTo(Date to) {
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,19 +4,27 @@
|
||||||
package org.gcube.resourcemanagement.model.reference.entities.facets;
|
package org.gcube.resourcemanagement.model.reference.entities.facets;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
|
import org.gcube.informationsystem.contexts.impl.entities.ContextImpl;
|
||||||
|
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||||
|
import org.gcube.informationsystem.model.impl.properties.EventImpl;
|
||||||
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
||||||
import org.gcube.informationsystem.model.reference.ModelElement;
|
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.Event;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
|
import org.gcube.resourcemanagement.contexts.impl.entities.GCubeContext;
|
||||||
|
import org.gcube.resourcemanagement.contexts.impl.properties.BasicInformation;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
|
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
|
||||||
|
@ -109,4 +117,44 @@ public class PolymorphismTest {
|
||||||
public void testUnmarshalling() throws JsonParseException, JsonMappingException, IOException {
|
public void testUnmarshalling() throws JsonParseException, JsonMappingException, IOException {
|
||||||
ElementMapper.unmarshal(Activates.class, AUX);
|
ElementMapper.unmarshal(Activates.class, AUX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGCubeContextImplementation() throws Exception {
|
||||||
|
Context c = new ContextImpl("test");
|
||||||
|
c.setID(UUID.randomUUID());
|
||||||
|
c.setState("created");
|
||||||
|
logger.debug(c.toString());
|
||||||
|
|
||||||
|
GCubeContext gcubeContext = new GCubeContext(c);
|
||||||
|
Event created = new EventImpl();
|
||||||
|
created.setWhat(c.getState());
|
||||||
|
created.setWho("luca.frosini");
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.add(Calendar.MINUTE, -1);
|
||||||
|
created.setWhen(cal.getTime());
|
||||||
|
gcubeContext.addEvent(created);
|
||||||
|
|
||||||
|
|
||||||
|
gcubeContext.setState("pending");
|
||||||
|
Event pending = new EventImpl();
|
||||||
|
pending.setWhat(gcubeContext.getState());
|
||||||
|
pending.setWho("luca.frosini");
|
||||||
|
pending.setWhen(Calendar.getInstance().getTime());
|
||||||
|
pending.setAdditionalProperty("report", "This is a report");
|
||||||
|
|
||||||
|
|
||||||
|
BasicInformation info = new BasicInformation();
|
||||||
|
info.addDesigner("luca.frosini");
|
||||||
|
info.addManager("luca.frosini");
|
||||||
|
info.addManager("pasquale.pagano");
|
||||||
|
Calendar from = Calendar.getInstance();
|
||||||
|
info.setFrom(from.getTime());
|
||||||
|
info.setDescription("This is a test VRE");
|
||||||
|
gcubeContext.setInformation(info);
|
||||||
|
|
||||||
|
gcubeContext.addEvent(pending);
|
||||||
|
logger.debug(gcubeContext.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue