Cleaned code
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134066 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d6b3db8609
commit
810ec013bf
|
@ -8,10 +8,6 @@ import java.util.UUID;
|
|||
|
||||
import org.gcube.informationsystem.model.embedded.Header;
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
import org.gcube.informationsystem.model.entity.Entity;
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.relation.IsParentOf;
|
||||
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
|
||||
|
@ -19,12 +15,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.utils.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.utils.HeaderUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.utils.Utility;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -109,9 +102,7 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
public Vertex getContext(OrientGraph orientGraph, UUID context)
|
||||
throws ContextNotFoundException {
|
||||
try {
|
||||
return Utility.getEntityByUUID(orientGraph,
|
||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||
context);
|
||||
return Utility.getEntityByUUID(orientGraph, Context.NAME, context);
|
||||
} catch (ResourceRegistryException e) {
|
||||
throw new ContextNotFoundException(e.getMessage());
|
||||
}
|
||||
|
@ -127,10 +118,7 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
try {
|
||||
logger.info(
|
||||
"Trying to create {} with name {} and parent {} UUID {}",
|
||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||
name,
|
||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||
parentContext);
|
||||
Context.NAME, name, Context.NAME, parentContext);
|
||||
|
||||
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||
|
@ -265,8 +253,7 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
try {
|
||||
logger.info(
|
||||
"Trying to move {} with UUID {} as child of {} with UUID {}",
|
||||
Context.NAME, contextToMoveUUID, Context.NAME,
|
||||
newParentUUID);
|
||||
Context.NAME, contextToMoveUUID, Context.NAME, newParentUUID);
|
||||
|
||||
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||
|
@ -374,59 +361,4 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
}
|
||||
}
|
||||
|
||||
protected <E extends Entity> boolean addEntityToContext(Class<E> clz,
|
||||
UUID uuid) throws FacetNotFoundException,
|
||||
ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
EntityManagementImpl entityManagement = new EntityManagementImpl();
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||
PermissionMode.WRITER).getTx();
|
||||
|
||||
Vertex vertex = entityManagement.getEntity(orientGraph, uuid, null,
|
||||
clz);
|
||||
|
||||
UUID contextUUID = ContextUtility.addToActualContext(orientGraph, vertex);
|
||||
|
||||
if (Resource.class.isAssignableFrom(clz)) {
|
||||
Iterable<Vertex> facets = vertex.getVertices(Direction.OUT,
|
||||
ConsistsOf.NAME);
|
||||
for (Vertex facet : facets) {
|
||||
ContextUtility.addToActualContext(orientGraph, facet);
|
||||
}
|
||||
}
|
||||
|
||||
orientGraph.commit();
|
||||
logger.info("{} with UUID {} successfully added to actual Context with UUID {}", clz.getSimpleName(),
|
||||
uuid, contextUUID);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw new ContextException(e.getMessage());
|
||||
} finally {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addResourceToContext(UUID uuid)
|
||||
throws ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
return addEntityToContext(Resource.class, uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFacetToContext(UUID uuid) throws FacetNotFoundException,
|
||||
ContextNotFoundException, ResourceRegistryException {
|
||||
return addEntityToContext(Facet.class, uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue