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);
} else if(oClass.isSubClassOf(Facet.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, FacetTypeDefinition.NAME);
} else if(oClass.isSubClassOf(Relation.NAME)) {
node.put(ISManageable.CLASS_PROPERTY, RelationTypeDefinition.NAME);
} else if(oClass.isSubClassOf(IsRelatedTo.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)) {
ArrayNode arrayNode = (ArrayNode) node.get(PropertyCapableTypeDefinition.PROPERTIES_PROPERTY);
ArrayNode arrayNode = (ArrayNode) node.get(EntityTypeDefinition.PROPERTIES_PROPERTY);
Iterator<JsonNode> iterator = arrayNode.iterator();
while(iterator.hasNext()) {
ObjectNode propertyNode = (ObjectNode) iterator.next();
@ -113,6 +115,7 @@ public class SchemaManagementImpl implements SchemaManagement {
}
*/
private TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException {
try {
ERManagement<? extends OElement> erManagement = null;
@ -128,12 +131,17 @@ public class SchemaManagementImpl implements SchemaManagement {
((FacetTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
erManagement = new IsRelatedToTypeDefinitionManagement();
((IsRelatedToTypeDefinitionManagement) erManagement).setName(oClass.getName());
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
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");
}
} catch(Exception e) {
throw new SchemaException(e);
}

View File

@ -262,7 +262,7 @@ public class SmartgearResourcesTest extends ContextTest {
Assert.assertTrue(sfList.size()==1);
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);
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.Relation;
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.SchemaManagementImpl;
import org.gcube.informationsystem.types.TypeBinder;
@ -117,29 +118,38 @@ public class SchemaManagementImplTest {
boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagementImpl();
String list = schemaManagement.read(BaseProperty.NAME, includeSubTypes);
logger.debug("{} list : {}", BaseProperty.NAME, list);
try {
schemaManagement.read(BaseProperty.NAME, includeSubTypes);
throw new Exception("Should not be allowed to get " + BaseProperty.NAME + " schema");
} catch (SchemaException e) {
List<TypeDefinition> typeDefinitions = ISMapper.unmarshalList(TypeDefinition.class, list);
logger.debug("{}", typeDefinitions);
}
list = schemaManagement.read(Entity.NAME, includeSubTypes);
logger.debug("{} list : {}", Entity.NAME, list);
try {
schemaManagement.read(Entity.NAME, includeSubTypes);
throw new Exception("Should not be allowed to get " + Entity.NAME + " schema");
} catch (SchemaException e) {
list = schemaManagement.read(Resource.NAME, includeSubTypes);
logger.debug("{} list : {}", Resource.NAME, list);
}
String list = schemaManagement.read(Resource.NAME, includeSubTypes);
logger.info("{} list : {}", Resource.NAME, list);
list = schemaManagement.read(Facet.NAME, includeSubTypes);
logger.debug("{} list : {}", Facet.NAME, list);
logger.info("{} list : {}", Facet.NAME, list);
list = schemaManagement.read(Relation.NAME, includeSubTypes);
logger.debug("{} list : {}", Relation.NAME, list);
try {
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);
logger.debug("{} list : {}", ConsistsOf.NAME, list);
logger.info("{} list : {}", ConsistsOf.NAME, list);
list = schemaManagement.read(IsRelatedTo.NAME, includeSubTypes);
logger.debug("{} list : {}", IsRelatedTo.NAME, list);
logger.info("{} list : {}", IsRelatedTo.NAME, list);
}