2019-11-04 18:01:20 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.instances.type.entities;
|
|
|
|
|
|
|
|
import javax.ws.rs.NotAcceptableException;
|
|
|
|
|
|
|
|
import org.gcube.informationsystem.base.reference.AccessType;
|
|
|
|
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.base.entities.BaseEntityManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
|
|
|
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
2019-11-05 18:36:44 +01:00
|
|
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
|
|
|
import com.orientechnologies.orient.core.record.OVertex;
|
2019-11-04 18:01:20 +01:00
|
|
|
|
|
|
|
public class EntityTypeDefinitionManagement<ETD extends EntityTypeDefinition<? extends BaseEntity>> extends BaseEntityManagement<ETD> {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ContextManagement.class);
|
|
|
|
|
|
|
|
protected String name;
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
this.elementType = EntityTypeDefinition.NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityTypeDefinitionManagement() {
|
|
|
|
super(AccessType.ENTITY_TYPE_DEFINITION);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2019-11-05 18:36:44 +01:00
|
|
|
public EntityTypeDefinitionManagement(ODatabaseDocument orientGraph) throws ResourceRegistryException {
|
2019-11-04 18:01:20 +01:00
|
|
|
this();
|
2019-11-05 18:36:44 +01:00
|
|
|
this.oDatabaseDocument = orientGraph;
|
2019-11-04 18:01:20 +01:00
|
|
|
getWorkingContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
if(name == null) {
|
|
|
|
if(element == null) {
|
|
|
|
if(jsonNode != null) {
|
|
|
|
name = jsonNode.get(EntityTypeDefinition.NAME_PROPERTY).asText();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
name = element.getProperty(EntityTypeDefinition.NAME_PROPERTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
|
|
|
if(workingContext == null) {
|
|
|
|
workingContext = ContextUtility.getInstance()
|
|
|
|
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
|
|
|
}
|
|
|
|
return workingContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SchemaNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
|
|
|
return new SchemaNotFoundException(e.getMessage(), e.getCause());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
|
|
|
throw new NotAcceptableException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected AlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
|
|
|
throw new NotAcceptableException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String serialize() throws ResourceRegistryException {
|
|
|
|
return serializeAsJson().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
|
|
|
return serializeSelfOnly();
|
|
|
|
// For Resources Definition include mandatory and suggested IsRelatedTo and ConsistsOf
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-05 18:36:44 +01:00
|
|
|
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
2019-11-04 18:01:20 +01:00
|
|
|
logger.debug("Going to create {} for {}", EntityTypeDefinition.NAME, getName());
|
|
|
|
return createVertex();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-05 18:36:44 +01:00
|
|
|
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
2019-11-04 18:01:20 +01:00
|
|
|
logger.debug("Going to update {} for {}", EntityTypeDefinition.NAME, getName());
|
2019-11-05 18:36:44 +01:00
|
|
|
OVertex entityTypeDefinition = getElement();
|
|
|
|
entityTypeDefinition = (OVertex) ERManagement.updateProperties(oClass, entityTypeDefinition, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
2019-11-04 18:01:20 +01:00
|
|
|
return entityTypeDefinition;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
|
|
|
logger.debug("Going to remove {} for {}", EntityTypeDefinition.NAME, getName());
|
2019-11-05 18:36:44 +01:00
|
|
|
getElement().delete();
|
2019-11-04 18:01:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|