Fixed Schema management and test

This commit is contained in:
Luca Frosini 2020-01-24 11:25:13 +01:00
parent ecc047889e
commit 5d9da98508
3 changed files with 42 additions and 24 deletions

View File

@ -90,12 +90,14 @@ public class SchemaManagementImpl implements SchemaManagement {
node.put(ISManageable.CLASS_PROPERTY, ResourceTypeDefinition.NAME); node.put(ISManageable.CLASS_PROPERTY, ResourceTypeDefinition.NAME);
} else if(oClass.isSubClassOf(Facet.NAME)) { } else if(oClass.isSubClassOf(Facet.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, FacetTypeDefinition.NAME); node.put(ISManageable.CLASS_PROPERTY, FacetTypeDefinition.NAME);
} else if(oClass.isSubClassOf(Relation.NAME)) { } else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, RelationTypeDefinition.NAME); node.put(ISManageable.CLASS_PROPERTY, IsRelatedToTypeDefinition.NAME);
} } else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, ConsistsOfTypeDefinition.NAME);
}
if(!oClass.isSubClassOf(Resource.NAME)) { if(!oClass.isSubClassOf(Resource.NAME)) {
ArrayNode arrayNode = (ArrayNode) node.get(PropertyCapableTypeDefinition.PROPERTIES_PROPERTY); ArrayNode arrayNode = (ArrayNode) node.get(EntityTypeDefinition.PROPERTIES_PROPERTY);
Iterator<JsonNode> iterator = arrayNode.iterator(); Iterator<JsonNode> iterator = arrayNode.iterator();
while(iterator.hasNext()) { while(iterator.hasNext()) {
ObjectNode propertyNode = (ObjectNode) iterator.next(); ObjectNode propertyNode = (ObjectNode) iterator.next();
@ -113,6 +115,7 @@ public class SchemaManagementImpl implements SchemaManagement {
} }
*/ */
private TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException { private TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException {
try { try {
ERManagement<? extends OElement> erManagement = null; ERManagement<? extends OElement> erManagement = null;
@ -128,12 +131,17 @@ public class SchemaManagementImpl implements SchemaManagement {
((FacetTypeDefinitionManagement) erManagement).setName(oClass.getName()); ((FacetTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) { } else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
erManagement = new IsRelatedToTypeDefinitionManagement(); erManagement = new IsRelatedToTypeDefinitionManagement();
((IsRelatedToTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) { } else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
erManagement = new ConsistsOfTypeDefinitionManagement(); erManagement = new ConsistsOfTypeDefinitionManagement();
((ConsistsOfTypeDefinitionManagement) erManagement).setName(oClass.getName());
}
if(erManagement!=null) {
String ret = erManagement.read();
return TypeBinder.deserializeTypeDefinition(ret);
}else {
throw new SchemaException("You can only request schema of IS Model types and their specilization");
} }
String ret = erManagement.read();
return TypeBinder.deserializeTypeDefinition(ret);
} catch(Exception e) { } catch(Exception e) {
throw new SchemaException(e); throw new SchemaException(e);
} }

View File

@ -262,7 +262,7 @@ public class SmartgearResourcesTest extends ContextTest {
Assert.assertTrue(sfList.size()==1); Assert.assertTrue(sfList.size()==1);
List<CPUFacet> cfList = hostingNodeToUpdate.getFacets(CPUFacet.class); List<CPUFacet> cfList = hostingNodeToUpdate.getFacets(CPUFacet.class);
Assert.assertTrue(cfList.size()==4); Assert.assertTrue(cfList.size()==cpuFacets.size());
List<NetworkingFacet> nfList = hostingNodeToUpdate.getFacets(NetworkingFacet.class); List<NetworkingFacet> nfList = hostingNodeToUpdate.getFacets(NetworkingFacet.class);
Assert.assertTrue(nfList.size()==1); Assert.assertTrue(nfList.size()==1);

View File

@ -20,6 +20,7 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement; import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement;
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl; import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.types.TypeBinder;
@ -117,29 +118,38 @@ public class SchemaManagementImplTest {
boolean includeSubTypes = true; boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagementImpl(); SchemaManagement schemaManagement = new SchemaManagementImpl();
String list = schemaManagement.read(BaseProperty.NAME, includeSubTypes); try {
logger.debug("{} list : {}", BaseProperty.NAME, list); schemaManagement.read(BaseProperty.NAME, includeSubTypes);
throw new Exception("Should not be allowed to get " + BaseProperty.NAME + " schema");
List<TypeDefinition> typeDefinitions = ISMapper.unmarshalList(TypeDefinition.class, list); } catch (SchemaException e) {
logger.debug("{}", typeDefinitions);
}
list = schemaManagement.read(Entity.NAME, includeSubTypes);
logger.debug("{} list : {}", Entity.NAME, list); try {
schemaManagement.read(Entity.NAME, includeSubTypes);
list = schemaManagement.read(Resource.NAME, includeSubTypes); throw new Exception("Should not be allowed to get " + Entity.NAME + " schema");
logger.debug("{} list : {}", Resource.NAME, list); } catch (SchemaException e) {
}
String list = schemaManagement.read(Resource.NAME, includeSubTypes);
logger.info("{} list : {}", Resource.NAME, list);
list = schemaManagement.read(Facet.NAME, includeSubTypes); list = schemaManagement.read(Facet.NAME, includeSubTypes);
logger.debug("{} list : {}", Facet.NAME, list); logger.info("{} list : {}", Facet.NAME, list);
list = schemaManagement.read(Relation.NAME, includeSubTypes); try {
logger.debug("{} list : {}", Relation.NAME, list); schemaManagement.read(Relation.NAME, includeSubTypes);
throw new Exception("Should not be allowed to get " + Relation.NAME + " schema");
} catch (SchemaException e) {
}
list = schemaManagement.read(ConsistsOf.NAME, includeSubTypes); list = schemaManagement.read(ConsistsOf.NAME, includeSubTypes);
logger.debug("{} list : {}", ConsistsOf.NAME, list); logger.info("{} list : {}", ConsistsOf.NAME, list);
list = schemaManagement.read(IsRelatedTo.NAME, includeSubTypes); list = schemaManagement.read(IsRelatedTo.NAME, includeSubTypes);
logger.debug("{} list : {}", IsRelatedTo.NAME, list); logger.info("{} list : {}", IsRelatedTo.NAME, list);
} }