Merged from private branch
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@133659 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a0d1bd8be4
commit
42372f041b
|
@ -7,6 +7,9 @@
|
||||||
<dependent-module archiveName="resource-registry-api-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/resource-registry-api/resource-registry-api">
|
<dependent-module archiveName="resource-registry-api-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/resource-registry-api/resource-registry-api">
|
||||||
<dependency-type>uses</dependency-type>
|
<dependency-type>uses</dependency-type>
|
||||||
</dependent-module>
|
</dependent-module>
|
||||||
|
<dependent-module archiveName="information-system-model-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/information-system-model/information-system-model">
|
||||||
|
<dependency-type>uses</dependency-type>
|
||||||
|
</dependent-module>
|
||||||
<dependent-module archiveName="information-system-model-orientdb-binding-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/information-system-model-orientdb-binding/information-system-model-orientdb-binding">
|
<dependent-module archiveName="information-system-model-orientdb-binding-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/information-system-model-orientdb-binding/information-system-model-orientdb-binding">
|
||||||
<dependency-type>uses</dependency-type>
|
<dependency-type>uses</dependency-type>
|
||||||
</dependent-module>
|
</dependent-module>
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.context;
|
package org.gcube.informationsystem.resourceregistry.context;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -35,53 +36,53 @@ public class SecurityContext {
|
||||||
public static final String DEFAULT_READER_ROLE = "reader";
|
public static final String DEFAULT_READER_ROLE = "reader";
|
||||||
|
|
||||||
public static void addToSecurityContext(OrientGraph orientGraph,
|
public static void addToSecurityContext(OrientGraph orientGraph,
|
||||||
Vertex vertex, String contextID) {
|
Vertex vertex, UUID context) {
|
||||||
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
|
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
|
||||||
.getSecurity();
|
.getSecurity();
|
||||||
SecurityContext.addToSecurityContext(oSecurity, vertex, contextID);
|
SecurityContext.addToSecurityContext(oSecurity, vertex, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToSecurityContext(OSecurity oSecurity, Vertex vertex,
|
public static void addToSecurityContext(OSecurity oSecurity, Vertex vertex,
|
||||||
String contextID) {
|
UUID context) {
|
||||||
OrientVertex orientVertex = (OrientVertex) vertex;
|
OrientVertex orientVertex = (OrientVertex) vertex;
|
||||||
|
|
||||||
SecurityContext.allowSecurityContextRoles(oSecurity,
|
SecurityContext.allowSecurityContextRoles(oSecurity,
|
||||||
orientVertex.getRecord(), contextID);
|
orientVertex.getRecord(), context);
|
||||||
|
|
||||||
Iterable<Edge> iterable = vertex.getEdges(Direction.BOTH);
|
Iterable<Edge> iterable = vertex.getEdges(Direction.BOTH);
|
||||||
Iterator<Edge> iterator = iterable.iterator();
|
Iterator<Edge> iterator = iterable.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
OrientEdge edge = (OrientEdge) iterator.next();
|
OrientEdge edge = (OrientEdge) iterator.next();
|
||||||
SecurityContext.allowSecurityContextRoles(oSecurity,
|
SecurityContext.allowSecurityContextRoles(oSecurity,
|
||||||
edge.getRecord(), contextID);
|
edge.getRecord(), context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToSecurityContext(OrientGraph orientGraph, Edge edge,
|
public static void addToSecurityContext(OrientGraph orientGraph, Edge edge,
|
||||||
String contextID) {
|
UUID context) {
|
||||||
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
|
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
|
||||||
.getSecurity();
|
.getSecurity();
|
||||||
SecurityContext.addToSecurityContext(oSecurity, edge, contextID);
|
SecurityContext.addToSecurityContext(oSecurity, edge, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToSecurityContext(OSecurity oSecurity, Edge edge,
|
public static void addToSecurityContext(OSecurity oSecurity, Edge edge,
|
||||||
String contextID) {
|
UUID context) {
|
||||||
OrientEdge orientEdge = (OrientEdge) edge;
|
OrientEdge orientEdge = (OrientEdge) edge;
|
||||||
SecurityContext.allowSecurityContextRoles(oSecurity,
|
SecurityContext.allowSecurityContextRoles(oSecurity,
|
||||||
orientEdge.getRecord(), contextID);
|
orientEdge.getRecord(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void allowSecurityContextRoles(OSecurity oSecurity,
|
protected static void allowSecurityContextRoles(OSecurity oSecurity,
|
||||||
ODocument oDocument, String contextID) {
|
ODocument oDocument, UUID context) {
|
||||||
oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_ALL,
|
oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_ALL,
|
||||||
SecurityContextMapper.getSecurityRoleOrUserName(
|
SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.WRITER,
|
SecurityContextMapper.PermissionMode.WRITER,
|
||||||
SecurityContextMapper.SecurityType.ROLE, contextID));
|
SecurityContextMapper.SecurityType.ROLE, context));
|
||||||
|
|
||||||
oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_READ,
|
oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_READ,
|
||||||
SecurityContextMapper.getSecurityRoleOrUserName(
|
SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.READER,
|
SecurityContextMapper.PermissionMode.READER,
|
||||||
SecurityContextMapper.SecurityType.ROLE, contextID));
|
SecurityContextMapper.SecurityType.ROLE, context));
|
||||||
|
|
||||||
// oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_ALL,
|
// oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_ALL,
|
||||||
// DEFAULT_WRITER_ROLE);
|
// DEFAULT_WRITER_ROLE);
|
||||||
|
@ -91,7 +92,7 @@ public class SecurityContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createSecurityContext(OrientGraph orientGraph,
|
public static void createSecurityContext(OrientGraph orientGraph,
|
||||||
String contextID, boolean commit) {
|
UUID context, boolean commit) {
|
||||||
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
|
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
|
||||||
.getSecurity();
|
.getSecurity();
|
||||||
|
|
||||||
|
@ -101,24 +102,24 @@ public class SecurityContext {
|
||||||
ORole writerRole = oSecurity.createRole(SecurityContextMapper
|
ORole writerRole = oSecurity.createRole(SecurityContextMapper
|
||||||
.getSecurityRoleOrUserName(
|
.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.WRITER,
|
SecurityContextMapper.PermissionMode.WRITER,
|
||||||
SecurityContextMapper.SecurityType.ROLE, contextID),
|
SecurityContextMapper.SecurityType.ROLE, context),
|
||||||
writer, ALLOW_MODES.DENY_ALL_BUT);
|
writer, ALLOW_MODES.DENY_ALL_BUT);
|
||||||
|
|
||||||
ORole readerRole = oSecurity.createRole(SecurityContextMapper
|
ORole readerRole = oSecurity.createRole(SecurityContextMapper
|
||||||
.getSecurityRoleOrUserName(
|
.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.READER,
|
SecurityContextMapper.PermissionMode.READER,
|
||||||
SecurityContextMapper.SecurityType.ROLE, contextID),
|
SecurityContextMapper.SecurityType.ROLE, context),
|
||||||
reader, ALLOW_MODES.DENY_ALL_BUT);
|
reader, ALLOW_MODES.DENY_ALL_BUT);
|
||||||
|
|
||||||
oSecurity.createUser(SecurityContextMapper.getSecurityRoleOrUserName(
|
oSecurity.createUser(SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.WRITER,
|
SecurityContextMapper.PermissionMode.WRITER,
|
||||||
SecurityContextMapper.SecurityType.USER, contextID),
|
SecurityContextMapper.SecurityType.USER, context),
|
||||||
DatabaseEnvironment.DEFAULT_PASSWORDS
|
DatabaseEnvironment.DEFAULT_PASSWORDS
|
||||||
.get(SecurityContextMapper.PermissionMode.WRITER),
|
.get(SecurityContextMapper.PermissionMode.WRITER),
|
||||||
writerRole);
|
writerRole);
|
||||||
oSecurity.createUser(SecurityContextMapper.getSecurityRoleOrUserName(
|
oSecurity.createUser(SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.READER,
|
SecurityContextMapper.PermissionMode.READER,
|
||||||
SecurityContextMapper.SecurityType.USER, contextID),
|
SecurityContextMapper.SecurityType.USER, context),
|
||||||
DatabaseEnvironment.DEFAULT_PASSWORDS
|
DatabaseEnvironment.DEFAULT_PASSWORDS
|
||||||
.get(SecurityContextMapper.PermissionMode.READER),
|
.get(SecurityContextMapper.PermissionMode.READER),
|
||||||
readerRole);
|
readerRole);
|
||||||
|
@ -129,22 +130,22 @@ public class SecurityContext {
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"Security Context (roles and users) with UUID {} successfully created",
|
"Security Context (roles and users) with UUID {} successfully created",
|
||||||
contextID);
|
context.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void deleteSecurityContext(OrientGraph orientGraph,
|
public static void deleteSecurityContext(OrientGraph orientGraph,
|
||||||
String contextID, boolean commit) {
|
UUID context, boolean commit) {
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"Going to remove Security Context (roles and users) with UUID {}",
|
"Going to remove Security Context (roles and users) with UUID {}",
|
||||||
contextID);
|
context.toString());
|
||||||
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraph.getRawGraph();
|
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraph.getRawGraph();
|
||||||
OSecurity oSecurity = oDatabaseDocumentTx.getMetadata().getSecurity();
|
OSecurity oSecurity = oDatabaseDocumentTx.getMetadata().getSecurity();
|
||||||
|
|
||||||
String user = SecurityContextMapper.getSecurityRoleOrUserName(
|
String user = SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.READER,
|
SecurityContextMapper.PermissionMode.READER,
|
||||||
SecurityContextMapper.SecurityType.USER, contextID);
|
SecurityContextMapper.SecurityType.USER, context);
|
||||||
boolean dropped = oSecurity.dropUser(user);
|
boolean dropped = oSecurity.dropUser(user);
|
||||||
if(dropped){
|
if(dropped){
|
||||||
logger.trace("{} successfully dropped", user);
|
logger.trace("{} successfully dropped", user);
|
||||||
|
@ -155,7 +156,7 @@ public class SecurityContext {
|
||||||
|
|
||||||
user = SecurityContextMapper.getSecurityRoleOrUserName(
|
user = SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.WRITER,
|
SecurityContextMapper.PermissionMode.WRITER,
|
||||||
SecurityContextMapper.SecurityType.USER, contextID);
|
SecurityContextMapper.SecurityType.USER, context);
|
||||||
dropped = oSecurity.dropUser(user);
|
dropped = oSecurity.dropUser(user);
|
||||||
if(dropped){
|
if(dropped){
|
||||||
logger.trace("{} successfully dropped", user);
|
logger.trace("{} successfully dropped", user);
|
||||||
|
@ -166,7 +167,7 @@ public class SecurityContext {
|
||||||
|
|
||||||
String role = SecurityContextMapper.getSecurityRoleOrUserName(
|
String role = SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.READER,
|
SecurityContextMapper.PermissionMode.READER,
|
||||||
SecurityContextMapper.SecurityType.ROLE, contextID);
|
SecurityContextMapper.SecurityType.ROLE, context);
|
||||||
dropped = oSecurity.dropRole(role);
|
dropped = oSecurity.dropRole(role);
|
||||||
if(dropped){
|
if(dropped){
|
||||||
logger.trace("{} successfully dropped", role);
|
logger.trace("{} successfully dropped", role);
|
||||||
|
@ -177,7 +178,7 @@ public class SecurityContext {
|
||||||
|
|
||||||
role = SecurityContextMapper.getSecurityRoleOrUserName(
|
role = SecurityContextMapper.getSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode.WRITER,
|
SecurityContextMapper.PermissionMode.WRITER,
|
||||||
SecurityContextMapper.SecurityType.ROLE, contextID);
|
SecurityContextMapper.SecurityType.ROLE, context);
|
||||||
dropped = oSecurity.dropRole(role);
|
dropped = oSecurity.dropRole(role);
|
||||||
if(dropped){
|
if(dropped){
|
||||||
logger.trace("{} successfully dropped", role);
|
logger.trace("{} successfully dropped", role);
|
||||||
|
@ -185,12 +186,10 @@ public class SecurityContext {
|
||||||
logger.error("{} was not dropped successfully", role);
|
logger.error("{} was not dropped successfully", role);
|
||||||
}
|
}
|
||||||
|
|
||||||
oSecurity.close(false);
|
|
||||||
oDatabaseDocumentTx.commit();
|
oDatabaseDocumentTx.commit();
|
||||||
oDatabaseDocumentTx.close();
|
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"Security Context (roles and users) with UUID {} successfully removed",
|
"Security Context (roles and users) with UUID {} successfully removed",
|
||||||
contextID);
|
context.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package org.gcube.informationsystem.resourceregistry.context;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseIntializator;
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseIntializator;
|
||||||
|
@ -24,9 +25,13 @@ public abstract class SecurityContextMapper {
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory
|
||||||
.getLogger(SecurityContextMapper.class);
|
.getLogger(SecurityContextMapper.class);
|
||||||
|
|
||||||
public static final String MANAGEMENT_SECURITY_CONTEXT = "ManagementSecurityContext";
|
public static final String ADMIN_SECURITY_CONTEXT = "00000000-0000-0000-0000-000000000000";
|
||||||
|
public static final UUID ADMIN_SECURITY_CONTEXT_UUID = UUID.fromString(ADMIN_SECURITY_CONTEXT);
|
||||||
|
|
||||||
private static final Map<PermissionMode, Map<String, OrientGraphFactory>> securityContextFactories;
|
public static final String MANAGEMENT_SECURITY_CONTEXT = "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
||||||
|
public static final UUID MANAGEMENT_SECURITY_CONTEXT_UUID = UUID.fromString(MANAGEMENT_SECURITY_CONTEXT);
|
||||||
|
|
||||||
|
private static final Map<PermissionMode, Map<UUID, OrientGraphFactory>> securityContextFactories;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
@ -48,20 +53,20 @@ public abstract class SecurityContextMapper {
|
||||||
.ROUND_ROBIN_CONNECT.toString());
|
.ROUND_ROBIN_CONNECT.toString());
|
||||||
|
|
||||||
for (PermissionMode p : PermissionMode.values()) {
|
for (PermissionMode p : PermissionMode.values()) {
|
||||||
Map<String, OrientGraphFactory> map = new HashMap<>();
|
Map<UUID, OrientGraphFactory> map = new HashMap<>();
|
||||||
map.put(null, factory);
|
map.put(ADMIN_SECURITY_CONTEXT_UUID, factory);
|
||||||
securityContextFactories.put(p, map);
|
securityContextFactories.put(p, map);
|
||||||
map.put(null, factory);
|
map.put(ADMIN_SECURITY_CONTEXT_UUID, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (created) {
|
if (created) {
|
||||||
OrientGraph orientGraph = factory.getTx();
|
OrientGraph orientGraph = factory.getTx();
|
||||||
SecurityContext.createSecurityContext(orientGraph,
|
SecurityContext.createSecurityContext(orientGraph,
|
||||||
MANAGEMENT_SECURITY_CONTEXT, true);
|
MANAGEMENT_SECURITY_CONTEXT_UUID, true);
|
||||||
|
|
||||||
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT,
|
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID,
|
||||||
PermissionMode.READER);
|
PermissionMode.READER);
|
||||||
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT,
|
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID,
|
||||||
PermissionMode.WRITER);
|
PermissionMode.WRITER);
|
||||||
|
|
||||||
DatabaseIntializator.createEntitiesAndRelations();
|
DatabaseIntializator.createEntitiesAndRelations();
|
||||||
|
@ -108,18 +113,18 @@ public abstract class SecurityContextMapper {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static OrientGraphFactory getSecurityContextFactory(
|
public static OrientGraphFactory getSecurityContextFactory(
|
||||||
String contextID, PermissionMode permissionMode) {
|
UUID context, PermissionMode permissionMode) {
|
||||||
OrientGraphFactory factory = null;
|
OrientGraphFactory factory = null;
|
||||||
|
|
||||||
Map<String, OrientGraphFactory> permissionSecurityContextFactories = securityContextFactories
|
Map<UUID, OrientGraphFactory> permissionSecurityContextFactories = securityContextFactories
|
||||||
.get(permissionMode);
|
.get(permissionMode);
|
||||||
|
|
||||||
factory = permissionSecurityContextFactories.get(contextID);
|
factory = permissionSecurityContextFactories.get(context);
|
||||||
|
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
|
|
||||||
String username = getSecurityRoleOrUserName(permissionMode,
|
String username = getSecurityRoleOrUserName(permissionMode,
|
||||||
SecurityType.USER, contextID);
|
SecurityType.USER, context);
|
||||||
String password = DatabaseEnvironment.DEFAULT_PASSWORDS
|
String password = DatabaseEnvironment.DEFAULT_PASSWORDS
|
||||||
.get(permissionMode);
|
.get(permissionMode);
|
||||||
|
|
||||||
|
@ -128,7 +133,7 @@ public abstract class SecurityContextMapper {
|
||||||
factory.setConnectionStrategy(OStorageRemote.CONNECTION_STRATEGY
|
factory.setConnectionStrategy(OStorageRemote.CONNECTION_STRATEGY
|
||||||
.ROUND_ROBIN_CONNECT.toString());
|
.ROUND_ROBIN_CONNECT.toString());
|
||||||
|
|
||||||
permissionSecurityContextFactories.put(contextID, factory);
|
permissionSecurityContextFactories.put(context, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory;
|
return factory;
|
||||||
|
@ -136,12 +141,12 @@ public abstract class SecurityContextMapper {
|
||||||
|
|
||||||
public static String getSecurityRoleOrUserName(
|
public static String getSecurityRoleOrUserName(
|
||||||
PermissionMode permissionMode, SecurityType securityType,
|
PermissionMode permissionMode, SecurityType securityType,
|
||||||
String contextID) {
|
UUID context) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append(permissionMode);
|
stringBuilder.append(permissionMode);
|
||||||
stringBuilder.append(securityType);
|
stringBuilder.append(securityType);
|
||||||
stringBuilder.append("_");
|
stringBuilder.append("_");
|
||||||
stringBuilder.append(contextID);
|
stringBuilder.append(context.toString());
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,9 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.utils.Entities;
|
||||||
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.ValueSchema;
|
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;
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -112,13 +110,7 @@ public class DatabaseIntializator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createEntitiesAndRelations() throws Exception {
|
public static void createEntitiesAndRelations() throws Exception {
|
||||||
ERDiscovery.addPackage(Embedded.class.getPackage());
|
ERDiscovery erDiscovery = Entities.getErdiscovery();
|
||||||
ERDiscovery.addPackage(Entity.class.getPackage());
|
|
||||||
ERDiscovery.addPackage(Relation.class.getPackage());
|
|
||||||
|
|
||||||
ERDiscovery erDiscovery = new ERDiscovery();
|
|
||||||
erDiscovery.discoverERTypes();
|
|
||||||
|
|
||||||
EntityRegistrationAction entityRegistrationAction = new EntityRegistrationAction();
|
EntityRegistrationAction entityRegistrationAction = new EntityRegistrationAction();
|
||||||
entityRegistrationAction.manageEmbeddedClass(ValueSchema.class);
|
entityRegistrationAction.manageEmbeddedClass(ValueSchema.class);
|
||||||
erDiscovery.manageDiscoveredERTypes(entityRegistrationAction);
|
erDiscovery.manageDiscoveredERTypes(entityRegistrationAction);
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.resources;
|
package org.gcube.informationsystem.resourceregistry.resources;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiResponse;
|
import io.swagger.annotations.ApiResponse;
|
||||||
import io.swagger.annotations.ApiResponses;
|
import io.swagger.annotations.ApiResponses;
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
|
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.Query;
|
import org.gcube.informationsystem.resourceregistry.api.Query;
|
||||||
|
@ -64,6 +68,7 @@ public class Access {
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code=200, message="Successful query"),
|
@ApiResponse(code=200, message="Successful query"),
|
||||||
@ApiResponse(code=400, message="Invalid or Non-Idempotent Query")})
|
@ApiResponse(code=400, message="Invalid or Non-Idempotent Query")})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String query(@QueryParam(AccessPath.QUERY_PARAM) String query,
|
public String query(@QueryParam(AccessPath.QUERY_PARAM) String query,
|
||||||
@QueryParam(AccessPath.LIMIT_PARAM) int limit,
|
@QueryParam(AccessPath.LIMIT_PARAM) int limit,
|
||||||
@QueryParam(AccessPath.FETCH_PLAN_PARAM) String fetchPlan)
|
@QueryParam(AccessPath.FETCH_PLAN_PARAM) String fetchPlan)
|
||||||
|
@ -81,10 +86,11 @@ public class Access {
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
@Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getFacet(@PathParam(ID_PATH_PARAM) String facetId)
|
public String getFacet(@PathParam(ID_PATH_PARAM) String facetId)
|
||||||
throws FacetNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ResourceRegistryException {
|
||||||
logger.info("Requested Facet with id {}", facetId);
|
logger.info("Requested Facet with id {}", facetId);
|
||||||
return entityManager.readFacet(facetId);
|
return entityManager.readFacet(UUID.fromString(facetId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,6 +101,7 @@ public class Access {
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
@Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getFacetSchema(@PathParam(TYPE_PATH_PARAM) String facetType)
|
public String getFacetSchema(@PathParam(TYPE_PATH_PARAM) String facetType)
|
||||||
throws SchemaNotFoundException {
|
throws SchemaNotFoundException {
|
||||||
logger.info("Requested Facet Schema for type {}", facetType);
|
logger.info("Requested Facet Schema for type {}", facetType);
|
||||||
|
@ -108,11 +115,13 @@ public class Access {
|
||||||
* @throws ResourceNotFoundException
|
* @throws ResourceNotFoundException
|
||||||
* @throws ResourceRegistryException
|
* @throws ResourceRegistryException
|
||||||
*/
|
*/
|
||||||
@GET @Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
@GET
|
||||||
|
@Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getResource(@PathParam(ID_PATH_PARAM) String resourceId)
|
public String getResource(@PathParam(ID_PATH_PARAM) String resourceId)
|
||||||
throws ResourceNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ResourceRegistryException {
|
||||||
logger.info("Requested Resource with id {}", resourceId);
|
logger.info("Requested Resource with id {}", resourceId);
|
||||||
return entityManager.readResource(resourceId);
|
return entityManager.readResource(UUID.fromString(resourceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +130,9 @@ public class Access {
|
||||||
* @return
|
* @return
|
||||||
* @throws SchemaNotFoundException
|
* @throws SchemaNotFoundException
|
||||||
*/
|
*/
|
||||||
@GET @Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
@GET
|
||||||
|
@Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getResourceSchema(@PathParam(TYPE_PATH_PARAM) String resourceType)
|
public String getResourceSchema(@PathParam(TYPE_PATH_PARAM) String resourceType)
|
||||||
throws SchemaNotFoundException {
|
throws SchemaNotFoundException {
|
||||||
logger.info("Requested Resource Schema for type {}", resourceType);
|
logger.info("Requested Resource Schema for type {}", resourceType);
|
||||||
|
|
|
@ -3,12 +3,16 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.informationsystem.resourceregistry.resources;
|
package org.gcube.informationsystem.resourceregistry.resources;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -46,12 +50,13 @@ public class ContextManager {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String create(
|
public String create(
|
||||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
|
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
|
||||||
@QueryParam(ContextPath.NAME_PARAM) String name)
|
@QueryParam(ContextPath.NAME_PARAM) String name)
|
||||||
throws ContextCreationException, InternalException {
|
throws ContextCreationException, InternalException {
|
||||||
logger.trace("requested to create context with name : {} ", name);
|
logger.trace("requested to create context with name : {} ", name);
|
||||||
return contextManager.create(parentUUID, name);
|
return contextManager.create(UUID.fromString(parentUUID), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,10 +67,11 @@ public class ContextManager {
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{" + ID_PATH_PARAM + "}")
|
@Path("{" + ID_PATH_PARAM + "}")
|
||||||
public String delete(@PathParam(ID_PATH_PARAM) String uuid)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public boolean delete(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ContextException {
|
||||||
logger.trace("requested to delete context with id {} ", uuid);
|
logger.trace("requested to delete context with id {} ", uuid);
|
||||||
return contextManager.delete(uuid);
|
return contextManager.delete(UUID.fromString(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,11 +84,12 @@ public class ContextManager {
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path(ContextPath.RENAME_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
@Path(ContextPath.RENAME_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String rename(@PathParam(ID_PATH_PARAM) String uuid,
|
public String rename(@PathParam(ID_PATH_PARAM) String uuid,
|
||||||
@QueryParam(ContextPath.NAME_PARAM) String name) throws ContextNotFoundException,
|
@QueryParam(ContextPath.NAME_PARAM) String name) throws ContextNotFoundException,
|
||||||
ContextException {
|
ContextException {
|
||||||
logger.trace("requested to rename context id {} with {} ", uuid, name);
|
logger.trace("requested to rename context id {} with {} ", uuid, name);
|
||||||
return contextManager.rename(uuid, name);
|
return contextManager.rename(UUID.fromString(uuid), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,13 +102,14 @@ public class ContextManager {
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
@Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String move(
|
public String move(
|
||||||
@PathParam(ID_PATH_PARAM) String uuid,
|
@PathParam(ID_PATH_PARAM) String uuid,
|
||||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID)
|
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ContextException {
|
||||||
logger.trace("requested to move context id {} with new parend id {} ",
|
logger.trace("requested to move context id {} with new parend id {} ",
|
||||||
uuid, newParentUUID);
|
uuid, newParentUUID);
|
||||||
return contextManager.move(newParentUUID, uuid);
|
return contextManager.move(UUID.fromString(newParentUUID), UUID.fromString(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.resources;
|
package org.gcube.informationsystem.resourceregistry.resources;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
|
@ -49,6 +54,8 @@ public class EntityManager {
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(EntityPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
@Path(EntityPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String createFacet(
|
public String createFacet(
|
||||||
@PathParam(TYPE_PATH_PARAM) String type,
|
@PathParam(TYPE_PATH_PARAM) String type,
|
||||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||||
|
@ -68,13 +75,15 @@ public class EntityManager {
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path(EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
@Path(EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String updateFacet(
|
public String updateFacet(
|
||||||
@PathParam(ID_PATH_PARAM) String uuid,
|
@PathParam(ID_PATH_PARAM) String uuid,
|
||||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||||
throws FacetNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ResourceRegistryException {
|
||||||
logger.trace("requested facet update for id {} with {}", uuid,
|
logger.trace("requested facet update for id {} with {}", uuid,
|
||||||
definition);
|
definition);
|
||||||
return entityManager.updateFacet(uuid, definition);
|
return entityManager.updateFacet(UUID.fromString(uuid), definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,7 +98,7 @@ public class EntityManager {
|
||||||
public boolean deleteFacet(@PathParam(ID_PATH_PARAM) String uuid)
|
public boolean deleteFacet(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws FacetNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ResourceRegistryException {
|
||||||
logger.trace("Requested to delete Facet with id {}", uuid);
|
logger.trace("Requested to delete Facet with id {}", uuid);
|
||||||
return entityManager.deleteFacet(uuid);
|
return entityManager.deleteFacet(UUID.fromString(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resources Methods */
|
/* Resources Methods */
|
||||||
|
@ -104,6 +113,8 @@ public class EntityManager {
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(EntityPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
@Path(EntityPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String createResource(
|
public String createResource(
|
||||||
@PathParam(TYPE_PATH_PARAM) String type,
|
@PathParam(TYPE_PATH_PARAM) String type,
|
||||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||||
|
@ -125,7 +136,7 @@ public class EntityManager {
|
||||||
public boolean deleteResource(@PathParam(ID_PATH_PARAM) String uuid)
|
public boolean deleteResource(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws ResourceNotFoundException, Exception {
|
throws ResourceNotFoundException, Exception {
|
||||||
logger.trace("requested resource deletion for id {}", uuid);
|
logger.trace("requested resource deletion for id {}", uuid);
|
||||||
return entityManager.deleteResource(uuid);
|
return entityManager.deleteResource(UUID.fromString(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Relations Methods */
|
/* Relations Methods */
|
||||||
|
@ -147,6 +158,7 @@ public class EntityManager {
|
||||||
+ SOURCE_ID_PATH_PARAM + "}/"
|
+ SOURCE_ID_PATH_PARAM + "}/"
|
||||||
+ EntityPath.TARGET_PATH_PART + "/{"
|
+ EntityPath.TARGET_PATH_PART + "/{"
|
||||||
+ TARGET_ID_PATH_PARAM + "}")
|
+ TARGET_ID_PATH_PARAM + "}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String attachFacet(
|
public String attachFacet(
|
||||||
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
|
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
|
||||||
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
|
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
|
||||||
|
@ -158,7 +170,7 @@ public class EntityManager {
|
||||||
"requested to attach resource {} to facet {} ({} Type {}) with properties {}",
|
"requested to attach resource {} to facet {} ({} Type {}) with properties {}",
|
||||||
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
|
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
|
||||||
type, properties);
|
type, properties);
|
||||||
return entityManager.attachFacet(resourceUUID, facetUUID, type,
|
return entityManager.attachFacet(UUID.fromString(resourceUUID), UUID.fromString(facetUUID), type,
|
||||||
properties);
|
properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,12 +181,11 @@ public class EntityManager {
|
||||||
* @throws ResourceRegistryException
|
* @throws ResourceRegistryException
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path(EntityPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM
|
@Path(EntityPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
+ "}")
|
|
||||||
public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID)
|
public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
logger.trace("requested to detach {}", consistOfUUID);
|
logger.trace("requested to detach {}", consistOfUUID);
|
||||||
return entityManager.detachFacet(consistOfUUID);
|
return entityManager.detachFacet(UUID.fromString(consistOfUUID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,6 +204,8 @@ public class EntityManager {
|
||||||
+ SOURCE_ID_PATH_PARAM + "}/"
|
+ SOURCE_ID_PATH_PARAM + "}/"
|
||||||
+ EntityPath.TARGET_PATH_PART + "/{"
|
+ EntityPath.TARGET_PATH_PART + "/{"
|
||||||
+ TARGET_ID_PATH_PARAM + "}")
|
+ TARGET_ID_PATH_PARAM + "}")
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String attachResource(
|
public String attachResource(
|
||||||
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
|
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
|
||||||
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,
|
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,
|
||||||
|
@ -203,8 +216,8 @@ public class EntityManager {
|
||||||
"requested to attach source resource {} and target resource {} ({} Type {}) with properties {}",
|
"requested to attach source resource {} and target resource {} ({} Type {}) with properties {}",
|
||||||
sourceResourceUUID, targetResourceUUID,
|
sourceResourceUUID, targetResourceUUID,
|
||||||
IsRelatedTo.class.getSimpleName(), type, properties);
|
IsRelatedTo.class.getSimpleName(), type, properties);
|
||||||
return entityManager.attachResource(sourceResourceUUID,
|
return entityManager.attachResource(UUID.fromString(sourceResourceUUID),
|
||||||
targetResourceUUID, type, properties);
|
UUID.fromString(targetResourceUUID), type, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,12 +227,11 @@ public class EntityManager {
|
||||||
* @throws ResourceRegistryException
|
* @throws ResourceRegistryException
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path(EntityPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM
|
@Path(EntityPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
+ "}")
|
|
||||||
public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID)
|
public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
logger.trace("requested to detach {}", relatedToUUID);
|
logger.trace("requested to detach {}", relatedToUUID);
|
||||||
return entityManager.detachResource(relatedToUUID);
|
return entityManager.detachResource(UUID.fromString(relatedToUUID));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.resources;
|
package org.gcube.informationsystem.resourceregistry.resources;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import javax.ws.rs.ext.ExceptionMapper;
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
@ -18,21 +19,19 @@ public class ResourceRegistryExceptionMapper implements ExceptionMapper<Resource
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(ResourceRegistryException exception) {
|
public Response toResponse(ResourceRegistryException exception) {
|
||||||
|
Status status = Status.BAD_REQUEST;
|
||||||
|
String entity = exception.getMessage();
|
||||||
|
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
||||||
|
|
||||||
if(ObjectNotFound.class.isAssignableFrom(exception.getClass())){
|
if(ObjectNotFound.class.isAssignableFrom(exception.getClass())){
|
||||||
return Response.status(Status.NOT_FOUND).entity(exception.getMessage()).build();
|
status = Status.NOT_FOUND;
|
||||||
|
}else if(NotAllowedException.class.isAssignableFrom(exception.getClass())){
|
||||||
|
status = Status.FORBIDDEN;
|
||||||
|
} else if(InternalException.class.isAssignableFrom(exception.getClass())){
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NotAllowedException.class.isAssignableFrom(exception.getClass())){
|
return Response.status(status).entity(entity).type(mediaType).build();
|
||||||
return Response.status(Status.FORBIDDEN).entity(exception.getMessage()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(InternalException.class.isAssignableFrom(exception.getClass())){
|
|
||||||
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.resources;
|
package org.gcube.informationsystem.resourceregistry.resources;
|
||||||
|
|
||||||
import javax.ws.rs.ApplicationPath;
|
import javax.ws.rs.ApplicationPath;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.SchemaManagement;
|
import org.gcube.informationsystem.resourceregistry.api.SchemaManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||||
|
@ -32,6 +35,8 @@ public class SchemaManager {
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(SchemaPath.EMBEDDED_PATH_PART)
|
@Path(SchemaPath.EMBEDDED_PATH_PART)
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String registerEmbeddedTypeSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
public String registerEmbeddedTypeSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
||||||
logger.trace("Requested Embedded registration with schema {}",jsonSchema);
|
logger.trace("Requested Embedded registration with schema {}",jsonSchema);
|
||||||
return schemaManager.registerEmbeddedTypeSchema(jsonSchema);
|
return schemaManager.registerEmbeddedTypeSchema(jsonSchema);
|
||||||
|
@ -45,6 +50,8 @@ public class SchemaManager {
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(SchemaPath.FACET_PATH_PART)
|
@Path(SchemaPath.FACET_PATH_PART)
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String registerFacetSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
public String registerFacetSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
||||||
logger.trace("Requested Facet registration with schema {}",jsonSchema);
|
logger.trace("Requested Facet registration with schema {}",jsonSchema);
|
||||||
return schemaManager.registerFacetSchema(jsonSchema);
|
return schemaManager.registerFacetSchema(jsonSchema);
|
||||||
|
@ -59,6 +66,8 @@ public class SchemaManager {
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(SchemaPath.RESOURCE_PATH_PART)
|
@Path(SchemaPath.RESOURCE_PATH_PART)
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String registerResourceSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
public String registerResourceSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
||||||
logger.trace("Requested Resource registration with schema {}",jsonSchema);
|
logger.trace("Requested Resource registration with schema {}",jsonSchema);
|
||||||
return schemaManager.registerResourceSchema(jsonSchema);
|
return schemaManager.registerResourceSchema(jsonSchema);
|
||||||
|
@ -72,6 +81,8 @@ public class SchemaManager {
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(SchemaPath.CONSIST_OF_PATH_PART)
|
@Path(SchemaPath.CONSIST_OF_PATH_PART)
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String registerConsistOfSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
public String registerConsistOfSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
||||||
logger.trace("Requested ConsistOf registration with schema {} ",jsonSchema);
|
logger.trace("Requested ConsistOf registration with schema {} ",jsonSchema);
|
||||||
return schemaManager.registerConsistOfSchema(jsonSchema);
|
return schemaManager.registerConsistOfSchema(jsonSchema);
|
||||||
|
@ -85,6 +96,8 @@ public class SchemaManager {
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(SchemaPath.RELATED_TO_PATH_PART)
|
@Path(SchemaPath.RELATED_TO_PATH_PART)
|
||||||
|
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String registerRelatedToSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
public String registerRelatedToSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
|
||||||
logger.trace("Requested RelatedTo registration with schema {} ",jsonSchema);
|
logger.trace("Requested RelatedTo registration with schema {} ",jsonSchema);
|
||||||
return schemaManager.registerRelatedToSchema(jsonSchema);
|
return schemaManager.registerRelatedToSchema(jsonSchema);
|
||||||
|
|
|
@ -39,28 +39,28 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory
|
||||||
.getLogger(ContextManagementImpl.class);
|
.getLogger(ContextManagementImpl.class);
|
||||||
|
|
||||||
protected Vertex checkContext(OrientGraph orientGraph,
|
protected Vertex checkContext(OrientGraph orientGraph, UUID parentContext,
|
||||||
String parentContextUUID, String contextName)
|
String contextName) throws ContextNotFoundException,
|
||||||
throws ContextNotFoundException, ContextException {
|
ContextException {
|
||||||
|
|
||||||
Vertex parent = null;
|
Vertex parent = null;
|
||||||
|
|
||||||
if (parentContextUUID != null) {
|
if (parentContext != null) {
|
||||||
|
|
||||||
parent = getContext(orientGraph, parentContextUUID);
|
parent = getContext(orientGraph, parentContext);
|
||||||
|
|
||||||
// TODO Rewrite using Gremlin
|
// TODO Rewrite using Gremlin
|
||||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME
|
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME
|
||||||
+ ") FROM " + parent.getId() + " MAXDEPTH 1) WHERE "
|
+ ") FROM " + parent.getId() + " MAXDEPTH 1) WHERE "
|
||||||
+ Context.NAME_PROPERTY + "=\"" + contextName + "\" AND "
|
+ Context.NAME_PROPERTY + "=\"" + contextName + "\" AND "
|
||||||
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
||||||
+ "<>\"" + parentContextUUID + "\"";
|
+ "<>\"" + parentContext.toString() + "\"";
|
||||||
|
|
||||||
logger.trace(select);
|
logger.trace(select);
|
||||||
|
|
||||||
String message = "A context with the same name (" + contextName
|
String message = "A context with the same name (" + contextName
|
||||||
+ ") has been already created as child of "
|
+ ") has been already created as child of "
|
||||||
+ parentContextUUID + "(name="
|
+ parentContext.toString() + "(name="
|
||||||
+ parent.getProperty(Context.NAME_PROPERTY).toString()
|
+ parent.getProperty(Context.NAME_PROPERTY).toString()
|
||||||
+ ")";
|
+ ")";
|
||||||
|
|
||||||
|
@ -99,46 +99,44 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vertex getContext(OrientGraph orientGraph, String contextUUID)
|
public Vertex getContext(OrientGraph orientGraph, UUID context)
|
||||||
throws ContextNotFoundException {
|
throws ContextNotFoundException {
|
||||||
try {
|
try {
|
||||||
return Utility.getEntityByUUID(orientGraph,
|
return Utility.getEntityByUUID(orientGraph,
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||||
contextUUID);
|
context);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw new ContextNotFoundException(e.getMessage());
|
throw new ContextNotFoundException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String create(String parentContextUUID, String name)
|
public String create(UUID parentContext, String name)
|
||||||
throws ContextCreationException, InternalException {
|
throws ContextCreationException, InternalException {
|
||||||
|
|
||||||
logger.info("Trying to create {} with name {} and parent {} UUID {}",
|
OrientGraph orientGraph = null;
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME, name,
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info(
|
||||||
|
"Trying to create {} with name {} and parent {} UUID {}",
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||||
parentContextUUID);
|
name,
|
||||||
|
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||||
|
parentContext);
|
||||||
|
|
||||||
if (parentContextUUID != null && parentContextUUID.compareTo("") == 0) {
|
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
||||||
parentContextUUID = null;
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
}
|
PermissionMode.WRITER).getTx();
|
||||||
|
|
||||||
OrientGraph orientGraph = SecurityContextMapper
|
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER).getTx();
|
|
||||||
|
|
||||||
Vertex parent;
|
Vertex parent;
|
||||||
try {
|
try {
|
||||||
parent = checkContext(orientGraph, parentContextUUID, name);
|
parent = checkContext(orientGraph, parentContext, name);
|
||||||
} catch (ContextException e) {
|
} catch (ContextException e) {
|
||||||
throw new ContextCreationException(e.getMessage());
|
throw new ContextCreationException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = UUID.randomUUID();
|
SecurityContext.createSecurityContext(orientGraph, uuid, true);
|
||||||
String uuidString = uuid.toString();
|
|
||||||
|
|
||||||
SecurityContext.createSecurityContext(orientGraph, uuidString, true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
OrientVertex context = orientGraph.addVertex("class:"
|
OrientVertex context = orientGraph.addVertex("class:"
|
||||||
+ Context.NAME);
|
+ Context.NAME);
|
||||||
|
@ -147,60 +145,71 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
|
|
||||||
HeaderUtility.addHeader(context, uuid);
|
HeaderUtility.addHeader(context, uuid);
|
||||||
|
|
||||||
if (parentContextUUID != null) {
|
if (parentContext != null) {
|
||||||
OrientEdge edge = orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
|
OrientEdge edge = orientGraph.addEdge(null, parent, context,
|
||||||
|
IsParentOf.NAME);
|
||||||
HeaderUtility.addHeader(edge, null);
|
HeaderUtility.addHeader(edge, null);
|
||||||
edge.save();
|
edge.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
SecurityContext.addToSecurityContext(orientGraph, context,
|
SecurityContext.addToSecurityContext(orientGraph, context, uuid);
|
||||||
uuidString);
|
|
||||||
|
|
||||||
String contextJsonString = Utility.toJsonString(context, true);
|
logger.trace("Creating {}", Utility.toJsonString(context, true));
|
||||||
logger.trace("Creating {}", contextJsonString);
|
|
||||||
|
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
|
|
||||||
logger.info("Context {} created", contextJsonString);
|
Vertex readContext = getContext(orientGraph, uuid);
|
||||||
return uuidString;
|
logger.info("Context {} created",
|
||||||
|
Utility.toJsonString((OrientVertex) readContext, true));
|
||||||
|
return Utility.toJsonString((OrientVertex) readContext, false);
|
||||||
|
|
||||||
|
} catch (ContextCreationException e) {
|
||||||
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (orientGraph != null) {
|
||||||
orientGraph.rollback();
|
orientGraph.rollback();
|
||||||
SecurityContext
|
SecurityContext.deleteSecurityContext(orientGraph, uuid, true);
|
||||||
.deleteSecurityContext(orientGraph, uuidString, true);
|
}
|
||||||
throw new InternalException(e.getMessage());
|
throw new InternalException(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
if (orientGraph != null) {
|
||||||
orientGraph.shutdown();
|
orientGraph.shutdown();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String read(String contextUUID) throws ContextNotFoundException,
|
public String read(UUID contextUUID) throws ContextNotFoundException,
|
||||||
ContextException {
|
ContextException {
|
||||||
|
|
||||||
OrientGraph orientGraph = SecurityContextMapper
|
OrientGraph orientGraph = SecurityContextMapper
|
||||||
.getSecurityContextFactory(null, PermissionMode.READER).getTx();
|
.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.READER).getTx();
|
||||||
Vertex context = getContext(orientGraph, contextUUID);
|
Vertex context = getContext(orientGraph, contextUUID);
|
||||||
return Utility.toJsonString(context, false);
|
return Utility.toJsonString((OrientVertex) context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String rename(String contextUUID, String newName)
|
public String rename(UUID contextUUID, String newName)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ContextException {
|
||||||
|
|
||||||
logger.info("Trying to rename {} with UUID {} to {}",
|
OrientGraph orientGraph = null;
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
|
||||||
|
try {
|
||||||
|
logger.info("Trying to rename {} with UUID {} to {}", Context.NAME,
|
||||||
contextUUID, newName);
|
contextUUID, newName);
|
||||||
|
|
||||||
OrientGraph orientGraph = SecurityContextMapper
|
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER).getTx();
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.WRITER).getTx();
|
||||||
|
|
||||||
Vertex context = getContext(orientGraph, contextUUID);
|
Vertex context = getContext(orientGraph, contextUUID);
|
||||||
|
|
||||||
String parentUUID = null;
|
UUID parentUUID = null;
|
||||||
|
|
||||||
Iterable<Edge> edges = context.getEdges(Direction.IN, IsParentOf.NAME);
|
Iterable<Edge> edges = context.getEdges(Direction.IN,
|
||||||
|
IsParentOf.NAME);
|
||||||
if (edges != null && edges.iterator().hasNext()) {
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
Iterator<Edge> iteratorEdge = edges.iterator();
|
Iterator<Edge> iteratorEdge = edges.iterator();
|
||||||
Edge edge = iteratorEdge.next();
|
Edge edge = iteratorEdge.next();
|
||||||
|
@ -210,9 +219,8 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex parent = edge.getVertex(Direction.OUT);
|
Vertex parent = edge.getVertex(Direction.OUT);
|
||||||
parentUUID = parent.getProperty(
|
parentUUID = UUID.fromString((String) parent.getProperty(Context.HEADER_PROPERTY + "."
|
||||||
Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY)
|
+ Header.UUID_PROPERTY));
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkContext(orientGraph, parentUUID, newName);
|
checkContext(orientGraph, parentUUID, newName);
|
||||||
|
@ -223,33 +231,49 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
String contextJsonString = Utility.toJsonString(context, true);
|
String contextJsonString = Utility.toJsonString(context, true);
|
||||||
logger.info("Context renamed {}", contextJsonString);
|
logger.info("Context renamed {}", contextJsonString);
|
||||||
|
|
||||||
|
return Utility.toJsonString((OrientVertex) context, false);
|
||||||
|
} catch (ContextException ce) {
|
||||||
|
if (orientGraph != null) {
|
||||||
|
orientGraph.rollback();
|
||||||
|
}
|
||||||
|
throw ce;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (orientGraph != null) {
|
||||||
|
orientGraph.rollback();
|
||||||
|
}
|
||||||
|
throw new ContextException(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (orientGraph != null) {
|
||||||
orientGraph.shutdown();
|
orientGraph.shutdown();
|
||||||
|
}
|
||||||
return contextUUID;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String move(String newParentUUID, String contextToMoveUUID)
|
public String move(UUID newParentUUID, UUID contextToMoveUUID)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ContextException {
|
||||||
|
|
||||||
|
OrientGraph orientGraph = null;
|
||||||
|
try {
|
||||||
logger.info(
|
logger.info(
|
||||||
"Trying to move {} with UUID {} as child of {} with UUID {}",
|
"Trying to move {} with UUID {} as child of {} with UUID {}",
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
Context.NAME, contextToMoveUUID, Context.NAME,
|
||||||
contextToMoveUUID,
|
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
|
||||||
newParentUUID);
|
newParentUUID);
|
||||||
|
|
||||||
OrientGraph orientGraph = SecurityContextMapper
|
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER).getTx();
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.WRITER).getTx();
|
||||||
Vertex context = getContext(orientGraph, contextToMoveUUID);
|
Vertex context = getContext(orientGraph, contextToMoveUUID);
|
||||||
|
|
||||||
logger.trace("Context to move {}", Utility.toJsonString(context, true));
|
logger.trace("Context to move {}",
|
||||||
|
Utility.toJsonString(context, true));
|
||||||
|
|
||||||
checkContext(orientGraph, newParentUUID,
|
checkContext(orientGraph, newParentUUID,
|
||||||
context.getProperty(Context.NAME_PROPERTY).toString());
|
context.getProperty(Context.NAME_PROPERTY).toString());
|
||||||
|
|
||||||
// Removing the old parent relationship if any
|
// Removing the old parent relationship if any
|
||||||
Iterable<Edge> edges = context.getEdges(Direction.IN, IsParentOf.NAME);
|
Iterable<Edge> edges = context.getEdges(Direction.IN,
|
||||||
|
IsParentOf.NAME);
|
||||||
if (edges != null && edges.iterator().hasNext()) {
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
Iterator<Edge> edgeIterator = edges.iterator();
|
Iterator<Edge> edgeIterator = edges.iterator();
|
||||||
Edge edge = edgeIterator.next();
|
Edge edge = edgeIterator.next();
|
||||||
|
@ -261,7 +285,10 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
Vertex parent = getContext(orientGraph, newParentUUID);
|
Vertex parent = getContext(orientGraph, newParentUUID);
|
||||||
logger.trace("New Parent Context {}",
|
logger.trace("New Parent Context {}",
|
||||||
Utility.toJsonString(parent, true));
|
Utility.toJsonString(parent, true));
|
||||||
orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
|
OrientEdge edge = orientGraph.addEdge(null, parent, context,
|
||||||
|
IsParentOf.NAME);
|
||||||
|
HeaderUtility.addHeader(edge, null);
|
||||||
|
edge.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
|
@ -270,24 +297,44 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
String contextJsonString = Utility.toJsonString(context, true);
|
String contextJsonString = Utility.toJsonString(context, true);
|
||||||
logger.info("Context moved {}", contextJsonString);
|
logger.info("Context moved {}", contextJsonString);
|
||||||
|
|
||||||
|
return Utility.toJsonString((OrientVertex) context, false);
|
||||||
|
|
||||||
|
} catch (ContextException ce) {
|
||||||
|
if (orientGraph != null) {
|
||||||
|
orientGraph.rollback();
|
||||||
|
}
|
||||||
|
throw ce;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (orientGraph != null) {
|
||||||
|
orientGraph.rollback();
|
||||||
|
}
|
||||||
|
throw new ContextException(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (orientGraph != null) {
|
||||||
orientGraph.shutdown();
|
orientGraph.shutdown();
|
||||||
return contextToMoveUUID;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String delete(String uuid) throws ContextNotFoundException,
|
public boolean delete(UUID uuid) throws ContextNotFoundException,
|
||||||
ContextException {
|
ContextException {
|
||||||
|
|
||||||
logger.info("Trying to remove {} with UUID {}",
|
OrientGraph orientGraph = null;
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME, uuid);
|
|
||||||
|
try {
|
||||||
|
logger.info("Trying to remove {} with UUID {}", Context.NAME, uuid);
|
||||||
|
|
||||||
|
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.WRITER).getTx();
|
||||||
|
|
||||||
OrientGraph orientGraph = SecurityContextMapper
|
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER).getTx();
|
|
||||||
Vertex context = getContext(orientGraph, uuid);
|
Vertex context = getContext(orientGraph, uuid);
|
||||||
logger.trace("Context to be delete {}",
|
logger.trace("Context to be delete {}",
|
||||||
Utility.toJsonString(context, true));
|
Utility.toJsonString(context, true));
|
||||||
|
|
||||||
Iterable<Edge> edges = context.getEdges(Direction.OUT, IsParentOf.NAME);
|
Iterable<Edge> edges = context.getEdges(Direction.OUT,
|
||||||
|
IsParentOf.NAME);
|
||||||
if (edges != null && edges.iterator().hasNext()) {
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
throw new ContextException(
|
throw new ContextException(
|
||||||
"Only context with no children can be deleted");
|
"Only context with no children can be deleted");
|
||||||
|
@ -298,12 +345,25 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
context.remove();
|
context.remove();
|
||||||
|
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
|
logger.info("{} with UUID {} successfully removed", Context.NAME,
|
||||||
|
uuid);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (ContextException ce) {
|
||||||
|
if (orientGraph != null) {
|
||||||
|
orientGraph.rollback();
|
||||||
|
}
|
||||||
|
throw ce;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (orientGraph != null) {
|
||||||
|
orientGraph.rollback();
|
||||||
|
}
|
||||||
|
throw new ContextException(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (orientGraph != null) {
|
||||||
orientGraph.shutdown();
|
orientGraph.shutdown();
|
||||||
|
}
|
||||||
logger.info("{} with UUID {} successfully removed",
|
}
|
||||||
org.gcube.informationsystem.model.entity.Context.NAME, uuid);
|
|
||||||
|
|
||||||
return uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONArray;
|
import org.codehaus.jettison.json.JSONArray;
|
||||||
import org.codehaus.jettison.json.JSONException;
|
import org.codehaus.jettison.json.JSONException;
|
||||||
|
@ -59,7 +60,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory
|
||||||
.getLogger(EntityManagementImpl.class);
|
.getLogger(EntityManagementImpl.class);
|
||||||
|
|
||||||
public Vertex getEntity(OrientGraph orientGraph, String uuid,
|
public Vertex getEntity(OrientGraph orientGraph, UUID uuid,
|
||||||
String entityType, Class<? extends Entity> entityClass)
|
String entityType, Class<? extends Entity> entityClass)
|
||||||
throws FacetNotFoundException, ResourceNotFoundException,
|
throws FacetNotFoundException, ResourceNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
|
@ -87,7 +88,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
|
|
||||||
public Edge getRelation(
|
public Edge getRelation(
|
||||||
OrientGraph orientGraph,
|
OrientGraph orientGraph,
|
||||||
String uuid,
|
UUID uuid,
|
||||||
String relationType,
|
String relationType,
|
||||||
@SuppressWarnings("rawtypes") Class<? extends Relation> relationClass)
|
@SuppressWarnings("rawtypes") Class<? extends Relation> relationClass)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
|
@ -308,7 +309,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetUUID = targetHeader.getUUID().toString();
|
UUID targetUUID = targetHeader.getUUID();
|
||||||
String entityType = getClassProperty(target);
|
String entityType = getClassProperty(target);
|
||||||
|
|
||||||
targetVertex = getEntity(orientGraph, targetUUID, entityType, targetClass);
|
targetVertex = getEntity(orientGraph, targetUUID, entityType, targetClass);
|
||||||
|
@ -427,8 +428,8 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Edge createEdgeRelation(
|
public Edge createEdgeRelation(
|
||||||
String sourceUUID, Class<? extends Entity> sourceClass,
|
UUID sourceUUID, Class<? extends Entity> sourceClass,
|
||||||
String targetUUID, Class<? extends Entity> targetClass,
|
UUID targetUUID, Class<? extends Entity> targetClass,
|
||||||
String relationType, @SuppressWarnings("rawtypes") Class<? extends Relation> relationBaseClass,
|
String relationType, @SuppressWarnings("rawtypes") Class<? extends Relation> relationBaseClass,
|
||||||
String jsonProperties)
|
String jsonProperties)
|
||||||
throws FacetNotFoundException, ResourceNotFoundException,
|
throws FacetNotFoundException, ResourceNotFoundException,
|
||||||
|
@ -555,13 +556,13 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readFacet(String uuid) throws FacetNotFoundException,
|
public String readFacet(UUID uuid) throws FacetNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
return readFacet(uuid, Facet.NAME);
|
return readFacet(uuid, Facet.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readFacet(String uuid, String facetType)
|
public String readFacet(UUID uuid, String facetType)
|
||||||
throws FacetNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ResourceRegistryException {
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
|
@ -587,7 +588,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String updateFacet(String uuid, String jsonRepresentation)
|
public String updateFacet(UUID uuid, String jsonRepresentation)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
|
@ -661,7 +662,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteFacet(String uuid) throws FacetNotFoundException,
|
public boolean deleteFacet(UUID uuid) throws FacetNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
|
@ -693,7 +694,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String attachFacet(String resourceUUID, String facetUUID,
|
public String attachFacet(UUID resourceUUID, UUID facetUUID,
|
||||||
String consistOfType, String jsonProperties)
|
String consistOfType, String jsonProperties)
|
||||||
throws FacetNotFoundException, ResourceNotFoundException,
|
throws FacetNotFoundException, ResourceNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
|
@ -705,7 +706,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean detachFacet(String consistOfUUID)
|
public boolean detachFacet(UUID consistOfUUID)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
|
@ -739,8 +740,8 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String attachResource(String sourceResourceUuid,
|
public String attachResource(UUID sourceResourceUuid,
|
||||||
String targetResourceUuid, String relatedToType,
|
UUID targetResourceUuid, String relatedToType,
|
||||||
String jsonProperties) throws ResourceNotFoundException,
|
String jsonProperties) throws ResourceNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
Edge edge = createEdgeRelation(sourceResourceUuid, Resource.class,
|
Edge edge = createEdgeRelation(sourceResourceUuid, Resource.class,
|
||||||
|
@ -751,7 +752,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean detachResource(String relatedToUUID)
|
public boolean detachResource(UUID relatedToUUID)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
|
@ -866,12 +867,12 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readResource(String uuid) throws ResourceNotFoundException {
|
public String readResource(UUID uuid) throws ResourceNotFoundException {
|
||||||
return readResource(uuid, Resource.NAME);
|
return readResource(uuid, Resource.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readResource(String uuid, String resourceType)
|
public String readResource(UUID uuid, String resourceType)
|
||||||
throws ResourceNotFoundException {
|
throws ResourceNotFoundException {
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
|
@ -898,7 +899,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteResource(String uuid)
|
public boolean deleteResource(UUID uuid)
|
||||||
throws ResourceNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ResourceRegistryException {
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
|
@ -913,6 +914,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
resource.remove();
|
resource.remove();
|
||||||
|
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
|
return true;
|
||||||
} catch (ResourceNotFoundException fnfe) {
|
} catch (ResourceNotFoundException fnfe) {
|
||||||
if (orientGraph != null) {
|
if (orientGraph != null) {
|
||||||
orientGraph.rollback();
|
orientGraph.rollback();
|
||||||
|
@ -928,8 +930,6 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
orientGraph.shutdown();
|
orientGraph.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory
|
||||||
.getLogger(SchemaManagementImpl.class);
|
.getLogger(SchemaManagementImpl.class);
|
||||||
|
|
||||||
protected static OClass getEntityOClass(OrientGraphNoTx orientGraphNoTx, String entityType) throws SchemaException {
|
protected static OClass getEntityOClass(OrientGraphNoTx orientGraphNoTx,
|
||||||
|
String entityType) throws SchemaException {
|
||||||
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
||||||
OSchema oSchema = oMetadata.getSchema();
|
OSchema oSchema = oMetadata.getSchema();
|
||||||
return oSchema.getClass(entityType);
|
return oSchema.getClass(entityType);
|
||||||
|
@ -59,7 +60,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
protected OClass getTypeSchema(String type, String baseType)
|
protected OClass getTypeSchema(String type, String baseType)
|
||||||
throws SchemaNotFoundException {
|
throws SchemaNotFoundException {
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
||||||
.getSecurityContextFactory(null, PermissionMode.READER);
|
.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.READER);
|
||||||
|
|
||||||
OrientGraphNoTx orientGraphNoTx = null;
|
OrientGraphNoTx orientGraphNoTx = null;
|
||||||
try {
|
try {
|
||||||
|
@ -128,7 +131,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
protected String getTypeSchemaAsString(String type, String baseType)
|
protected String getTypeSchemaAsString(String type, String baseType)
|
||||||
throws SchemaNotFoundException {
|
throws SchemaNotFoundException {
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
||||||
.getSecurityContextFactory(null, PermissionMode.READER);
|
.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.READER);
|
||||||
|
|
||||||
OrientGraphNoTx orientGraphNoTx = null;
|
OrientGraphNoTx orientGraphNoTx = null;
|
||||||
try {
|
try {
|
||||||
|
@ -148,7 +153,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
Class<?> baseType) throws SchemaException {
|
Class<?> baseType) throws SchemaException {
|
||||||
|
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER);
|
.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.WRITER);
|
||||||
|
|
||||||
OrientGraphNoTx orientGraphNoTx = null;
|
OrientGraphNoTx orientGraphNoTx = null;
|
||||||
try {
|
try {
|
||||||
|
@ -166,7 +173,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
try {
|
try {
|
||||||
ovt.setAbstract(typeDefinition.isAbstractType());
|
ovt.setAbstract(typeDefinition.isAbstractType());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to set the Vertex Type {} as abstract. This is an OrientDB bug. The Type will be created as it is not abstarct.", typeDefinition.getName());
|
logger.error(
|
||||||
|
"Unable to set the Vertex Type {} as abstract. This is an OrientDB bug. The Type will be created as it is not abstarct.",
|
||||||
|
typeDefinition.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(
|
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(
|
||||||
|
@ -186,7 +195,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
OType.getById(property.getType().byteValue()));
|
OType.getById(property.getType().byteValue()));
|
||||||
ovp.setDescription(property.getDescription());
|
ovp.setDescription(property.getDescription());
|
||||||
|
|
||||||
/* Mandatory and notNull does not work in distributed mode:
|
/*
|
||||||
|
* Mandatory and notNull does not work in distributed mode:
|
||||||
* so that on Type declaration they are forced to false
|
* so that on Type declaration they are forced to false
|
||||||
* ovp.setMandatory(property.isMandatory());
|
* ovp.setMandatory(property.isMandatory());
|
||||||
* ovp.setNotNull(property.isNotnull());
|
* ovp.setNotNull(property.isNotnull());
|
||||||
|
@ -197,7 +207,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
ovp.setReadonly(property.isReadonly());
|
ovp.setReadonly(property.isReadonly());
|
||||||
ovp.setRegexp(property.getRegexpr());
|
ovp.setRegexp(property.getRegexpr());
|
||||||
if (property.getLinkedClass() != null) {
|
if (property.getLinkedClass() != null) {
|
||||||
OClass linkedClass = getEntityOClass(orientGraphNoTx, property.getLinkedClass());
|
OClass linkedClass = getEntityOClass(orientGraphNoTx,
|
||||||
|
property.getLinkedClass());
|
||||||
if (linkedClass == null) {
|
if (linkedClass == null) {
|
||||||
logger.trace("class {} not found in schema",
|
logger.trace("class {} not found in schema",
|
||||||
property.getLinkedClass());
|
property.getLinkedClass());
|
||||||
|
@ -237,7 +248,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
protected String registerEdgeTypeSchema(String jsonSchema, String baseType)
|
protected String registerEdgeTypeSchema(String jsonSchema, String baseType)
|
||||||
throws SchemaException {
|
throws SchemaException {
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER);
|
.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.WRITER);
|
||||||
|
|
||||||
OrientGraphNoTx orientGraphNoTx = null;
|
OrientGraphNoTx orientGraphNoTx = null;
|
||||||
try {
|
try {
|
||||||
|
@ -255,7 +268,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
try {
|
try {
|
||||||
oet.setAbstract(typeDefinition.isAbstractType());
|
oet.setAbstract(typeDefinition.isAbstractType());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to set the Edge Type {} as abstract. This is an OrientDB bug. The Type will be created as it is not abstarct.", typeDefinition.getName());
|
logger.error(
|
||||||
|
"Unable to set the Edge Type {} as abstract. This is an OrientDB bug. The Type will be created as it is not abstarct.",
|
||||||
|
typeDefinition.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(
|
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(
|
||||||
|
@ -267,8 +282,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
OType.getById(property.getType().byteValue()));
|
OType.getById(property.getType().byteValue()));
|
||||||
op.setDescription(property.getDescription());
|
op.setDescription(property.getDescription());
|
||||||
|
|
||||||
/* Mandatory and notNull does not work in distributed mode:
|
/*
|
||||||
* so that on Type declaration they are forced to false
|
* Mandatory and notNull does not work in distributed mode: so
|
||||||
|
* that on Type declaration they are forced to false
|
||||||
* op.setMandatory(property.isMandatory());
|
* op.setMandatory(property.isMandatory());
|
||||||
* op.setNotNull(property.isNotnull());
|
* op.setNotNull(property.isNotnull());
|
||||||
*/
|
*/
|
||||||
|
@ -313,7 +329,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
public String registerDocumentSchema(String jsonSchema)
|
public String registerDocumentSchema(String jsonSchema)
|
||||||
throws SchemaException {
|
throws SchemaException {
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER);
|
.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.WRITER);
|
||||||
|
|
||||||
OrientGraphNoTx orientGraphNoTx = null;
|
OrientGraphNoTx orientGraphNoTx = null;
|
||||||
try {
|
try {
|
||||||
|
@ -325,7 +343,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
orientGraphNoTx = orientGraphFactory.getNoTx();
|
orientGraphNoTx = orientGraphFactory.getNoTx();
|
||||||
|
|
||||||
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraphNoTx.getRawGraph();
|
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraphNoTx
|
||||||
|
.getRawGraph();
|
||||||
OMetadata oMetadata = oDatabaseDocumentTx.getMetadata();
|
OMetadata oMetadata = oDatabaseDocumentTx.getMetadata();
|
||||||
OSchema oSchema = oMetadata.getSchema();
|
OSchema oSchema = oMetadata.getSchema();
|
||||||
|
|
||||||
|
@ -339,14 +358,14 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
oDatabaseDocumentTx.commit();
|
oDatabaseDocumentTx.commit();
|
||||||
|
|
||||||
|
|
||||||
for (Property property : typeDefinition.getProperties()) {
|
for (Property property : typeDefinition.getProperties()) {
|
||||||
OProperty ovp = oClass.createProperty(property.getName(),
|
OProperty ovp = oClass.createProperty(property.getName(),
|
||||||
OType.getById(property.getType().byteValue()));
|
OType.getById(property.getType().byteValue()));
|
||||||
ovp.setDescription(property.getDescription());
|
ovp.setDescription(property.getDescription());
|
||||||
|
|
||||||
/* Mandatory and notNull does not work in distributed mode:
|
/*
|
||||||
* so that on Type declaration they are forced to false
|
* Mandatory and notNull does not work in distributed mode: so
|
||||||
|
* that on Type declaration they are forced to false
|
||||||
* ovp.setMandatory(property.isMandatory());
|
* ovp.setMandatory(property.isMandatory());
|
||||||
* ovp.setNotNull(property.isNotnull());
|
* ovp.setNotNull(property.isNotnull());
|
||||||
*/
|
*/
|
||||||
|
@ -389,60 +408,44 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public void addDocumentProperties(TypeDefinition typeDefinition) throws SchemaException {
|
* public void addDocumentProperties(TypeDefinition typeDefinition) throws
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
* SchemaException { OrientGraphFactory orientGraphFactory =
|
||||||
.getSecurityContextFactory(null, PermissionMode.WRITER);
|
* SecurityContextMapper .getSecurityContextFactory(null,
|
||||||
|
* PermissionMode.WRITER);
|
||||||
OrientGraphNoTx orientGraphNoTx = null;
|
*
|
||||||
try {
|
* OrientGraphNoTx orientGraphNoTx = null; try {
|
||||||
logger.trace("Adding properties to {}", typeDefinition);
|
* logger.trace("Adding properties to {}", typeDefinition);
|
||||||
|
*
|
||||||
OClass oClass = getEntityOClass(orientGraphNoTx, typeDefinition.getName());
|
* OClass oClass = getEntityOClass(orientGraphNoTx,
|
||||||
|
* typeDefinition.getName());
|
||||||
orientGraphNoTx = orientGraphFactory.getNoTx();
|
*
|
||||||
|
* orientGraphNoTx = orientGraphFactory.getNoTx();
|
||||||
for (Property property : typeDefinition.getProperties()) {
|
*
|
||||||
OProperty ovp = oClass.createProperty(property.getName(),
|
* for (Property property : typeDefinition.getProperties()) { OProperty ovp
|
||||||
OType.getById(property.getType().byteValue()));
|
* = oClass.createProperty(property.getName(),
|
||||||
ovp.setDescription(property.getDescription());
|
* OType.getById(property.getType().byteValue()));
|
||||||
|
* ovp.setDescription(property.getDescription());
|
||||||
/* Mandatory and notNull does not work in distributed mode:
|
*
|
||||||
* so that on Type declaration they are forced to false
|
* /* Mandatory and notNull does not work in distributed mode: so that on
|
||||||
|
* Type declaration they are forced to false
|
||||||
* ovp.setMandatory(property.isMandatory());
|
* ovp.setMandatory(property.isMandatory());
|
||||||
* ovp.setNotNull(property.isNotnull());
|
* ovp.setNotNull(property.isNotnull()); / ovp.setMandatory(false);
|
||||||
* /
|
* ovp.setNotNull(false);
|
||||||
ovp.setMandatory(false);
|
*
|
||||||
ovp.setNotNull(false);
|
* ovp.setReadonly(property.isReadonly());
|
||||||
|
* ovp.setRegexp(property.getRegexpr()); if (property.getLinkedClass() !=
|
||||||
ovp.setReadonly(property.isReadonly());
|
* null) { OClass linkedClass = getEntityOClass(orientGraphNoTx,
|
||||||
ovp.setRegexp(property.getRegexpr());
|
* property.getLinkedClass()); if (linkedClass == null) {
|
||||||
if (property.getLinkedClass() != null) {
|
* logger.trace("class {} not found in schema", property.getLinkedClass());
|
||||||
OClass linkedClass = getEntityOClass(orientGraphNoTx,
|
* throw new Exception("class " + property.getLinkedClass() +
|
||||||
property.getLinkedClass());
|
* " not found in schema"); }
|
||||||
if (linkedClass == null) {
|
*
|
||||||
logger.trace("class {} not found in schema",
|
* if (linkedClass.isEdgeType() || linkedClass.isVertexType()) { throw new
|
||||||
property.getLinkedClass());
|
* Exception( "An Embedded Field cannot be an Entity or a Relation"); }
|
||||||
throw new Exception("class "
|
*
|
||||||
+ property.getLinkedClass()
|
* ovp.setLinkedClass(linkedClass); } } } catch (Exception e) { throw new
|
||||||
+ " not found in schema");
|
* SchemaException(e); } finally { if (orientGraphNoTx != null) {
|
||||||
}
|
* orientGraphNoTx.shutdown(); } } }
|
||||||
|
|
||||||
if (linkedClass.isEdgeType() || linkedClass.isVertexType()) {
|
|
||||||
throw new Exception(
|
|
||||||
"An Embedded Field cannot be an Entity or a Relation");
|
|
||||||
}
|
|
||||||
|
|
||||||
ovp.setLinkedClass(linkedClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new SchemaException(e);
|
|
||||||
} finally {
|
|
||||||
if (orientGraphNoTx != null) {
|
|
||||||
orientGraphNoTx.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -522,20 +525,13 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
return registerDocumentSchema(jsonSchema);
|
return registerDocumentSchema(jsonSchema);
|
||||||
/*
|
/*
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
* ObjectMapper mapper = new ObjectMapper(); TypeDefinition
|
||||||
TypeDefinition typeDefinition;
|
* typeDefinition; try { typeDefinition = mapper.readValue(jsonSchema,
|
||||||
try {
|
* TypeDefinition.class); registerDocumentSchema(typeDefinition);
|
||||||
typeDefinition = mapper.readValue(jsonSchema,
|
* addDocumentProperties(typeDefinition);
|
||||||
TypeDefinition.class);
|
*
|
||||||
registerDocumentSchema(typeDefinition);
|
* return jsonSchema; } catch (SchemaException e) { throw e; } catch
|
||||||
addDocumentProperties(typeDefinition);
|
* (Exception e) { throw new SchemaException(e); }
|
||||||
|
|
||||||
return jsonSchema;
|
|
||||||
} catch (SchemaException e) {
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new SchemaException(e);
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.resources.utils;
|
package org.gcube.informationsystem.resourceregistry.resources.utils;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -34,42 +35,47 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
*/
|
*/
|
||||||
public class ContextUtility {
|
public class ContextUtility {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ContextUtility.class);
|
private static final Logger logger = LoggerFactory
|
||||||
|
.getLogger(ContextUtility.class);
|
||||||
|
|
||||||
public static void addToActualContext(OrientGraph orientGraph, Vertex vertex)
|
public static void addToActualContext(OrientGraph orientGraph, Vertex vertex)
|
||||||
throws ContextException {
|
throws ContextException {
|
||||||
String contextID = ContextUtility.getActualContextUUID();
|
UUID contextUUID = ContextUtility.getActualContextUUID();
|
||||||
SecurityContext.addToSecurityContext(orientGraph, vertex, contextID);
|
SecurityContext.addToSecurityContext(orientGraph, vertex, contextUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToActualContext(OSecurity oSecurity, Vertex vertex)
|
public static void addToActualContext(OSecurity oSecurity, Vertex vertex)
|
||||||
throws ContextException {
|
throws ContextException {
|
||||||
String contextID = ContextUtility.getActualContextUUID();
|
UUID contextUUID = ContextUtility.getActualContextUUID();
|
||||||
SecurityContext.addToSecurityContext(oSecurity, vertex, contextID);
|
SecurityContext.addToSecurityContext(oSecurity, vertex, contextUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToActualContext(OrientGraph orientGraph, Edge edge)
|
public static void addToActualContext(OrientGraph orientGraph, Edge edge)
|
||||||
throws ContextException {
|
throws ContextException {
|
||||||
String contextID = ContextUtility.getActualContextUUID();
|
UUID contextUUID = ContextUtility.getActualContextUUID();
|
||||||
SecurityContext.addToSecurityContext(orientGraph, edge, contextID);
|
SecurityContext.addToSecurityContext(orientGraph, edge, contextUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToActualContext(OSecurity oSecurity, Edge edge)
|
public static void addToActualContext(OSecurity oSecurity, Edge edge)
|
||||||
throws ContextException {
|
throws ContextException {
|
||||||
String contextID = ContextUtility.getActualContextUUID();
|
UUID contextUUID = ContextUtility.getActualContextUUID();
|
||||||
SecurityContext.addToSecurityContext(oSecurity, edge, contextID);
|
SecurityContext.addToSecurityContext(oSecurity, edge, contextUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String getContextUUIDFromContextVertex(Vertex vertex) {
|
protected static UUID getContextUUIDFromContextVertex(Vertex vertex) {
|
||||||
ODocument header = vertex.getProperty(Entity.HEADER_PROPERTY);
|
ODocument header = vertex.getProperty(Entity.HEADER_PROPERTY);
|
||||||
String contextID = header.field(org.gcube.informationsystem.model.embedded.Header.UUID_PROPERTY);
|
String contextID = header
|
||||||
return contextID;
|
.field(org.gcube.informationsystem.model.embedded.Header.UUID_PROPERTY);
|
||||||
|
return UUID.fromString(contextID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getActualContextUUID() throws ContextException {
|
public static UUID getActualContextUUID() throws ContextException {
|
||||||
try {
|
try {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
OrientGraphFactory factory = SecurityContextMapper.getSecurityContextFactory(null, PermissionMode.READER);
|
OrientGraphFactory factory = SecurityContextMapper
|
||||||
|
.getSecurityContextFactory(
|
||||||
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.READER);
|
||||||
Vertex context = ContextUtility.getContextVertexByFullName(
|
Vertex context = ContextUtility.getContextVertexByFullName(
|
||||||
factory.getTx(), scope);
|
factory.getTx(), scope);
|
||||||
return getContextUUIDFromContextVertex(context);
|
return getContextUUIDFromContextVertex(context);
|
||||||
|
@ -79,12 +85,12 @@ public class ContextUtility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static OrientGraphFactory getFactory(PermissionMode permissionMode)
|
||||||
public static OrientGraphFactory getFactory(PermissionMode permissionMode) throws ResourceRegistryException{
|
throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String contextID = getActualContextUUID();
|
UUID contextUUID = getActualContextUUID();
|
||||||
return SecurityContextMapper
|
return SecurityContextMapper.getSecurityContextFactory(contextUUID,
|
||||||
.getSecurityContextFactory(contextID, permissionMode);
|
permissionMode);
|
||||||
} catch (ContextException ce) {
|
} catch (ContextException ce) {
|
||||||
logger.error("Unable to retrieve context.", ce);
|
logger.error("Unable to retrieve context.", ce);
|
||||||
throw ce;
|
throw ce;
|
||||||
|
@ -136,7 +142,6 @@ public class ContextUtility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Vertex getContextVertexByFullName(OrientGraph orientGraph,
|
public static Vertex getContextVertexByFullName(OrientGraph orientGraph,
|
||||||
String fullName) throws ContextNotFoundException {
|
String fullName) throws ContextNotFoundException {
|
||||||
|
|
||||||
|
@ -177,10 +182,11 @@ public class ContextUtility {
|
||||||
|
|
||||||
public static String getActualSecurityRoleOrUserName(
|
public static String getActualSecurityRoleOrUserName(
|
||||||
SecurityContextMapper.PermissionMode permissionMode,
|
SecurityContextMapper.PermissionMode permissionMode,
|
||||||
SecurityContextMapper.SecurityType securityType) throws ContextException {
|
SecurityContextMapper.SecurityType securityType)
|
||||||
String contexUUID = getActualContextUUID();
|
throws ContextException {
|
||||||
|
UUID contextUUID = getActualContextUUID();
|
||||||
return SecurityContextMapper.getSecurityRoleOrUserName(permissionMode,
|
return SecurityContextMapper.getSecurityRoleOrUserName(permissionMode,
|
||||||
securityType, contexUUID);
|
securityType, contextUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ package org.gcube.informationsystem.resourceregistry.resources.utils;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONException;
|
import org.codehaus.jettison.json.JSONException;
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
|
@ -77,7 +78,7 @@ public class Utility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vertex getEntityByUUID(OrientGraph orientGraph,
|
public static Vertex getEntityByUUID(OrientGraph orientGraph,
|
||||||
String entityType, String uuid) throws ResourceRegistryException {
|
String entityType, UUID uuid) throws ResourceRegistryException {
|
||||||
|
|
||||||
if (entityType == null) {
|
if (entityType == null) {
|
||||||
entityType = Entity.NAME;
|
entityType = Entity.NAME;
|
||||||
|
@ -86,7 +87,7 @@ public class Utility {
|
||||||
// TODO Rewrite using Gremlin
|
// TODO Rewrite using Gremlin
|
||||||
String select = "SELECT FROM " + entityType + " WHERE "
|
String select = "SELECT FROM " + entityType + " WHERE "
|
||||||
+ Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY + " = \""
|
+ Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY + " = \""
|
||||||
+ uuid + "\"";
|
+ uuid.toString() + "\"";
|
||||||
|
|
||||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
||||||
select);
|
select);
|
||||||
|
@ -95,7 +96,7 @@ public class Utility {
|
||||||
.execute();
|
.execute();
|
||||||
if (vertexes == null || !vertexes.iterator().hasNext()) {
|
if (vertexes == null || !vertexes.iterator().hasNext()) {
|
||||||
String error = String.format("No %s with UUID %s was found",
|
String error = String.format("No %s with UUID %s was found",
|
||||||
entityType, uuid);
|
entityType, uuid.toString());
|
||||||
logger.info(error);
|
logger.info(error);
|
||||||
throw new EntityException(error);
|
throw new EntityException(error);
|
||||||
}
|
}
|
||||||
|
@ -103,11 +104,11 @@ public class Utility {
|
||||||
Iterator<Vertex> iterator = vertexes.iterator();
|
Iterator<Vertex> iterator = vertexes.iterator();
|
||||||
Vertex entity = iterator.next();
|
Vertex entity = iterator.next();
|
||||||
|
|
||||||
logger.trace("{} with {} is : {}", entityType, uuid, Utility.toJsonString(entity, true));
|
logger.trace("{} with {} is : {}", entityType, uuid.toString(), Utility.toJsonString(entity, true));
|
||||||
|
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
throw new ResourceRegistryException("Found more than one "
|
throw new ResourceRegistryException("Found more than one "
|
||||||
+ entityType + " with uuid " + uuid
|
+ entityType + " with uuid " + uuid.toString()
|
||||||
+ ". This is a fatal error please contact Admnistrator");
|
+ ". This is a fatal error please contact Admnistrator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ public class Utility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Edge getRelationByUUID(OrientGraph orientGraph,
|
public static Edge getRelationByUUID(OrientGraph orientGraph,
|
||||||
String relationType, String uuid) throws ResourceRegistryException {
|
String relationType, UUID uuid) throws ResourceRegistryException {
|
||||||
|
|
||||||
if (relationType == null) {
|
if (relationType == null) {
|
||||||
relationType = Relation.class.getSimpleName();
|
relationType = Relation.class.getSimpleName();
|
||||||
|
@ -124,14 +125,14 @@ public class Utility {
|
||||||
// TODO Rewrite using Gremlin
|
// TODO Rewrite using Gremlin
|
||||||
String select = "SELECT FROM " + relationType + " WHERE "
|
String select = "SELECT FROM " + relationType + " WHERE "
|
||||||
+ Relation.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
+ Relation.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
||||||
+ " = \"" + uuid + "\"";
|
+ " = \"" + uuid.toString() + "\"";
|
||||||
|
|
||||||
OSQLSynchQuery<Edge> osqlSynchQuery = new OSQLSynchQuery<Edge>(select);
|
OSQLSynchQuery<Edge> osqlSynchQuery = new OSQLSynchQuery<Edge>(select);
|
||||||
|
|
||||||
Iterable<Edge> edges = orientGraph.command(osqlSynchQuery).execute();
|
Iterable<Edge> edges = orientGraph.command(osqlSynchQuery).execute();
|
||||||
if (edges == null || !edges.iterator().hasNext()) {
|
if (edges == null || !edges.iterator().hasNext()) {
|
||||||
String error = String.format("No %s with UUID %s was found",
|
String error = String.format("No %s with UUID %s was found",
|
||||||
relationType, uuid);
|
relationType, uuid.toString());
|
||||||
logger.info(error);
|
logger.info(error);
|
||||||
throw new FacetNotFoundException(error);
|
throw new FacetNotFoundException(error);
|
||||||
}
|
}
|
||||||
|
@ -139,12 +140,12 @@ public class Utility {
|
||||||
Iterator<Edge> iterator = edges.iterator();
|
Iterator<Edge> iterator = edges.iterator();
|
||||||
Edge relation = iterator.next();
|
Edge relation = iterator.next();
|
||||||
|
|
||||||
logger.trace("{} with {} is : {}", relationType, uuid,
|
logger.trace("{} with {} is : {}", relationType, uuid.toString(),
|
||||||
Utility.toJsonString(relation, true));
|
Utility.toJsonString(relation, true));
|
||||||
|
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
throw new ResourceRegistryException("Found more than one "
|
throw new ResourceRegistryException("Found more than one "
|
||||||
+ relationType + " with uuid " + uuid
|
+ relationType + " with uuid " + uuid.toString()
|
||||||
+ ". This is a fatal error please contact Admnistrator");
|
+ ". This is a fatal error please contact Admnistrator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry;
|
package org.gcube.informationsystem.resourceregistry;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
|
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
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.ContextException;
|
||||||
|
@ -17,34 +19,34 @@ public class ContextManagerFactory implements Factory<ContextManagement> {
|
||||||
return new ContextManagement() {
|
return new ContextManagement() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String delete(String uuid) throws ContextNotFoundException {
|
public boolean delete(UUID uuid) throws ContextNotFoundException {
|
||||||
return "{fake resource}";
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String create(String parentContextUUID, String name)
|
public String create(UUID parentContextUUID, String name)
|
||||||
throws ContextCreationException {
|
throws ContextCreationException {
|
||||||
return parentContextUUID+"newContext-"+name;
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String rename(String contextUUID, String name)
|
public String rename(UUID contextUUID, String name)
|
||||||
throws ContextNotFoundException {
|
throws ContextNotFoundException {
|
||||||
return contextUUID+"-newName:"+name;
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String move(String newParentUUID, String contextToMoveUUID)
|
public String move(UUID newParentUUID, UUID contextToMoveUUID)
|
||||||
throws ContextNotFoundException {
|
throws ContextNotFoundException {
|
||||||
return newParentUUID+"-"+contextToMoveUUID;
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String read(String contextUUID)
|
public String read(UUID contextUUID)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ContextException {
|
||||||
return contextUUID;
|
return "{}";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry;
|
package org.gcube.informationsystem.resourceregistry;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
|
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetNotFoundException;
|
||||||
|
@ -18,30 +20,30 @@ public class EntityManagementFactory implements Factory<EntityManagement> {
|
||||||
return new EntityManagement() {
|
return new EntityManagement() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String updateFacet(String uuid, String jsonRepresentation)
|
public String updateFacet(UUID uuid, String jsonRepresentation)
|
||||||
throws FacetNotFoundException {
|
throws FacetNotFoundException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readResource(String uuid)
|
public String readResource(UUID uuid)
|
||||||
throws ResourceNotFoundException {
|
throws ResourceNotFoundException {
|
||||||
return "resource";
|
return "resource";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readFacet(String uuid) throws FacetNotFoundException {
|
public String readFacet(UUID uuid) throws FacetNotFoundException {
|
||||||
return "facet";
|
return "facet";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteResource(String uuid)
|
public boolean deleteResource(UUID uuid)
|
||||||
throws ResourceNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ResourceRegistryException {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteFacet(String uuid)
|
public boolean deleteFacet(UUID uuid)
|
||||||
throws FacetNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ResourceRegistryException {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -59,15 +61,15 @@ public class EntityManagementFactory implements Factory<EntityManagement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String attachResource(String sourceResourceUuid,
|
public String attachResource(UUID sourceResourceUuid,
|
||||||
String targetResourceUuid, String relatedToType,
|
UUID targetResourceUuid, String relatedToType,
|
||||||
String jsonProperties) throws ResourceNotFoundException,
|
String jsonProperties) throws ResourceNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String attachFacet(String resourceUuid, String facetUuid,
|
public String attachFacet(UUID resourceUuid, UUID facetUuid,
|
||||||
String consistOfType, String jsonProperties)
|
String consistOfType, String jsonProperties)
|
||||||
throws FacetNotFoundException, ResourceNotFoundException,
|
throws FacetNotFoundException, ResourceNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
|
@ -75,28 +77,28 @@ public class EntityManagementFactory implements Factory<EntityManagement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readFacet(String uuid, String facetType)
|
public String readFacet(UUID uuid, String facetType)
|
||||||
throws FacetNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readResource(String uuid, String resourceType)
|
public String readResource(UUID uuid, String resourceType)
|
||||||
throws ResourceNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean detachFacet(String consistOfUUID)
|
public boolean detachFacet(UUID consistOfUUID)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean detachResource(String relatedToUUID)
|
public boolean detachResource(UUID relatedToUUID)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.informationsystem.resourceregistry.resources.impl;
|
package org.gcube.informationsystem.resourceregistry.resources.impl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.utils.Entities;
|
||||||
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
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.ContextException;
|
||||||
|
@ -12,28 +17,29 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ContextManagementImplTest {
|
public class ContextManagementImplTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ContextManagementImplTest.class);
|
private static Logger logger = LoggerFactory
|
||||||
|
.getLogger(ContextManagementImplTest.class);
|
||||||
|
|
||||||
protected ContextManagementImpl contextManagementImpl;
|
protected ContextManagementImpl contextManagementImpl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
private static final String VALID_CHARACTER = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
* private static final String VALID_CHARACTER =
|
||||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
* "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; private
|
||||||
|
* static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||||
private String randomString(int lenght) {
|
*
|
||||||
StringBuilder sb = new StringBuilder(lenght);
|
* private String randomString(int lenght) { StringBuilder sb = new
|
||||||
for (int i = 0; i < lenght; i++) {
|
* StringBuilder(lenght); for (int i = 0; i < lenght; i++) {
|
||||||
sb.append(VALID_CHARACTER.charAt(SECURE_RANDOM
|
* sb.append(VALID_CHARACTER.charAt(SECURE_RANDOM
|
||||||
.nextInt(VALID_CHARACTER.length())));
|
* .nextInt(VALID_CHARACTER.length()))); } return sb.toString(); }
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public ContextManagementImplTest() {
|
public ContextManagementImplTest() {
|
||||||
|
@ -44,301 +50,415 @@ public class ContextManagementImplTest {
|
||||||
public static final String CTX_NAME_B = "B";
|
public static final String CTX_NAME_B = "B";
|
||||||
public static final String CTX_NAME_C = "C";
|
public static final String CTX_NAME_C = "C";
|
||||||
|
|
||||||
protected void invalidCreation(String parentUUID, String name) throws InternalException {
|
protected void invalidCreation(UUID parentUUID, String name)
|
||||||
|
throws InternalException {
|
||||||
try {
|
try {
|
||||||
contextManagementImpl.create(parentUUID, name);
|
contextManagementImpl.create(parentUUID, name);
|
||||||
throw new RuntimeException("The context " + name + " with parent " + parentUUID + " was already created and MUST throw " + ContextCreationException.class.getSimpleName() + ". This is a bug in your code.");
|
throw new RuntimeException("The context " + name + " with parent "
|
||||||
|
+ parentUUID + " was already created and MUST throw "
|
||||||
|
+ ContextCreationException.class.getSimpleName()
|
||||||
|
+ ". This is a bug in your code.");
|
||||||
} catch (ContextCreationException e) {
|
} catch (ContextCreationException e) {
|
||||||
logger.debug("As expected the context {} with parent {} was already created and a {} has been thrown", name, parentUUID, e.getClass().getSimpleName());
|
logger.debug(
|
||||||
|
"As expected the context {} with parent {} was already created and a {} has been thrown",
|
||||||
|
name, parentUUID, e.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void invalidMoving(String parentUUID, String name){
|
protected void invalidMoving(UUID parentUUID, UUID contextToMove) {
|
||||||
try {
|
try {
|
||||||
contextManagementImpl.move(parentUUID, name);
|
contextManagementImpl.move(parentUUID, contextToMove);
|
||||||
throw new RuntimeException("The context " + name + " with parent " + parentUUID + " was already created and MUST throw " + ContextException.class.getSimpleName() + ". This is a bug in your code.");
|
throw new RuntimeException("The context " + contextToMove
|
||||||
|
+ " with parent " + parentUUID
|
||||||
|
+ " was already created and MUST throw "
|
||||||
|
+ ContextException.class.getSimpleName()
|
||||||
|
+ ". This is a bug in your code.");
|
||||||
} catch (ContextNotFoundException e) {
|
} catch (ContextNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (ContextException e) {
|
} catch (ContextException e) {
|
||||||
logger.debug("As expected the context {} with parent {} was already created and a {} has been thrown", name, parentUUID, e.getClass().getSimpleName());
|
logger.debug(
|
||||||
|
"As expected the context {} with parent {} was already created and a {} has been thrown",
|
||||||
|
contextToMove, parentUUID, e.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void invalidRename(String uuid, String newName){
|
protected void invalidRename(UUID uuid, String newName) {
|
||||||
try {
|
try {
|
||||||
contextManagementImpl.rename(uuid, newName);
|
contextManagementImpl.rename(uuid, newName);
|
||||||
throw new RuntimeException("The context with uuid " + uuid + " cannot be renamed to " + newName + " and MUST throw " + ContextException.class.getSimpleName() + ". This is a bug in your code.");
|
throw new RuntimeException("The context with uuid " + uuid
|
||||||
|
+ " cannot be renamed to " + newName + " and MUST throw "
|
||||||
|
+ ContextException.class.getSimpleName()
|
||||||
|
+ ". This is a bug in your code.");
|
||||||
} catch (ContextNotFoundException e) {
|
} catch (ContextNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (ContextException e) {
|
} catch (ContextException e) {
|
||||||
logger.debug("As expected the context with uuid {} cannot be renamed to {} and a {} has been thrown", uuid, newName, e.getClass().getSimpleName());
|
logger.debug(
|
||||||
|
"As expected the context with uuid {} cannot be renamed to {} and a {} has been thrown",
|
||||||
|
uuid, newName, e.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void invalidDelete(UUID uuid) {
|
||||||
protected void invalidDelete(String uuid){
|
|
||||||
try {
|
try {
|
||||||
contextManagementImpl.delete(uuid);
|
contextManagementImpl.delete(uuid);
|
||||||
throw new RuntimeException("The context with uuid " + uuid + " cannot be deleted and MUST throw " + ContextException.class.getSimpleName() + ". This is a bug in your code.");
|
throw new RuntimeException("The context with uuid " + uuid
|
||||||
|
+ " cannot be deleted and MUST throw "
|
||||||
|
+ ContextException.class.getSimpleName()
|
||||||
|
+ ". This is a bug in your code.");
|
||||||
} catch (ContextNotFoundException e) {
|
} catch (ContextNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (ContextException e) {
|
} catch (ContextException e) {
|
||||||
logger.debug("As expected the context with uuid {} cannot be deleted and a {} has been thrown", uuid, e.getClass().getSimpleName());
|
logger.debug(
|
||||||
|
"As expected the context with uuid {} cannot be deleted and a {} has been thrown",
|
||||||
|
uuid, e.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleTest() throws ContextNotFoundException, ContextException, InternalException {
|
public void simpleTest() throws ContextNotFoundException, ContextException,
|
||||||
String A_1 = contextManagementImpl.create(null, CTX_NAME_A);
|
InternalException, JsonParseException, JsonMappingException,
|
||||||
|
IOException {
|
||||||
|
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||||
|
Context createdContexA1 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonA1);
|
||||||
|
UUID A_1 = createdContexA1.getHeader().getUUID();
|
||||||
|
logger.info("{}", contextJsonA1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A(1)
|
* A(1)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String A_2 = contextManagementImpl.create(A_1, CTX_NAME_A);
|
String contextJsonA2 = contextManagementImpl.create(A_1, CTX_NAME_A);
|
||||||
|
Context createdContexA2 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonA2);
|
||||||
|
logger.info("{}", contextJsonA2);
|
||||||
|
UUID A_2 = createdContexA2.getHeader().getUUID();
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2
|
||||||
* A_2
|
|
||||||
*/
|
|
||||||
String B_3 = contextManagementImpl.create(A_2, CTX_NAME_B);
|
|
||||||
/*
|
|
||||||
* A_1
|
|
||||||
* A_2
|
|
||||||
* B_3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contextManagementImpl.move(A_1, B_3);
|
String contextJsonB3 = contextManagementImpl.create(A_2, CTX_NAME_B);
|
||||||
|
Context createdContexB3 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonB3);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
|
UUID B_3 = createdContexB3.getHeader().getUUID();
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_3
|
||||||
* A_2 B_3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contextManagementImpl.rename(B_3, CTX_NAME_C);
|
contextJsonB3 = contextManagementImpl.move(A_1, B_3);
|
||||||
|
createdContexB3 = Entities.unmarshal(Context.class, contextJsonB3);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_3
|
||||||
* A_2 C_3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contextManagementImpl.rename(B_3, CTX_NAME_B);
|
contextJsonB3 = contextManagementImpl.rename(B_3, CTX_NAME_C);
|
||||||
|
createdContexB3 = Entities.unmarshal(Context.class, contextJsonB3);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 C_3
|
||||||
* A_2 C_3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contextManagementImpl.move(A_2, B_3);
|
contextJsonB3 = contextManagementImpl.rename(B_3, CTX_NAME_B);
|
||||||
|
createdContexB3 = Entities.unmarshal(Context.class, contextJsonB3);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_3
|
||||||
* A_2
|
|
||||||
* B_3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contextManagementImpl.delete(B_3);
|
contextJsonB3 = contextManagementImpl.move(A_2, B_3);
|
||||||
|
createdContexB3 = Entities.unmarshal(Context.class, contextJsonB3);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_3
|
||||||
* A_2
|
|
||||||
*/
|
*/
|
||||||
contextManagementImpl.delete(A_2);
|
|
||||||
|
boolean deleted = contextManagementImpl.delete(B_3);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
/*
|
||||||
|
* A_1 A_2
|
||||||
|
*/
|
||||||
|
|
||||||
|
deleted = contextManagementImpl.delete(A_2);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1
|
||||||
*/
|
*/
|
||||||
contextManagementImpl.delete(A_1);
|
|
||||||
|
deleted = contextManagementImpl.delete(A_1);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
logger.debug("The DB should be now clean");
|
logger.debug("The DB should be now clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDevContext() throws ContextNotFoundException, ContextException, InternalException {
|
public void createDevContext() throws ContextNotFoundException,
|
||||||
String gcube = contextManagementImpl.create(null, "gcube");
|
ContextException, InternalException, JsonParseException,
|
||||||
logger.trace("/gcube : {}", gcube);
|
JsonMappingException, IOException {
|
||||||
String devsec = contextManagementImpl.create(gcube, "devsec");
|
String gcubeJson = contextManagementImpl.create(null, "gcube");
|
||||||
logger.trace("/gcube/devsec : {}", devsec);
|
Context gcubeContex = Entities.unmarshal(Context.class, gcubeJson);
|
||||||
String devVRE = contextManagementImpl.create(devsec, "devVRE");
|
UUID gcube = gcubeContex.getHeader().getUUID();
|
||||||
logger.trace("/gcube/devsec/devVRE : {}", devVRE);
|
logger.trace("/gcube : {}", gcubeJson);
|
||||||
String devNext = contextManagementImpl.create(gcube, "devNext");
|
|
||||||
logger.trace("/gcube/devNext : {}", devNext);
|
String devsecJson = contextManagementImpl.create(gcube, "devsec");
|
||||||
String NextNext = contextManagementImpl.create(devNext, "NextNext");
|
Context devsecContex = Entities.unmarshal(Context.class, devsecJson);
|
||||||
logger.trace("/gcube/devNext/NextNext : {}", NextNext);
|
UUID devsec = devsecContex.getHeader().getUUID();
|
||||||
|
logger.trace("/gcube/devsec : {}", devsecJson);
|
||||||
|
|
||||||
|
String devVREJson = contextManagementImpl.create(devsec, "devVRE");
|
||||||
|
Context devVREContex = Entities.unmarshal(Context.class, devVREJson);
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
UUID devVRE = devVREContex.getHeader().getUUID();
|
||||||
|
logger.trace("/gcube/devsec/devVRE : {}", devVREJson);
|
||||||
|
|
||||||
|
String devNextJson = contextManagementImpl.create(gcube, "devNext");
|
||||||
|
Context devNextContex = Entities.unmarshal(Context.class, devNextJson);
|
||||||
|
UUID devNext = devNextContex.getHeader().getUUID();
|
||||||
|
logger.trace("/gcube/devNext : {}", devNextJson);
|
||||||
|
|
||||||
|
String NextNextJson = contextManagementImpl.create(devNext, "NextNext");
|
||||||
|
Context NextNextContex = Entities.unmarshal(Context.class, NextNextJson);
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
UUID NextNext = NextNextContex.getHeader().getUUID();
|
||||||
|
logger.trace("/gcube/devNext/NextNext : {}", NextNextJson);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
contextManagementImpl.delete(NextNext);
|
* contextManagementImpl.delete(NextNext);
|
||||||
contextManagementImpl.delete(devNext);
|
* contextManagementImpl.delete(devNext);
|
||||||
contextManagementImpl.delete(devVRE);
|
* contextManagementImpl.delete(devVRE);
|
||||||
contextManagementImpl.delete(devsec);
|
* contextManagementImpl.delete(devsec);
|
||||||
contextManagementImpl.delete(gcube);
|
* contextManagementImpl.delete(gcube);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
logger.debug("The DB should be now clean");
|
logger.debug("The DB should be now clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void removeDevContext() throws ContextNotFoundException, ContextException, InternalException {
|
public void removeDevContext() throws ContextNotFoundException,
|
||||||
contextManagementImpl.delete("508da10a-b8e7-414f-b176-65e227addcae");
|
ContextException, InternalException {
|
||||||
contextManagementImpl.delete("d729c993-32f9-4bcd-9311-d92f791e5e12");
|
contextManagementImpl.delete(UUID
|
||||||
contextManagementImpl.delete("8bf286f8-a93c-4936-9826-91f1b1c2af34");
|
.fromString("28f2ce60-e1dd-47e6-9780-58ad8aeb35ed"));
|
||||||
contextManagementImpl.delete("7273c1c7-bc06-4d49-bade-19dc3ab322f7");
|
|
||||||
contextManagementImpl.delete("132691d2-e22d-4e3b-b605-f8b2c94f2c77");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readTest() throws ContextNotFoundException, ContextException, InternalException {
|
public void readTest() throws ContextNotFoundException, ContextException,
|
||||||
String A_1 = contextManagementImpl.create(null, "LLL");
|
InternalException, JsonParseException, JsonMappingException,
|
||||||
String read = contextManagementImpl.read(A_1);
|
IOException {
|
||||||
logger.trace("A : {}", read);
|
String name = "LLL";
|
||||||
contextManagementImpl.delete(A_1);
|
String contextJsonA1 = contextManagementImpl.create(null, name);
|
||||||
|
Context createdContexA1 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonA1);
|
||||||
|
UUID A_1 = createdContexA1.getHeader().getUUID();
|
||||||
|
logger.info("{}", contextJsonA1);
|
||||||
|
Assert.assertTrue(createdContexA1.getName().compareTo(name) == 0);
|
||||||
|
|
||||||
|
String readContextJsonA1 = contextManagementImpl.read(A_1);
|
||||||
|
Context readContexA1 = Entities.unmarshal(Context.class,
|
||||||
|
readContextJsonA1);
|
||||||
|
Assert.assertTrue(readContexA1.getName().compareTo(name) == 0);
|
||||||
|
Assert.assertTrue(A_1.compareTo(readContexA1.getHeader().getUUID()) == 0);
|
||||||
|
logger.trace("{}", createdContexA1);
|
||||||
|
|
||||||
|
boolean deleted = contextManagementImpl.delete(A_1);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void completeTest() throws ContextNotFoundException, ContextException, InternalException {
|
public void completeTest() throws ContextNotFoundException,
|
||||||
String A_1 = contextManagementImpl.create(null, CTX_NAME_A);
|
ContextException, InternalException, JsonParseException,
|
||||||
|
JsonMappingException, IOException {
|
||||||
|
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||||
|
Context createdContexA1 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonA1);
|
||||||
|
UUID A_1 = createdContexA1.getHeader().getUUID();
|
||||||
|
logger.info("{}", contextJsonA1);
|
||||||
/*
|
/*
|
||||||
* A(1)
|
* A(1)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String A_2 = contextManagementImpl.create(A_1, CTX_NAME_A);
|
String contextJsonA2 = contextManagementImpl.create(A_1, CTX_NAME_A);
|
||||||
|
Context createdContexA2 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonA2);
|
||||||
|
logger.info("{}", contextJsonA2);
|
||||||
|
UUID A_2 = createdContexA2.getHeader().getUUID();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2
|
||||||
* A_2
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String B_3 = contextManagementImpl.create(A_2, CTX_NAME_B);
|
String contextJsonB3 = contextManagementImpl.create(A_2, CTX_NAME_B);
|
||||||
|
Context createdContexB3 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonB3);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
|
UUID B_3 = createdContexB3.getHeader().getUUID();
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_3
|
||||||
* A_2
|
|
||||||
* B_3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
String contextJsonB4 = contextManagementImpl.create(A_1, CTX_NAME_B);
|
||||||
String B_4 = contextManagementImpl.create(A_1, CTX_NAME_B);
|
Context createdContexB4 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonB4);
|
||||||
|
logger.info("{}", contextJsonB4);
|
||||||
|
UUID B_4 = createdContexB4.getHeader().getUUID();
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4 B_3
|
||||||
* A_2 B_4
|
|
||||||
* B_3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String A_5 = contextManagementImpl.create(B_4, CTX_NAME_A);
|
String contextJsonA5 = contextManagementImpl.create(B_4, CTX_NAME_A);
|
||||||
|
Context createdContexA5 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonA5);
|
||||||
|
logger.info("{}", contextJsonA5);
|
||||||
|
UUID A_5 = createdContexA5.getHeader().getUUID();
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4 B_3 A_5
|
||||||
* A_2 B_4
|
|
||||||
* B_3 A_5
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
invalidCreation(null, CTX_NAME_A); // Trying to recreate A_1. Fails
|
invalidCreation(null, CTX_NAME_A); // Trying to recreate A_1. Fails
|
||||||
invalidCreation(A_1, CTX_NAME_A); // Trying to recreate A_2. Fails
|
invalidCreation(A_1, CTX_NAME_A); // Trying to recreate A_2. Fails
|
||||||
invalidCreation(A_2, CTX_NAME_B); // Trying to recreate B_3. Fails
|
invalidCreation(A_2, CTX_NAME_B); // Trying to recreate B_3. Fails
|
||||||
invalidCreation(A_1, CTX_NAME_B); // Trying to recreate B_4. Fails
|
invalidCreation(A_1, CTX_NAME_B); // Trying to recreate B_4. Fails
|
||||||
invalidCreation(B_4, CTX_NAME_A); // Trying to recreate A_5. Fails
|
invalidCreation(B_4, CTX_NAME_A); // Trying to recreate A_5. Fails
|
||||||
|
|
||||||
|
|
||||||
// Trying to move B_3 as child of A_1. It fails due to B_4. Fails
|
// Trying to move B_3 as child of A_1. It fails due to B_4. Fails
|
||||||
invalidMoving(A_1, B_3);
|
invalidMoving(A_1, B_3);
|
||||||
// Trying to move A_5 as child of A_1. It fails due to A_2. Fails
|
// Trying to move A_5 as child of A_1. It fails due to A_2. Fails
|
||||||
invalidMoving(A_1, A_5);
|
invalidMoving(A_1, A_5);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Moving B_3 as child of B_4. OK
|
// Moving B_3 as child of B_4. OK
|
||||||
contextManagementImpl.move(B_4, B_3);
|
String movedContextJsonB3 = contextManagementImpl.move(B_4, B_3);
|
||||||
|
Context movedContexB3 = Entities.unmarshal(Context.class,
|
||||||
|
movedContextJsonB3);
|
||||||
|
Assert.assertTrue(B_3.compareTo(movedContexB3.getHeader().getUUID()) == 0);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4 B_3 A_5
|
||||||
* A_2 B_4
|
|
||||||
* B_3 A_5
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Restoring the initial situation by moving B_3 as child of A_2
|
// Restoring the initial situation by moving B_3 as child of A_2
|
||||||
contextManagementImpl.move(A_2, B_3);
|
String movedAgainJsonB3 = contextManagementImpl.move(A_2, B_3);
|
||||||
|
Context movedAgainContexB3 = Entities.unmarshal(Context.class,
|
||||||
|
movedAgainJsonB3);
|
||||||
|
Assert.assertTrue(B_3.compareTo(movedAgainContexB3.getHeader()
|
||||||
|
.getUUID()) == 0);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4 B_3 A_5
|
||||||
* A_2 B_4
|
|
||||||
* B_3 A_5
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Trying to move B_3 as child of A_1. It fails due to B_4. Fails
|
// Trying to move B_3 as child of A_1. It fails due to B_4. Fails
|
||||||
invalidMoving(A_1, B_3);
|
invalidMoving(A_1, B_3);
|
||||||
|
|
||||||
// Renaming B_3 as C_3
|
// Renaming B_3 as C_3
|
||||||
String C_3 = contextManagementImpl.rename(B_3, CTX_NAME_C);
|
String contextJsonC3 = contextManagementImpl.rename(B_3, CTX_NAME_C);
|
||||||
|
Context createdContexC3 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonC3);
|
||||||
|
logger.info("{}", contextJsonC3);
|
||||||
|
UUID C_3 = createdContexC3.getHeader().getUUID();
|
||||||
Assert.assertTrue(C_3.compareTo(B_3) == 0);
|
Assert.assertTrue(C_3.compareTo(B_3) == 0);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4 C_3 A_5
|
||||||
* A_2 B_4
|
|
||||||
* C_3 A_5
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Moving C_3 (was B_3) as child of A_1. Now it is possible
|
// Moving C_3 (was B_3) as child of A_1. Now it is possible
|
||||||
contextManagementImpl.move(A_1, B_3);
|
contextJsonC3 = contextManagementImpl.move(A_1, C_3);
|
||||||
|
createdContexC3 = Entities.unmarshal(Context.class, contextJsonC3);
|
||||||
|
logger.info("{}", contextJsonC3);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 C_3 A_2 B_4 A_5
|
||||||
* C_3 A_2 B_4
|
|
||||||
* A_5
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Trying to rename C_3 (was B_3) newly to B_3. Fails due to B_4
|
// Trying to rename C_3 (was B_3) newly to B_3. Fails due to B_4
|
||||||
invalidRename(C_3, CTX_NAME_B);
|
invalidRename(C_3, CTX_NAME_B);
|
||||||
|
|
||||||
|
|
||||||
// Moving back C_3 (was B_3) as child of A_2.
|
// Moving back C_3 (was B_3) as child of A_2.
|
||||||
contextManagementImpl.move(A_2, B_3);
|
contextJsonB3 = contextManagementImpl.move(A_2, C_3);
|
||||||
String BC_3 = contextManagementImpl.rename(C_3, CTX_NAME_B);
|
createdContexB3 = Entities.unmarshal(Context.class, contextJsonB3);
|
||||||
|
logger.info("{}", contextJsonB3);
|
||||||
|
|
||||||
|
String contextJsonBC3 = contextManagementImpl.rename(C_3, CTX_NAME_B);
|
||||||
|
Context createdContexBC3 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonBC3);
|
||||||
|
logger.info("{}", contextJsonBC3);
|
||||||
|
UUID BC_3 = createdContexBC3.getHeader().getUUID();
|
||||||
Assert.assertTrue(BC_3.compareTo(B_3) == 0);
|
Assert.assertTrue(BC_3.compareTo(B_3) == 0);
|
||||||
Assert.assertTrue(BC_3.compareTo(C_3) == 0);
|
Assert.assertTrue(BC_3.compareTo(C_3) == 0);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4 B_3 A_5
|
||||||
* A_2 B_4
|
|
||||||
* B_3 A_5
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
invalidDelete(A_1);
|
invalidDelete(A_1);
|
||||||
invalidDelete(A_2);
|
invalidDelete(A_2);
|
||||||
invalidDelete(B_4);
|
invalidDelete(B_4);
|
||||||
contextManagementImpl.delete(A_5);
|
boolean deleted = contextManagementImpl.delete(A_5);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4 B_3
|
||||||
* A_2 B_4
|
|
||||||
* B_3
|
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
contextManagementImpl.delete(A_5);
|
contextManagementImpl.delete(A_5);
|
||||||
} catch (ContextNotFoundException e) {
|
} catch (ContextNotFoundException e) {
|
||||||
logger.debug("The context with uuid {} was not found. (Was already deleted)", A_5);
|
logger.debug(
|
||||||
|
"The context with uuid {} was not found. (Was already deleted)",
|
||||||
|
A_5);
|
||||||
}
|
}
|
||||||
|
|
||||||
contextManagementImpl.delete(B_3);
|
deleted = contextManagementImpl.delete(B_3);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2 B_4
|
||||||
* A_2 B_4
|
|
||||||
*/
|
*/
|
||||||
invalidDelete(A_1);
|
invalidDelete(A_1);
|
||||||
contextManagementImpl.delete(B_4);
|
deleted = contextManagementImpl.delete(B_4);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1 A_2
|
||||||
* A_2
|
|
||||||
*/
|
*/
|
||||||
contextManagementImpl.delete(A_2);
|
deleted = contextManagementImpl.delete(A_2);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
/*
|
/*
|
||||||
* A_1
|
* A_1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contextManagementImpl.delete(A_1);
|
deleted = contextManagementImpl.delete(A_1);
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
|
||||||
logger.debug("The DB should be now clean");
|
logger.debug("The DB should be now clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void moveToRootTest() throws ContextNotFoundException, ContextException, InternalException {
|
public void moveToRootTest() throws ContextNotFoundException,
|
||||||
String A_1 = contextManagementImpl.create(null, CTX_NAME_A);
|
ContextException, InternalException, JsonParseException,
|
||||||
String A_2 = contextManagementImpl.create(A_1, CTX_NAME_B);
|
JsonMappingException, IOException {
|
||||||
contextManagementImpl.move(null, A_2);
|
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||||
|
Context createdContexA1 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonA1);
|
||||||
|
UUID A_1 = createdContexA1.getHeader().getUUID();
|
||||||
|
logger.info("{}", contextJsonA1);
|
||||||
|
/*
|
||||||
|
* A(1)
|
||||||
|
*/
|
||||||
|
|
||||||
|
String contextJsonB2 = contextManagementImpl.create(A_1, CTX_NAME_B);
|
||||||
|
Context createdContexB2 = Entities.unmarshal(Context.class,
|
||||||
|
contextJsonB2);
|
||||||
|
logger.info("{}", contextJsonB2);
|
||||||
|
UUID B_2 = createdContexB2.getHeader().getUUID();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A_1 B_2
|
||||||
|
*/
|
||||||
|
|
||||||
|
String movedContextJsonB2 = contextManagementImpl.move(null, B_2);
|
||||||
|
Context movedContexB2 = Entities.unmarshal(Context.class,
|
||||||
|
movedContextJsonB2);
|
||||||
|
Assert.assertTrue(B_2.compareTo(movedContexB2.getHeader().getUUID()) == 0);
|
||||||
contextManagementImpl.delete(A_1);
|
contextManagementImpl.delete(A_1);
|
||||||
contextManagementImpl.delete(A_2);
|
contextManagementImpl.delete(B_2);
|
||||||
logger.debug("The DB should be now clean");
|
logger.debug("The DB should be now clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class EntityManagementImplTest {
|
||||||
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
||||||
|
|
||||||
|
|
||||||
String readJson = entityManagementImpl.readFacet(uuid.toString());
|
String readJson = entityManagementImpl.readFacet(uuid);
|
||||||
CPUFacet readCpuFacet = Entities.unmarshal(CPUFacet.class, readJson);
|
CPUFacet readCpuFacet = Entities.unmarshal(CPUFacet.class, readJson);
|
||||||
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet);
|
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet);
|
||||||
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed())==0);
|
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed())==0);
|
||||||
|
@ -92,7 +92,7 @@ public class EntityManagementImplTest {
|
||||||
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
|
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
|
||||||
|
|
||||||
|
|
||||||
String updatedJson = entityManagementImpl.updateFacet(uuid.toString(),Entities.marshal(readCpuFacet));
|
String updatedJson = entityManagementImpl.updateFacet(uuid,Entities.marshal(readCpuFacet));
|
||||||
CPUFacet updatedCpuFacet = Entities.unmarshal(CPUFacet.class, updatedJson);
|
CPUFacet updatedCpuFacet = Entities.unmarshal(CPUFacet.class, updatedJson);
|
||||||
logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet);
|
logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet);
|
||||||
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed())==0);
|
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed())==0);
|
||||||
|
@ -102,7 +102,7 @@ public class EntityManagementImplTest {
|
||||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
|
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
|
||||||
|
|
||||||
|
|
||||||
String readUpdatedJson = entityManagementImpl.readFacet(uuid.toString());
|
String readUpdatedJson = entityManagementImpl.readFacet(uuid);
|
||||||
CPUFacet readUpdatedCpuFacet = Entities.unmarshal(CPUFacet.class, readUpdatedJson);
|
CPUFacet readUpdatedCpuFacet = Entities.unmarshal(CPUFacet.class, readUpdatedJson);
|
||||||
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
|
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
|
||||||
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed())==0);
|
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed())==0);
|
||||||
|
@ -111,7 +111,7 @@ public class EntityManagementImplTest {
|
||||||
Assert.assertTrue(((String)updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
|
Assert.assertTrue(((String)updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
|
||||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
|
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
|
||||||
|
|
||||||
boolean deleted = entityManagementImpl.deleteFacet(uuid.toString());
|
boolean deleted = entityManagementImpl.deleteFacet(uuid);
|
||||||
Assert.assertTrue(deleted);
|
Assert.assertTrue(deleted);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class EntityManagementImplTest {
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject(json);
|
JSONObject jsonObject = new JSONObject(json);
|
||||||
JSONObject header = jsonObject.getJSONObject(Entity.HEADER_PROPERTY);
|
JSONObject header = jsonObject.getJSONObject(Entity.HEADER_PROPERTY);
|
||||||
String uuid = header.getString(Header.UUID_PROPERTY);
|
UUID uuid = UUID.fromString(header.getString(Header.UUID_PROPERTY));
|
||||||
|
|
||||||
String readJson = entityManagementImpl.readFacet(uuid);
|
String readJson = entityManagementImpl.readFacet(uuid);
|
||||||
logger.debug("Read : {}", readJson);
|
logger.debug("Read : {}", readJson);
|
||||||
|
@ -308,7 +308,7 @@ public class EntityManagementImplTest {
|
||||||
|
|
||||||
String json = entityManagementImpl.createResource(
|
String json = entityManagementImpl.createResource(
|
||||||
HostingNode.class.getSimpleName(), "{}");
|
HostingNode.class.getSimpleName(), "{}");
|
||||||
String resourceUUID = Utility.getUUIDFromJSONString(json);
|
UUID resourceUUID = Utility.getUUIDFromJSONString(json);
|
||||||
|
|
||||||
CPUFacetImpl cpuFacetImpl = new CPUFacetImpl();
|
CPUFacetImpl cpuFacetImpl = new CPUFacetImpl();
|
||||||
cpuFacetImpl.setClockSpeed("1 GHz");
|
cpuFacetImpl.setClockSpeed("1 GHz");
|
||||||
|
@ -320,13 +320,13 @@ public class EntityManagementImplTest {
|
||||||
json = entityManagementImpl.createFacet(CPUFacet.class.getSimpleName(),
|
json = entityManagementImpl.createFacet(CPUFacet.class.getSimpleName(),
|
||||||
stringWriter.toString());
|
stringWriter.toString());
|
||||||
logger.debug("Created : {}", json);
|
logger.debug("Created : {}", json);
|
||||||
String facetUUID = Utility.getUUIDFromJSONString(json);
|
UUID facetUUID = Utility.getUUIDFromJSONString(json);
|
||||||
|
|
||||||
json = entityManagementImpl.attachFacet(resourceUUID, facetUUID,
|
json = entityManagementImpl.attachFacet(resourceUUID, facetUUID,
|
||||||
ConsistsOf.class.getSimpleName(), null);
|
ConsistsOf.class.getSimpleName(), null);
|
||||||
logger.debug("Facet attached : {}", json);
|
logger.debug("Facet attached : {}", json);
|
||||||
|
|
||||||
String consistOfUUID = Utility.getUUIDFromJSONString(json);
|
UUID consistOfUUID = Utility.getUUIDFromJSONString(json);
|
||||||
|
|
||||||
boolean detached = entityManagementImpl.detachFacet(consistOfUUID);
|
boolean detached = entityManagementImpl.detachFacet(consistOfUUID);
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ public class EntityManagementImplTest {
|
||||||
String json = entityManagementImpl.createFacet(CPUFacet.class.getSimpleName(),
|
String json = entityManagementImpl.createFacet(CPUFacet.class.getSimpleName(),
|
||||||
stringWriter.toString());
|
stringWriter.toString());
|
||||||
logger.debug("Created : {}", json);
|
logger.debug("Created : {}", json);
|
||||||
String createdFacetUUID = Utility.getUUIDFromJSONString(json);
|
UUID createdFacetUUID = Utility.getUUIDFromJSONString(json);
|
||||||
|
|
||||||
HostingNode hostingNode = new HostingNodeImpl();
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ public class EntityManagementImplTest {
|
||||||
|
|
||||||
hostingNode.addFacet(cpuFacetImpl);
|
hostingNode.addFacet(cpuFacetImpl);
|
||||||
|
|
||||||
hostingNode.attachFacet(UUID.fromString(createdFacetUUID));
|
hostingNode.attachFacet(createdFacetUUID);
|
||||||
|
|
||||||
|
|
||||||
StringWriter resourceStringWriter = new StringWriter();
|
StringWriter resourceStringWriter = new StringWriter();
|
||||||
|
@ -381,9 +381,9 @@ public class EntityManagementImplTest {
|
||||||
|
|
||||||
json = entityManagementImpl.createResource(
|
json = entityManagementImpl.createResource(
|
||||||
HostingNode.class.getSimpleName(), resourceStringWriter.toString());
|
HostingNode.class.getSimpleName(), resourceStringWriter.toString());
|
||||||
String resourceUUID = Utility.getUUIDFromJSONString(json);
|
UUID resourceUUID = Utility.getUUIDFromJSONString(json);
|
||||||
|
|
||||||
logger.debug(resourceUUID);
|
logger.debug("{}", resourceUUID);
|
||||||
|
|
||||||
//entityManagementImpl.deleteResource(resourceUUID);
|
//entityManagementImpl.deleteResource(resourceUUID);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue