Added Resource to Resource schema definition
This commit is contained in:
parent
6162719723
commit
f5f69bc6a6
|
@ -0,0 +1,2 @@
|
|||
/org.eclipse.jdt.core.prefs
|
||||
/org.eclipse.core.resources.prefs
|
|
@ -11,6 +11,7 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
|||
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 com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
@ -25,6 +26,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|||
@ResourceSchema(
|
||||
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."),
|
||||
},
|
||||
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 {
|
||||
|
|
|
@ -14,4 +14,5 @@ public @interface ResourceSchema {
|
|||
|
||||
ResourceSchemaEntry[] facets() default {};
|
||||
|
||||
ResourceSchemaRelatedEntry[] resources() default {};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
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,6 +19,7 @@ import org.gcube.informationsystem.types.annotations.Abstract;
|
|||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
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.impl.entities.EntityTypeDefinitionImpl;
|
||||
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
|
||||
import org.gcube.informationsystem.types.impl.properties.PropertyTypeDefinitionImpl;
|
||||
|
@ -53,6 +54,7 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
|||
protected Set<String> superClasses;
|
||||
protected Set<PropertyDefinition> properties;
|
||||
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){
|
||||
Set<String> interfaceList = new HashSet<>();
|
||||
|
@ -159,6 +161,7 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
|||
private void setResourceSchemaEntries(Class<? extends Resource> clz){
|
||||
if(clz.isAnnotationPresent(ResourceSchema.class)) {
|
||||
this.facets = new ArrayList<>();
|
||||
this.resources = new ArrayList<>();
|
||||
ResourceSchema[] resourceSchemaArray = clz.getAnnotationsByType(ResourceSchema.class);
|
||||
for(ResourceSchemaEntry resourceSchemaEntry : resourceSchemaArray[0].facets()) {
|
||||
ResourceEntryDefinitionImpl resourceSchemaEntryDefinition = new ResourceEntryDefinitionImpl();
|
||||
|
@ -170,6 +173,16 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
|||
resourceSchemaEntryDefinition.setMax(resourceSchemaEntry.max());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,4 +215,8 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
|||
return facets;
|
||||
}
|
||||
|
||||
public List<ResourceEntryDefinition> getResources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue