diff --git a/.settings/.gitignore b/.settings/.gitignore new file mode 100644 index 0000000..57d3934 --- /dev/null +++ b/.settings/.gitignore @@ -0,0 +1,2 @@ +/org.eclipse.jdt.core.prefs +/org.eclipse.core.resources.prefs diff --git a/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java b/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java index 4180a0e..8226a87 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java @@ -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 { diff --git a/src/main/java/org/gcube/informationsystem/types/annotations/ResourceSchema.java b/src/main/java/org/gcube/informationsystem/types/annotations/ResourceSchema.java index 2ad0af1..5b1b7d8 100644 --- a/src/main/java/org/gcube/informationsystem/types/annotations/ResourceSchema.java +++ b/src/main/java/org/gcube/informationsystem/types/annotations/ResourceSchema.java @@ -13,5 +13,6 @@ import java.lang.annotation.Target; public @interface ResourceSchema { ResourceSchemaEntry[] facets() default {}; - + + ResourceSchemaRelatedEntry[] resources() default {}; } diff --git a/src/main/java/org/gcube/informationsystem/types/annotations/ResourceSchemaRelatedEntry.java b/src/main/java/org/gcube/informationsystem/types/annotations/ResourceSchemaRelatedEntry.java new file mode 100644 index 0000000..568a824 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/annotations/ResourceSchemaRelatedEntry.java @@ -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 source() default Resource.class; + + @SuppressWarnings("rawtypes") + @JsonProperty + Class relation() default IsRelatedTo.class; + + @JsonProperty + Class target() default Resource.class; + + @JsonProperty + String description() default ""; + + @JsonProperty + int min() default 0; + + @JsonProperty + int max() default -1; + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java index f39e86d..207b9fc 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java @@ -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 superClasses; protected Set properties; protected List facets; + protected List resources; protected static Set retrieveSuperClasses(Class type, Class baseClass, String topSuperClass){ Set interfaceList = new HashSet<>(); @@ -159,6 +161,7 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition { private void setResourceSchemaEntries(Class 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 getResources() { + return resources; + } + }