All the refactored code has been tested with existing JUnit tests
This commit is contained in:
parent
6e985eec65
commit
90a25ee7e7
|
@ -103,8 +103,7 @@ public class ContextUtility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AdminSecurityContext getAdminSecurityContext() throws ResourceRegistryException {
|
public static AdminSecurityContext getAdminSecurityContext() throws ResourceRegistryException {
|
||||||
AdminSecurityContext adminSecurityContext = (AdminSecurityContext) ContextUtility.getInstance()
|
AdminSecurityContext adminSecurityContext = AdminSecurityContext.getInstance();
|
||||||
.getSecurityContextByUUID(AdminSecurityContext.ADMIN_SECURITY_CONTEXT_UUID);
|
|
||||||
return adminSecurityContext;
|
return adminSecurityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,7 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if (workingContext == null) {
|
if (workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = ContextSecurityContext.getInstance();
|
||||||
.getSecurityContextByUUID(ContextSecurityContext.CONTEXT_SECURITY_CONTEXT_UUID);
|
|
||||||
}
|
}
|
||||||
return workingContext;
|
return workingContext;
|
||||||
}
|
}
|
||||||
|
@ -149,13 +148,14 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
||||||
select.append("\"");
|
select.append("\"");
|
||||||
select.append(QueryLogicalOperator.AND.getLogicalOperator());
|
select.append(QueryLogicalOperator.AND.getLogicalOperator());
|
||||||
select.append(Context.HEADER_PROPERTY);
|
select.append(Context.HEADER_PROPERTY);
|
||||||
|
select.append(".");
|
||||||
select.append(Header.UUID_PROPERTY);
|
select.append(Header.UUID_PROPERTY);
|
||||||
select.append(QueryConditionalOperator.NE.getConditionalOperator());
|
select.append(QueryConditionalOperator.NE.getConditionalOperator());
|
||||||
select.append("\"");
|
select.append("\"");
|
||||||
select.append(parentContext.uuid);
|
select.append(parentContext.uuid);
|
||||||
select.append("\"");
|
select.append("\"");
|
||||||
|
|
||||||
errorMessage.append("A root ");
|
errorMessage.append("A ");
|
||||||
errorMessage.append(Context.NAME);
|
errorMessage.append(Context.NAME);
|
||||||
errorMessage.append(" with ");
|
errorMessage.append(" with ");
|
||||||
errorMessage.append(this.getName());
|
errorMessage.append(this.getName());
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
|
@ -51,8 +50,7 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if (workingContext == null) {
|
if (workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = ContextSecurityContext.getInstance();
|
||||||
.getSecurityContextByUUID(ContextSecurityContext.CONTEXT_SECURITY_CONTEXT_UUID);
|
|
||||||
}
|
}
|
||||||
return workingContext;
|
return workingContext;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.contexts.security;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -18,15 +19,26 @@ public class AdminSecurityContext extends SecurityContext {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
||||||
|
|
||||||
public static final String ADMIN_SECURITY_CONTEXT;
|
private static final String ADMIN_SECURITY_CONTEXT;
|
||||||
public static final UUID ADMIN_SECURITY_CONTEXT_UUID;
|
private static final UUID ADMIN_SECURITY_CONTEXT_UUID;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ADMIN_SECURITY_CONTEXT = "00000000-0000-0000-0000-000000000000";
|
ADMIN_SECURITY_CONTEXT = "00000000-0000-0000-0000-000000000000";
|
||||||
ADMIN_SECURITY_CONTEXT_UUID = UUID.fromString(ADMIN_SECURITY_CONTEXT);
|
ADMIN_SECURITY_CONTEXT_UUID = UUID.fromString(ADMIN_SECURITY_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdminSecurityContext() throws ResourceRegistryException {
|
private static AdminSecurityContext instance;
|
||||||
|
|
||||||
|
public static AdminSecurityContext getInstance() throws ResourceRegistryException {
|
||||||
|
if(instance==null) {
|
||||||
|
instance = new AdminSecurityContext();
|
||||||
|
ContextUtility contextUtility = ContextUtility.getInstance();
|
||||||
|
contextUtility.addSecurityContext(ADMIN_SECURITY_CONTEXT, instance);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AdminSecurityContext() throws ResourceRegistryException {
|
||||||
super(ADMIN_SECURITY_CONTEXT_UUID, false);
|
super(ADMIN_SECURITY_CONTEXT_UUID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.contexts.security;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -16,15 +17,26 @@ public class ContextSecurityContext extends SecurityContext {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
||||||
|
|
||||||
public static final String CONTEXT_SECURITY_CONTEXT;
|
private static final String CONTEXT_SECURITY_CONTEXT;
|
||||||
public static final UUID CONTEXT_SECURITY_CONTEXT_UUID;
|
private static final UUID CONTEXT_SECURITY_CONTEXT_UUID;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
CONTEXT_SECURITY_CONTEXT = "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
CONTEXT_SECURITY_CONTEXT = "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
||||||
CONTEXT_SECURITY_CONTEXT_UUID = UUID.fromString(CONTEXT_SECURITY_CONTEXT);
|
CONTEXT_SECURITY_CONTEXT_UUID = UUID.fromString(CONTEXT_SECURITY_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContextSecurityContext() throws ResourceRegistryException {
|
private static ContextSecurityContext instance;
|
||||||
|
|
||||||
|
public static ContextSecurityContext getInstance() throws ResourceRegistryException {
|
||||||
|
if(instance==null) {
|
||||||
|
instance = new ContextSecurityContext();
|
||||||
|
ContextUtility contextUtility = ContextUtility.getInstance();
|
||||||
|
contextUtility.addSecurityContext(CONTEXT_SECURITY_CONTEXT, instance);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContextSecurityContext() throws ResourceRegistryException {
|
||||||
super(CONTEXT_SECURITY_CONTEXT_UUID, false);
|
super(CONTEXT_SECURITY_CONTEXT_UUID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.contexts.security;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -16,15 +17,26 @@ public class QueryTemplatesSecurityContext extends SecurityContext {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
||||||
|
|
||||||
public static final String QUERY_TEMPLATES_SECURITY_CONTEXT;
|
private static final String QUERY_TEMPLATES_SECURITY_CONTEXT;
|
||||||
public static final UUID QUERY_TEMPLATES_SECURITY_CONTEXT_UUID;
|
private static final UUID QUERY_TEMPLATES_SECURITY_CONTEXT_UUID;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
QUERY_TEMPLATES_SECURITY_CONTEXT = "dddddddd-dddd-dddd-dddd-dddddddddddd";
|
QUERY_TEMPLATES_SECURITY_CONTEXT = "dddddddd-dddd-dddd-dddd-dddddddddddd";
|
||||||
QUERY_TEMPLATES_SECURITY_CONTEXT_UUID = UUID.fromString(QUERY_TEMPLATES_SECURITY_CONTEXT);
|
QUERY_TEMPLATES_SECURITY_CONTEXT_UUID = UUID.fromString(QUERY_TEMPLATES_SECURITY_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryTemplatesSecurityContext() throws ResourceRegistryException {
|
private static QueryTemplatesSecurityContext instance;
|
||||||
|
|
||||||
|
public static QueryTemplatesSecurityContext getInstance() throws ResourceRegistryException {
|
||||||
|
if(instance==null) {
|
||||||
|
instance = new QueryTemplatesSecurityContext();
|
||||||
|
ContextUtility contextUtility = ContextUtility.getInstance();
|
||||||
|
contextUtility.addSecurityContext(QUERY_TEMPLATES_SECURITY_CONTEXT, instance);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private QueryTemplatesSecurityContext() throws ResourceRegistryException {
|
||||||
super(QUERY_TEMPLATES_SECURITY_CONTEXT_UUID, false);
|
super(QUERY_TEMPLATES_SECURITY_CONTEXT_UUID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.contexts.security;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -16,16 +17,26 @@ public class SchemaSecurityContext extends SecurityContext {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
||||||
|
|
||||||
// Used to persist Schemas
|
private static final String SCHEMA_SECURITY_CONTEXT;
|
||||||
public static final String SCHEMA_SECURITY_CONTEXT;
|
private static final UUID SCHEMA_SECURITY_CONTEXT_UUID;
|
||||||
public static final UUID SCHEMA_SECURITY_CONTEXT_UUID;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
SCHEMA_SECURITY_CONTEXT = "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee";
|
SCHEMA_SECURITY_CONTEXT = "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee";
|
||||||
SCHEMA_SECURITY_CONTEXT_UUID = UUID.fromString(SCHEMA_SECURITY_CONTEXT);
|
SCHEMA_SECURITY_CONTEXT_UUID = UUID.fromString(SCHEMA_SECURITY_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SchemaSecurityContext() throws ResourceRegistryException {
|
private static SchemaSecurityContext instance;
|
||||||
|
|
||||||
|
public static SchemaSecurityContext getInstance() throws ResourceRegistryException {
|
||||||
|
if(instance==null) {
|
||||||
|
instance = new SchemaSecurityContext();
|
||||||
|
ContextUtility contextUtility = ContextUtility.getInstance();
|
||||||
|
contextUtility.addSecurityContext(SCHEMA_SECURITY_CONTEXT, instance);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SchemaSecurityContext() throws ResourceRegistryException {
|
||||||
super(SCHEMA_SECURITY_CONTEXT_UUID, false);
|
super(SCHEMA_SECURITY_CONTEXT_UUID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||||
import org.gcube.informationsystem.base.reference.relations.RelationElement;
|
import org.gcube.informationsystem.base.reference.relations.RelationElement;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext;
|
||||||
|
@ -183,19 +182,11 @@ public class DatabaseEnvironment {
|
||||||
try {
|
try {
|
||||||
boolean created = initGraphDB();
|
boolean created = initGraphDB();
|
||||||
|
|
||||||
ContextUtility contextUtility = ContextUtility.getInstance();
|
AdminSecurityContext adminSecurityContext = AdminSecurityContext.getInstance();
|
||||||
|
|
||||||
AdminSecurityContext adminSecurityContext = new AdminSecurityContext();
|
QueryTemplatesSecurityContext queryTemplatesSecurityContext = QueryTemplatesSecurityContext.getInstance();
|
||||||
contextUtility.addSecurityContext(adminSecurityContext.getUUID().toString(), adminSecurityContext);
|
SchemaSecurityContext schemaSecurityContext = SchemaSecurityContext.getInstance();
|
||||||
|
ContextSecurityContext contextSecurityContext = ContextSecurityContext.getInstance();
|
||||||
QueryTemplatesSecurityContext queryTemplatesSecurityContext = new QueryTemplatesSecurityContext();
|
|
||||||
contextUtility.addSecurityContext(queryTemplatesSecurityContext.getUUID().toString(), queryTemplatesSecurityContext);
|
|
||||||
|
|
||||||
ContextSecurityContext contextSecurityContext = new ContextSecurityContext();
|
|
||||||
contextUtility.addSecurityContext(contextSecurityContext.getUUID().toString(), contextSecurityContext);
|
|
||||||
|
|
||||||
SchemaSecurityContext schemaSecurityContext = new SchemaSecurityContext();
|
|
||||||
contextUtility.addSecurityContext(schemaSecurityContext.getUUID().toString(), schemaSecurityContext);
|
|
||||||
|
|
||||||
if(created) {
|
if(created) {
|
||||||
ODatabasePool pool = new ODatabasePool(DatabaseEnvironment.DB_URI, CHANGED_ADMIN_USERNAME,
|
ODatabasePool pool = new ODatabasePool(DatabaseEnvironment.DB_URI, CHANGED_ADMIN_USERNAME,
|
||||||
|
@ -206,9 +197,10 @@ public class DatabaseEnvironment {
|
||||||
oDatabaseDocument.close();
|
oDatabaseDocument.close();
|
||||||
pool.close();
|
pool.close();
|
||||||
|
|
||||||
|
queryTemplatesSecurityContext.create();
|
||||||
|
schemaSecurityContext.create();
|
||||||
contextSecurityContext.create();
|
contextSecurityContext.create();
|
||||||
|
|
||||||
schemaSecurityContext.create();
|
|
||||||
|
|
||||||
List<Class<? extends Element>> definitionToBeCreated = new ArrayList<>();
|
List<Class<? extends Element>> definitionToBeCreated = new ArrayList<>();
|
||||||
definitionToBeCreated.add(PropertyElement.class);
|
definitionToBeCreated.add(PropertyElement.class);
|
||||||
|
|
|
@ -2,25 +2,28 @@ package org.gcube.informationsystem.resourceregistry.query.templates;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.query.templates.reference.entities.QueryTemplate;
|
import org.gcube.informationsystem.query.templates.reference.entities.QueryTemplate;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||||
import com.orientechnologies.orient.core.record.OVertex;
|
import com.orientechnologies.orient.core.record.OVertex;
|
||||||
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,8 +66,7 @@ public class QueryTemplateManagement extends EntityElementManagement<Context, En
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if (workingContext == null) {
|
if (workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = QueryTemplatesSecurityContext.getInstance();
|
||||||
.getSecurityContextByUUID(QueryTemplatesSecurityContext.QUERY_TEMPLATES_SECURITY_CONTEXT_UUID);
|
|
||||||
}
|
}
|
||||||
return workingContext;
|
return workingContext;
|
||||||
}
|
}
|
||||||
|
@ -125,8 +127,9 @@ public class QueryTemplateManagement extends EntityElementManagement<Context, En
|
||||||
@Override
|
@Override
|
||||||
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
tryTemplate();
|
tryTemplate();
|
||||||
|
OVertex queryTemplate = getElement();
|
||||||
|
queryTemplate = (OVertex) updateProperties(oClass, queryTemplate, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||||
return getElement();
|
return getElement();
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -139,8 +142,7 @@ public class QueryTemplateManagement extends EntityElementManagement<Context, En
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void reallyDelete() throws NotFoundException, ResourceRegistryException {
|
protected void reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
getElement().delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -155,8 +157,25 @@ public class QueryTemplateManagement extends EntityElementManagement<Context, En
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
return null;
|
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||||
|
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(typeName, polymorphic);
|
||||||
|
for (ODocument vertex : iterable) {
|
||||||
|
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||||
|
queryTemplateManagement.setElement((OVertex) vertex);
|
||||||
|
try {
|
||||||
|
JsonNode jsonObject = queryTemplateManagement.serializeAsJsonNode();
|
||||||
|
arrayNode.add(jsonObject);
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||||
|
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return objectMapper.writeValueAsString(arrayNode);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.Entity
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SchemaSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SchemaSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||||
|
@ -50,8 +49,7 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if (workingContext == null) {
|
if (workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = SchemaSecurityContext.getInstance();
|
||||||
.getSecurityContextByUUID(SchemaSecurityContext.SCHEMA_SECURITY_CONTEXT_UUID);
|
|
||||||
}
|
}
|
||||||
return workingContext;
|
return workingContext;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SchemaSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SchemaSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||||
|
@ -57,8 +56,7 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if(workingContext == null) {
|
if(workingContext == null) {
|
||||||
workingContext = ContextUtility.getInstance()
|
workingContext = SchemaSecurityContext.getInstance();
|
||||||
.getSecurityContextByUUID(SchemaSecurityContext.SCHEMA_SECURITY_CONTEXT_UUID);
|
|
||||||
}
|
}
|
||||||
return workingContext;
|
return workingContext;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.Rela
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SchemaSecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SchemaSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||||
|
@ -61,8 +60,7 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
@Override
|
@Override
|
||||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||||
if (workingContext == null) {
|
if (workingContext == null) {
|
||||||
this.workingContext = ContextUtility.getInstance()
|
this.workingContext = SchemaSecurityContext.getInstance();
|
||||||
.getSecurityContextByUUID(SchemaSecurityContext.SCHEMA_SECURITY_CONTEXT_UUID);
|
|
||||||
}
|
}
|
||||||
return workingContext;
|
return workingContext;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,9 +84,7 @@ public class ContextManagementTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void roleUserAssertions(UUID uuid, UUID oldParentUUID, boolean deleted) throws ResourceRegistryException {
|
protected void roleUserAssertions(UUID uuid, UUID oldParentUUID, boolean deleted) throws ResourceRegistryException {
|
||||||
ContextSecurityContext contextSecurityContext = new ContextSecurityContext();
|
ContextSecurityContext contextSecurityContext = ContextSecurityContext.getInstance();
|
||||||
ContextUtility.getInstance().addSecurityContext(contextSecurityContext.getUUID().toString(),
|
|
||||||
contextSecurityContext);
|
|
||||||
|
|
||||||
ODatabaseDocument oDatabaseDocument = contextSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
ODatabaseDocument oDatabaseDocument = contextSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||||
OSecurity oSecurity = oDatabaseDocument.getMetadata().getSecurity();
|
OSecurity oSecurity = oDatabaseDocument.getMetadata().getSecurity();
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class JsonQueryTest extends ContextTest {
|
||||||
|
|
||||||
File queriesDirectory = getQueriesDirectory();
|
File queriesDirectory = getQueriesDirectory();
|
||||||
|
|
||||||
for(int i=1; i<6; i++) {
|
for(int i=1; i<7; i++) {
|
||||||
File jsonQueryFile = new File(queriesDirectory, "query" + i + ".json");
|
File jsonQueryFile = new File(queriesDirectory, "query" + i + ".json");
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
JsonNode jsonNode = objectMapper.readTree(jsonQueryFile);
|
JsonNode jsonNode = objectMapper.readTree(jsonQueryFile);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.query.templates;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class QueryTemplateManagementTest {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(QueryTemplateManagementTest.class);
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testCreate() throws ResourceRegistryException {
|
||||||
|
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||||
|
queryTemplateManagement.setName("Test");
|
||||||
|
queryTemplateManagement.setJson("");
|
||||||
|
String created = queryTemplateManagement.create();
|
||||||
|
logger.debug(created);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdate() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDelete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"@class": "EService",
|
||||||
|
"consistsOf": [
|
||||||
|
{
|
||||||
|
"@class": "ConsistsOf",
|
||||||
|
"propagationConstraint" : {
|
||||||
|
"add": "propagate"
|
||||||
|
},
|
||||||
|
"target": {
|
||||||
|
"@class": "StateFacet",
|
||||||
|
"value": "down"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@class": "IsIdentifiedBy",
|
||||||
|
"target": {
|
||||||
|
"@class": "SoftwareFacet",
|
||||||
|
"name": "data-transfer-service",
|
||||||
|
"group": "DataTransfer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
TRAVERSE outV("EService") FROM ( TRAVERSE inE("IsIdentifiedBy") FROM ( SELECT FROM ( TRAVERSE inV("SoftwareFacet") FROM ( TRAVERSE outE("IsIdentifiedBy") FROM ( TRAVERSE outV("EService") FROM ( SELECT FROM ( TRAVERSE inE("ConsistsOf") FROM ( SELECT FROM StateFacet WHERE value = "down")) WHERE propagationConstraint.add = "propagate")))) WHERE name = "data-transfer-service" AND group = "DataTransfer"))
|
Loading…
Reference in New Issue