2019-11-04 18:01:20 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.instances.context.relations;
|
2018-06-06 19:26:19 +02:00
|
|
|
|
2019-10-25 17:45:59 +02:00
|
|
|
import org.gcube.informationsystem.base.reference.AccessType;
|
2019-11-04 18:01:20 +01:00
|
|
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.relations.Relation;
|
2019-11-04 18:01:20 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
2018-06-04 15:31:13 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
2017-11-15 19:31:49 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2017-11-17 11:42:37 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfNotFoundException;
|
2020-01-27 17:04:45 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.contexts.SecurityContext;
|
2017-11-28 17:34:43 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
2019-11-04 18:01:20 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
2017-11-23 09:39:21 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
2017-11-15 19:31:49 +01:00
|
|
|
|
2017-11-23 09:39:21 +01:00
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
2019-02-13 12:33:29 +01:00
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
2019-11-05 18:36:44 +01:00
|
|
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
|
|
|
import com.orientechnologies.orient.core.record.ODirection;
|
|
|
|
import com.orientechnologies.orient.core.record.OVertex;
|
2017-11-15 19:31:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2019-11-08 12:29:32 +01:00
|
|
|
public class IsParentOfManagement extends BaseRelationManagement<ContextManagement,ContextManagement> {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
public IsParentOfManagement() {
|
2019-11-04 18:01:20 +01:00
|
|
|
super(AccessType.IS_PARENT_OF, Context.class, Context.class);
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-11-05 18:36:44 +01:00
|
|
|
public IsParentOfManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
2017-11-28 17:34:43 +01:00
|
|
|
this();
|
2019-11-05 18:36:44 +01:00
|
|
|
this.oDatabaseDocument = oDatabaseDocument;
|
2017-11-28 17:34:43 +01:00
|
|
|
getWorkingContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
|
|
|
if(workingContext == null) {
|
2017-12-05 10:10:34 +01:00
|
|
|
workingContext = ContextUtility.getInstance()
|
2017-11-30 18:06:08 +01:00
|
|
|
.getSecurityContextByUUID(DatabaseEnvironment.CONTEXT_SECURITY_CONTEXT_UUID);
|
2017-11-28 17:34:43 +01:00
|
|
|
}
|
|
|
|
return workingContext;
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|
2017-11-23 09:39:21 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
@Override
|
2018-06-04 15:31:13 +02:00
|
|
|
protected IsParentOfNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
2017-11-17 11:42:37 +01:00
|
|
|
return new IsParentOfNotFoundException(e.getMessage(), e.getCause());
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
@Override
|
|
|
|
protected IsParentOfAlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
|
|
|
return new IsParentOfAlreadyPresentException(message);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
@Override
|
2019-02-13 12:33:29 +01:00
|
|
|
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
2017-11-15 19:31:49 +01:00
|
|
|
return serializeAsJson(false, true);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-02-13 12:33:29 +01:00
|
|
|
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
|
|
|
JsonNode relation = serializeSelfOnly();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
try {
|
2019-11-05 18:36:44 +01:00
|
|
|
OVertex source = element.getVertex(ODirection.OUT);
|
|
|
|
ContextManagement sourceContextManagement = new ContextManagement(oDatabaseDocument);
|
2017-11-15 19:31:49 +01:00
|
|
|
sourceContextManagement.setElement(source);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(includeSource) {
|
2019-02-13 12:33:29 +01:00
|
|
|
((ObjectNode)relation).replace(Relation.SOURCE_PROPERTY, sourceContextManagement.serializeSelfOnly());
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2019-11-05 18:36:44 +01:00
|
|
|
OVertex target = element.getVertex(ODirection.IN);
|
|
|
|
ContextManagement targetContextManagement = new ContextManagement(oDatabaseDocument);
|
2017-11-15 19:31:49 +01:00
|
|
|
targetContextManagement.setElement(target);
|
2017-11-30 18:06:08 +01:00
|
|
|
if(includeTarget) {
|
2019-02-13 12:33:29 +01:00
|
|
|
((ObjectNode)relation).replace(Relation.TARGET_PROPERTY, targetContextManagement.serializeSelfOnly());
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
2017-11-15 19:31:49 +01:00
|
|
|
throw e;
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
2017-11-15 19:31:49 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
return relation;
|
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
@Override
|
2019-11-04 18:01:20 +01:00
|
|
|
protected ContextManagement newSourceEntityManagement() throws ResourceRegistryException {
|
2019-11-05 18:36:44 +01:00
|
|
|
return new ContextManagement(oDatabaseDocument);
|
2017-11-17 11:42:37 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
@Override
|
2019-11-04 18:01:20 +01:00
|
|
|
protected ContextManagement newTargetEntityManagement() throws ResourceRegistryException {
|
2019-11-05 18:36:44 +01:00
|
|
|
return new ContextManagement(oDatabaseDocument);
|
2019-11-04 18:01:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException {
|
2017-11-17 11:42:37 +01:00
|
|
|
throw new UnsupportedOperationException();
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|
2019-11-04 18:01:20 +01:00
|
|
|
|
2017-11-17 12:31:22 +01:00
|
|
|
@Override
|
2019-11-04 18:01:20 +01:00
|
|
|
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
|
|
|
throws ContextException, ResourceRegistryException {
|
|
|
|
throw new UnsupportedOperationException();
|
2017-11-17 12:31:22 +01:00
|
|
|
}
|
2019-11-04 18:01:20 +01:00
|
|
|
|
2017-11-17 12:31:22 +01:00
|
|
|
@Override
|
2019-11-04 18:01:20 +01:00
|
|
|
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
|
|
|
throw new UnsupportedOperationException();
|
2017-11-17 12:31:22 +01:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2017-11-15 19:31:49 +01:00
|
|
|
}
|