Added management of delete propagation constraint

This commit is contained in:
Luca Frosini 2023-02-02 21:18:28 +01:00
parent 89f2dd84cb
commit 768dc47183
7 changed files with 64 additions and 11 deletions

View File

@ -2,12 +2,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Resource Registry Service # Changelog for Resource Registry Service
## [v4.1.1-SNAPSHOT] ## [v4.2.0-SNAPSHOT]
- Fixed bug on JSONQuery for Facets which does not have any properties to match [#24237] - Fixed bug on JSONQuery for Facets which does not have any properties to match [#24237]
- Fixed bug on JSONQuery for IsRelatedTo relations indicating both source and target resources [#24264] - Fixed bug on JSONQuery for IsRelatedTo relations indicating both source and target resources [#24264]
- Fixed bug on returned boolean values as string [#24240] - Fixed bug on returned boolean values as string [#24240]
- Enabled array properties [#24225] - Enabled array properties [#24225]
- Using delete in propagation contraint as action indication for delete operation [#24224]
## [v4.1.0] ## [v4.1.0]

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.information-system</groupId> <groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry</artifactId> <artifactId>resource-registry</artifactId>
<version>4.1.1-SNAPSHOT</version> <version>4.2.0-SNAPSHOT</version>
<name>Resource Registry Service</name> <name>Resource Registry Service</name>
<description>The Resource Registry is a web-service which represent the core component of the gCube Information System</description> <description>The Resource Registry is a web-service which represent the core component of the gCube Information System</description>
<packaging>war</packaging> <packaging>war</packaging>

View File

@ -193,6 +193,7 @@ public class DatabaseEnvironment {
TypeSecurityContext.getInstance().create(); TypeSecurityContext.getInstance().create();
ContextSecurityContext.getInstance().create(); ContextSecurityContext.getInstance().create();
/* We must create only OrientDB types */
List<Class<? extends Element>> definitionToBeCreated = new ArrayList<>(); List<Class<? extends Element>> definitionToBeCreated = new ArrayList<>();
definitionToBeCreated.add(PropertyElement.class); definitionToBeCreated.add(PropertyElement.class);
definitionToBeCreated.add(Property.class); definitionToBeCreated.add(Property.class);
@ -221,6 +222,15 @@ public class DatabaseEnvironment {
} }
} }
/*
* We have already created Property and Header
* because Header is needed to create
* types for internal use (i.e. Context, EntityType).
*
* For Property and Header we also need
* to create the instance in TypeSecurityContext
* as we will do for any other Property specialization.
*/
List<Class<? extends Element>> schemaToBeCreated = new ArrayList<>(); List<Class<? extends Element>> schemaToBeCreated = new ArrayList<>();
schemaToBeCreated.add(Property.class); schemaToBeCreated.add(Property.class);
schemaToBeCreated.add(Header.class); schemaToBeCreated.add(Header.class);
@ -236,6 +246,8 @@ public class DatabaseEnvironment {
Class<Type> typeClz = Type.class; Class<Type> typeClz = Type.class;
packages.add(typeClz.getPackage()); packages.add(typeClz.getPackage());
// Adding packages of AccessType
AccessType[] accessTypes = AccessType.values(); AccessType[] accessTypes = AccessType.values();
for(AccessType accessType : accessTypes) { for(AccessType accessType : accessTypes) {
Class<Element> clz = accessType.getTypeClass(); Class<Element> clz = accessType.getTypeClass();

View File

@ -7,6 +7,7 @@ import org.gcube.informationsystem.model.impl.properties.PropagationConstraintIm
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; 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.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -35,6 +36,7 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement, Fa
static { static {
DEFAULT_CONSISTS_OF_PC = new PropagationConstraintImpl(); DEFAULT_CONSISTS_OF_PC = new PropagationConstraintImpl();
DEFAULT_CONSISTS_OF_PC.setDeleteConstraint(DeleteConstraint.cascade);
DEFAULT_CONSISTS_OF_PC.setRemoveConstraint(RemoveConstraint.cascade); DEFAULT_CONSISTS_OF_PC.setRemoveConstraint(RemoveConstraint.cascade);
DEFAULT_CONSISTS_OF_PC.setAddConstraint(AddConstraint.propagate); DEFAULT_CONSISTS_OF_PC.setAddConstraint(AddConstraint.propagate);
} }

View File

@ -8,6 +8,7 @@ import org.gcube.informationsystem.model.impl.properties.PropagationConstraintIm
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; 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.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -31,6 +32,7 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
static { static {
DEFAULT_IS_RELATED_TO_PC = new PropagationConstraintImpl(); DEFAULT_IS_RELATED_TO_PC = new PropagationConstraintImpl();
DEFAULT_IS_RELATED_TO_PC.setDeleteConstraint(DeleteConstraint.keep);
DEFAULT_IS_RELATED_TO_PC.setRemoveConstraint(RemoveConstraint.keep); DEFAULT_IS_RELATED_TO_PC.setRemoveConstraint(RemoveConstraint.keep);
DEFAULT_IS_RELATED_TO_PC.setAddConstraint(AddConstraint.unpropagate); DEFAULT_IS_RELATED_TO_PC.setAddConstraint(AddConstraint.unpropagate);
} }

View File

@ -17,6 +17,7 @@ import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; 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.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.model.reference.relations.Relation;
@ -282,6 +283,22 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
} }
propagationConstraintOrient.setRemoveConstraint(removeConstraint); propagationConstraintOrient.setRemoveConstraint(removeConstraint);
DeleteConstraint deleteConstraint = propagationConstraint.getDeleteConstraint();
if(deleteConstraint == null) {
deleteConstraint = defaultPropagationConstraint.getDeleteConstraint();
logger.debug("Unable to get {}. Default value ({}) will be used", DeleteConstraint.class.getSimpleName(),
deleteConstraint);
}else {
if (this instanceof ConsistsOfManagement && deleteConstraint == DeleteConstraint.keep) {
deleteConstraint = defaultPropagationConstraint.getDeleteConstraint();
logger.warn("A {} cannot use {}.{}. Default value ({}) will be used", ConsistsOf.NAME,
DeleteConstraint.class.getSimpleName(), DeleteConstraint.keep, deleteConstraint);
}
}
propagationConstraintOrient.setDeleteConstraint(deleteConstraint);
return propagationConstraintOrient; return propagationConstraintOrient;
} }
@ -702,23 +719,32 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
getSourceEntityManagement().getElement(); getSourceEntityManagement().getElement();
RemoveConstraint removeConstraint = RemoveConstraint.keep; DeleteConstraint deleteConstraint = DeleteConstraint.keep;
try { try {
PropagationConstraint propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, PropagationConstraint propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class,
element, Relation.PROPAGATION_CONSTRAINT_PROPERTY); element, Relation.PROPAGATION_CONSTRAINT_PROPERTY);
if(propagationConstraint.getRemoveConstraint() != null) { if(propagationConstraint.getDeleteConstraint() != null) {
removeConstraint = propagationConstraint.getRemoveConstraint(); deleteConstraint = propagationConstraint.getDeleteConstraint();
} else { } else {
String error = String.format("%s.%s in %s is null. %s", Relation.PROPAGATION_CONSTRAINT_PROPERTY, String error = String.format("%s.%s in %s is null. %s", Relation.PROPAGATION_CONSTRAINT_PROPERTY,
PropagationConstraint.REMOVE_PROPERTY, Utility.toJsonString(element, true), PropagationConstraint.DELETE_PROPERTY, Utility.toJsonString(element, true),
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
logger.error(error);
throw new ResourceRegistryException(error); logger.warn(error);
// logger.error(error);
// TODO Added for backward compatibility
deleteConstraint = DeleteConstraint.values()[propagationConstraint.getRemoveConstraint().ordinal()];
/*
* TODO Restore the exception raising and remove the line above
*
* throw new ResourceRegistryException(error);
*/
} }
} catch(Exception e) { } catch(Exception e) {
logger.warn("Error while getting {} from {}. Assuming {}. {}", Relation.PROPAGATION_CONSTRAINT_PROPERTY, logger.warn("Error while getting {} from {}. Assuming {}. {}", Relation.PROPAGATION_CONSTRAINT_PROPERTY,
Utility.toJsonString(element, true), removeConstraint, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); Utility.toJsonString(element, true), deleteConstraint, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
} }
// pre-loading target entity because after deleting the relation we will not be able to get it // pre-loading target entity because after deleting the relation we will not be able to get it
@ -730,7 +756,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
affectedInstances.put(uuid, serializeAsAffectedInstance()); affectedInstances.put(uuid, serializeAsAffectedInstance());
element.delete(); element.delete();
switch(removeConstraint) { switch(deleteConstraint) {
case cascade: case cascade:
t.internalDelete(); t.internalDelete();
break; break;
@ -741,7 +767,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
Iterator<OEdge> iterator = iterable.iterator(); Iterator<OEdge> iterator = iterable.iterator();
if(iterator.hasNext()) { if(iterator.hasNext()) {
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element, logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
target, removeConstraint); target, deleteConstraint);
} else { } else {
getTargetEntityManagement().internalDelete(); getTargetEntityManagement().internalDelete();
} }

View File

@ -19,6 +19,16 @@ public class PropagationConstraintOrient extends ODocument implements org.gcube.
super(iClassName); super(iClassName);
} }
@Override
public DeleteConstraint getDeleteConstraint() {
return DeleteConstraint.valueOf((String) this.field(PropagationConstraint.DELETE_PROPERTY));
}
@Override
public void setDeleteConstraint(DeleteConstraint deleteConstraint) {
this.field(PropagationConstraint.REMOVE_PROPERTY, deleteConstraint.name());
}
@Override @Override
public RemoveConstraint getRemoveConstraint() { public RemoveConstraint getRemoveConstraint() {
return RemoveConstraint.valueOf((String) this.field(PropagationConstraint.REMOVE_PROPERTY)); return RemoveConstraint.valueOf((String) this.field(PropagationConstraint.REMOVE_PROPERTY));