Refs #10207: Improve management of SchemaException
Task-Url: https://support.d4science.org/issues/10207 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158163 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
394f39918d
commit
3fd72527ed
|
@ -16,6 +16,7 @@ import org.gcube.informationsystem.model.entity.Entity;
|
||||||
import org.gcube.informationsystem.model.entity.Resource;
|
import org.gcube.informationsystem.model.entity.Resource;
|
||||||
import org.gcube.informationsystem.model.relation.Relation;
|
import org.gcube.informationsystem.model.relation.Relation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
||||||
|
@ -27,6 +28,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.orientechnologies.orient.core.exception.OSchemaException;
|
||||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClassImpl;
|
import com.orientechnologies.orient.core.metadata.schema.OClassImpl;
|
||||||
|
@ -149,6 +151,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
List<OClass> oSuperclasses = new ArrayList<>();
|
List<OClass> oSuperclasses = new ArrayList<>();
|
||||||
for (String superClass : superClasses) {
|
for (String superClass : superClasses) {
|
||||||
OClass oSuperClass = getOClass(oSchema, superClass);
|
OClass oSuperClass = getOClass(oSchema, superClass);
|
||||||
|
if(oSuperClass==null){
|
||||||
|
throw new SchemaNotFoundException("Superclass "+ superClass + " does not exists");
|
||||||
|
}
|
||||||
if (baseType != null) {
|
if (baseType != null) {
|
||||||
if (typeDefinition.getName().compareTo(baseType) != 0) {
|
if (typeDefinition.getName().compareTo(baseType) != 0) {
|
||||||
if (!oSuperClass.isSubClassOf(baseType)) {
|
if (!oSuperClass.isSubClassOf(baseType)) {
|
||||||
|
@ -212,6 +217,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
if (typeDefinition.getDescription() != null) {
|
if (typeDefinition.getDescription() != null) {
|
||||||
try {
|
try {
|
||||||
oClass.setDescription(typeDefinition.getDescription());
|
oClass.setDescription(typeDefinition.getDescription());
|
||||||
|
@ -313,9 +320,19 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
logger.info("{} type registered successfully: {}",
|
logger.info("{} type registered successfully: {}",
|
||||||
baseType.getName(), jsonSchema);
|
baseType.getName(), jsonSchema);
|
||||||
return ret;
|
return ret;
|
||||||
|
}catch (Exception e) {
|
||||||
} catch (Exception e) {
|
oSchema. dropClass(typeDefinition.getName());
|
||||||
throw new SchemaException(e);
|
throw e;
|
||||||
|
}
|
||||||
|
} catch (OSchemaException ex) {
|
||||||
|
if(ex.getMessage().contains("already exists")){
|
||||||
|
throw new SchemaAlreadyPresentException(ex);
|
||||||
|
}
|
||||||
|
throw new SchemaException(ex);
|
||||||
|
} catch (SchemaException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new SchemaException(ex);
|
||||||
} finally {
|
} finally {
|
||||||
if (orientGraphNoTx != null) {
|
if (orientGraphNoTx != null) {
|
||||||
orientGraphNoTx.shutdown();
|
orientGraphNoTx.shutdown();
|
||||||
|
|
Loading…
Reference in New Issue