extracted function to get the proper type management class
This commit is contained in:
parent
648abc52c3
commit
1a82b13878
|
@ -131,27 +131,73 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
*/
|
||||
|
||||
private ElementManagement<? extends OElement> getTypeManagement(AccessType 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;
|
||||
}
|
||||
|
||||
return erManagement;
|
||||
}
|
||||
|
||||
private ElementManagement<? extends OElement> getTypeManagement(OClass oClass) {
|
||||
ElementManagement<? extends OElement> erManagement = null;
|
||||
if(oClass.isSubClassOf(Property.NAME)) {
|
||||
erManagement = new PropertyTypeDefinitionManagement();
|
||||
((PropertyTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
erManagement = new ResourceTypeDefinitionManagement();
|
||||
((ResourceTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
erManagement = new FacetTypeDefinitionManagement();
|
||||
((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());
|
||||
}
|
||||
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 = null;
|
||||
ElementManagement<? extends OElement> erManagement = getTypeManagement(oClass);
|
||||
|
||||
if(oClass.isSubClassOf(Property.NAME)) {
|
||||
erManagement = new PropertyTypeDefinitionManagement();
|
||||
((PropertyTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
erManagement = new ResourceTypeDefinitionManagement();
|
||||
((ResourceTypeDefinitionManagement) erManagement).setName(oClass.getName());
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
erManagement = new FacetTypeDefinitionManagement();
|
||||
((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 TypeMapper.deserializeTypeDefinition(ret);
|
||||
|
@ -400,8 +446,6 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
throw new SchemaNotFoundException(typeName + " does not Exists");
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
String description = type.getDescription();
|
||||
|
@ -629,31 +673,17 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
||||
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;
|
||||
if(erManagement!=null) {
|
||||
erManagement.setJson(jsonSchema);
|
||||
|
|
Loading…
Reference in New Issue