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