Adding the possibility to define Resource Schema refs #18213
This commit is contained in:
parent
6a3688cc89
commit
6162719723
|
@ -11,7 +11,6 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.types.annotations.Abstract;
|
import org.gcube.informationsystem.types.annotations.Abstract;
|
||||||
import org.gcube.informationsystem.types.annotations.ResourceSchema;
|
import org.gcube.informationsystem.types.annotations.ResourceSchema;
|
||||||
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
|
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
|
||||||
import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
@ -26,9 +25,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
@ResourceSchema(
|
@ResourceSchema(
|
||||||
facets={
|
facets={
|
||||||
@ResourceSchemaEntry(relation=ConsistsOf.class, facet=Facet.class, min=1, description="Any Resource consists of one or more Facets which describes the different aspects of the resource."),
|
@ResourceSchemaEntry(relation=ConsistsOf.class, facet=Facet.class, min=1, description="Any Resource consists of one or more Facets which describes the different aspects of the resource."),
|
||||||
},
|
|
||||||
resources= {
|
|
||||||
@ResourceSchemaRelatedEntry(source=Resource.class, relation=IsRelatedTo.class, target=Resource.class, description="Any Resource can be related to any other resource.")
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public interface Resource extends Entity {
|
public interface Resource extends Entity {
|
||||||
|
|
|
@ -13,6 +13,5 @@ import java.lang.annotation.Target;
|
||||||
public @interface ResourceSchema {
|
public @interface ResourceSchema {
|
||||||
|
|
||||||
ResourceSchemaEntry[] facets() default {};
|
ResourceSchemaEntry[] facets() default {};
|
||||||
|
|
||||||
ResourceSchemaRelatedEntry[] resources() default {};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
package org.gcube.informationsystem.types.annotations;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
|
||||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
|
||||||
import org.gcube.informationsystem.types.TypeBinder;
|
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
|
||||||
* It is used by {@link TypeBinder} to identify which getter method are
|
|
||||||
* related to and {@link Entity} {@link PropertyDefinition}.
|
|
||||||
* The name of the property is obtained by removing "get" or "is" from method
|
|
||||||
* name and lower casing the first letter.
|
|
||||||
*/
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface ResourceSchemaRelatedEntry {
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
Class<? extends Resource> source() default Resource.class;
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@JsonProperty
|
|
||||||
Class<? extends IsRelatedTo> relation() default IsRelatedTo.class;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
Class<? extends Resource> target() default Resource.class;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
String description() default "";
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
int min() default 0;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
int max() default -1;
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,7 +19,6 @@ import org.gcube.informationsystem.types.annotations.Abstract;
|
||||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||||
import org.gcube.informationsystem.types.annotations.ResourceSchema;
|
import org.gcube.informationsystem.types.annotations.ResourceSchema;
|
||||||
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
|
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
|
||||||
import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
|
|
||||||
import org.gcube.informationsystem.types.impl.entities.EntityTypeDefinitionImpl;
|
import org.gcube.informationsystem.types.impl.entities.EntityTypeDefinitionImpl;
|
||||||
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
|
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
|
||||||
import org.gcube.informationsystem.types.impl.properties.PropertyTypeDefinitionImpl;
|
import org.gcube.informationsystem.types.impl.properties.PropertyTypeDefinitionImpl;
|
||||||
|
@ -54,7 +53,6 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
||||||
protected Set<String> superClasses;
|
protected Set<String> superClasses;
|
||||||
protected Set<PropertyDefinition> properties;
|
protected Set<PropertyDefinition> properties;
|
||||||
protected List<ResourceEntryDefinition> facets;
|
protected List<ResourceEntryDefinition> facets;
|
||||||
protected List<ResourceEntryDefinition> resources;
|
|
||||||
|
|
||||||
protected static <ISM extends ISManageable> Set<String> retrieveSuperClasses(Class<? extends ISM> type, Class<ISM> baseClass, String topSuperClass){
|
protected static <ISM extends ISManageable> Set<String> retrieveSuperClasses(Class<? extends ISM> type, Class<ISM> baseClass, String topSuperClass){
|
||||||
Set<String> interfaceList = new HashSet<>();
|
Set<String> interfaceList = new HashSet<>();
|
||||||
|
@ -161,7 +159,6 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
||||||
private void setResourceSchemaEntries(Class<? extends Resource> clz){
|
private void setResourceSchemaEntries(Class<? extends Resource> clz){
|
||||||
if(clz.isAnnotationPresent(ResourceSchema.class)) {
|
if(clz.isAnnotationPresent(ResourceSchema.class)) {
|
||||||
this.facets = new ArrayList<>();
|
this.facets = new ArrayList<>();
|
||||||
this.resources = new ArrayList<>();
|
|
||||||
ResourceSchema[] resourceSchemaArray = clz.getAnnotationsByType(ResourceSchema.class);
|
ResourceSchema[] resourceSchemaArray = clz.getAnnotationsByType(ResourceSchema.class);
|
||||||
for(ResourceSchemaEntry resourceSchemaEntry : resourceSchemaArray[0].facets()) {
|
for(ResourceSchemaEntry resourceSchemaEntry : resourceSchemaArray[0].facets()) {
|
||||||
ResourceEntryDefinitionImpl resourceSchemaEntryDefinition = new ResourceEntryDefinitionImpl();
|
ResourceEntryDefinitionImpl resourceSchemaEntryDefinition = new ResourceEntryDefinitionImpl();
|
||||||
|
@ -173,16 +170,6 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
||||||
resourceSchemaEntryDefinition.setMax(resourceSchemaEntry.max());
|
resourceSchemaEntryDefinition.setMax(resourceSchemaEntry.max());
|
||||||
this.facets.add(resourceSchemaEntryDefinition);
|
this.facets.add(resourceSchemaEntryDefinition);
|
||||||
}
|
}
|
||||||
for(ResourceSchemaRelatedEntry resourceSchemaRelatedEntry : resourceSchemaArray[0].resources()) {
|
|
||||||
ResourceEntryDefinition resourceSchemaEntryDefinition = new ResourceEntryDefinitionImpl();
|
|
||||||
resourceSchemaEntryDefinition.setSource(TypeBinder.getType(resourceSchemaRelatedEntry.source()));
|
|
||||||
resourceSchemaEntryDefinition.setRelation(TypeBinder.getType(resourceSchemaRelatedEntry.relation()));
|
|
||||||
resourceSchemaEntryDefinition.setTarget(TypeBinder.getType(resourceSchemaRelatedEntry.target()));
|
|
||||||
resourceSchemaEntryDefinition.setDescription(resourceSchemaRelatedEntry.description());
|
|
||||||
resourceSchemaEntryDefinition.setMin(resourceSchemaRelatedEntry.min());
|
|
||||||
resourceSchemaEntryDefinition.setMax(resourceSchemaRelatedEntry.max());
|
|
||||||
this.resources.add(resourceSchemaEntryDefinition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,8 +202,4 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
||||||
return facets;
|
return facets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResourceEntryDefinition> getResources() {
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue