Implementing type update

This commit is contained in:
Luca Frosini 2021-01-12 15:41:19 +01:00
parent e51c635dea
commit c0fb892279
1 changed files with 54 additions and 28 deletions

View File

@ -131,24 +131,29 @@ public class SchemaManagementImpl implements SchemaManagement {
}
*/
private ElementManagement<? extends OElement> getTypeManagement(AccessType accessType) {
private static ElementManagement<? extends OElement> getTypeManagement(AccessType accessType, String name) {
ElementManagement<? extends OElement> erManagement = null;
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
((PropertyTypeDefinitionManagement) erManagement).setName(name);
break;
case RESOURCE:
erManagement = new ResourceTypeDefinitionManagement();
((ResourceTypeDefinitionManagement) erManagement).setName(name);
break;
case FACET:
erManagement = new FacetTypeDefinitionManagement();
((FacetTypeDefinitionManagement) erManagement).setName(name);
break;
case IS_RELATED_TO:
erManagement = new IsRelatedToTypeDefinitionManagement();
((IsRelatedToTypeDefinitionManagement) erManagement).setName(name);
break;
case CONSISTS_OF:
erManagement = new ConsistsOfTypeDefinitionManagement();
((ConsistsOfTypeDefinitionManagement) erManagement).setName(name);
break;
default:
break;
@ -157,7 +162,7 @@ public class SchemaManagementImpl implements SchemaManagement {
return erManagement;
}
private ElementManagement<? extends OElement> getTypeManagement(OClass oClass) {
private static ElementManagement<? extends OElement> getTypeManagement(OClass oClass) {
ElementManagement<? extends OElement> erManagement = null;
if(oClass.isSubClassOf(Property.NAME)) {
erManagement = new PropertyTypeDefinitionManagement();
@ -178,13 +183,11 @@ public class SchemaManagementImpl implements SchemaManagement {
return erManagement;
}
private Type getType(AccessType accessType) throws SchemaException {
private String getTypeAsString(ElementManagement<? extends OElement> erManagement) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType);
if(erManagement!=null) {
String ret = erManagement.read();
return TypeMapper.deserializeTypeDefinition(ret);
return ret;
}else {
throw new SchemaException("You can only request schema of IS Model types and their specilization");
}
@ -193,26 +196,49 @@ public class SchemaManagementImpl implements SchemaManagement {
}
}
private String getTypeAsString(OClass oClass) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(oClass);
return getTypeAsString(erManagement);
} catch(Exception e) {
throw new SchemaException(e);
}
}
private Type getType(ElementManagement<? extends OElement> erManagement) throws SchemaException {
try {
String typeString = getTypeAsString(erManagement);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
/*
private String getTypeAsString(AccessType accessType, String name) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType, name);
return getTypeAsString(erManagement);
} catch(Exception e) {
throw new SchemaException(e);
}
}
/*
private Type getType(AccessType accessType, String name) throws SchemaException {
try {
String typeString = getTypeAsString(accessType, name);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
}
*/
private Type getType(OClass oClass) throws SchemaException {
try {
ElementManagement<? extends OElement> erManagement = getTypeManagement(oClass);
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);
}
}
protected String getTypeDefinitionAsString(OClass oClass) throws SchemaException {
try {
Type type = getType(oClass);
return TypeMapper.serializeTypeDefinition(type);
String typeString = getTypeAsString(oClass);
return TypeMapper.deserializeTypeDefinition(typeString);
} catch(Exception e) {
throw new SchemaException(e);
}
@ -657,7 +683,6 @@ public class SchemaManagementImpl implements SchemaManagement {
}
// TODO
@Override
public String update(String jsonSchema, AccessType accessType)
throws SchemaNotFoundException, SchemaException {
@ -665,16 +690,17 @@ public class SchemaManagementImpl implements SchemaManagement {
try {
try {
typeDefinition = TypeMapper.deserializeTypeDefinition(jsonSchema);
logger.info("Trying to register {} {} : {}", accessType.getName(), typeDefinition.getName(),
logger.info("Trying to update {} {} : {}", accessType.getName(), typeDefinition.getName(),
jsonSchema);
} catch(Exception e) {
logger.error("Error while trying to register {} {}", accessType.getName(), jsonSchema);
throw new SchemaCreationException(e);
}
// TODO check if the version is greater
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType);
Type actualTypeDefinition = getType(accessType);
setTypeName(typeDefinition.getName());
ElementManagement<? extends OElement> erManagement = getTypeManagement(accessType, typeDefinition.getName());
Type actualTypeDefinition = getType(erManagement);
if(typeDefinition.getVersion().compareTo(actualTypeDefinition.getVersion())<=0) {
throw new SchemaAlreadyPresentException("The type " + typeDefinition.getName() +