Refactoring service

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@133536 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-10-25 15:58:40 +00:00
parent 31210ba8c3
commit a887ffaaf2
13 changed files with 93 additions and 77 deletions

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>Resource Registry</name>
<description>Resource Registry</description>
<packaging>war</packaging>

View File

@ -130,7 +130,8 @@ public class SecurityContext {
"Security Context (roles and users) with UUID {} successfully created",
contextID);
}
public static void deleteSecurityContext(OrientGraph orientGraph,
String contextID, boolean commit) {
@ -141,19 +142,50 @@ public class SecurityContext {
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
.getSecurity();
oSecurity.dropUser(SecurityContextMapper.getSecurityRoleOrUserName(
String user = SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.PermissionMode.READER,
SecurityContextMapper.SecurityType.USER, contextID));
oSecurity.dropUser(SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.SecurityType.USER, contextID);
boolean dropped = oSecurity.dropUser(user);
if(dropped){
logger.trace("{} successfully dropped", user);
}else{
logger.error("{} was not dropped successfully", user);
}
user = SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.PermissionMode.WRITER,
SecurityContextMapper.SecurityType.USER, contextID));
oSecurity.dropRole(SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.SecurityType.USER, contextID);
dropped = oSecurity.dropUser(user);
if(dropped){
logger.trace("{} successfully dropped", user);
}else{
logger.error("{} was not dropped successfully", user);
}
String role = SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.PermissionMode.READER,
SecurityContextMapper.SecurityType.ROLE, contextID));
oSecurity.dropRole(SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.SecurityType.ROLE, contextID);
dropped = oSecurity.dropRole(role);
if(dropped){
logger.trace("{} successfully dropped", role);
}else{
logger.error("{} was not dropped successfully", role);
}
role = SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.PermissionMode.WRITER,
SecurityContextMapper.SecurityType.ROLE, contextID));
SecurityContextMapper.SecurityType.ROLE, contextID);
dropped = oSecurity.dropRole(role);
if(dropped){
logger.trace("{} successfully dropped", role);
}else{
logger.error("{} was not dropped successfully", role);
}
if (commit) {
orientGraph.commit();
}

View File

@ -30,7 +30,7 @@ public abstract class SecurityContextMapper {
static {
try {
boolean created = DatabaseIntializator.initGraphDB();
logger.trace("Creating factory for {} connecting as {}",
DatabaseEnvironment.DB_URI,
DatabaseEnvironment.DEFAULT_ADMIN_USERNAME);

View File

@ -5,6 +5,7 @@ package org.gcube.informationsystem.resourceregistry.dbinitialization;
import org.gcube.informationsystem.impl.utils.discovery.ERDiscovery;
import org.gcube.informationsystem.model.embedded.Embedded;
import org.gcube.informationsystem.model.embedded.ValueSchema;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.relation.Relation;
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
@ -38,11 +39,13 @@ public class DatabaseIntializator {
private static final String O_RESTRICTED_CLASS = "ORestricted";
public static boolean initGraphDB() throws Exception {
/*
OLogManager.instance().setWarnEnabled(false);
OLogManager.instance().setErrorEnabled(false);
OLogManager.instance().setInfoEnabled(false);
OLogManager.instance().setDebugEnabled(false);
*/
logger.trace("Connecting to {} as {} to create new DB",
DatabaseEnvironment.SERVER_URI, DatabaseEnvironment.USERNAME);
@ -119,6 +122,7 @@ public class DatabaseIntializator {
erDiscovery.discoverERTypes();
EntityRegistrationAction entityRegistrationAction = new EntityRegistrationAction();
entityRegistrationAction.manageEmbeddedClass(ValueSchema.class);
erDiscovery.manageDiscoveredERTypes(entityRegistrationAction);
}

View File

@ -46,7 +46,7 @@ public class EntityRegistrationAction implements ERAction {
schemaManagement.registerRelationSchema(json);
}
} catch(Exception ex){
logger.error("Error creating schema for {} type {} : {}", Relation.NAME, r.getClass().getSimpleName(), ex.getMessage());
logger.error("Error creating schema for {} type {} : {}", Relation.NAME, r.getSimpleName(), ex.getMessage());
throw ex;
}
}
@ -64,7 +64,7 @@ public class EntityRegistrationAction implements ERAction {
schemaManagement.registerEntitySchema(json);
}
} catch(Exception ex){
logger.error("Error creating schema for {} type {} : {}", Entity.NAME, e.getClass().getSimpleName(), ex.getMessage());
logger.error("Error creating schema for {} type {} : {}", Entity.NAME, e.getSimpleName(), ex.getMessage());
throw ex;
}
}
@ -74,15 +74,18 @@ public class EntityRegistrationAction implements ERAction {
if(e==Embedded.class){
logger.trace("Discarding {} because is just a convenient interface", e);
return;
}else{
try{
String json = TypeBinder.serializeType(e);
logger.trace(json);
schemaManagement.registerEmbeddedTypeSchema(json);
} catch(Exception ex){
logger.error("Error creating schema for {} type {} : {}", Embedded.NAME, e.getClass().getSimpleName(), ex.getMessage());
throw ex;
}
}
try {
String json = TypeBinder.serializeType(e);
logger.trace(json);
schemaManagement.registerEmbeddedTypeSchema(json);
} catch (Exception ex) {
logger.error("Error creating schema for {} type {} : {}",
Embedded.NAME, e.getSimpleName(),
ex.getMessage());
throw ex;
}
}
}

View File

@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
* @author Lucio Lelii (ISTI - CNR)
*/
@Path(ContextPath.CONTEXT_PATH_PART)
public class ContextManager {

View File

@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
* @author Lucio Lelii (ISTI - CNR)
*/
@Path(EntityPath.ENTITY_PATH_PART)
public class EntityManager {

View File

@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
* @author Lucio Lelii (ISTI - CNR)
*/
@ApplicationPath(SchemaPath.SCHEMA_PATH_PART)
public class SchemaManager {

View File

@ -7,7 +7,7 @@ import java.util.Iterator;
import java.util.UUID;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.orientdb.impl.entity.Context;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.model.relation.IsParentOf;
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
@ -28,8 +28,7 @@ import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.frames.FramedGraph;
import com.tinkerpop.frames.FramedGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
/**
* @author Luca Frosini (ISTI - CNR)
@ -132,35 +131,28 @@ public class ContextManagementImpl implements ContextManagement {
} catch (ContextException e) {
throw new ContextCreationException(e.getMessage());
}
UUID uuid = UUID.randomUUID();
String uuidString = uuid.toString();
SecurityContext.createSecurityContext(orientGraph, uuidString, true);
try {
FramedGraphFactory framedGraphFactory = new FramedGraphFactory();
FramedGraph<OrientGraph> framedGraph = framedGraphFactory
.create(orientGraph);
Context context = framedGraph.addVertex("class:"
+ org.gcube.informationsystem.model.entity.Context.NAME,
Context.class);
context.setName(name);
try {
OrientVertex context = orientGraph.addVertex("class:"
+ Context.NAME);
context.setProperty(Context.NAME_PROPERTY, name);
HeaderUtility.addHeader(context, uuid);
if (parentContextUUID != null) {
orientGraph.addEdge(null, parent, context.asVertex(),
IsParentOf.NAME);
orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
}
SecurityContext.addToSecurityContext(orientGraph,
context.asVertex(), uuidString);
SecurityContext.addToSecurityContext(orientGraph, context,
uuidString);
String contextJsonString = Utility.toJsonString(context.asVertex(), true);
String contextJsonString = Utility.toJsonString(context, true);
logger.trace("Creating {}", contextJsonString);
orientGraph.commit();
@ -170,7 +162,8 @@ public class ContextManagementImpl implements ContextManagement {
} catch (Exception e) {
orientGraph.rollback();
SecurityContext.deleteSecurityContext(orientGraph, uuidString, true);
SecurityContext
.deleteSecurityContext(orientGraph, uuidString, true);
throw new InternalException(e.getMessage());
} finally {
orientGraph.shutdown();
@ -227,7 +220,7 @@ public class ContextManagementImpl implements ContextManagement {
logger.info("Context renamed {}", contextJsonString);
orientGraph.shutdown();
return contextUUID;
}
@ -268,11 +261,11 @@ public class ContextManagementImpl implements ContextManagement {
}
orientGraph.commit();
context = getContext(orientGraph, contextToMoveUUID);
String contextJsonString = Utility.toJsonString(context, true);
logger.info("Context moved {}", contextJsonString);
orientGraph.shutdown();
return contextToMoveUUID;
}

View File

@ -273,10 +273,8 @@ public class EntityManagementImpl implements EntityManagement {
try {
targetHeader = getHeader(target);
} catch (IOException e) {
new ResourceRegistryException(e);
throw new ResourceRegistryException(e);
}
Class<? extends Entity> targetClass = null;
Vertex targetVertex = null;
@ -284,9 +282,7 @@ public class EntityManagementImpl implements EntityManagement {
if (ConsistsOf.class.isAssignableFrom(relation)) {
targetVertex = createVertexEntity(
orientGraph, getClassProperty(target),
Facet.class,
target.toString(), true);
targetClass = Facet.class;
Facet.class, target.toString(), true);
targetHeader = targetVertex.getProperty(Facet.HEADER_PROPERTY);
} else {
String error = String.format(
@ -299,6 +295,7 @@ public class EntityManagementImpl implements EntityManagement {
}else {
// The target Entity was already created we just need to create
// the right relation
Class<? extends Entity> targetClass = null;
if(ConsistsOf.class.isAssignableFrom(relation)) {
targetClass = Facet.class;
@ -467,7 +464,7 @@ public class EntityManagementImpl implements EntityManagement {
edgeProperties = getPropertyMap(jsonNode, ignoreKeys);
} catch (Exception e) {
new ResourceRegistryException(
throw new ResourceRegistryException(
"Error while setting Relation Properties", e);
}
}

View File

@ -153,7 +153,7 @@ public class SchemaManagementImpl implements SchemaManagement {
OrientGraphNoTx orientGraphNoTx = null;
try {
logger.trace("Trying to register {} {}", baseType, jsonSchema);
logger.info("Trying to register {} {}", baseType, jsonSchema);
ObjectMapper mapper = new ObjectMapper();
TypeDefinition typeDefinition = mapper.readValue(jsonSchema,
@ -239,7 +239,7 @@ public class SchemaManagementImpl implements SchemaManagement {
OrientGraphNoTx orientGraphNoTx = null;
try {
logger.trace("Trying to register {} {}", baseType, jsonSchema);
logger.info("Trying to register {} {}", baseType, jsonSchema);
ObjectMapper mapper = new ObjectMapper();
TypeDefinition typeDefinition = mapper.readValue(jsonSchema,
@ -311,7 +311,7 @@ public class SchemaManagementImpl implements SchemaManagement {
OrientGraphNoTx orientGraphNoTx = null;
try {
logger.trace("Trying to register {}", jsonSchema);
logger.info("Trying to register {}", jsonSchema);
ObjectMapper mapper = new ObjectMapper();
TypeDefinition typeDefinition = mapper.readValue(jsonSchema,

View File

@ -7,8 +7,8 @@ import java.util.Iterator;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.informationsystem.model.orientdb.impl.entity.Context;
import org.gcube.informationsystem.model.orientdb.impl.entity.Entity;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;

View File

@ -12,8 +12,7 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.informationsystem.model.orientdb.impl.embedded.Header;
import org.gcube.informationsystem.model.orientdb.impl.entity.Entity;
import org.gcube.informationsystem.model.orientdb.impl.relation.Relation;
import org.gcube.informationsystem.model.entity.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -72,23 +71,11 @@ public class HeaderUtility {
return header;
}
public static Header addHeader(Entity entity, UUID uuid) {
Header header = createHeader(uuid);
entity.setHeader(header);
return header;
}
public static Header addHeader(Edge edge, UUID uuid) {
Header header = createHeader(uuid);
edge.setProperty(Entity.HEADER_PROPERTY, header);
return header;
}
public static Header addHeader(@SuppressWarnings("rawtypes") Relation relation, UUID uuid) {
Header header = createHeader(uuid);
relation.setHeader(header);
return header;
}
}