Fixing code due to refactoring

This commit is contained in:
Luca Frosini 2021-02-12 12:09:33 +01:00
parent a518f98235
commit 319fa760e3
4 changed files with 24 additions and 34 deletions

View File

@ -57,9 +57,6 @@ public class SchemaActionImpl implements SchemaAction {
((SchemaManagement) schemaManagement).setSkipTypeDefinitionCreation(true);
}
schemaManagement.create();
schemaManagement.setTypeName(TypeMapper.getType(p));
String json = TypeMapper.serializeType(p);
logger.trace(json);
} catch(SchemaAlreadyPresentException sape) {
logger.warn("{} already exists. It will be ignored", TypeMapper.getType(p));
} catch(Exception ex) {

View File

@ -3,11 +3,6 @@ package org.gcube.informationsystem.resourceregistry.types;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
@ -89,24 +84,17 @@ public class CachedType {
return oClass;
}
private AccessType getAccessTypeFromOClass(OClass oClass) throws ResourceRegistryException {
if(oClass.isSubClassOf(Resource.NAME)) {
return AccessType.RESOURCE;
} else if(oClass.isSubClassOf(Facet.NAME)) {
return AccessType.FACET;
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
return AccessType.CONSISTS_OF;
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
return AccessType.IS_RELATED_TO;
} else if(oClass.isSubClassOf(Property.NAME)) {
return AccessType.PROPERTY;
}else {
throw new ResourceRegistryException(typeName + " is not a base type");
AccessType[] accessTypes = AccessType.values();
for(int i=accessTypes.length-1; i>=0; i--) {
AccessType accessType = accessTypes[i];
if(oClass.isSubClassOf(accessType.getName())) {
return accessType;
}
}
throw new ResourceRegistryException(typeName + " is not a base type");
}
public synchronized AccessType getAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
if(accessType==null) {
if(type!=null) {

View File

@ -119,9 +119,10 @@ public class SchemaManagement {
this.typeName = typeName;
}
public void setTypeAndTypeName(Class<? extends Element> clz) {
public void setTypeAndTypeName(Class<? extends Element> clz) throws Exception {
this.type = TypeMapper.createTypeDefinition(clz);
this.typeName = type.getName();
this.json = TypeMapper.serializeTypeDefinition(type);
}
/*
@ -331,7 +332,7 @@ public class SchemaManagement {
typeList.add(ConsistsOfType.NAME);
}
protected void registerTypeSchema(Type type)
protected void registerTypeSchema()
throws SchemaAlreadyPresentException, SchemaException {
ODatabaseDocument oDatabaseDocument = null;
@ -353,13 +354,15 @@ public class SchemaManagement {
OClass oClass = null;
AccessType accessType = type.getAccessType();
Class<? extends Element> typeClass = accessType.getTypeClass();
String typeName = type.getName();
if(EntityElement.class.isAssignableFrom(accessType.getTypeClass())) {
oClass = oDatabaseDocument.createVertexClass(type.getName());
} else if(RelationElement.class.isAssignableFrom(accessType.getTypeClass())) {
oClass = oDatabaseDocument.createEdgeClass(type.getName());
} else if(PropertyElement.class.isAssignableFrom(accessType.getTypeClass())) {
oClass = oSchema.createClass(type.getName());
if(EntityElement.class.isAssignableFrom(typeClass)) {
oClass = oDatabaseDocument.createVertexClass(typeName);
} else if(RelationElement.class.isAssignableFrom(typeClass)) {
oClass = oDatabaseDocument.createEdgeClass(typeName);
} else if(PropertyElement.class.isAssignableFrom(typeClass)) {
oClass = oSchema.createClass(typeName);
} else {
String error = String.format("Allowed superclass are %s, %s, %s, or any subclasses of them.",
Entity.NAME, Relation.NAME, Property.NAME);
@ -739,11 +742,11 @@ public class SchemaManagement {
AccessType accessType = type.getAccessType();
logger.info("Trying to register {} {} : {}", accessType.getName(), type.getName(), json);
registerTypeSchema(type);
registerTypeSchema();
ElementManagement<? extends OElement> erManagement = null;
switch(type.getAccessType()) {
switch(accessType) {
case PROPERTY:
erManagement = new PropertyTypeDefinitionManagement();
break;

View File

@ -212,7 +212,8 @@ public class SchemaManagementImplTest extends ContextTest {
}
protected String create(Class<? extends Element> clz) throws SchemaAlreadyPresentException, SchemaException {
protected String create(Class<? extends Element> clz)
throws SchemaAlreadyPresentException, SchemaException, Exception {
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeAndTypeName(clz);
String ret = schemaManagement.create();
@ -220,7 +221,8 @@ public class SchemaManagementImplTest extends ContextTest {
return ret;
}
protected String update(Class<? extends Element> clz, boolean skipVersionCheckOnUpdate) throws SchemaAlreadyPresentException, SchemaException, SchemaNotFoundException {
protected String update(Class<? extends Element> clz, boolean skipVersionCheckOnUpdate)
throws SchemaAlreadyPresentException, SchemaException, SchemaNotFoundException, Exception {
SchemaManagement schemaManagement = new SchemaManagement();
schemaManagement.setTypeAndTypeName(clz);
schemaManagement.setSkipVersionCheckOnUpdate(skipVersionCheckOnUpdate);