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> </parent>
<groupId>org.gcube.information-system</groupId> <groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry</artifactId> <artifactId>resource-registry</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<name>Resource Registry</name> <name>Resource Registry</name>
<description>Resource Registry</description> <description>Resource Registry</description>
<packaging>war</packaging> <packaging>war</packaging>

View File

@ -131,6 +131,7 @@ public class SecurityContext {
contextID); contextID);
} }
public static void deleteSecurityContext(OrientGraph orientGraph, public static void deleteSecurityContext(OrientGraph orientGraph,
String contextID, boolean commit) { String contextID, boolean commit) {
@ -141,18 +142,49 @@ public class SecurityContext {
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata() OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
.getSecurity(); .getSecurity();
oSecurity.dropUser(SecurityContextMapper.getSecurityRoleOrUserName( String user = SecurityContextMapper.getSecurityRoleOrUserName(
SecurityContextMapper.PermissionMode.READER, SecurityContextMapper.PermissionMode.READER,
SecurityContextMapper.SecurityType.USER, contextID)); SecurityContextMapper.SecurityType.USER, contextID);
oSecurity.dropUser(SecurityContextMapper.getSecurityRoleOrUserName( 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.PermissionMode.WRITER,
SecurityContextMapper.SecurityType.USER, contextID)); SecurityContextMapper.SecurityType.USER, contextID);
oSecurity.dropRole(SecurityContextMapper.getSecurityRoleOrUserName( 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.PermissionMode.READER,
SecurityContextMapper.SecurityType.ROLE, contextID)); SecurityContextMapper.SecurityType.ROLE, contextID);
oSecurity.dropRole(SecurityContextMapper.getSecurityRoleOrUserName( 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.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) { if (commit) {
orientGraph.commit(); orientGraph.commit();

View File

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

View File

@ -46,7 +46,7 @@ public class EntityRegistrationAction implements ERAction {
schemaManagement.registerRelationSchema(json); schemaManagement.registerRelationSchema(json);
} }
} catch(Exception ex){ } 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; throw ex;
} }
} }
@ -64,7 +64,7 @@ public class EntityRegistrationAction implements ERAction {
schemaManagement.registerEntitySchema(json); schemaManagement.registerEntitySchema(json);
} }
} catch(Exception ex){ } 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; throw ex;
} }
} }
@ -74,15 +74,18 @@ public class EntityRegistrationAction implements ERAction {
if(e==Embedded.class){ if(e==Embedded.class){
logger.trace("Discarding {} because is just a convenient interface", e); logger.trace("Discarding {} because is just a convenient interface", e);
return; 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 Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (lucio.lelii@isti.cnr.it) * @author Lucio Lelii (ISTI - CNR)
*/ */
@Path(ContextPath.CONTEXT_PATH_PART) @Path(ContextPath.CONTEXT_PATH_PART)
public class ContextManager { public class ContextManager {

View File

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

View File

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

View File

@ -7,7 +7,7 @@ import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
import org.gcube.informationsystem.model.embedded.Header; 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.model.relation.IsParentOf;
import org.gcube.informationsystem.resourceregistry.api.ContextManagement; import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException; 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.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph; import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.frames.FramedGraph; import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import com.tinkerpop.frames.FramedGraphFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -136,31 +135,24 @@ public class ContextManagementImpl implements ContextManagement {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
String uuidString = uuid.toString(); String uuidString = uuid.toString();
SecurityContext.createSecurityContext(orientGraph, uuidString, true); SecurityContext.createSecurityContext(orientGraph, uuidString, true);
try { try {
FramedGraphFactory framedGraphFactory = new FramedGraphFactory(); OrientVertex context = orientGraph.addVertex("class:"
FramedGraph<OrientGraph> framedGraph = framedGraphFactory + Context.NAME);
.create(orientGraph); context.setProperty(Context.NAME_PROPERTY, name);
Context context = framedGraph.addVertex("class:"
+ org.gcube.informationsystem.model.entity.Context.NAME,
Context.class);
context.setName(name);
HeaderUtility.addHeader(context, uuid); HeaderUtility.addHeader(context, uuid);
if (parentContextUUID != null) { if (parentContextUUID != null) {
orientGraph.addEdge(null, parent, context.asVertex(), orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
IsParentOf.NAME);
} }
SecurityContext.addToSecurityContext(orientGraph, SecurityContext.addToSecurityContext(orientGraph, context,
context.asVertex(), uuidString); uuidString);
String contextJsonString = Utility.toJsonString(context.asVertex(), true); String contextJsonString = Utility.toJsonString(context, true);
logger.trace("Creating {}", contextJsonString); logger.trace("Creating {}", contextJsonString);
orientGraph.commit(); orientGraph.commit();
@ -170,7 +162,8 @@ public class ContextManagementImpl implements ContextManagement {
} catch (Exception e) { } catch (Exception e) {
orientGraph.rollback(); orientGraph.rollback();
SecurityContext.deleteSecurityContext(orientGraph, uuidString, true); SecurityContext
.deleteSecurityContext(orientGraph, uuidString, true);
throw new InternalException(e.getMessage()); throw new InternalException(e.getMessage());
} finally { } finally {
orientGraph.shutdown(); orientGraph.shutdown();

View File

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

View File

@ -153,7 +153,7 @@ public class SchemaManagementImpl implements SchemaManagement {
OrientGraphNoTx orientGraphNoTx = null; OrientGraphNoTx orientGraphNoTx = null;
try { try {
logger.trace("Trying to register {} {}", baseType, jsonSchema); logger.info("Trying to register {} {}", baseType, jsonSchema);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
TypeDefinition typeDefinition = mapper.readValue(jsonSchema, TypeDefinition typeDefinition = mapper.readValue(jsonSchema,
@ -239,7 +239,7 @@ public class SchemaManagementImpl implements SchemaManagement {
OrientGraphNoTx orientGraphNoTx = null; OrientGraphNoTx orientGraphNoTx = null;
try { try {
logger.trace("Trying to register {} {}", baseType, jsonSchema); logger.info("Trying to register {} {}", baseType, jsonSchema);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
TypeDefinition typeDefinition = mapper.readValue(jsonSchema, TypeDefinition typeDefinition = mapper.readValue(jsonSchema,
@ -311,7 +311,7 @@ public class SchemaManagementImpl implements SchemaManagement {
OrientGraphNoTx orientGraphNoTx = null; OrientGraphNoTx orientGraphNoTx = null;
try { try {
logger.trace("Trying to register {}", jsonSchema); logger.info("Trying to register {}", jsonSchema);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
TypeDefinition typeDefinition = mapper.readValue(jsonSchema, 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.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.informationsystem.model.orientdb.impl.entity.Context; import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.model.orientdb.impl.entity.Entity; import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; 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.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; 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.provider.ClientInfo;
import org.gcube.common.authorization.library.utils.Caller; import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.informationsystem.model.orientdb.impl.embedded.Header; import org.gcube.informationsystem.model.orientdb.impl.embedded.Header;
import org.gcube.informationsystem.model.orientdb.impl.entity.Entity; import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.orientdb.impl.relation.Relation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -72,12 +71,6 @@ public class HeaderUtility {
return header; 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) { public static Header addHeader(Edge edge, UUID uuid) {
Header header = createHeader(uuid); Header header = createHeader(uuid);
@ -85,10 +78,4 @@ public class HeaderUtility {
return header; return header;
} }
public static Header addHeader(@SuppressWarnings("rawtypes") Relation relation, UUID uuid) {
Header header = createHeader(uuid);
relation.setHeader(header);
return header;
}
} }