Improved Resource definition
This commit is contained in:
parent
6ddcd7c7fd
commit
f18743308b
|
@ -13,7 +13,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 org.gcube.informationsystem.types.annotations.RelatedResourcesEntry;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.TypeVersion;
|
||||
|
@ -31,7 +31,7 @@ import org.gcube.informationsystem.utils.TypeVersion;
|
|||
@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.")
|
||||
@RelatedResourcesEntry(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)
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyDefinition
|
|||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ResourceSchemaRelatedEntry {
|
||||
public @interface RelatedResourcesEntry {
|
||||
|
||||
@JsonProperty
|
||||
Class<? extends Resource> source() default Resource.class;
|
||||
|
@ -37,10 +37,4 @@ public @interface ResourceSchemaRelatedEntry {
|
|||
@JsonProperty
|
||||
String description() default "";
|
||||
|
||||
@JsonProperty
|
||||
int min() default 0;
|
||||
|
||||
@JsonProperty
|
||||
int max() default -1;
|
||||
|
||||
}
|
|
@ -16,5 +16,5 @@ public @interface ResourceSchema {
|
|||
|
||||
ResourceSchemaEntry[] facets() default {};
|
||||
|
||||
ResourceSchemaRelatedEntry[] resources() default {};
|
||||
RelatedResourcesEntry[] resources() default {};
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
|
|||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
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.annotations.RelatedResourcesEntry;
|
||||
import org.gcube.informationsystem.types.impl.properties.LinkedEntityImpl;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
@ -47,24 +47,28 @@ public class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
|
|||
this.resources = new ArrayList<>();
|
||||
ResourceSchema[] resourceSchemaArray = clz.getAnnotationsByType(ResourceSchema.class);
|
||||
for(ResourceSchemaEntry resourceSchemaEntry : resourceSchemaArray[0].facets()) {
|
||||
LinkedEntityImpl resourceSchemaEntryDefinition = new LinkedEntityImpl();
|
||||
resourceSchemaEntryDefinition.setSource(TypeMapper.getType(clz));
|
||||
resourceSchemaEntryDefinition.setRelation(TypeMapper.getType(resourceSchemaEntry.relation()));
|
||||
resourceSchemaEntryDefinition.setTarget(TypeMapper.getType(resourceSchemaEntry.facet()));
|
||||
resourceSchemaEntryDefinition.setDescription(resourceSchemaEntry.description());
|
||||
resourceSchemaEntryDefinition.setMin(resourceSchemaEntry.min());
|
||||
resourceSchemaEntryDefinition.setMax(resourceSchemaEntry.max());
|
||||
this.facets.add(resourceSchemaEntryDefinition);
|
||||
LinkedEntity linkedEntity = new LinkedEntityImpl();
|
||||
linkedEntity.setSource(TypeMapper.getType(clz));
|
||||
linkedEntity.setRelation(TypeMapper.getType(resourceSchemaEntry.relation()));
|
||||
linkedEntity.setTarget(TypeMapper.getType(resourceSchemaEntry.facet()));
|
||||
linkedEntity.setDescription(resourceSchemaEntry.description());
|
||||
linkedEntity.setMin(resourceSchemaEntry.min());
|
||||
linkedEntity.setMax(resourceSchemaEntry.max());
|
||||
this.facets.add(linkedEntity);
|
||||
}
|
||||
for(ResourceSchemaRelatedEntry resourceSchemaRelatedEntry : resourceSchemaArray[0].resources()) {
|
||||
LinkedEntity resourceSchemaEntryDefinition = new LinkedEntityImpl();
|
||||
resourceSchemaEntryDefinition.setSource(TypeMapper.getType(resourceSchemaRelatedEntry.source()));
|
||||
resourceSchemaEntryDefinition.setRelation(TypeMapper.getType(resourceSchemaRelatedEntry.relation()));
|
||||
resourceSchemaEntryDefinition.setTarget(TypeMapper.getType(resourceSchemaRelatedEntry.target()));
|
||||
resourceSchemaEntryDefinition.setDescription(resourceSchemaRelatedEntry.description());
|
||||
resourceSchemaEntryDefinition.setMin(resourceSchemaRelatedEntry.min());
|
||||
resourceSchemaEntryDefinition.setMax(resourceSchemaRelatedEntry.max());
|
||||
this.resources.add(resourceSchemaEntryDefinition);
|
||||
for(RelatedResourcesEntry resourceSchemaRelatedEntry : resourceSchemaArray[0].resources()) {
|
||||
LinkedEntity linkedEntity = new LinkedEntityImpl();
|
||||
linkedEntity.setSource(TypeMapper.getType(resourceSchemaRelatedEntry.source()));
|
||||
linkedEntity.setRelation(TypeMapper.getType(resourceSchemaRelatedEntry.relation()));
|
||||
linkedEntity.setTarget(TypeMapper.getType(resourceSchemaRelatedEntry.target()));
|
||||
linkedEntity.setDescription(resourceSchemaRelatedEntry.description());
|
||||
/*
|
||||
* We cannot impose any constraint on related resources.
|
||||
* The annotation are only for documentation purpose.
|
||||
*/
|
||||
linkedEntity.setMin(0);
|
||||
linkedEntity.setMax(-1);
|
||||
this.resources.add(linkedEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.types.impl.properties;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
@ -93,4 +95,26 @@ public final class LinkedEntityImpl extends PropertyElementImpl implements Linke
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(source, relation, target, min, max, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
LinkedEntityImpl other = (LinkedEntityImpl) obj;
|
||||
return Objects.equals(source, other.source) &&
|
||||
Objects.equals(relation, other.relation) &&
|
||||
Objects.equals(target, other.target) &&
|
||||
Objects.equals(min, other.min) &&
|
||||
Objects.equals(max, other.max) &&
|
||||
Objects.equals(description, other.description);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue