extracted function to get the proper type management class

This commit is contained in:
Luca Frosini 2020-12-22 11:37:36 +01:00
parent 648abc52c3
commit 1a82b13878
1 changed files with 71 additions and 41 deletions

View File

@ -131,11 +131,34 @@ public class SchemaManagementImpl implements SchemaManagement {
} }
*/ */
private ElementManagement<? extends OElement> getTypeManagement(AccessType accessType) {
private Type getType(OClass oClass) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = null; ElementManagement<? extends OElement> erManagement = null;
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
break;
case RESOURCE:
erManagement = new ResourceTypeDefinitionManagement();
break;
case FACET:
erManagement = new FacetTypeDefinitionManagement();
break;
case IS_RELATED_TO:
erManagement = new IsRelatedToTypeDefinitionManagement();
break;
case CONSISTS_OF:
erManagement = new ConsistsOfTypeDefinitionManagement();
break;
default:
break;
}
return erManagement;
}
private ElementManagement<? extends OElement> getTypeManagement(OClass oClass) {
ElementManagement<? extends OElement> erManagement = null;
if(oClass.isSubClassOf(Property.NAME)) { if(oClass.isSubClassOf(Property.NAME)) {
erManagement = new PropertyTypeDefinitionManagement(); erManagement = new PropertyTypeDefinitionManagement();
((PropertyTypeDefinitionManagement) erManagement).setName(oClass.getName()); ((PropertyTypeDefinitionManagement) erManagement).setName(oClass.getName());
@ -152,6 +175,29 @@ public class SchemaManagementImpl implements SchemaManagement {
erManagement = new ConsistsOfTypeDefinitionManagement(); erManagement = new ConsistsOfTypeDefinitionManagement();
((ConsistsOfTypeDefinitionManagement) erManagement).setName(oClass.getName()); ((ConsistsOfTypeDefinitionManagement) erManagement).setName(oClass.getName());
} }
return erManagement;
}
private Type getType(AccessType accessType) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType);
if(erManagement!=null) {
String ret = erManagement.read();
return TypeMapper.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);
}
}
private Type getType(OClass oClass) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(oClass);
if(erManagement!=null) { if(erManagement!=null) {
String ret = erManagement.read(); String ret = erManagement.read();
return TypeMapper.deserializeTypeDefinition(ret); return TypeMapper.deserializeTypeDefinition(ret);
@ -400,8 +446,6 @@ public class SchemaManagementImpl implements SchemaManagement {
throw new SchemaNotFoundException(typeName + " does not Exists"); throw new SchemaNotFoundException(typeName + " does not Exists");
} }
try { try {
String description = type.getDescription(); String description = type.getDescription();
@ -629,31 +673,17 @@ public class SchemaManagementImpl implements SchemaManagement {
} }
// TODO check if the version is greater // TODO check if the version is greater
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType);
Type actualTypeDefinition = getType(accessType);
if(typeDefinition.getVersion().compareTo(actualTypeDefinition.getVersion())<=0) {
throw new SchemaAlreadyPresentException("The type " + typeDefinition.getName() +
" exists and the existing version (.i.e " + actualTypeDefinition.getVersion().toString() +
") is greater of equal to the one provided for update (i.e. " + typeDefinition.getVersion() + ")");
}
updateTypeSchema(typeDefinition, accessType); updateTypeSchema(typeDefinition, accessType);
ElementManagement<? extends OElement> erManagement = null;
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
break;
case RESOURCE:
erManagement = new ResourceTypeDefinitionManagement();
break;
case FACET:
erManagement = new FacetTypeDefinitionManagement();
break;
case IS_RELATED_TO:
erManagement = new IsRelatedToTypeDefinitionManagement();
break;
case CONSISTS_OF:
erManagement = new ConsistsOfTypeDefinitionManagement();
break;
default:
break;
}
String ret = null; String ret = null;
if(erManagement!=null) { if(erManagement!=null) {
erManagement.setJson(jsonSchema); erManagement.setJson(jsonSchema);