Add to context add only the ERElement in the source context #12218
This commit is contained in:
parent
78d1f71aa6
commit
f17106e42e
|
@ -10,8 +10,10 @@ import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||||
|
@ -29,6 +31,7 @@ import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||||
import com.orientechnologies.orient.core.record.ODirection;
|
import com.orientechnologies.orient.core.record.ODirection;
|
||||||
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.OResult;
|
import com.orientechnologies.orient.core.sql.executor.OResult;
|
||||||
import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
||||||
|
|
||||||
|
@ -115,6 +118,8 @@ public class ContextUtility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized SecurityContext getSecurityContextByFullName(String fullName) throws ContextException {
|
public synchronized SecurityContext getSecurityContextByFullName(String fullName) throws ContextException {
|
||||||
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
|
ODatabaseDocument oDatabaseDocument = null;
|
||||||
try {
|
try {
|
||||||
SecurityContext securityContext = null;
|
SecurityContext securityContext = null;
|
||||||
|
|
||||||
|
@ -128,14 +133,18 @@ public class ContextUtility {
|
||||||
if(securityContext==null) {
|
if(securityContext==null) {
|
||||||
logger.trace("{} for {} is not in cache. Going to get it", SecurityContext.class.getSimpleName(),
|
logger.trace("{} for {} is not in cache. Going to get it", SecurityContext.class.getSimpleName(),
|
||||||
fullName);
|
fullName);
|
||||||
|
oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
OVertex contextVertex = getContextVertexByFullName(fullName);
|
OVertex contextVertex = getContextVertexByFullName(oDatabaseDocument, fullName);
|
||||||
|
|
||||||
uuid = Utility.getUUID(contextVertex);
|
ODocument oDocument = contextVertex.getProperty(IdentifiableElement.HEADER_PROPERTY);
|
||||||
|
|
||||||
|
uuid = UUID.fromString(oDocument.getProperty(Header.UUID_PROPERTY));
|
||||||
|
|
||||||
securityContext = getSecurityContextByUUID(uuid, contextVertex);
|
securityContext = getSecurityContextByUUID(uuid, contextVertex);
|
||||||
|
|
||||||
addSecurityContext(fullName, securityContext);
|
addSecurityContext(fullName, securityContext);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return securityContext;
|
return securityContext;
|
||||||
|
@ -144,6 +153,14 @@ public class ContextUtility {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new ContextException("Unable to retrieve Context UUID from current Context", e);
|
throw new ContextException("Unable to retrieve Context UUID from current Context", e);
|
||||||
|
} finally {
|
||||||
|
if(oDatabaseDocument!=null) {
|
||||||
|
oDatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,12 +180,21 @@ public class ContextUtility {
|
||||||
|
|
||||||
private OVertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException {
|
private OVertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException {
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
OVertex oVertex = Utility.getElementByUUID(getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER), Context.NAME, uuid,
|
ODatabaseDocument oDatabaseDocument = null;
|
||||||
OVertex.class);
|
try {
|
||||||
if(current!=null) {
|
oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER);
|
||||||
current.activateOnCurrentThread();
|
OVertex oVertex = Utility.getElementByUUID(oDatabaseDocument, Context.NAME, uuid,
|
||||||
|
OVertex.class);
|
||||||
|
return oVertex;
|
||||||
|
} finally {
|
||||||
|
if(oDatabaseDocument!=null) {
|
||||||
|
oDatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return oVertex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SecurityContext getSecurityContextByUUID(UUID uuid, OVertex contextVertex) throws ResourceRegistryException {
|
private SecurityContext getSecurityContextByUUID(UUID uuid, OVertex contextVertex) throws ResourceRegistryException {
|
||||||
|
@ -198,14 +224,14 @@ public class ContextUtility {
|
||||||
return securityContext;
|
return securityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
protected UUID getContextUUIDFromFullName(String fullName) throws ResourceRegistryException {
|
protected UUID getContextUUIDFromFullName(String fullName) throws ResourceRegistryException {
|
||||||
OVertex contextVertex = getContextVertexByFullName(fullName);
|
OVertex contextVertex = getContextVertexByFullName(fullName);
|
||||||
return Utility.getUUID(contextVertex);
|
return Utility.getUUID(contextVertex);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private OVertex getContextVertexByFullName(ODatabaseDocument oDatabaseDocument, String fullName) throws ResourceRegistryException {
|
||||||
private OVertex getContextVertexByFullName(String fullName) throws ResourceRegistryException {
|
|
||||||
|
|
||||||
logger.trace("Going to get {} {} with full name '{}'", Context.NAME, OVertex.class.getSimpleName(), fullName);
|
logger.trace("Going to get {} {} with full name '{}'", Context.NAME, OVertex.class.getSimpleName(), fullName);
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(fullName);
|
ScopeBean scopeBean = new ScopeBean(fullName);
|
||||||
|
@ -216,9 +242,7 @@ public class ContextUtility {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("name", name);
|
map.put("name", name);
|
||||||
|
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
OResultSet resultSet = oDatabaseDocument.query(select, map);
|
||||||
|
|
||||||
OResultSet resultSet = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER).query(select, map);
|
|
||||||
|
|
||||||
if(resultSet == null || !resultSet.hasNext()) {
|
if(resultSet == null || !resultSet.hasNext()) {
|
||||||
throw new ContextNotFoundException("Error retrieving context with name " + fullName);
|
throw new ContextNotFoundException("Error retrieving context with name " + fullName);
|
||||||
|
@ -234,10 +258,6 @@ public class ContextUtility {
|
||||||
+ "but required the one with path" + fullName + ". Please Reimplement the query");
|
+ "but required the one with path" + fullName + ". Please Reimplement the query");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current!=null) {
|
|
||||||
current.activateOnCurrentThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -308,11 +308,18 @@ public class SecurityContext {
|
||||||
|
|
||||||
public void addElement(OElement element) throws ResourceRegistryException {
|
public void addElement(OElement element) throws ResourceRegistryException {
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
ODatabaseDocument adminDatabaseDocument = null;
|
||||||
adminDatabaseDocument.activateOnCurrentThread();
|
try {
|
||||||
addElement(element, adminDatabaseDocument);
|
adminDatabaseDocument = getAdminDatabaseDocument();
|
||||||
if(current!=null) {
|
addElement(element, adminDatabaseDocument);
|
||||||
current.activateOnCurrentThread();
|
}finally {
|
||||||
|
if(adminDatabaseDocument!=null) {
|
||||||
|
adminDatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,18 +332,26 @@ public class SecurityContext {
|
||||||
|
|
||||||
public boolean isElementInContext(final OElement element) throws ResourceRegistryException {
|
public boolean isElementInContext(final OElement element) throws ResourceRegistryException {
|
||||||
ORID orid = element.getIdentity();
|
ORID orid = element.getIdentity();
|
||||||
|
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
ODatabaseDocument contextODatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
ODatabaseDocument contextODatabaseDocument = null;
|
||||||
contextODatabaseDocument.activateOnCurrentThread();
|
|
||||||
|
|
||||||
ORecord oRecord = contextODatabaseDocument.getRecord(orid);
|
try {
|
||||||
logger.trace("{}", oRecord);
|
contextODatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
if(current!=null) {
|
ORecord oRecord = contextODatabaseDocument.getRecord(orid);
|
||||||
current.activateOnCurrentThread();
|
logger.trace("{}", oRecord);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if(contextODatabaseDocument!=null) {
|
||||||
|
contextODatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addElement(OElement element, ODatabaseDocument oDatabaseDocument) {
|
public void addElement(OElement element, ODatabaseDocument oDatabaseDocument) {
|
||||||
|
@ -352,11 +367,18 @@ public class SecurityContext {
|
||||||
|
|
||||||
public void removeElement(OElement element) throws ResourceRegistryException {
|
public void removeElement(OElement element) throws ResourceRegistryException {
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
ODatabaseDocument adminDatabaseDocument = null;
|
||||||
adminDatabaseDocument.activateOnCurrentThread();
|
try {
|
||||||
removeElement(element, adminDatabaseDocument);
|
adminDatabaseDocument = getAdminDatabaseDocument();
|
||||||
if(current!=null) {
|
removeElement(element, adminDatabaseDocument);
|
||||||
current.activateOnCurrentThread();
|
}finally {
|
||||||
|
if(adminDatabaseDocument!=null) {
|
||||||
|
adminDatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,8 +417,11 @@ public class SecurityContext {
|
||||||
@Override
|
@Override
|
||||||
public Boolean call() throws Exception {
|
public Boolean call() throws Exception {
|
||||||
ContextUtility.getHierarchicalMode().set(false);
|
ContextUtility.getHierarchicalMode().set(false);
|
||||||
ODatabaseDocument oDatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
|
||||||
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
|
ODatabaseDocument oDatabaseDocument = null;
|
||||||
try {
|
try {
|
||||||
|
oDatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
||||||
oDatabaseDocument.activateOnCurrentThread();
|
oDatabaseDocument.activateOnCurrentThread();
|
||||||
ORecord element = oDatabaseDocument.getRecord(oDocument.getIdentity());
|
ORecord element = oDatabaseDocument.getRecord(oDocument.getIdentity());
|
||||||
if(element == null) {
|
if(element == null) {
|
||||||
|
@ -406,7 +431,13 @@ public class SecurityContext {
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
oDatabaseDocument.close();
|
if(oDatabaseDocument!=null) {
|
||||||
|
oDatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,16 +453,21 @@ public class SecurityContext {
|
||||||
|
|
||||||
public void create() throws ResourceRegistryException {
|
public void create() throws ResourceRegistryException {
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
|
ODatabaseDocument adminDatabaseDocument = null;
|
||||||
|
try {
|
||||||
|
adminDatabaseDocument = getAdminDatabaseDocument();
|
||||||
|
|
||||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
create(adminDatabaseDocument);
|
||||||
adminDatabaseDocument.activateOnCurrentThread();
|
|
||||||
|
|
||||||
create(adminDatabaseDocument);
|
adminDatabaseDocument.commit();
|
||||||
adminDatabaseDocument.commit();
|
} finally {
|
||||||
adminDatabaseDocument.close();
|
if(adminDatabaseDocument!=null) {
|
||||||
|
adminDatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
if(current!=null) {
|
if(current!=null) {
|
||||||
current.activateOnCurrentThread();
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,16 +554,23 @@ public class SecurityContext {
|
||||||
|
|
||||||
public void delete() throws ResourceRegistryException {
|
public void delete() throws ResourceRegistryException {
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
ODatabaseDocument adminDatabaseDocument = null;
|
||||||
adminDatabaseDocument.activateOnCurrentThread();
|
try {
|
||||||
|
adminDatabaseDocument = getAdminDatabaseDocument();
|
||||||
|
|
||||||
delete(adminDatabaseDocument);
|
delete(adminDatabaseDocument);
|
||||||
adminDatabaseDocument.commit();
|
|
||||||
adminDatabaseDocument.close();
|
|
||||||
|
|
||||||
if(current!=null) {
|
adminDatabaseDocument.commit();
|
||||||
current.activateOnCurrentThread();
|
} finally {
|
||||||
|
if(adminDatabaseDocument!=null) {
|
||||||
|
adminDatabaseDocument.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeChildrenHRolesFromParents(OSecurity oSecurity) {
|
protected void removeChildrenHRolesFromParents(OSecurity oSecurity) {
|
||||||
|
|
|
@ -776,7 +776,8 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
|
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
// oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||||
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
setAsEntryPoint();
|
setAsEntryPoint();
|
||||||
|
|
||||||
|
@ -1224,6 +1225,14 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
// https://www.orientdb.com/docs/last/java/Graph-Schema-Property.html#using-constraints
|
// https://www.orientdb.com/docs/last/java/Graph-Schema-Property.html#using-constraints
|
||||||
// Going to validate them here
|
// Going to validate them here
|
||||||
|
|
||||||
|
if(operation.isSafe()) {
|
||||||
|
/*
|
||||||
|
* The sanity check is not required for a safe operation.
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Set<PropertyDefinition> definedProperties = getAllProperties();
|
Set<PropertyDefinition> definedProperties = getAllProperties();
|
||||||
|
|
||||||
if(definedProperties==null) {
|
if(definedProperties==null) {
|
||||||
|
|
|
@ -113,12 +113,11 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
|
||||||
if(!entryPoint) {
|
if(!entryPoint) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(operation.isSafe()) {
|
if(operation.isSafe()) {
|
||||||
/* You should not be here.
|
/*
|
||||||
* The sanity check should not be triggered for a safety operation.
|
* The sanity check is not required for a safe operation.
|
||||||
* Anyway, using this code as guard.
|
|
||||||
*/
|
*/
|
||||||
logger.warn("sanityCheck should not be triggered for a safe method (i.e. {}). It is not an error but it slow down the performace. Please contact the developer", operation.toString());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +160,7 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceManagement.setOperation(operation);
|
resourceManagement.setOperation(operation);
|
||||||
|
|
||||||
resourceManagement.sanityCheck();
|
resourceManagement.sanityCheck();
|
||||||
|
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||||
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.SecurityContext.PermissionMode;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.Operation;
|
import org.gcube.informationsystem.resourceregistry.instances.model.Operation;
|
||||||
|
@ -35,6 +36,7 @@ import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
|
|
||||||
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||||
import com.orientechnologies.orient.core.record.ODirection;
|
import com.orientechnologies.orient.core.record.ODirection;
|
||||||
import com.orientechnologies.orient.core.record.OEdge;
|
import com.orientechnologies.orient.core.record.OEdge;
|
||||||
|
@ -304,10 +306,12 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public String all(boolean polymorphic) throws ResourceRegistryException {
|
public String all(boolean polymorphic) throws ResourceRegistryException {
|
||||||
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
return reallyGetAll(polymorphic);
|
return reallyGetAll(polymorphic);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -317,6 +321,9 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
if(oDatabaseDocument != null) {
|
if(oDatabaseDocument != null) {
|
||||||
oDatabaseDocument.close();
|
oDatabaseDocument.close();
|
||||||
}
|
}
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,6 +411,13 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
|
if(operation.isSafe()) {
|
||||||
|
/*
|
||||||
|
* The sanity check is not required for a safe operation.
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// In case of a resource is deleted due to cascade effect is look like is the entry point
|
// In case of a resource is deleted due to cascade effect is look like is the entry point
|
||||||
// of the operation and the sanity check is not required. The Resource and all its facets are deleted.
|
// of the operation and the sanity check is not required. The Resource and all its facets are deleted.
|
||||||
|
|
|
@ -94,11 +94,9 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement, Fa
|
||||||
}
|
}
|
||||||
|
|
||||||
if(operation.isSafe()) {
|
if(operation.isSafe()) {
|
||||||
/* You should not be here.
|
/*
|
||||||
* The sanity check should not be triggered for a safety operation.
|
* The sanity check is not required for a safe operation.
|
||||||
* Anyway, using this code as guard.
|
|
||||||
*/
|
*/
|
||||||
logger.warn("sanityCheck should not be triggered for a safe method (i.e. {}). It is not an error but it slow down the performace. Please contact the developer", operation.toString());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,7 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
super.sanityCheck();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,12 @@ public class ContextTest {
|
||||||
|
|
||||||
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
|
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
|
||||||
|
|
||||||
|
public static final String GCUBE;
|
||||||
|
public static final String DEVNEXT;
|
||||||
|
public static final String NEXTNEXT;
|
||||||
|
public static final String DEVSEC;
|
||||||
|
public static final String DEVVRE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
properties = new Properties();
|
properties = new Properties();
|
||||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||||
|
@ -51,6 +57,11 @@ public class ContextTest {
|
||||||
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
|
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
|
||||||
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
||||||
|
|
||||||
|
GCUBE = "/gcube";
|
||||||
|
DEVNEXT = GCUBE + "/devNext";
|
||||||
|
NEXTNEXT = DEVNEXT + "/NextNext";
|
||||||
|
DEVSEC = GCUBE + "/devsec";
|
||||||
|
DEVVRE = DEVSEC + "/devVRE";
|
||||||
|
|
||||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||||
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
||||||
|
|
|
@ -81,6 +81,8 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.orientechnologies.orient.core.exception.ODatabaseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
@ -105,6 +107,8 @@ public class ERManagementTest extends ContextTest {
|
||||||
ERManagementTest.deleteResource(r);
|
ERManagementTest.deleteResource(r);
|
||||||
}catch (ResourceNotFoundException e) {
|
}catch (ResourceNotFoundException e) {
|
||||||
// A resource could be already deleted deleting another resource giving the propagation constraint
|
// A resource could be already deleted deleting another resource giving the propagation constraint
|
||||||
|
}catch (ODatabaseException e) {
|
||||||
|
// could occur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +169,7 @@ public class ERManagementTest extends ContextTest {
|
||||||
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
||||||
licenseFacet.setName("EUPL");
|
licenseFacet.setName("EUPL");
|
||||||
licenseFacet.setTextURL(
|
licenseFacet.setTextURL(
|
||||||
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
new URL("https://joinup.ec.europa.eu/community/etestAddToContextFromDifferentSourceContextupl/og_page/european-union-public-licence-eupl-v11"));
|
||||||
eService.addFacet(licenseFacet);
|
eService.addFacet(licenseFacet);
|
||||||
|
|
||||||
return eService;
|
return eService;
|
||||||
|
|
|
@ -1,17 +1,54 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.instances.multicontext;
|
package org.gcube.informationsystem.resourceregistry.instances.multicontext;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||||
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
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.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
|
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
||||||
|
import org.gcube.informationsystem.utils.ElementMapper;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.ContactFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.CoverageFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.resources.DatasetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasOwnerImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasSpatialCoverageImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.IsCorrelatedToImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.CoverageFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Dataset;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasCoverage;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasOwner;
|
||||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.IsCorrelatedTo;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class AddToContextTest extends MultiContextTest {
|
public class AddToContextTest extends MultiContextTest {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(AddToContextTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception {
|
public void testCreateEServiceAndRemoveFromContextRequiredFacet() throws Exception {
|
||||||
EService eService = ERManagementTest.createEService();
|
EService eService = ERManagementTest.createEService();
|
||||||
|
@ -51,4 +88,195 @@ public class AddToContextTest extends MultiContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Dataset createDataset(String id, String uuidString) throws Exception {
|
||||||
|
Dataset dataset = new DatasetImpl();
|
||||||
|
dataset.setHeader(new HeaderImpl(UUID.fromString(uuidString)));
|
||||||
|
|
||||||
|
IdentifierFacet identifierFacet = new IdentifierFacetImpl();
|
||||||
|
identifierFacet.setValue(id);
|
||||||
|
identifierFacet.setType(IdentificationType.STRING);
|
||||||
|
identifierFacet.setPersistent(false);
|
||||||
|
IsIdentifiedBy<Dataset, IdentifierFacet> isIdentifiedBy = new IsIdentifiedByImpl<>(dataset, identifierFacet);
|
||||||
|
dataset.addFacet(isIdentifiedBy);
|
||||||
|
|
||||||
|
ContactFacet contactFacet = new ContactFacetImpl();
|
||||||
|
contactFacet.setTitle("Dr.");
|
||||||
|
contactFacet.setName("Luca");
|
||||||
|
contactFacet.setSurname("Frosini");
|
||||||
|
contactFacet.setEMail("luca.frosini@d4science.org");
|
||||||
|
HasOwner<Dataset, ContactFacet> hasOwner = new HasOwnerImpl<>(dataset, contactFacet);
|
||||||
|
dataset.addFacet(hasOwner);
|
||||||
|
|
||||||
|
CoverageFacet coverageFacet = new CoverageFacetImpl();
|
||||||
|
ValueSchema coverage = new ValueSchemaImpl();
|
||||||
|
coverage.setValue("Test");
|
||||||
|
coverage.setSchema(new URI("String"));
|
||||||
|
coverageFacet.setCoverage(coverage);
|
||||||
|
HasCoverage<Dataset, CoverageFacet> hasCoverage = new HasSpatialCoverageImpl<Dataset, CoverageFacet>(dataset, coverageFacet);
|
||||||
|
dataset.addFacet(hasCoverage);
|
||||||
|
|
||||||
|
try {
|
||||||
|
deleteResource(dataset);
|
||||||
|
}catch (NotFoundException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
return createResource(dataset);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PropagationConstraint getPropagationConstraint() {
|
||||||
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||||
|
propagationConstraint.setAddConstraint(AddConstraint.propagate);
|
||||||
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||||
|
return propagationConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected IsCorrelatedTo<Dataset, Dataset> createIsCorrelatedTo(Dataset source, Dataset target) throws Exception {
|
||||||
|
PropagationConstraint propagationConstraint = getPropagationConstraint();
|
||||||
|
IsCorrelatedTo<Dataset, Dataset> isCorrelatedTo = new IsCorrelatedToImpl<Dataset, Dataset>(source, target, propagationConstraint);
|
||||||
|
|
||||||
|
IsRelatedToManagement isRelatedToManagement = getIsRelatedToManagement(isCorrelatedTo);
|
||||||
|
String json = isRelatedToManagement.create();
|
||||||
|
|
||||||
|
isCorrelatedTo = ElementMapper.unmarshal(isCorrelatedTo.getClass(), json);
|
||||||
|
|
||||||
|
return isCorrelatedTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddToContextFromDifferentSourceContext() throws Exception {
|
||||||
|
setContextByName(GCUBE);
|
||||||
|
|
||||||
|
Dataset datasetR1 = createDataset("R1", "da111111-dada-1111-1111-111111111111");
|
||||||
|
Dataset datasetR2 = null;
|
||||||
|
Dataset datasetR3 = null;
|
||||||
|
try {
|
||||||
|
addToContextThenTestIfBehaveProperly(datasetR1, false, DEVNEXT);
|
||||||
|
addToContextThenTestIfBehaveProperly(datasetR1, false, DEVSEC);
|
||||||
|
|
||||||
|
setContextByName(DEVNEXT);
|
||||||
|
datasetR2 = createDataset("R2", "da222222-dada-2222-2222-222222222222");
|
||||||
|
IsCorrelatedTo<Dataset, Dataset> isCorrelatedToR1R2 = createIsCorrelatedTo(datasetR1, datasetR2);
|
||||||
|
|
||||||
|
getResourceManagement(datasetR1).exists();
|
||||||
|
getIsRelatedToManagement(isCorrelatedToR1R2).exists();
|
||||||
|
getResourceManagement(datasetR2).exists();
|
||||||
|
|
||||||
|
|
||||||
|
setContextByName(DEVSEC);
|
||||||
|
datasetR3 = createDataset("R3", "da333333-dada-3333-3333-333333333333");
|
||||||
|
IsCorrelatedTo<Dataset, Dataset> isCorrelatedToR1R3 = createIsCorrelatedTo(datasetR1, datasetR3);
|
||||||
|
|
||||||
|
getResourceManagement(datasetR1).exists();
|
||||||
|
getIsRelatedToManagement(isCorrelatedToR1R3).exists();
|
||||||
|
getResourceManagement(datasetR3).exists();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
getIsRelatedToManagement(isCorrelatedToR1R2).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
getResourceManagement(datasetR2).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setContextByName(DEVNEXT);
|
||||||
|
try {
|
||||||
|
getIsRelatedToManagement(isCorrelatedToR1R3).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
getResourceManagement(datasetR3).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setContextByName(GCUBE);
|
||||||
|
getResourceManagement(datasetR1).exists();
|
||||||
|
try {
|
||||||
|
getIsRelatedToManagement(isCorrelatedToR1R2).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
getResourceManagement(datasetR2).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
getIsRelatedToManagement(isCorrelatedToR1R3).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
getResourceManagement(datasetR3).exists();
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
logger.trace("As expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextUtility.getHierarchicalMode().set(true);
|
||||||
|
ContextUtility.getIncludeInstanceContexts().set(true);
|
||||||
|
|
||||||
|
Dataset r1 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR1).read());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> contextsR1 = (List<String>) r1.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
||||||
|
Assert.assertTrue(contextsR1.size()==3);
|
||||||
|
|
||||||
|
Dataset r2 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR2).read());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> contextsR2 = (List<String>) r2.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
||||||
|
Assert.assertTrue(contextsR2.size()==1);
|
||||||
|
|
||||||
|
Dataset r3 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR3).read());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> contextsR3 = (List<String>) r3.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
||||||
|
Assert.assertTrue(contextsR3.size()==1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("", e);
|
||||||
|
throw e;
|
||||||
|
}finally {
|
||||||
|
ContextUtility.getHierarchicalMode().set(false);
|
||||||
|
ContextUtility.getIncludeInstanceContexts().set(false);
|
||||||
|
|
||||||
|
setContextByName(GCUBE);
|
||||||
|
deleteResource(datasetR1);
|
||||||
|
|
||||||
|
if(datasetR2!=null) {
|
||||||
|
setContextByName(DEVNEXT);
|
||||||
|
deleteResource(datasetR2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(datasetR3!=null) {
|
||||||
|
setContextByName(DEVSEC);
|
||||||
|
deleteResource(datasetR3);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
|
||||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
|
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
|
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||||
|
@ -33,7 +32,7 @@ public class ComplexTest extends MultiContextTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetInstancesContexts() throws ResourceRegistryException, Exception {
|
public void testGetInstancesContexts() throws ResourceRegistryException, Exception {
|
||||||
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
|
ContextTest.setContextByName(DEVNEXT);
|
||||||
|
|
||||||
ContextCache contextCache = ContextCache.getInstance();
|
ContextCache contextCache = ContextCache.getInstance();
|
||||||
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
||||||
|
@ -47,10 +46,8 @@ public class ComplexTest extends MultiContextTest {
|
||||||
|
|
||||||
/* Creating Activates Relation */
|
/* Creating Activates Relation */
|
||||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||||
propagationConstraint
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||||
.setRemoveConstraint(RemoveConstraint.cascade);
|
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
|
||||||
propagationConstraint
|
|
||||||
.setAddConstraint(AddConstraint.unpropagate);
|
|
||||||
|
|
||||||
|
|
||||||
Activates<HostingNode, EService> activates = new ActivatesImpl<>(hostingNode, eService,
|
Activates<HostingNode, EService> activates = new ActivatesImpl<>(hostingNode, eService,
|
||||||
|
@ -69,10 +66,10 @@ public class ComplexTest extends MultiContextTest {
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
addToContextThenTestIfBehaveProperly(hostingNode, false, ALTERNATIVE_TEST_SCOPE);
|
addToContextThenTestIfBehaveProperly(hostingNode, false, NEXTNEXT);
|
||||||
|
|
||||||
logger.debug("Switching to alternative scope");
|
logger.debug("Switching to alternative scope");
|
||||||
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
|
ContextTest.setContextByName(NEXTNEXT);
|
||||||
|
|
||||||
ResourceManagement hostingNodeManagement = ERManagementTest.getResourceManagement(hostingNode);
|
ResourceManagement hostingNodeManagement = ERManagementTest.getResourceManagement(hostingNode);
|
||||||
|
|
||||||
|
@ -128,10 +125,10 @@ public class ComplexTest extends MultiContextTest {
|
||||||
ERManagementTest.deleteResource(hostingNode);
|
ERManagementTest.deleteResource(hostingNode);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
ContextTest.setContextByName(DEVNEXT);
|
||||||
ERManagementTest.deleteResource(eService);
|
ERManagementTest.deleteResource(eService);
|
||||||
throw new Exception(EService.NAME + " should be already deleted giving the cascade");
|
} catch (Exception e) {
|
||||||
}catch (ResourceNotFoundException e) {
|
logger.error("",e);
|
||||||
// As expected
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue