Implementing update. Removed uneeded interface

This commit is contained in:
Luca Frosini 2021-01-13 21:52:09 +01:00
parent c0fb892279
commit 0606d291a4
9 changed files with 1015 additions and 787 deletions

View File

@ -11,7 +11,7 @@ import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagementImpl;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.utils.discovery.SchemaAction;
import org.slf4j.Logger;
@ -28,7 +28,7 @@ public class SchemaActionImpl implements SchemaAction {
public <R extends RelationElement<? extends EntityElement,? extends EntityElement>> void manageRelationClass(Class<R> r)
throws Exception {
try {
SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(TypeMapper.getType(r));
String json = TypeMapper.serializeType(r);
logger.trace(json);
@ -50,7 +50,7 @@ public class SchemaActionImpl implements SchemaAction {
@Override
public <E extends EntityElement> void manageEntityClass(Class<E> e) throws Exception {
try {
SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(TypeMapper.getType(e));
String json = TypeMapper.serializeType(e);
logger.trace(json);
@ -72,13 +72,13 @@ public class SchemaActionImpl implements SchemaAction {
@Override
public <P extends PropertyElement> void managePropertyClass(Class<P> p) throws Exception {
try {
SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(TypeMapper.getType(p));
String json = TypeMapper.serializeType(p);
logger.trace(json);
if(Property.class.isAssignableFrom(p)) {
if(p.equals(Property.class) || p.equals(Header.class) ) {
((SchemaManagementImpl) schemaManagement).setSkipTypeDefinitionCreation(true);
((SchemaManagement) schemaManagement).setSkipTypeDefinitionCreation(true);
}
schemaManagement.create(json, AccessType.PROPERTY);
}else {

View File

@ -35,7 +35,6 @@ import org.gcube.informationsystem.resourceregistry.instances.model.entities.Res
import org.gcube.informationsystem.resourceregistry.query.Query;
import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagementImpl;
import com.orientechnologies.orient.core.record.ODirection;
import com.tinkerpop.blueprints.Direction;
@ -157,8 +156,9 @@ public class Access extends BaseRest {
*/
CalledMethodProvider.instance.set("readType");
SchemaManagement schemaManagement = new SchemaManagementImpl();
return schemaManagement.read(type, polymorphic);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(type);
return schemaManagement.read(polymorphic);
}
/*

View File

@ -24,7 +24,6 @@ import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagementImpl;
import org.gcube.informationsystem.types.TypeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -92,8 +91,8 @@ public class SchemaManager {
throw new ResourceRegistryException(error);
}
SchemaManagement schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(type);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(type);
String ret = schemaManagement.create(json, accessType);
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
.build();
@ -113,8 +112,9 @@ public class SchemaManager {
logger.info("Requested Schema for type {}", type);
// setRESTCalledMethod(HTTPMETHOD.GET, type, polymorphic);
CalledMethodProvider.instance.set("readType");
SchemaManagement schemaManagement = new SchemaManagementImpl();
return schemaManagement.read(type, polymorphic);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(type);
return schemaManagement.read(polymorphic);
}
}

View File

@ -1,24 +1,826 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.types;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.activation.UnsupportedDataTypeException;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaCreationException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
import org.gcube.informationsystem.resourceregistry.types.entities.FacetTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.entities.ResourceTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.properties.PropertyTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.relations.ConsistsOfTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.relations.IsRelatedToTypeDefinitionManagement;
import org.gcube.informationsystem.types.OrientDBType;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
import org.gcube.informationsystem.types.reference.relations.RelationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.exception.OSchemaException;
import com.orientechnologies.orient.core.metadata.OMetadata;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.OElement;
/**
* @author Luca Frosini (ISTI - CNR)
*
* For JSON schema see http://orientdb.com/docs/last/OrientDB-REST.html#class
*
*/
public interface SchemaManagement {
public class SchemaManagement {
public String create(String json, AccessType accessType) throws SchemaAlreadyPresentException, SchemaException;
private static Logger logger = LoggerFactory.getLogger(SchemaManagement.class);
public String read(String type, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException;
protected String typeName;
public String update(String json, AccessType accessType) throws SchemaNotFoundException, SchemaException;
protected boolean skipVersionCheckOnUpdate;
public boolean isSkipVersionCheckOnUpdate() {
return skipVersionCheckOnUpdate;
}
public void setSkipVersionCheckOnUpdate(boolean skipVersionCheckOnUpdate) {
this.skipVersionCheckOnUpdate = skipVersionCheckOnUpdate;
}
public String delete(String type, AccessType accessType) throws SchemaNotFoundException;
protected boolean skipTypeDefinitionCreation;
public boolean isSkipTypeDefinitionCreation() {
return skipTypeDefinitionCreation;
}
public void setSkipTypeDefinitionCreation(boolean skipTypeDefinitionCreation) {
this.skipTypeDefinitionCreation = skipTypeDefinitionCreation;
}
public SchemaManagement() {
this.skipTypeDefinitionCreation = false;
}
protected OClass getOClass(OSchema oSchema, String typeName) throws SchemaException {
return oSchema.getClass(typeName);
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
/*
private static TypeDefinition getOClassTypeDefinition(OClass oClass) throws SchemaException {
try {
ODocument oDocument = ((OClassImpl) oClass).toStream();
String json = oDocument.toJSON();
ObjectMapper mapper = new ObjectMapper();
ObjectNode node = (ObjectNode) mapper.readTree(json);
if(oClass.isSubClassOf(Property.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, PropertyTypeDefinition.NAME);
} else if(oClass.isSubClassOf(Resource.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, ResourceTypeDefinition.NAME);
} else if(oClass.isSubClassOf(Facet.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, FacetTypeDefinition.NAME);
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, IsRelatedToTypeDefinition.NAME);
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, ConsistsOfTypeDefinition.NAME);
}
if(!oClass.isSubClassOf(Resource.NAME)) {
ArrayNode arrayNode = (ArrayNode) node.get(EntityTypeDefinition.PROPERTIES_PROPERTY);
Iterator<JsonNode> iterator = arrayNode.iterator();
while(iterator.hasNext()) {
ObjectNode propertyNode = (ObjectNode) iterator.next();
propertyNode.put(ISManageable.CLASS_PROPERTY, PropertyDefinition.NAME);
}
}
String managedJson = mapper.writeValueAsString(node);
logger.trace("{} -> {}", json, managedJson);
return TypeBinder.deserializeTypeDefinition(managedJson);
} catch(Exception e) {
throw new SchemaException(e);
}
}
*/
private static ElementManagement<? extends OElement> getTypeManagement(AccessType accessType, String name) {
ElementManagement<? extends OElement> erManagement = null;
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
((PropertyTypeDefinitionManagement) erManagement).setName(name);
break;
case RESOURCE:
erManagement = new ResourceTypeDefinitionManagement();
((ResourceTypeDefinitionManagement) erManagement).setName(name);
break;
case FACET:
erManagement = new FacetTypeDefinitionManagement();
((FacetTypeDefinitionManagement) erManagement).setName(name);
break;
case IS_RELATED_TO:
erManagement = new IsRelatedToTypeDefinitionManagement();
((IsRelatedToTypeDefinitionManagement) erManagement).setName(name);
break;
case CONSISTS_OF:
erManagement = new ConsistsOfTypeDefinitionManagement();
((ConsistsOfTypeDefinitionManagement) erManagement).setName(name);
break;
default:
break;
}
return erManagement;
}
private static ElementManagement<? extends OElement> getTypeManagement(OClass oClass) {
ElementManagement<? extends OElement> erManagement = null;
if(oClass.isSubClassOf(Property.NAME)) {
erManagement = new PropertyTypeDefinitionManagement();
((PropertyTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(Resource.NAME)) {
erManagement = new ResourceTypeDefinitionManagement();
((ResourceTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(Facet.NAME)) {
erManagement = new FacetTypeDefinitionManagement();
((FacetTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
erManagement = new IsRelatedToTypeDefinitionManagement();
((IsRelatedToTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
erManagement = new ConsistsOfTypeDefinitionManagement();
((ConsistsOfTypeDefinitionManagement) erManagement).setName(oClass.getName());
}
return erManagement;
}
private String getTypeAsString(ElementManagement<? extends OElement> erManagement) throws SchemaException {
try {
if(erManagement!=null) {
String ret = erManagement.read();
return ret;
}else {
throw new SchemaException("You can only request schema of IS Model types and their specilization");
}
} catch(Exception e) {
throw new SchemaException(e);
}
}
private String getTypeAsString(OClass oClass) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(oClass);
return getTypeAsString(erManagement);
} catch(Exception e) {
throw new SchemaException(e);
}
}
private Type getType(ElementManagement<? extends OElement> erManagement) throws SchemaException {
try {
String typeString = getTypeAsString(erManagement);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
/*
private String getTypeAsString(AccessType accessType, String name) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType, name);
return getTypeAsString(erManagement);
} catch(Exception e) {
throw new SchemaException(e);
}
}
/*
private Type getType(AccessType accessType, String name) throws SchemaException {
try {
String typeString = getTypeAsString(accessType, name);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
*/
private Type getType(OClass oClass) throws SchemaException {
try {
String typeString = getTypeAsString(oClass);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
protected List<OClass> getSuperclassesAndCheckCompliancy(ODatabaseDocument oDatabaseDocument,
Type type, String baseType) throws SchemaException, SchemaNotFoundException {
Set<String> superClasses = type.getSuperClasses();
if(baseType != null) {
if(superClasses == null || superClasses.size() == 0) {
throw new RuntimeException(
String.format("No Superclass found in schema %s. The Type Definition must extend %s",
type, baseType));
}
}
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
List<OClass> oSuperclasses = new ArrayList<>();
for(String superClass : superClasses) {
OClass oSuperClass = getOClass(oSchema, superClass);
if(oSuperClass == null) {
throw new SchemaNotFoundException("Superclass " + superClass + " does not exists");
}
if(baseType != null) {
if(type.getName().compareTo(baseType) != 0) {
if(!oSuperClass.isSubClassOf(baseType)) {
throw new RuntimeException(superClass + " is not a subsclass of " + baseType
+ ". Each Superclass MUST be a subclass of " + baseType);
}
}
}
oSuperclasses.add(oSuperClass);
}
return oSuperclasses;
}
private static Set<String> baseElementTypes;
public static Set<String> typeList;
static {
baseElementTypes = new HashSet<String>();
baseElementTypes.add(PropertyElement.NAME);
baseElementTypes.add(EntityElement.NAME);
baseElementTypes.add(RelationElement.NAME);
typeList = new HashSet<String>();
typeList.add(PropertyType.NAME);
typeList.add(LinkedEntity.NAME);
typeList.add(EntityType.NAME);
typeList.add(ResourceType.NAME);
typeList.add(FacetType.NAME);
typeList.add(RelationType.NAME);
typeList.add(IsRelatedToType.NAME);
typeList.add(ConsistsOfType.NAME);
}
protected void registerTypeSchema(Type type, AccessType baseElementAccessType)
throws SchemaAlreadyPresentException, SchemaException {
ODatabaseDocument oDatabaseDocument = null;
try {
if(typeName.compareTo(type.getName()) != 0) {
String error = String.format(
"Provided type name path argument %s does not match with the type name in the definition %S. Please be coherent.",
typeName, type.getName());
throw new SchemaCreationException(error);
}
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
OClass oClass = null;
if(EntityElement.class.isAssignableFrom(baseElementAccessType.getTypeClass())) {
oClass = oDatabaseDocument.createVertexClass(type.getName());
} else if(RelationElement.class.isAssignableFrom(baseElementAccessType.getTypeClass())) {
oClass = oDatabaseDocument.createEdgeClass(type.getName());
} else if(PropertyElement.class.isAssignableFrom(baseElementAccessType.getTypeClass())) {
oClass = oSchema.createClass(type.getName());
} else {
String error = String.format("Allowed superclass are %s, %s, %s, or any subclasses of them.",
Entity.NAME, Relation.NAME, Property.NAME);
throw new SchemaCreationException(error);
}
try {
String description = type.getDescription();
if(description != null && description.compareTo("") != 0) {
try {
oClass.setDescription(description);
} catch(Exception e) {
logger.warn(
"Unable to set description. This is an orient bug. See https://github.com/orientechnologies/orientdb/issues/7065");
}
}
try {
// oClass.setAbstract(false); // Used to allow to persist Schema in Context
// Management
oClass.setAbstract(type.isAbstract());
} catch(Exception e) {
logger.error(
"Unable to set the Vertex Type {} as abstract. This is an OrientDB <= 2.2.12 bug. The Type will be created as it is not abstract.",
type.getName());
}
if(!baseElementTypes.contains(type.getName())) {
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(oDatabaseDocument, type,
baseElementAccessType.getName());
oClass.setSuperClasses(oSuperclasses);
}
if(!(type instanceof ResourceType)) {
// A Resource cannot contains any properties.
Set<PropertyDefinition> propertyDefinitions = type.getProperties();
if(propertyDefinitions!=null) {
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
OType oType = OType.getById(propertyDefinition.getType().byteValue());
/*
* Types update is not allowed,
* hence bug https://github.com/orientechnologies/orientdb/issues/7354 cannot occur
* Excluding the check from types used for type definition
*
*/
if(!typeList.contains(type.getName())) {
switch(oType) {
case EMBEDDEDLIST:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
case EMBEDDEDSET:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
default:
break;
}
}
OProperty op = oClass.createProperty(propertyDefinition.getName(), oType);
op.setDescription(propertyDefinition.getDescription());
/*
* Mandatory and notNull does not work in distributed mode: so that on Type
* declaration they are forced to false
* ovp.setMandatory(property.isMandatory());
* ovp.setNotNull(property.isNotnull()); This information are persisted in
* Management Context
*/
op.setMandatory(false);
op.setNotNull(false);
op.setReadonly(propertyDefinition.isReadonly());
op.setRegexp(propertyDefinition.getRegexp());
if(propertyDefinition.getLinkedClass() != null) {
OClass linkedClass = getOClass(oSchema, propertyDefinition.getLinkedClass());
if(linkedClass == null) {
logger.trace("class {} not found in schema", propertyDefinition.getLinkedClass());
throw new Exception(
"class " + propertyDefinition.getLinkedClass() + " not found in schema");
}
if(linkedClass.isEdgeType() || linkedClass.isVertexType()) {
throw new Exception("A Property Field cannot be an Entity or a Relation");
}
op.setLinkedClass(linkedClass);
} else if(propertyDefinition.getLinkedType() != null) {
op.setLinkedType(OType.getById(propertyDefinition.getLinkedType().byteValue()));
}
}
}
}
oDatabaseDocument.commit();
logger.info("{} {} registered successfully", baseElementAccessType.getName(), type.getName());
} catch(Exception e) {
oSchema.dropClass(type.getName());
throw e;
}
} catch(OSchemaException ex) {
if(ex.getMessage().contains("already exists")) {
throw new SchemaAlreadyPresentException(ex);
}
throw new SchemaException(ex);
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaCreationException(ex);
} finally {
oDatabaseDocument.close();
}
}
private boolean superClassesMatch(Type actualTypeDefinition, Type newTypeDefinition) {
// Checking superclasses. Must be the same. If differs the operation will be aborted.
Set<String> actualSuperClasses = new HashSet<>(actualTypeDefinition.getSuperClasses());
Set<String> newSuperClasses = newTypeDefinition.getSuperClasses();
if(actualSuperClasses.size()!=newSuperClasses.size()) {
return false;
}
actualSuperClasses.removeAll(newSuperClasses);
if(actualSuperClasses.size()>0) {
return false;
}
actualSuperClasses = new HashSet<>(actualTypeDefinition.getSuperClasses());
newSuperClasses.removeAll(actualSuperClasses);
if(actualSuperClasses.size()>0) {
return false;
}
return true;
}
// TODO
protected void updateTypeSchema(Type actualTypeDefinition, Type newTypeDefinition, AccessType baseElementAccessType)
throws SchemaNotFoundException, SchemaException {
ODatabaseDocument oDatabaseDocument = null;
try {
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
OClass oClass = oSchema.getClass(typeName);
if(oClass == null) {
throw new SchemaNotFoundException(typeName + " does not Exists");
}
if(!superClassesMatch(actualTypeDefinition, newTypeDefinition)){
StringBuffer error = new StringBuffer();
error.append("The new type definition has a different set of superclasses. Actual version superclasses are: ");
error.append(actualTypeDefinition.getSuperClasses());
error.append(". New version superclasses are: ");
error.append(newTypeDefinition.getSuperClasses());
error.append(". This kind update is not supported for a type.");
throw new SchemaException(error.toString());
}
try {
String description = newTypeDefinition.getDescription();
if(description != null && description.compareTo("") != 0) {
try {
oClass.setDescription(description);
} catch(Exception e) {
logger.warn(
"Unable to set description. This is an orient bug. See https://github.com/orientechnologies/orientdb/issues/7065");
}
}
try {
// oClass.setAbstract(false); // Used to allow to persist Schema in Context
// Management
oClass.setAbstract(newTypeDefinition.isAbstract());
} catch(Exception e) {
logger.error(
"Unable to set the Vertex Type {} as abstract. This is an OrientDB <= 2.2.12 bug. The Type will be created as it is not abstract.",
newTypeDefinition.getName());
}
if(!(newTypeDefinition instanceof ResourceType)) {
// A Resource cannot contains any properties.
Set<PropertyDefinition> actualPropertyDefinitions = new HashSet<>(actualTypeDefinition.getProperties());
Map<String, PropertyDefinition> actualPropertyDefinitionMap = new HashMap<>(actualPropertyDefinitions.size());
for(PropertyDefinition actualPropertyDefinition : actualPropertyDefinitions) {
actualPropertyDefinitionMap.put(actualPropertyDefinition.getName(), actualPropertyDefinition);
}
Set<PropertyDefinition> newPropertyDefinitions = newTypeDefinition.getProperties();
if(newPropertyDefinitions!=null) {
for(PropertyDefinition newPropertyDefinition : newPropertyDefinitions) {
if(newTypeDefinition.getName().compareTo(IdentifiableElement.HEADER_PROPERTY)==0 || newTypeDefinition.getName().compareTo(Relation.PROPAGATION_CONSTRAINT_PROPERTY)==0) {
continue;
}
if(newPropertyDefinition.equals(actualPropertyDefinitionMap.get(newPropertyDefinition.getName()))) {
// This property was not changed. Checking the next one.
continue;
}
OType oType = OType.getById(newPropertyDefinition.getType().byteValue());
/*
* Excluding EMBEDDEDLIST and EMBEDDEDSET
* to avoid bug https://github.com/orientechnologies/orientdb/issues/7354
*
*/
if(!typeList.contains(newTypeDefinition.getName())) {
switch(oType) {
case EMBEDDEDLIST:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
case EMBEDDEDSET:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
default:
break;
}
}
OProperty op = oClass.createProperty(newPropertyDefinition.getName(), oType);
op.setDescription(newPropertyDefinition.getDescription());
/*
* Mandatory and notNull does not work in distributed mode: so that on Type
* declaration they are forced to false
* ovp.setMandatory(property.isMandatory());
* ovp.setNotNull(property.isNotnull()); This information are persisted in
* Management Context
*/
op.setMandatory(false);
op.setNotNull(false);
op.setReadonly(newPropertyDefinition.isReadonly());
op.setRegexp(newPropertyDefinition.getRegexp());
if(newPropertyDefinition.getLinkedClass() != null) {
OClass linkedClass = getOClass(oSchema, newPropertyDefinition.getLinkedClass());
if(linkedClass == null) {
logger.trace("class {} not found in schema", newPropertyDefinition.getLinkedClass());
throw new Exception(
"class " + newPropertyDefinition.getLinkedClass() + " not found in schema");
}
if(linkedClass.isEdgeType() || linkedClass.isVertexType()) {
throw new Exception("A Property Field cannot be an Entity or a Relation");
}
op.setLinkedClass(linkedClass);
} else if(newPropertyDefinition.getLinkedType() != null) {
op.setLinkedType(OType.getById(newPropertyDefinition.getLinkedType().byteValue()));
}
}
}
actualPropertyDefinitions.removeAll(newPropertyDefinitions);
// Removing old properties which are no more present in the new type definition
for(PropertyDefinition propertyDefinitionToRemove : actualPropertyDefinitions) {
oClass.dropProperty(propertyDefinitionToRemove.getName());
}
}
oDatabaseDocument.commit();
logger.info("{} {} updated successfully", baseElementAccessType.getName(), newTypeDefinition.getName());
} catch(Exception e) {
oSchema.dropClass(newTypeDefinition.getName());
throw e;
}
} catch(SchemaNotFoundException e) {
throw e;
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaException(ex);
} finally {
oDatabaseDocument.close();
}
}
protected String getSchema(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
ODatabaseDocument oDatabaseDocument = null;
try {
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
OClass baseOClass = oSchema.getClass(typeName);
if(baseOClass == null) {
throw new SchemaNotFoundException(typeName + " does not Exists");
}
List<Type> typeDefinitions = new ArrayList<>();
typeDefinitions.add(getType(baseOClass));
if(includeSubtypes) {
Collection<OClass> subClasses = baseOClass.getAllSubclasses();
for(OClass oClass : subClasses) {
typeDefinitions.add(getType(oClass));
}
}
return TypeMapper.serializeTypeDefinitions(typeDefinitions);
} catch(SchemaException e) {
throw e;
} catch(SchemaNotFoundException e) {
throw e;
} catch(Exception e) {
throw new SchemaException(e);
} finally {
if(oDatabaseDocument != null) {
oDatabaseDocument.close();
}
}
}
public String create(String jsonSchema, AccessType accessType) throws SchemaAlreadyPresentException, SchemaException {
Type typeDefinition = null;
try {
try {
typeDefinition = TypeMapper.deserializeTypeDefinition(jsonSchema);
logger.info("Trying to register {} {} : {}", accessType.getName(), typeDefinition.getName(),
jsonSchema);
} catch(Exception e) {
logger.error("Error while trying to register {} {}", accessType.getName(), jsonSchema);
throw new SchemaCreationException(e);
}
registerTypeSchema(typeDefinition, accessType);
ElementManagement<? extends OElement> erManagement = null;
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
break;
case RESOURCE:
erManagement = new ResourceTypeDefinitionManagement();
break;
case FACET:
erManagement = new FacetTypeDefinitionManagement();
break;
case IS_RELATED_TO:
erManagement = new IsRelatedToTypeDefinitionManagement();
break;
case CONSISTS_OF:
erManagement = new ConsistsOfTypeDefinitionManagement();
break;
default:
break;
}
String ret = null;
if(erManagement!=null && !skipTypeDefinitionCreation) {
erManagement.setJson(jsonSchema);
ret = erManagement.create();
}else {
ret = TypeMapper.serializeTypeDefinition(typeDefinition);
}
return ret;
} catch(SchemaAlreadyPresentException e) {
throw e;
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaCreationException(ex);
}
}
public String read(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
return getSchema(includeSubtypes);
}
private boolean typeCanBeUpdated() throws SchemaException {
for(AccessType accessType : AccessType.values()) {
if(accessType.getName().compareTo(typeName)==0) {
return false;
}
}
return true;
}
public String update(String jsonSchema, AccessType accessType)
throws SchemaNotFoundException, SchemaException {
try {
Type newTypeDefinition = null;
try {
newTypeDefinition = TypeMapper.deserializeTypeDefinition(jsonSchema);
logger.info("Trying to update {} {} : {}", accessType.getName(), newTypeDefinition.getName(),
jsonSchema);
} catch(Exception e) {
logger.error("Error while trying to deserialise provided type definition {}", jsonSchema);
throw new SchemaCreationException(e);
}
if(typeName.compareTo(newTypeDefinition.getName()) != 0) {
String error = String.format(
"Provided type name path argument %s does not match with the type name in the definition %S. Please be coherent.",
typeName, newTypeDefinition.getName());
throw new SchemaCreationException(error);
}
if(!typeCanBeUpdated()) {
throw new SchemaException(typeName + " is a base type. Cannot update the definition of base types.");
}
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType, newTypeDefinition.getName());
Type actualTypeDefinition = getType(erManagement);
if(!skipVersionCheckOnUpdate) {
if(newTypeDefinition.getVersion().compareTo(actualTypeDefinition.getVersion())<=0) {
throw new SchemaAlreadyPresentException("The type " + newTypeDefinition.getName() +
" exists and the existing version (.i.e " + actualTypeDefinition.getVersion().toString() +
") is greater of equal to the one provided for update (i.e. " + newTypeDefinition.getVersion() + ")");
}
}
updateTypeSchema(actualTypeDefinition, newTypeDefinition, accessType);
String ret = null;
if(erManagement!=null) {
erManagement.setJson(jsonSchema);
ret = erManagement.update();
}else {
ret = TypeMapper.serializeTypeDefinition(newTypeDefinition);
}
return ret;
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaCreationException(ex);
}
}
protected boolean delete(AccessType accessType) throws SchemaException, SchemaNotFoundException{
ODatabaseDocument oDatabaseDocument = null;
try {
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
oSchema.dropClass(typeName);
oDatabaseDocument.commit();
return true;
} catch(SchemaException e) {
throw e;
} catch(SchemaNotFoundException e) {
throw e;
} catch(Exception e) {
throw new SchemaException(e);
} finally {
if(oDatabaseDocument != null) {
oDatabaseDocument.close();
}
}
}
}

View File

@ -1,733 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.types;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.activation.UnsupportedDataTypeException;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaCreationException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
import org.gcube.informationsystem.resourceregistry.types.entities.FacetTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.entities.ResourceTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.properties.PropertyTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.relations.ConsistsOfTypeDefinitionManagement;
import org.gcube.informationsystem.resourceregistry.types.relations.IsRelatedToTypeDefinitionManagement;
import org.gcube.informationsystem.types.OrientDBType;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
import org.gcube.informationsystem.types.reference.relations.RelationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.exception.OSchemaException;
import com.orientechnologies.orient.core.metadata.OMetadata;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.OElement;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class SchemaManagementImpl implements SchemaManagement {
private static Logger logger = LoggerFactory.getLogger(SchemaManagementImpl.class);
protected String typeName;
protected boolean skipTypeDefinitionCreation;
public boolean isSkipTypeDefinitionCreation() {
return skipTypeDefinitionCreation;
}
public void setSkipTypeDefinitionCreation(boolean skipTypeDefinitionCreation) {
this.skipTypeDefinitionCreation = skipTypeDefinitionCreation;
}
public SchemaManagementImpl() {
this.skipTypeDefinitionCreation = false;
}
protected OClass getOClass(OSchema oSchema, String typeName) throws SchemaException {
return oSchema.getClass(typeName);
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
/*
private static TypeDefinition getOClassTypeDefinition(OClass oClass) throws SchemaException {
try {
ODocument oDocument = ((OClassImpl) oClass).toStream();
String json = oDocument.toJSON();
ObjectMapper mapper = new ObjectMapper();
ObjectNode node = (ObjectNode) mapper.readTree(json);
if(oClass.isSubClassOf(Property.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, PropertyTypeDefinition.NAME);
} else if(oClass.isSubClassOf(Resource.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, ResourceTypeDefinition.NAME);
} else if(oClass.isSubClassOf(Facet.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, FacetTypeDefinition.NAME);
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, IsRelatedToTypeDefinition.NAME);
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, ConsistsOfTypeDefinition.NAME);
}
if(!oClass.isSubClassOf(Resource.NAME)) {
ArrayNode arrayNode = (ArrayNode) node.get(EntityTypeDefinition.PROPERTIES_PROPERTY);
Iterator<JsonNode> iterator = arrayNode.iterator();
while(iterator.hasNext()) {
ObjectNode propertyNode = (ObjectNode) iterator.next();
propertyNode.put(ISManageable.CLASS_PROPERTY, PropertyDefinition.NAME);
}
}
String managedJson = mapper.writeValueAsString(node);
logger.trace("{} -> {}", json, managedJson);
return TypeBinder.deserializeTypeDefinition(managedJson);
} catch(Exception e) {
throw new SchemaException(e);
}
}
*/
private static ElementManagement<? extends OElement> getTypeManagement(AccessType accessType, String name) {
ElementManagement<? extends OElement> erManagement = null;
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
((PropertyTypeDefinitionManagement) erManagement).setName(name);
break;
case RESOURCE:
erManagement = new ResourceTypeDefinitionManagement();
((ResourceTypeDefinitionManagement) erManagement).setName(name);
break;
case FACET:
erManagement = new FacetTypeDefinitionManagement();
((FacetTypeDefinitionManagement) erManagement).setName(name);
break;
case IS_RELATED_TO:
erManagement = new IsRelatedToTypeDefinitionManagement();
((IsRelatedToTypeDefinitionManagement) erManagement).setName(name);
break;
case CONSISTS_OF:
erManagement = new ConsistsOfTypeDefinitionManagement();
((ConsistsOfTypeDefinitionManagement) erManagement).setName(name);
break;
default:
break;
}
return erManagement;
}
private static ElementManagement<? extends OElement> getTypeManagement(OClass oClass) {
ElementManagement<? extends OElement> erManagement = null;
if(oClass.isSubClassOf(Property.NAME)) {
erManagement = new PropertyTypeDefinitionManagement();
((PropertyTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(Resource.NAME)) {
erManagement = new ResourceTypeDefinitionManagement();
((ResourceTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(Facet.NAME)) {
erManagement = new FacetTypeDefinitionManagement();
((FacetTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
erManagement = new IsRelatedToTypeDefinitionManagement();
((IsRelatedToTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
erManagement = new ConsistsOfTypeDefinitionManagement();
((ConsistsOfTypeDefinitionManagement) erManagement).setName(oClass.getName());
}
return erManagement;
}
private String getTypeAsString(ElementManagement<? extends OElement> erManagement) throws SchemaException {
try {
if(erManagement!=null) {
String ret = erManagement.read();
return ret;
}else {
throw new SchemaException("You can only request schema of IS Model types and their specilization");
}
} catch(Exception e) {
throw new SchemaException(e);
}
}
private String getTypeAsString(OClass oClass) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(oClass);
return getTypeAsString(erManagement);
} catch(Exception e) {
throw new SchemaException(e);
}
}
private Type getType(ElementManagement<? extends OElement> erManagement) throws SchemaException {
try {
String typeString = getTypeAsString(erManagement);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
/*
private String getTypeAsString(AccessType accessType, String name) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType, name);
return getTypeAsString(erManagement);
} catch(Exception e) {
throw new SchemaException(e);
}
}
/*
private Type getType(AccessType accessType, String name) throws SchemaException {
try {
String typeString = getTypeAsString(accessType, name);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
*/
private Type getType(OClass oClass) throws SchemaException {
try {
String typeString = getTypeAsString(oClass);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
protected List<OClass> getSuperclassesAndCheckCompliancy(ODatabaseDocument oDatabaseDocument,
Type type, String baseType) throws SchemaException, SchemaNotFoundException {
Set<String> superClasses = type.getSuperClasses();
if(baseType != null) {
if(superClasses == null || superClasses.size() == 0) {
throw new RuntimeException(
String.format("No Superclass found in schema %s. The Type Definition must extend %s",
type, baseType));
}
}
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
List<OClass> oSuperclasses = new ArrayList<>();
for(String superClass : superClasses) {
OClass oSuperClass = getOClass(oSchema, superClass);
if(oSuperClass == null) {
throw new SchemaNotFoundException("Superclass " + superClass + " does not exists");
}
if(baseType != null) {
if(type.getName().compareTo(baseType) != 0) {
if(!oSuperClass.isSubClassOf(baseType)) {
throw new RuntimeException(superClass + " is not a subsclass of " + baseType
+ ". Each Superclass MUST be a subclass of " + baseType);
}
}
}
oSuperclasses.add(oSuperClass);
}
return oSuperclasses;
}
private static Set<String> baseElementTypes;
public static Set<String> typeList;
static {
baseElementTypes = new HashSet<String>();
baseElementTypes.add(PropertyElement.NAME);
baseElementTypes.add(EntityElement.NAME);
baseElementTypes.add(RelationElement.NAME);
typeList = new HashSet<String>();
typeList.add(PropertyType.NAME);
typeList.add(LinkedEntity.NAME);
typeList.add(EntityType.NAME);
typeList.add(ResourceType.NAME);
typeList.add(FacetType.NAME);
typeList.add(RelationType.NAME);
typeList.add(IsRelatedToType.NAME);
typeList.add(ConsistsOfType.NAME);
}
protected void registerTypeSchema(Type type, AccessType baseElementAccessType)
throws SchemaAlreadyPresentException, SchemaException {
ODatabaseDocument oDatabaseDocument = null;
try {
if(typeName.compareTo(type.getName()) != 0) {
String error = String.format(
"Provided type name path argument %s does not match with the type name in the definition %S. Please be coherent.",
typeName, type.getName());
throw new SchemaCreationException(error);
}
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
OClass oClass = null;
if(EntityElement.class.isAssignableFrom(baseElementAccessType.getTypeClass())) {
oClass = oDatabaseDocument.createVertexClass(type.getName());
} else if(RelationElement.class.isAssignableFrom(baseElementAccessType.getTypeClass())) {
oClass = oDatabaseDocument.createEdgeClass(type.getName());
} else if(PropertyElement.class.isAssignableFrom(baseElementAccessType.getTypeClass())) {
oClass = oSchema.createClass(type.getName());
} else {
String error = String.format("Allowed superclass are %s, %s, %s, or any subclasses of them.",
Entity.NAME, Relation.NAME, Property.NAME);
throw new SchemaCreationException(error);
}
try {
String description = type.getDescription();
if(description != null && description.compareTo("") != 0) {
try {
oClass.setDescription(description);
} catch(Exception e) {
logger.warn(
"Unable to set description. This is an orient bug. See https://github.com/orientechnologies/orientdb/issues/7065");
}
}
try {
// oClass.setAbstract(false); // Used to allow to persist Schema in Context
// Management
oClass.setAbstract(type.isAbstract());
} catch(Exception e) {
logger.error(
"Unable to set the Vertex Type {} as abstract. This is an OrientDB <= 2.2.12 bug. The Type will be created as it is not abstract.",
type.getName());
}
if(!baseElementTypes.contains(type.getName())) {
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(oDatabaseDocument, type,
baseElementAccessType.getName());
oClass.setSuperClasses(oSuperclasses);
}
if(!(type instanceof ResourceType)) {
// A Resource cannot contains any properties.
Set<PropertyDefinition> propertyDefinitions = type.getProperties();
if(propertyDefinitions!=null) {
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
OType oType = OType.getById(propertyDefinition.getType().byteValue());
/*
* Types update is not allowed,
* hence bug https://github.com/orientechnologies/orientdb/issues/7354 cannot occur
* Excluding the check from types used for type definition
*
*/
if(!typeList.contains(type.getName())) {
switch(oType) {
case EMBEDDEDLIST:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
case EMBEDDEDSET:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
default:
break;
}
}
OProperty op = oClass.createProperty(propertyDefinition.getName(), oType);
op.setDescription(propertyDefinition.getDescription());
/*
* Mandatory and notNull does not work in distributed mode: so that on Type
* declaration they are forced to false
* ovp.setMandatory(property.isMandatory());
* ovp.setNotNull(property.isNotnull()); This information are persisted in
* Management Context
*/
op.setMandatory(false);
op.setNotNull(false);
op.setReadonly(propertyDefinition.isReadonly());
op.setRegexp(propertyDefinition.getRegexp());
if(propertyDefinition.getLinkedClass() != null) {
OClass linkedClass = getOClass(oSchema, propertyDefinition.getLinkedClass());
if(linkedClass == null) {
logger.trace("class {} not found in schema", propertyDefinition.getLinkedClass());
throw new Exception(
"class " + propertyDefinition.getLinkedClass() + " not found in schema");
}
if(linkedClass.isEdgeType() || linkedClass.isVertexType()) {
throw new Exception("A Property Field cannot be an Entity or a Relation");
}
op.setLinkedClass(linkedClass);
} else if(propertyDefinition.getLinkedType() != null) {
op.setLinkedType(OType.getById(propertyDefinition.getLinkedType().byteValue()));
}
}
}
}
oDatabaseDocument.commit();
logger.info("{} {} registered successfully", baseElementAccessType.getName(), type.getName());
} catch(Exception e) {
oSchema.dropClass(type.getName());
throw e;
}
} catch(OSchemaException ex) {
if(ex.getMessage().contains("already exists")) {
throw new SchemaAlreadyPresentException(ex);
}
throw new SchemaException(ex);
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaCreationException(ex);
} finally {
oDatabaseDocument.close();
}
}
// TODO
protected void updateTypeSchema(Type type, AccessType baseElementAccessType)
throws SchemaNotFoundException, SchemaException {
ODatabaseDocument oDatabaseDocument = null;
try {
if(typeName.compareTo(type.getName()) != 0) {
String error = String.format(
"Provided type name path argument %s does not match with the type name in the definition %S. Please be coherent.",
typeName, type.getName());
throw new SchemaCreationException(error);
}
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
OClass oClass = oSchema.getClass(typeName);
if(oClass == null) {
throw new SchemaNotFoundException(typeName + " does not Exists");
}
try {
String description = type.getDescription();
if(description != null && description.compareTo("") != 0) {
try {
oClass.setDescription(description);
} catch(Exception e) {
logger.warn(
"Unable to set description. This is an orient bug. See https://github.com/orientechnologies/orientdb/issues/7065");
}
}
try {
// oClass.setAbstract(false); // Used to allow to persist Schema in Context
// Management
oClass.setAbstract(type.isAbstract());
} catch(Exception e) {
logger.error(
"Unable to set the Vertex Type {} as abstract. This is an OrientDB <= 2.2.12 bug. The Type will be created as it is not abstract.",
type.getName());
}
if(!baseElementTypes.contains(type.getName())) {
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(oDatabaseDocument, type,
baseElementAccessType.getName());
oClass.setSuperClasses(oSuperclasses);
}
// TODO check removed/added properties
if(!(type instanceof ResourceType)) {
// A Resource cannot contains any properties.
Set<PropertyDefinition> propertyDefinitions = type.getProperties();
if(propertyDefinitions!=null) {
for(PropertyDefinition propertyDefinition : propertyDefinitions) {
OType oType = OType.getById(propertyDefinition.getType().byteValue());
/*
* Types update is not allowed,
* hence bug https://github.com/orientechnologies/orientdb/issues/7354 cannot occur
* Excluding the check from types used for type definition
*
*/
if(!typeList.contains(type.getName())) {
switch(oType) {
case EMBEDDEDLIST:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYLIST
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
case EMBEDDEDSET:
throw new UnsupportedDataTypeException(OrientDBType.OType.PROPERTYSET
+ " support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
default:
break;
}
}
OProperty op = oClass.createProperty(propertyDefinition.getName(), oType);
op.setDescription(propertyDefinition.getDescription());
/*
* Mandatory and notNull does not work in distributed mode: so that on Type
* declaration they are forced to false
* ovp.setMandatory(property.isMandatory());
* ovp.setNotNull(property.isNotnull()); This information are persisted in
* Management Context
*/
op.setMandatory(false);
op.setNotNull(false);
op.setReadonly(propertyDefinition.isReadonly());
op.setRegexp(propertyDefinition.getRegexp());
if(propertyDefinition.getLinkedClass() != null) {
OClass linkedClass = getOClass(oSchema, propertyDefinition.getLinkedClass());
if(linkedClass == null) {
logger.trace("class {} not found in schema", propertyDefinition.getLinkedClass());
throw new Exception(
"class " + propertyDefinition.getLinkedClass() + " not found in schema");
}
if(linkedClass.isEdgeType() || linkedClass.isVertexType()) {
throw new Exception("A Property Field cannot be an Entity or a Relation");
}
op.setLinkedClass(linkedClass);
} else if(propertyDefinition.getLinkedType() != null) {
op.setLinkedType(OType.getById(propertyDefinition.getLinkedType().byteValue()));
}
}
}
}
oDatabaseDocument.commit();
logger.info("{} {} registered successfully", baseElementAccessType.getName(), type.getName());
} catch(Exception e) {
oSchema.dropClass(type.getName());
throw e;
}
} catch(SchemaNotFoundException e) {
throw e;
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaException(ex);
} finally {
oDatabaseDocument.close();
}
}
protected String getSchema(String typeName, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
ODatabaseDocument oDatabaseDocument = null;
try {
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
OMetadata oMetadata = oDatabaseDocument.getMetadata();
OSchema oSchema = oMetadata.getSchema();
OClass baseOClass = oSchema.getClass(typeName);
if(baseOClass == null) {
throw new SchemaNotFoundException(typeName + " does not Exists");
}
List<Type> typeDefinitions = new ArrayList<>();
typeDefinitions.add(getType(baseOClass));
if(includeSubtypes) {
Collection<OClass> subClasses = baseOClass.getAllSubclasses();
for(OClass oClass : subClasses) {
typeDefinitions.add(getType(oClass));
}
}
return TypeMapper.serializeTypeDefinitions(typeDefinitions);
} catch(SchemaException e) {
throw e;
} catch(SchemaNotFoundException e) {
throw e;
} catch(Exception e) {
throw new SchemaException(e);
} finally {
if(oDatabaseDocument != null) {
oDatabaseDocument.close();
}
}
}
@Override
public String create(String jsonSchema, AccessType accessType) throws SchemaAlreadyPresentException, SchemaException {
Type typeDefinition = null;
try {
try {
typeDefinition = TypeMapper.deserializeTypeDefinition(jsonSchema);
logger.info("Trying to register {} {} : {}", accessType.getName(), typeDefinition.getName(),
jsonSchema);
} catch(Exception e) {
logger.error("Error while trying to register {} {}", accessType.getName(), jsonSchema);
throw new SchemaCreationException(e);
}
registerTypeSchema(typeDefinition, accessType);
ElementManagement<? extends OElement> erManagement = null;
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
break;
case RESOURCE:
erManagement = new ResourceTypeDefinitionManagement();
break;
case FACET:
erManagement = new FacetTypeDefinitionManagement();
break;
case IS_RELATED_TO:
erManagement = new IsRelatedToTypeDefinitionManagement();
break;
case CONSISTS_OF:
erManagement = new ConsistsOfTypeDefinitionManagement();
break;
default:
break;
}
String ret = null;
if(erManagement!=null && !skipTypeDefinitionCreation) {
erManagement.setJson(jsonSchema);
ret = erManagement.create();
}else {
ret = TypeMapper.serializeTypeDefinition(typeDefinition);
}
return ret;
} catch(SchemaAlreadyPresentException e) {
throw e;
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaCreationException(ex);
}
}
@Override
public String read(String typeName, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
return getSchema(typeName, includeSubtypes);
}
@Override
public String update(String jsonSchema, AccessType accessType)
throws SchemaNotFoundException, SchemaException {
Type typeDefinition = null;
try {
try {
typeDefinition = TypeMapper.deserializeTypeDefinition(jsonSchema);
logger.info("Trying to update {} {} : {}", accessType.getName(), typeDefinition.getName(),
jsonSchema);
} catch(Exception e) {
logger.error("Error while trying to register {} {}", accessType.getName(), jsonSchema);
throw new SchemaCreationException(e);
}
setTypeName(typeDefinition.getName());
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType, typeDefinition.getName());
Type actualTypeDefinition = getType(erManagement);
if(typeDefinition.getVersion().compareTo(actualTypeDefinition.getVersion())<=0) {
throw new SchemaAlreadyPresentException("The type " + typeDefinition.getName() +
" exists and the existing version (.i.e " + actualTypeDefinition.getVersion().toString() +
") is greater of equal to the one provided for update (i.e. " + typeDefinition.getVersion() + ")");
}
updateTypeSchema(typeDefinition, accessType);
String ret = null;
if(erManagement!=null) {
erManagement.setJson(jsonSchema);
ret = erManagement.update();
}else {
ret = TypeMapper.serializeTypeDefinition(typeDefinition);
}
return ret;
} catch(SchemaException e) {
throw e;
} catch(Exception ex) {
throw new SchemaCreationException(ex);
}
}
@Override
public String delete(String typeName, AccessType accessType) throws SchemaNotFoundException {
throw new UnsupportedOperationException();
}
}

View File

@ -59,7 +59,9 @@ public class SchemaManagementImplTest {
@Test
public void getPropertyTypeSchema() throws Exception {
String json = new SchemaManagementImpl().read(Property.NAME, false);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(Property.NAME);
String json = schemaManagement.read(false);
logger.debug(json);
}
@ -82,7 +84,9 @@ public class SchemaManagementImplTest {
@Test
public void getFacetSchema() throws Exception {
String json = new SchemaManagementImpl().read(ContactFacet.NAME, false);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(ContactFacet.NAME);
String json = schemaManagement.read(false);
logger.info(json);
List<Type> typeDefinitions = TypeMapper.deserializeTypeDefinitions(json);
logger.info("{}", typeDefinitions);
@ -107,7 +111,9 @@ public class SchemaManagementImplTest {
@Test
public void getResourceSchema() throws Exception {
String json = new SchemaManagementImpl().read(Actor.NAME, false);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(Actor.NAME);
String json = schemaManagement.read(false);
logger.trace(json);
}
@ -125,9 +131,9 @@ public class SchemaManagementImplTest {
boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagementImpl();
String list = schemaManagement.read(Resource.NAME, includeSubTypes);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(Resource.NAME);
String list = schemaManagement.read(includeSubTypes);
logger.info("{} list : {}", Resource.NAME, list);
}
@ -137,9 +143,9 @@ public class SchemaManagementImplTest {
boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagementImpl();
String list = schemaManagement.read(Facet.NAME, includeSubTypes);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(Facet.NAME);
String list = schemaManagement.read(includeSubTypes);
logger.info("{} list : {}", Facet.NAME, list);
}
@ -149,9 +155,9 @@ public class SchemaManagementImplTest {
boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagementImpl();
String list = schemaManagement.read(ConsistsOf.NAME, includeSubTypes);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(ConsistsOf.NAME);
String list = schemaManagement.read(includeSubTypes);
logger.info("{} list : {}", ConsistsOf.NAME, list);
}
@ -161,9 +167,9 @@ public class SchemaManagementImplTest {
boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagementImpl();
String list = schemaManagement.read(IsRelatedTo.NAME, includeSubTypes);
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(IsRelatedTo.NAME);
String list = schemaManagement.read(includeSubTypes);
logger.info("{} list : {}", IsRelatedTo.NAME, list);
}
@ -175,23 +181,28 @@ public class SchemaManagementImplTest {
boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagementImpl();
SchemaManagement schemaManagement = new SchemaManagement();
try {
schemaManagement.read(PropertyElement.NAME, includeSubTypes);
schemaManagement.setTypeName(PropertyElement.NAME);
schemaManagement.read(includeSubTypes);
throw new Exception("Should not be allowed to get " + PropertyElement.NAME + " schema");
} catch (SchemaException e) {
}
try {
schemaManagement.read(Entity.NAME, includeSubTypes);
schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(Entity.NAME);
schemaManagement.read(includeSubTypes);
throw new Exception("Should not be allowed to get " + Entity.NAME + " schema");
} catch (SchemaException e) {
}
try {
schemaManagement.read(Relation.NAME, includeSubTypes);
schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(Relation.NAME);
schemaManagement.read(includeSubTypes);
throw new Exception("Should not be allowed to get " + Relation.NAME + " schema");
} catch (SchemaException e) {
@ -203,8 +214,8 @@ public class SchemaManagementImplTest {
public void createPropertyType() throws Exception {
PropertyType<ValueSchema> propertyTypeDefinition = new PropertyTypeImpl<>(ValueSchema.class);
SchemaManagement schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(ValueSchema.NAME);
SchemaManagement schemaManagement = new SchemaManagement();
((SchemaManagement) schemaManagement).setTypeName(ValueSchema.NAME);
String ret = schemaManagement.create(ElementMapper.marshal(propertyTypeDefinition), AccessType.PROPERTY);
logger.debug(ret);
@ -215,8 +226,8 @@ public class SchemaManagementImplTest {
public void createEncryptedType() throws Exception {
PropertyType<Encrypted> propertyTypeDefinition = new PropertyTypeImpl<>(Encrypted.class);
SchemaManagement schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(Encrypted.NAME);
SchemaManagement schemaManagement = new SchemaManagement();
((SchemaManagement) schemaManagement).setTypeName(Encrypted.NAME);
String ret = schemaManagement.create(ElementMapper.marshal(propertyTypeDefinition), AccessType.PROPERTY);
logger.debug(ret);
@ -227,8 +238,8 @@ public class SchemaManagementImplTest {
public void createContextType() throws Exception {
EntityType entityTypeDefinition = new EntityTypeImpl(Context.class);
SchemaManagement schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(Context.NAME);
SchemaManagement schemaManagement = new SchemaManagement();
((SchemaManagement) schemaManagement).setTypeName(Context.NAME);
String ret = schemaManagement.create(ElementMapper.marshal(entityTypeDefinition), AccessType.ENTITY_ELEMENT);
logger.debug(ret);
@ -239,8 +250,8 @@ public class SchemaManagementImplTest {
public void createFacetType() throws Exception {
EntityType entityTypeDefinition = new EntityTypeImpl(AccessPointFacet.class);
SchemaManagement schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(AccessPointFacet.NAME);
SchemaManagement schemaManagement = new SchemaManagement();
((SchemaManagement) schemaManagement).setTypeName(AccessPointFacet.NAME);
String ret = schemaManagement.create(ElementMapper.marshal(entityTypeDefinition), AccessType.FACET);
logger.debug(ret);
@ -251,16 +262,16 @@ public class SchemaManagementImplTest {
public void createResourceType() throws Exception {
EntityType entityTypeDefinition = new EntityTypeImpl(EService.class);
SchemaManagement schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(EService.NAME);
SchemaManagement schemaManagement = new SchemaManagement();
((SchemaManagement) schemaManagement).setTypeName(EService.NAME);
String ret = schemaManagement.create(ElementMapper.marshal(entityTypeDefinition), AccessType.RESOURCE);
logger.debug(ret);
entityTypeDefinition = new EntityTypeImpl(RunningPlugin.class);
schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(RunningPlugin.NAME);
schemaManagement = new SchemaManagement();
((SchemaManagement) schemaManagement).setTypeName(RunningPlugin.NAME);
ret = schemaManagement.create(ElementMapper.marshal(entityTypeDefinition), AccessType.RESOURCE);
logger.debug(ret);
@ -272,8 +283,8 @@ public class SchemaManagementImplTest {
@SuppressWarnings({"unchecked", "rawtypes"})
RelationType<?, ?> relationTypeDefinition = new RelationTypeImpl(RelationType.class);
SchemaManagement schemaManagement = new SchemaManagementImpl();
((SchemaManagementImpl) schemaManagement).setTypeName(RelationType.NAME);
SchemaManagement schemaManagement = new SchemaManagement();
((SchemaManagement) schemaManagement).setTypeName(RelationType.NAME);
String ret = ElementMapper.marshal(relationTypeDefinition);
@ -311,4 +322,21 @@ public class SchemaManagementImplTest {
}
*/
@Test
public void createUpdateDeleteFacetType() throws Exception {
@SuppressWarnings("unchecked")
Class<? extends Facet>[] classes = new Class[]{TestFacet.class, TestFacet1_0_1.class, TestFacet1_0_2.class};
for(Class<? extends Facet> c : classes) {
SchemaManagement schemaManagement = new SchemaManagement();
Type type = TypeMapper.createTypeDefinition(c);
schemaManagement.setTypeName(type.getName());
schemaManagement.update(TypeMapper.serializeTypeDefinition(type), AccessType.FACET);
}
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeName(TestFacet.NAME);
schemaManagement.delete(AccessType.FACET);
}
}

View File

@ -0,0 +1,42 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.types;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
/**
* A sort of catch all.
* It does not define any property.
* It is mainly used to one or more arbitrary properties to the resource.
* Before using SimpleFacet a developer should evaluate if it is possible to identify a specific Facet
* to capture the particular aspect of the resource.
* The usage of SimpleFacet should be reduced to the maximum.
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Simple_Property_Facet
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=SimpleFacetImpl.class)
@TypeMetadata(
name = TestFacet.NAME,
description = "TestFacet 1.0.0",
version = TypeVersion.MINIMAL_VERSION_STRING
)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface TestFacet extends Facet {
public static final String NAME = "TestFacet"; // SimpleFacet.class.getSimpleName();
@ISProperty(description = "Description of name for TestFacet 1.0.0", mandatory=true, nullable=false)
public String getName();
public void setName(String name);
}

View File

@ -0,0 +1,42 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.types;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
/**
* A sort of catch all.
* It does not define any property.
* It is mainly used to one or more arbitrary properties to the resource.
* Before using SimpleFacet a developer should evaluate if it is possible to identify a specific Facet
* to capture the particular aspect of the resource.
* The usage of SimpleFacet should be reduced to the maximum.
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Simple_Property_Facet
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=SimpleFacetImpl.class)
@TypeMetadata(
name = TestFacet.NAME,
description = "TestFacet 1.0.1",
version = "1.0.1"
)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface TestFacet1_0_1 extends Facet {
public static final String NAME = TestFacet.NAME; // SimpleFacet.class.getSimpleName();
@ISProperty(description = "Description of title for TestFacet 1.0.1", mandatory=true, nullable=false)
public String getTitle();
public void setTitle(String title);
}

View File

@ -0,0 +1,47 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.types;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
/**
* A sort of catch all.
* It does not define any property.
* It is mainly used to one or more arbitrary properties to the resource.
* Before using SimpleFacet a developer should evaluate if it is possible to identify a specific Facet
* to capture the particular aspect of the resource.
* The usage of SimpleFacet should be reduced to the maximum.
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Simple_Property_Facet
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=SimpleFacetImpl.class)
@TypeMetadata(
name = TestFacet.NAME,
description = "TestFacet 1.0.2",
version = "1.0.2"
)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface TestFacet1_0_2 extends Facet {
public static final String NAME = TestFacet.NAME; // SimpleFacet.class.getSimpleName();
@ISProperty(description = "Description of name for TestFacet 1.0.2", mandatory=true, nullable=false)
public String getName();
public void setName(String name);
@ISProperty(description = "Description of title for TestFacet 1.0.2", mandatory=false, nullable=true)
public String getTitle();
public void setTitle(String title);
}