Using annotation to define name, description, version and chagelog for

any Element
This commit is contained in:
Luca Frosini 2020-12-15 11:28:34 +01:00
parent 0915af9dc1
commit e697ef2cf5
23 changed files with 297 additions and 34 deletions

View File

@ -7,6 +7,9 @@ import java.io.Serializable;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
@ -14,6 +17,8 @@ import org.gcube.informationsystem.types.annotations.Abstract;
@Abstract
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.CLASS_PROPERTY)
// @JsonTypeIdResolver(ElementTypeIdResolver.class)
@TypeMetadata(name = Element.NAME, description = "This is the base class for Element", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Element extends Serializable {
public static final String NAME = "Element"; //Element.class.getSimpleName();

View File

@ -4,7 +4,7 @@ import org.gcube.informationsystem.model.reference.properties.Header;
/**
* @author Luca Frosini (ISTI - CNR)
* this is just a useful interface
* This interfaces is an helper to identify elements could be identified via {@link Header}
*/
public interface IdentifiableElement extends Element {

View File

@ -6,10 +6,15 @@ import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.types.annotations.Abstract;
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;
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonDeserialize(as=EntityElementImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = EntityElement.NAME, description = "This is the base class for any EntityElement", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface EntityElement extends Element, IdentifiableElement {
public static final String NAME = "EntityElement"; //Entity.class.getSimpleName();

View File

@ -3,6 +3,9 @@ package org.gcube.informationsystem.base.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
@ -10,10 +13,10 @@ import org.gcube.informationsystem.base.reference.Element;
* for management purpose.
*/
@JsonDeserialize(as=PropertyElementImpl.class)
@TypeMetadata(name = PropertyElement.NAME, description = "This is the base class for any PropertyElement", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface PropertyElement extends Element {
public static final String NAME = "PropertyElement"; //PropertyElement.class.getSimpleName();
public static final String DESCRIPTION = "This is the very base class for Property";
public static final String VERSION = "1.0.0";
}

View File

@ -8,9 +8,14 @@ import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.types.annotations.Abstract;
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;
@Abstract
//@JsonDeserialize(as=RelationElementImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = RelationElement.NAME, description = "This is the base class for any RelationElement", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface RelationElement<S extends EntityElement, T extends EntityElement> extends Element, IdentifiableElement {
public static final String NAME = "RelationElement"; // RelationElement.class.getSimpleName();

View File

@ -15,12 +15,17 @@ import org.gcube.informationsystem.context.impl.entities.ContextImpl;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.reference.relations.Relation;
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;
/**
* @author Luca Frosini (ISTI - CNR) This Entity is for internal use only
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Context
*/
@JsonDeserialize(as = ContextImpl.class)
@TypeMetadata(name = Context.NAME, description = "This class is the used to define a Context", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Context extends EntityElement {
public static final String NAME = "Context"; // Context.class.getSimpleName();

View File

@ -10,12 +10,17 @@ import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isParentOf
*/
@JsonDeserialize(as = IsParentOfImpl.class)
@TypeMetadata(name = IsParentOf.NAME, description = "This class is the used to define parental relations between Context", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface IsParentOf extends RelationElement<Context,Context> {
public static final String NAME = "IsParentOf"; //IsParentOf.class.getSimpleName();

View File

@ -5,18 +5,20 @@ package org.gcube.informationsystem.model.reference.entities;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Basic_Concepts
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Basic_Concepts
*/
@Abstract
//@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = Entity.NAME, description = "This is the base class for Entities", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Entity extends EntityElement {
public static final String NAME = "Entity"; //Entity.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Entities";
public static final String VERSION = "1.0.0";
}

View File

@ -7,7 +7,10 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
@ -15,11 +18,11 @@ import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
*/
@Abstract
// @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = "Facet", description = "This is the base class for Facets", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Facet extends Entity, SchemaMixedElement {
public static final String NAME = "Facet"; //Facet.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Facets";
public static final String VERSION = "1.0.0";
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)

View File

@ -14,6 +14,9 @@ import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ResourceSchema;
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
@ -30,11 +33,11 @@ import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
@ResourceSchemaRelatedEntry(source=Resource.class, relation=IsRelatedTo.class, target=Resource.class, description="Any Resource can be related to any other resource.")
}
)
@TypeMetadata(name = Resource.NAME, description = "This is the base class for Resources", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Resource extends Entity {
public static final String NAME = "Resource"; //Resource.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Resources";
public static final String VERSION = "1.0.0";
public static final String CONSISTS_OF_PROPERTY = "consistsOf";
public static final String IS_RELATED_TO_PROPERTY = "isRelatedTo";

View File

@ -5,17 +5,18 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
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;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=EncryptedImpl.class)
@TypeMetadata(name = "Encrypted", description = "This is the base class for Encrypted values", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Encrypted extends Property {
public static final String NAME = "Encrypted"; //Encrypted.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Encrypted values";
public static final String VERSION = "1.0.0";
public static final String VALUE = "value";
@ISProperty(name=VALUE, readonly=false, mandatory=true, nullable=false)

View File

@ -11,12 +11,17 @@ import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
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;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Header
*/
@JsonDeserialize(as=HeaderImpl.class)
@TypeMetadata(name = Header.NAME, description = "This class provides metadata per every IdentifiableElement", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Header extends Property {
public static final String NAME = "Header"; // Header.class.getSimpleName();

View File

@ -6,12 +6,17 @@ package org.gcube.informationsystem.model.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
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;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint
*/
@JsonDeserialize(as=PropagationConstraintImpl.class)
@TypeMetadata(name = PropagationConstraint.NAME, description = "This class provides propation constraint for Relation", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface PropagationConstraint extends Property {
public static final String NAME = "PropagationConstraint"; // PropagationConstraint.class.getSimpleName();

View File

@ -12,7 +12,10 @@ import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.model.impl.properties.PropertyImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
@ -21,11 +24,11 @@ import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
*/
// @JsonIgnoreProperties(ignoreUnknown=true)
@JsonDeserialize(as=PropertyImpl.class)
@TypeMetadata(name = Property.NAME, description = "This is the base class for Properties", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Property extends PropertyElement, SchemaMixedElement {
public static final String NAME = "Property"; //Property.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Properties";
public static final String VERSION = "1.0.0";
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)

View File

@ -7,12 +7,17 @@ import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#consistsOf
*/
@JsonDeserialize(as=ConsistsOfImpl.class)
@TypeMetadata(name = ConsistsOf.NAME, description = "This is the base class for ConsistsOf relations", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface ConsistsOf<S extends Resource, T extends Facet>
extends Relation<S, T> {

View File

@ -5,6 +5,9 @@ package org.gcube.informationsystem.model.reference.relations;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
@ -13,6 +16,8 @@ import org.gcube.informationsystem.types.annotations.Abstract;
*/
@Abstract
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is the base class for IsRelatedTo relations", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface IsRelatedTo<S extends Resource, T extends Resource>
extends Relation<S, T> {

View File

@ -18,7 +18,10 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.types.annotations.Abstract;
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.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
@ -26,6 +29,8 @@ import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
*/
@Abstract
// @JsonDeserialize(as=RelationImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = Relation.NAME, description = "This is the base class for Relations", version = TypeVersion.MINIMAL_VERSION_STRING)
@Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface Relation<S extends Resource, T extends Entity> extends RelationElement<S,T>, SchemaMixedElement {
public static final String NAME = "Relation"; //Relation.class.getSimpleName();

View File

@ -1,8 +1,9 @@
package org.gcube.informationsystem.types;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.com.fasterxml.jackson.databind.DeserializationFeature;
@ -10,7 +11,10 @@ import org.gcube.com.fasterxml.jackson.databind.JavaType;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.Changelog;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
@ -20,15 +24,13 @@ 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.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypeMapper {
private final static String NAME = "NAME";
protected static final ObjectMapper mapper;
static {
@ -90,13 +92,95 @@ public class TypeMapper {
}
public static String getType(Class<? extends Element> clz){
String classSimpleName = clz.getSimpleName();
String name = null;
if(clz.isAnnotationPresent(JsonTypeName.class)) {
JsonTypeName jsonTypeName = clz.getAnnotation(JsonTypeName.class);
return jsonTypeName.value();
name = jsonTypeName.value();
if(name==null || name.compareTo("")!=0) {
throw new RuntimeException("Invalid annotation @JsonTypeName for type " + classSimpleName);
}
}
if(clz.isAnnotationPresent(TypeMetadata.class)) {
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
String typeMetadataName = typeMetadata.name();
if(typeMetadataName!=null && typeMetadataName.compareTo("")!=0) {
if(name!=null && typeMetadataName.compareTo(name)!=0) {
throw new RuntimeException("Name in annotation @TypeMetadata differ from annotation in @JsonTypeName for type " + classSimpleName + ". Please be coerent");
}
return name;
}else {
throw new RuntimeException("Invalid Name in annotation @TypeMetadata for type " + classSimpleName);
}
}else {
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
}
return getStaticStringFieldByName(clz, NAME, clz.getSimpleName());
}
public static String getTypeDescription(Class<? extends Element> clz){
String classSimpleName = clz.getSimpleName();
if(clz.isAnnotationPresent(TypeMetadata.class)) {
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
String description = typeMetadata.description();
if(description!=null && description.compareTo("")!=0) {
return description;
}else {
throw new RuntimeException("Invalid Description in annotation @TypeMetadata for type " + classSimpleName);
}
}else {
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
}
}
public static TypeVersion getTypeVersion(Class<? extends Element> clz){
String classSimpleName = clz.getSimpleName();
if(clz.isAnnotationPresent(TypeMetadata.class)) {
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
return new TypeVersion(typeMetadata.version());
}else {
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
}
}
public static Map<TypeVersion, String> getTypeChangelog(Class<? extends Element> clz){
Map<TypeVersion, String> map = new HashMap<>();
if(clz.isAnnotationPresent(Changelog.class)) {
Changelog changelog = clz.getAnnotation(Changelog.class);
Change[] changes = changelog.value();
for(Change change : changes) {
String version = change.version();
TypeVersion typeVersion = new TypeVersion(version);
if(map.containsKey(typeVersion)) {
throw new RuntimeException("Duplicated version " + version +" in @Change annotation");
}
String description = change.description();
if(description==null || description.compareTo("")==0) {
throw new RuntimeException("A valid description for version " + version +" must be provided in @Change annotation");
}
map.put(typeVersion, description);
}
}
if(!map.containsKey(TypeVersion.MINIMAL_VERSION)) {
map.putAll(TypeImpl.DEFAULT_CHANGELOG_MAP);
}
TypeVersion typeVersion = getTypeVersion(clz);
if (!map.containsKey(typeVersion)) {
throw new RuntimeException("The Type " + clz.getSimpleName() + " does not provided the appropriated changelog Map");
}
return map;
}
/*
private final static String NAME = "NAME";
public static String getStaticStringFieldByName(Class<? extends Element> clz, String fieldName, String defaultValue){
Field field;
try {
@ -119,5 +203,6 @@ public class TypeMapper {
return defaultValue;
}
}
*/
}

View File

@ -40,10 +40,12 @@ public class TypeImpl implements Type {
*/
private static final long serialVersionUID = -4333954207969059451L;
/*
public final static String DESCRIPTION = "DESCRIPTION";
public final static String VERSION = "VERSION";
public final static String CHANGELOG = "CHANGELOG";
*/
public static final Map<TypeVersion, String> DEFAULT_CHANGELOG_MAP;
private static final Map<String, String> DEFAULT_CHANGELOG_MAP_KEY_AS_STRING;
@ -52,9 +54,9 @@ public class TypeImpl implements Type {
DEFAULT_CHANGELOG_MAP.put(new TypeVersion(TypeVersion.MINIMAL_VERSION_STRING), TypeVersion.MINIMAL_VERSION_DESCRIPTION);
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING = new HashMap<>();
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING.put(TypeVersion.MINIMAL_VERSION_STRING, TypeVersion.MINIMAL_VERSION_DESCRIPTION);
}
protected Header header;
protected String name;
@ -156,17 +158,15 @@ public class TypeImpl implements Type {
protected TypeImpl() {
}
protected TypeImpl(Class<? extends Element> clz) {
this.name = TypeMapper.getType(clz);
this.description = TypeMapper.getStaticStringFieldByName(clz, DESCRIPTION, "");
String versionString = TypeMapper.getStaticStringFieldByName(clz, VERSION, TypeVersion.MINIMAL_VERSION_STRING);
this.version = new TypeVersion(versionString);
this.changelog = TypeMapper.getStaticFieldByName(clz, CHANGELOG, DEFAULT_CHANGELOG_MAP);
if (!changelog.containsKey(version)) {
throw new RuntimeException("The Type " + name + " does not provided the appropriated changelog Map");
}
this.description = TypeMapper.getTypeDescription(clz);
this.version = TypeMapper.getTypeVersion(clz);
this.changelog = TypeMapper.getTypeChangelog(clz);
this.abstractType = false;
if (clz.isAnnotationPresent(Abstract.class)) {

View File

@ -0,0 +1,21 @@
package org.gcube.informationsystem.types.reference;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Target(TYPE)
@Repeatable(Changelog.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface Change {
String version();
String description();
}

View File

@ -0,0 +1,17 @@
package org.gcube.informationsystem.types.reference;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Target(TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Changelog {
Change[] value() default {};
}

View File

@ -0,0 +1,23 @@
package org.gcube.informationsystem.types.reference;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Documented;
import java.lang.annotation.Target;
import org.gcube.informationsystem.utils.TypeVersion;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Documented
@Target(TYPE)
public @interface TypeMetadata {
String name() default "";
String description() default "";
String version() default TypeVersion.MINIMAL_VERSION_STRING;
}

View File

@ -1,6 +1,15 @@
package org.gcube.informationsystem.utils.discovery;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
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.types.reference.Type;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.junit.Test;
@ -11,4 +20,47 @@ public class ISMDiscoveryTest {
ElementSpecilizationDiscovery<PropertyElement> propertyDiscovery = new ElementSpecilizationDiscovery<>(PropertyElement.class);
propertyDiscovery.analizeISM(PropertyType.class);
}
@Test
public void test() throws Exception {
List<Package> packages = new ArrayList<Package>();
Class<Type> tdClz = Type.class;
packages.add(tdClz.getPackage());
AccessType[] accessTypes = AccessType.values();
for(AccessType accessType : accessTypes) {
Class<Element> clz = accessType.getTypeClass();
packages.add(clz.getPackage());
}
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader
.load(RegistrationProvider.class);
for(RegistrationProvider registrationProvider : regsitrationProviders) {
packages.addAll(registrationProvider.getPackagesToRegister());
}
SchemaAction schemaAction = new SchemaAction() {
@Override
public <R extends RelationElement<? extends EntityElement, ? extends EntityElement>> void manageRelationClass(
Class<R> r) throws Exception {
}
@Override
public <P extends PropertyElement> void managePropertyClass(Class<P> e) throws Exception {
}
@Override
public <E extends EntityElement> void manageEntityClass(Class<E> e) throws Exception {
}
};
ElementSpecilizationDiscovery.manageISM(schemaAction , packages);
}
}