Class RelationManagement<T extends EntityManagement<? extends org.gcube.informationsystem.model.reference.entities.Entity,TET>,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>

java.lang.Object
org.gcube.informationsystem.resourceregistry.persistence.orientdb.base.ElementManagement<com.orientechnologies.orient.core.record.OEdge,org.gcube.informationsystem.types.reference.relations.RelationSchema<SET,TET>>
org.gcube.informationsystem.resourceregistry.persistence.orientdb.base.RelationElementManagement<ResourceManagement,T,org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET>
org.gcube.informationsystem.resourceregistry.persistence.orientdb.instances.relations.RelationManagement<T,TET>
All Implemented Interfaces:
ERManagement
Direct Known Subclasses:
ConsistsOfManagement, IsRelatedToManagement

public abstract class RelationManagement<T extends EntityManagement<? extends org.gcube.informationsystem.model.reference.entities.Entity,TET>,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema> extends RelationElementManagement<ResourceManagement,T,org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET> implements ERManagement
Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • sourceInstanceEnvironment

      protected InstanceEnvironment sourceInstanceEnvironment
      The source context of an addToContext
    • targetInstanceEnvironment

      protected InstanceEnvironment targetInstanceEnvironment
      The target context of an addToContext/removeFromContext
    • propagationMode

      protected org.gcube.informationsystem.resourceregistry.api.rest.PropagationMode propagationMode
      By default the system honours the propagation constraints so this variable is initialised as true. To revert a previous operation or for a particular maintenance we could ask the service not to honour the propagation constraints, but only under certain conditions and with some limitations. These limitations are required to keep the system in a consistent state. In fact, this directive is only valid for Resources and IsRelatedTo relations. We need to take into account that when adding an IsRelatedTo to a context, the source and target Resources must always be in such a Context. Please also take into account that adding a Resource to a context always implies honouring the propagation constraints of ConsistsOf relations. In fact, a resource must be characterised by at least one facet in any context it belongs to. Given that we cannot make assumptions on which facets must be used, a way could be to consider only the facets that are mandatory for such a Resource Type, but the type could not have mandatory facets (even though every Resource Type in the gCube Model has one mandatory facet). Conversely, when a Resource is removed from a Context all the facets characterising it must be removed. This option can also be used in conjunction with ElementManagement.dryRun=true. This allows simulating a sharing operation without honouring the propagation constraints.
    • visited

      protected Set<UUID> visited
      Shared, mutable set of UUIDs (entities and relations alike) already visited during the current addToContext(UUID) cascade. Guarantees termination on a graph cycle (e.g. a cyclic IsRelatedTo chain) independently of PropagationMode — populated and checked unconditionally, even in modes (SHALLOW) whose own already-present check would already prevent a re-visit, so the guard stays uniform and orthogonal to mode semantics.

      Not the same bookkeeping as ElementManagement.affectedInstances: this set is marked on entry, before recursing into children (pre-order) - a node re-entered mid-cycle is caught here even though its own processing hasn't finished yet. ElementManagement.affectedInstances is only populated when processing completes successfully (post-order), so it cannot double as a cycle guard - a node being re-entered mid-recursion has not been added to it yet.

    • addedToContext

      protected boolean addedToContext
      Whether reallyAddToContext() actually called targetInstanceEnvironment.addElement(...) for this relation on its last run, i.e. whether its add constraint let it (and its target) into the target Context.

      Distinct from both visited (has this UUID been attempted at all, in this cascade - the cycle guard) and ElementManagement.affectedInstances (what should be reported back to the caller): this field only answers "did this specific run of reallyAddToContext() actually add the element to the target Context."

    • forceAddToContext

      protected boolean forceAddToContext
      The instance is added to the context even if not in source context.
    • hierarchical

      protected boolean hierarchical
      Whether hierarchical lookup is enabled.
    • activeOnlyHierarchical

      protected boolean activeOnlyHierarchical
      Whether the active-only hierarchical reader channel must be used.
    • workingContextUUID

      protected UUID workingContextUUID
      The Context the instance is looked up in; null for the token Context.
    • contextsPolicy

      protected org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy
      The contexts inclusion policy for responses.
    • orphanCandidates

      protected OrphanCandidates orphanCandidates
      The targets of the dropped cascadeWhenOrphan relations of the current RemoveFromContext avalanche, shared by every management taking part in it. They are evaluated when the avalanche of one Context has finished.
    • defaultPropagationConstraint

      public final org.gcube.informationsystem.model.reference.properties.PropagationConstraint defaultPropagationConstraint
      The default propagation constraint.
    • propagationConstraint

      protected org.gcube.informationsystem.model.reference.properties.PropagationConstraint propagationConstraint
      The active propagation constraint for this relation.
    • skipped

      protected boolean skipped
      Whether the last AddToContext or RemoveFromContext skipped this relation.
    • removalFromTarget

      protected boolean removalFromTarget
      Whether the RemoveFromContext comes from the target of this relation, which has already left the Context: the relation leaves it too, and its remove constraint is not evaluated.
  • Constructor Details

    • RelationManagement

      protected RelationManagement(org.gcube.informationsystem.base.reference.AccessType accessType, Class<? extends org.gcube.informationsystem.model.reference.entities.Entity> targetEntityClass, org.gcube.informationsystem.model.reference.properties.PropagationConstraint defaultPropagationConstraint)
      Creates a new RelationManagement instance.
      Parameters:
      accessType - the JAX-RS access type
      targetEntityClass - the target entity class
      defaultPropagationConstraint - the default propagation constraint
  • Method Details

    • setMembershipView

      public void setMembershipView(MembershipView membershipView)
      Description copied from interface: ERManagement
      Sets the view that selects the memberships listed by the contexts maps.
      Specified by:
      setMembershipView in interface ERManagement
      Parameters:
      membershipView - the membership view to apply
    • getMembershipView

      public MembershipView getMembershipView()
      Description copied from interface: ERManagement
      Gets the view that selects the memberships listed by the contexts maps.
      Specified by:
      getMembershipView in interface ERManagement
      Returns:
      the membership view
    • isAddedToContext

      public boolean isAddedToContext()
      Returns whether the last reallyAddToContext() run added this relation to the target Context.
      Returns:
      true if the relation was added to the target Context
    • isHierarchical

      public boolean isHierarchical()
      Description copied from interface: ERManagement
      Gets whether hierarchical lookup is enabled.
      Specified by:
      isHierarchical in interface ERManagement
      Returns:
      true if hierarchical, false otherwise
    • setHierarchical

      public void setHierarchical(boolean hierarchical)
      Description copied from interface: ERManagement
      Sets whether hierarchical lookup is enabled.
      Specified by:
      setHierarchical in interface ERManagement
      Parameters:
      hierarchical - true to enable hierarchical, false otherwise
    • isActiveOnlyHierarchical

      public boolean isActiveOnlyHierarchical()
      Description copied from interface: ERManagement
      Gets whether the active-only hierarchical reader channel must be used instead of the unrestricted one - meaningless unless ERManagement.isHierarchical() is also true.
      Specified by:
      isActiveOnlyHierarchical in interface ERManagement
      Returns:
      true if the active-only channel must be used, false otherwise
    • setActiveOnlyHierarchical

      public void setActiveOnlyHierarchical(boolean activeOnlyHierarchical)
      Description copied from interface: ERManagement
      Sets whether the active-only hierarchical reader channel must be used instead of the unrestricted one. The PEP layer sets this to false for ALL_ADMIN_ROLES holders (unchanged, unrestricted behavior) and true for everyone else.
      Specified by:
      setActiveOnlyHierarchical in interface ERManagement
      Parameters:
      activeOnlyHierarchical - true to use the active-only channel
    • getContextsPolicy

      public org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy getContextsPolicy()
      Description copied from interface: ERManagement
      Returns the contexts inclusion policy for responses.
      Specified by:
      getContextsPolicy in interface ERManagement
      Returns:
      the contexts policy, or null if not explicitly set (falls back to ContextsPolicy.DEFAULT)
    • setContextsPolicy

      public void setContextsPolicy(org.gcube.informationsystem.resourceregistry.api.rest.ContextsPolicy contextsPolicy)
      Description copied from interface: ERManagement
      Sets the contexts inclusion policy for responses.
      Specified by:
      setContextsPolicy in interface ERManagement
      Parameters:
      contextsPolicy - the contexts policy to set
    • setSourceInstanceEnvironment

      public void setSourceInstanceEnvironment(InstanceEnvironment source)
      Description copied from interface: ERManagement
      Sets the source InstanceEnvironment used to evaluate addToContext
      Specified by:
      setSourceInstanceEnvironment in interface ERManagement
      Parameters:
      source - the source security context
    • getContextsSet

      public Set<String> getContextsSet() throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from interface: ERManagement
      Returns the Context UUID strings of the memberships listed by ERManagement.getMembershipView().
      Specified by:
      getContextsSet in interface ERManagement
      Returns:
      the set of Context UUID strings
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if context mapping fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database error
    • getContexts

      public String getContexts() throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns all contexts where this element is visible as a formatted JSON string.

      Warning: Any changes made to this implementation must also be applied to the corresponding method in EntityManagement to keep both ER hierarchies synchronized.

      Specified by:
      getContexts in interface ERManagement
      Returns:
      the JSON string of contexts mapping
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if context mapping fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database error
    • getContextsAsObjectNode

      public org.gcube.com.fasterxml.jackson.databind.node.ObjectNode getContextsAsObjectNode() throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from interface: ERManagement
      Returns all contexts where this element is visible as an ObjectNode mapping Context UUIDs to paths.
      Specified by:
      getContextsAsObjectNode in interface ERManagement
      Returns:
      the JSON ObjectNode of contexts mapping
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if context mapping fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database error
    • getSourceInstanceEnvironment

      public InstanceEnvironment getSourceInstanceEnvironment()
      Description copied from interface: ERManagement
      Returns the source InstanceEnvironment used to evaluate context sharing operations.
      Specified by:
      getSourceInstanceEnvironment in interface ERManagement
      Returns:
      the source instance environment
    • setTargetInstanceEnvironment

      public void setTargetInstanceEnvironment(InstanceEnvironment target)
      Description copied from interface: ERManagement
      Sets the target security context of addToContext/removeFromContext
      Specified by:
      setTargetInstanceEnvironment in interface ERManagement
      Parameters:
      target - the target instance environment to set
    • getTargetInstanceEnvironment

      public InstanceEnvironment getTargetInstanceEnvironment()
      Description copied from interface: ERManagement
      Returns the target InstanceEnvironment of the operation.
      Specified by:
      getTargetInstanceEnvironment in interface ERManagement
      Returns:
      the target instance environment
    • getPropagationMode

      public org.gcube.informationsystem.resourceregistry.api.rest.PropagationMode getPropagationMode()
      Description copied from interface: ERManagement
      Returns the propagation mode for context sharing.
      Specified by:
      getPropagationMode in interface ERManagement
      Returns:
      the propagation mode
    • setPropagationMode

      public void setPropagationMode(org.gcube.informationsystem.resourceregistry.api.rest.PropagationMode propagationMode)
      Description copied from interface: ERManagement
      Sets the propagation mode for context sharing.
      Specified by:
      setPropagationMode in interface ERManagement
      Parameters:
      propagationMode - the propagation mode to set
    • isForceAddToContext

      public boolean isForceAddToContext()
      Description copied from interface: ERManagement
      Gets whether the operation should force add to context even if the instance is not in source context.
      Specified by:
      isForceAddToContext in interface ERManagement
      Returns:
      true if force add, false otherwise
    • setForceAddToContext

      public void setForceAddToContext(boolean forceAddToContext)
      Description copied from interface: ERManagement
      Sets whether the operation should force add to context even if the instance is not in source context.
      Specified by:
      setForceAddToContext in interface ERManagement
      Parameters:
      forceAddToContext - true to force add, false otherwise
    • setOrphanCandidates

      public void setOrphanCandidates(OrphanCandidates orphanCandidates)
      Sets the record shared by the current RemoveFromContext avalanche.
      Parameters:
      orphanCandidates - the shared record of cascadeWhenOrphan targets
    • getOrphanCandidates

      protected OrphanCandidates getOrphanCandidates()
      Returns the record shared by the current RemoveFromContext avalanche, creating it when this management is the one the avalanche starts from.
      Returns:
      the shared record of cascadeWhenOrphan targets
    • setVisited

      public void setVisited(Set<UUID> visited)
      Description copied from interface: ERManagement
      Sets the shared, mutable set of UUIDs (entities and relations alike) already visited during the current ERManagement.addToContext(UUID) cascade. Checked and populated unconditionally by every ERManagement instance in the cascade, regardless of PropagationMode — cycle-safety is kept orthogonal to whatever each mode otherwise decides about re-visiting an already-present instance, so it does not need to be re-derived if propagation semantics change later.
      Specified by:
      setVisited in interface ERManagement
      Parameters:
      visited - the shared visited-UUID set; the same instance must be threaded through the whole cascade of a single ERManagement.addToContext(UUID) call
    • getVisited

      public Set<UUID> getVisited()
      Description copied from interface: ERManagement
      Returns the shared, mutable set of UUIDs already visited during the current ERManagement.addToContext(UUID) cascade.
      Specified by:
      getVisited in interface ERManagement
      Returns:
      the shared visited-UUID set, or null if not yet initialised
    • isAvailableOnContext

      public boolean isAvailableOnContext(InstanceEnvironment instanceEnvironment)
      Returns true if this relation is available in the specified context.
      Parameters:
      instanceEnvironment - the instance environment context
      Returns:
      true if available, false otherwise
    • getWorkingEnvironment

      protected Environment getWorkingEnvironment() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from class: ElementManagement
      Returns the active database working environment.
      Specified by:
      getWorkingEnvironment in class ElementManagement<com.orientechnologies.orient.core.record.OEdge,org.gcube.informationsystem.types.reference.relations.RelationSchema<org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>>
      Returns:
      the working environment
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the environment cannot be resolved
    • setWorkingContext

      public void setWorkingContext(UUID contextUUID)
      Description copied from interface: ERManagement
      Sets the Context the instance is looked up in, in place of the token Context: the Context a Remove from Context acts on, and with ERManagement.isHierarchical() its descendants too.
      Specified by:
      setWorkingContext in interface ERManagement
      Parameters:
      contextUUID - the UUID of the Context, or null for the token Context
    • setRemovalFromTarget

      public void setRemovalFromTarget(boolean removalFromTarget)
      Sets whether the RemoveFromContext comes from the target of this relation.
      Parameters:
      removalFromTarget - true if the target has already left the Context
    • getElement

      public com.orientechnologies.orient.core.record.OEdge getElement() throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.instances.AvailableInAnotherContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from class: ElementManagement
      Returns the OrientDB element instance, retrieving and caching it if not already present.
      Overrides:
      getElement in class ElementManagement<com.orientechnologies.orient.core.record.OEdge,org.gcube.informationsystem.types.reference.relations.RelationSchema<org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>>
      Returns:
      the OrientDB element instance
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.instances.AvailableInAnotherContextException - if the element belongs to another context
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database error
    • giveMeSourceEntityManagementAsIs

      public ResourceManagement giveMeSourceEntityManagementAsIs() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns the source entity manager as-is (without lazy-loading).
      Returns:
      the source entity manager instance
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the lookup fails
    • fullSerialize

      protected Map<String,org.gcube.com.fasterxml.jackson.databind.JsonNode> fullSerialize(Map<String,org.gcube.com.fasterxml.jackson.databind.JsonNode> visitedSourceResources) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Serializes this relation fully into the given map of visited resources.
      Parameters:
      visitedSourceResources - the map of already-visited resources to update
      Returns:
      the updated visited resources map
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if serialization fails
    • getPropagationConstraint

      protected PropagationConstraintOrient getPropagationConstraint(com.orientechnologies.orient.core.record.impl.ODocument oDocument) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Resolves the propagation constraint for this relation from the given document, falling back to the default constraint if needed.
      Parameters:
      oDocument - the database document representing the constraint
      Returns:
      the resolved PropagationConstraintOrient
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the constraint is invalid or parsing fails
      jakarta.ws.rs.BadRequestException - if this is a ConsistsOf and removeConstraint is anything other than PropagationConstraint.RemoveConstraint.cascade (a structurally invalid enum combination, per the 400 Bad Request disambiguation rule in 07-api-foundations-and-roles.md)
    • checkPropagationConstraint

      protected void checkPropagationConstraint() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Verifies, normalizes, and sets the propagation constraint on the database element.
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if validation or database set fails
    • reallyCreate

      protected com.orientechnologies.orient.core.record.OEdge reallyCreate() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from class: ElementManagement
      Persists a new element in the database (subclass hook).
      Overrides:
      reallyCreate in class RelationElementManagement<ResourceManagement,T extends EntityManagement<? extends org.gcube.informationsystem.model.reference.entities.Entity,TET>,org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>
      Returns:
      the persisted OrientDB vertex
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException - if the element already exists in the database
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on any database error
    • newSourceEntityManagement

      protected ResourceManagement newSourceEntityManagement() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from class: RelationElementManagement
      Creates a new management instance for the source entity of the relation (subclass hook).
      Specified by:
      newSourceEntityManagement in class RelationElementManagement<ResourceManagement,T extends EntityManagement<? extends org.gcube.informationsystem.model.reference.entities.Entity,TET>,org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>
      Returns:
      the source entity management instance
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or lookup error
    • getEntityTypeNotValidErrroMessage

      protected String getEntityTypeNotValidErrroMessage(String entityPosition, String requiredType, String effectiveType)
      Generates a schema violation error message when an entity type is not compatible with relation constraints.
      Parameters:
      entityPosition - the position of the entity (source or target)
      requiredType - the required schema type
      effectiveType - the actual entity type provided
      Returns:
      the formatted error message
    • checksourceAndTargetEntityCompliancy

      protected void checksourceAndTargetEntityCompliancy() throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.instances.AvailableInAnotherContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from class: RelationElementManagement
      Validates that both source and target entities comply with relation constraints and schema rules.
      Specified by:
      checksourceAndTargetEntityCompliancy in class RelationElementManagement<ResourceManagement,T extends EntityManagement<? extends org.gcube.informationsystem.model.reference.entities.Entity,TET>,org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if either the source or target entity is missing
      org.gcube.informationsystem.resourceregistry.api.exceptions.instances.AvailableInAnotherContextException - if any context boundary violations are found
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException - if any database/model schema constraints are violated
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if any other database error occurs
    • reallyUpdate

      protected com.orientechnologies.orient.core.record.OEdge reallyUpdate() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from class: ElementManagement
      Updates an existing element in the database (subclass hook).
      Overrides:
      reallyUpdate in class RelationElementManagement<ResourceManagement,T extends EntityManagement<? extends org.gcube.informationsystem.model.reference.entities.Entity,TET>,org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>
      Returns:
      the updated OrientDB vertex
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist in the database
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on any database error
    • serializeAsAffectedInstance

      public org.gcube.com.fasterxml.jackson.databind.JsonNode serializeAsAffectedInstance() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Serializes this relation as an element of an Operation Envelope: its own representation plus its source and target as endpoint references, which carry metadata and contexts only with the all policies.
      Overrides:
      serializeAsAffectedInstance in class ElementManagement<com.orientechnologies.orient.core.record.OEdge,org.gcube.informationsystem.types.reference.relations.RelationSchema<org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>>
      Returns:
      the serialized JSON node representation
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if serialization fails
    • reallyAddToContext

      protected void reallyAddToContext() throws org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Adds this relation and potentially its target to the target context environment, adhering to propagation constraints.
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if a context error occurs
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if database or constraint processing fails
    • internalAddToContext

      public void internalAddToContext() throws org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from interface: ERManagement
      Performs the internal low-level operations to add the entity/relationship to the target context.
      Specified by:
      internalAddToContext in interface ERManagement
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if context assignment violates rules
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or system error
    • forcedAddToContext

      public void forcedAddToContext() throws org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Adds this relation, as the direct target of the operation, to the target context environment. Propagation travels downstream only: the source Resource must already be in the target Context and is never pulled, while the target entity is always brought along, whatever the add constraint.
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if a context error occurs
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException - if the source Resource is not in the target Context
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if database operations fail
    • addToContext

      public void addToContext(UUID contextUUID) throws org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException, org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from interface: ERManagement
      Adds the entity/relationship to the specified context, evaluating schemas and constraints.
      Specified by:
      addToContext in interface ERManagement
      Parameters:
      contextUUID - the UUID of the destination context
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException - if schema rules are violated
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the context does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if context assignment violates rules
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or system error
    • reallyRemoveFromContext

      protected Map<UUID,org.gcube.com.fasterxml.jackson.databind.JsonNode> reallyRemoveFromContext() throws org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Removes this relation and potentially its target from the target context environment, adhering to propagation constraints.
      Returns:
      the map of affected instances and their JSON representations
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if a context error occurs
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if database operations fail
    • internalRemoveFromContext

      public void internalRemoveFromContext() throws org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from interface: ERManagement
      Performs the internal low-level operations to remove the entity/relationship from the context.
      Specified by:
      internalRemoveFromContext in interface ERManagement
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if removal violates rules
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or system error
    • removeFromContext

      public void removeFromContext(UUID contextUUID) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from interface: ERManagement
      Removes the entity/relationship from the specified context.
      Specified by:
      removeFromContext in interface ERManagement
      Parameters:
      contextUUID - the UUID of the context from which to remove
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the context does not exist
      org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException - if removal violates rules
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException - if schema rules are violated
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database or system error
    • internalDelete

      public void internalDelete()
      An instance is never deleted directly: it is deleted when it leaves its last Context (see removeFromContext(UUID)).

      Warning: Any changes made to this implementation must also be applied to the corresponding method in EntityManagement to keep both ER hierarchies synchronized.

      Overrides:
      internalDelete in class ElementManagement<com.orientechnologies.orient.core.record.OEdge,org.gcube.informationsystem.types.reference.relations.RelationSchema<org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>>
      Throws:
      UnsupportedOperationException - always
    • serializeJsonNodeCollectionAsString

      protected String serializeJsonNodeCollectionAsString(Collection<org.gcube.com.fasterxml.jackson.databind.JsonNode> collection) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Serializes a collection of JsonNode entities into a JSON array string.
      Parameters:
      collection - the collection of JSON nodes to serialize
      Returns:
      the serialized JSON array string
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if serialization fails
    • reallyGetAll

      public String reallyGetAll() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Description copied from class: ElementManagement
      Retrieves all elements from the database and returns them as a JSON array string.
      Specified by:
      reallyGetAll in class ElementManagement<com.orientechnologies.orient.core.record.OEdge,org.gcube.informationsystem.types.reference.relations.RelationSchema<org.gcube.informationsystem.types.reference.entities.ResourceSchema,TET extends org.gcube.informationsystem.types.reference.entities.EntitySchema>>
      Returns:
      JSON array string of all elements
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database traversal or serialization error