Class AspectRelation<T extends ComplexEntity>

java.lang.Object
mc.core.system.base.BaseBean
mc.core.domain.base.dobj.AbstractAspect<T>
mc.core.domain.base.aspect.AspectRelation<T>

public class AspectRelation<T extends ComplexEntity> extends AbstractAspect<T>
  • Constructor Details

    • AspectRelation

      public AspectRelation()
  • Method Details

    • getRelatedEntities

      public List<T> getRelatedEntities(T entity, RelationType relationType)
      Searches for ComplexEntities that are in a Relation of given RelationType with given ComplexEntity. If RelationType is MASTER_SLAVE returns the entities2 of Relation, for EQUAL-RelationType returns all ComplexEntities except the given. A Relation is stored as EntityToEntity. WARNING: this method assumes that related entity is of same objectClass as given entity!
      Parameters:
      entity - ComplexEntity, mandatory
      relationType - optional, default is to return all relations
      Returns:
      List of ComplexEntity of the same class as given ComplexEntity, if none found return empty list.
    • getRelatedEntities

      public List<T> getRelatedEntities(T entity, RelationType relationType, boolean includeSlaveToMaster)
      Searches for ComplexEntities that are in a Relation of given RelationType with given ComplexEntity. If RelationType is MASTER_SLAVE returns the entities2 of Relation, for EQUAL-RelationType returns all ComplexEntities except the given. A Relation is stored as EntityToEntity.
      Parameters:
      entity - ComplexEntity, mandatory
      relationType - optional, default is to return all relations
      includeSlaveToMaster - boolean: if true also returns the master of MASTER_SLAVE Relations where given ComplexEntity is the slave
      Returns:
      List of related ComplexEntity of the same class as given ComplexEntity, if none found return empty List.
    • getRelatedEntities

      public Map<RelationType,List<T>> getRelatedEntities(T entity, List<RelationType> relationTypes, boolean includeSlaveToMaster)
      Searches for ComplexEntities that are in a Relation of one of the given RelationTypes with given ComplexEntity. If RelationType is MASTER_SLAVE returns the entities2 of Relation, for EQUAL-RelationType returns all ComplexEntities except the given. A Relation is stored as EntityToEntity.
      Parameters:
      entity - ComplexEntity, mandatory
      relationTypes - list of RelationType, mandatory, can be empty
      includeSlaveToMaster - boolean: if true also returns the master of MASTER_SLAVE Relations where given ComplexEntity is the slave. in Relations with DependencyType MASTER_SLAVE per default a slave does not see its master. Set this flag to true if also master of slave should be returned. WARNING: this method assumes that related entity is of same objectClass as given entity!
      Returns:
      Map with List of related ComplexEntity mapped by RelationType
    • getRelatedEntities

      public Map<T,List<T>> getRelatedEntities(List<T> entities, RelationType relationType, boolean includeSlaveToMaster)
      Searches for ComplexEntities that are in a Relation of one of the given RelationTypes with given ComplexEntity. If RelationType is MASTER_SLAVE returns the entities2 of Relation, for EQUAL-RelationType returns all ComplexEntities except the given. A Relation is stored as EntityToEntity.
      Parameters:
      entities - list of ComplexEntity, mandatory. If empty returns empty map.
      relationType - RelationType, mandatory
      includeSlaveToMaster - boolean: if true also returns the master of MASTER_SLAVE Relations where given ComplexEntity is the slave. in Relations with DependencyType MASTER_SLAVE per default a slave does not see its master. Set this flag to true if also master of slave should be returned. WARNING: this method assumes that related entity is of same objectClass as given entity!
      Returns:
      Map with List of related ComplexEntity mapped to the original objects. If an object has no relations it will not be in the map.
    • getRelatedEntities

      public Map<RelationType,Map<T,List<T>>> getRelatedEntities(List<T> entities, List<RelationType> relationTypes, boolean includeSlaveToMaster)
      Build map of related entities
      Parameters:
      entities -
      relationTypes -
      includeSlaveToMaster -
      Returns:
      Map on relation type of mapped related objects on given entities
    • getRelations

      public List<EntityToEntity> getRelations(T entity, RelationType relationType, boolean includeSlaveToMaster)
    • getRelations

      public List<EntityToEntity> getRelations(T entity, List<RelationType> relationTypes, boolean includeSlaveToMaster)
      get relations in form of EntityToEntity objects for the nodes of relationTypes (if given) and with snapshot flag. include slaveToMaster relations for slaveToMaster relationType if flag is true. if relationTypes is null or empty, get relations of all types.

      method is primarily used in channels. NOTE: grouping the result for entities and filtering for MASTER-SLAVE (includeSlaveToMaster) must be done in calling code.

      Parameters:
      entity - mandatory
      relationTypes - optional
      Returns:
    • getRelations

      public List<EntityToEntity> getRelations(List<T> entities, List<RelationType> relationTypes)
      get all relations for given entities (including slaveToMaster)
      Parameters:
      entities - mandatory
      relationTypes - optional
      Returns:
    • getRelationTypes

      public List<RelationType> getRelationTypes(ComplexTypeEntity typeEntity)
      Returns list with relationTypes where given typeEntity is either defined as master or the RolationType is EQUAL and given typeEntity is either entity1 or in entities2.
      Parameters:
      typeEntity - mandatory
      Returns:
      List of RelationType or empty list if no such RelationType exist
    • getRelationTypes

      public List<RelationType> getRelationTypes(ComplexTypeEntity typeEntity, boolean includeSlaveToMaster)
      Returns list with relationTypes where given typeEntity is either entity1 or in entities2 (includeSlaveToMaster == true)
      or (includeSlaveToMaster == false)
      where given typeEntity is either defined as master or the relationType is EQUAL and given typeEntity is either entity1 or in entities2
      Parameters:
      typeEntity - mandatory
      Returns:
      List of RelationType or empty list if no such RelationType exist
    • remove

      public void remove(T entity, RelationType relationType, T relatedObject) throws ApplicationException
      removes relationship of given type between entity and relatedEntity. If relatedEntity is null removes all relationship of given type from entity.
      If relation is a master-relation entity is treated as master (entity1), if it is bidirectional any relation of given type involving entity and, if given, relatedEntity will be removed. It is assumed that in a bidirectional relation no relations of entity to itself exist, otherwise they will be removed, too.
      Parameters:
      entity - mandatory, object from which relations of given type should be removed
      relationType - mandatory
      relatedObject - optional, if given, only removes relations to this object, otherwise all of given type
      Throws:
      ApplicationException
    • deleteRelation

      public void deleteRelation(EntityToEntity entToEnt) throws ApplicationException
      Throws:
      ApplicationException
    • checkDeleteOnlyByForce

      public boolean checkDeleteOnlyByForce(T entity) throws ApplicationException
      checks if this entity has master-slave-relations where it is the slave.
      Parameters:
      entity - mandatory, must be attached
      Throws:
      ApplicationException
    • relationSet

      public RelationValue<T> relationSet(SystemRelationType systemRelationType, T source, T related, int prio) throws ApplicationException
      Throws:
      ApplicationException
    • systemGetAll

      public RelationValues<T> systemGetAll(SystemRelationType systemRelationType, T source, boolean includeSlaveToMaster) throws ApplicationException
      Throws:
      ApplicationException
    • getAll

      public RelationValues<T> getAll(T source, List<RelationType> relationTypes, boolean includeSlaveToMaster)
    • relationRemove

      public void relationRemove(SystemRelationType systemRelationType) throws ApplicationException
      Throws:
      ApplicationException
    • relationRemoveAll

      public void relationRemoveAll(SystemRelationType systemRelationType) throws ApplicationException
      Throws:
      ApplicationException
    • add

      public RelationValue<T> add(T entity, T related, RelationType relationType) throws ApplicationException
      creates a new relation for given entity, related entity and relationType if such a relation does not already exist. Add the new relation at the end of list of related objects of this relationType. for relation exist rules see add(ComplexEntity, List, RelationType)
      Parameters:
      entity - mandatory
      related - mandatory
      relationType - mandatory
      Returns:
      relation value for inserted or existing relation
      Throws:
      ApplicationException
    • add

      public RelationValues<T> add(T entity, List<T> relatedList, RelationType relationType) throws ApplicationException
      creates for each entity from relatedList a new relation for given entity and relationType if such a relation does not already exist. Adds the new relations at the end of list of related objects of this relationType.

      relation exists if relationType is RelationType.RelationDependency.EQUAL and complexEntity/related are either entity1 or entity2, or relationType is RelationType.RelationDependency.MASTER_SLAVE and complexEntity is entity1 and related is entity2. In other words: for EQUAL relationTypes there can only be one relation link between to entities, for MASTER_SLAVE there can be two in reverse directions

      Parameters:
      entity - mandatory
      relatedList - mandatory, if empty returns empty RelationValues
      relationType - mandatory
      Returns:
      relation values for inserted or existing relations
      Throws:
      ApplicationException
    • getTargetRelationsCount

      public int getTargetRelationsCount(T entity, RelationType relationTypes)
    • orderChange

      public void orderChange(T entity, T relatedEntity, RelationType relationType, boolean decreaseOrder) throws UserException
      Parameters:
      entity - mandatory
      relatedEntity - mandatory
      relationType - mandatory
      decreaseOrder -
      Throws:
      UserException
    • orderSetForList

      public void orderSetForList(T entity, Map<EntityToEntity,Integer> prioMap) throws UserException
      set prio of EntityToEntity for list of all Relations of this ComplexEntity according to given map.
      Type Parameters:
      T -
      Parameters:
      entity - the entity for which the list of relations is to be ordered. Can be entity1 or entity2 of relation
      prioMap - mandatory, key EntityToEntity as key, the prio to set as value
      Throws:
      UserException
    • getAttributeProfile

      public EntityProfile getAttributeProfile(EntityToEntity entityToEntity) throws ApplicationException
      get attribute profile for e2e. create if type exists. else return null
      Throws:
      ApplicationException
    • getAttributeProfile

      public EntityProfile getAttributeProfile(EntityToEntity entityToEntity, boolean createProfileType) throws ApplicationException
      get attribute profile for e2e. create if type exists or createProfileType=true. else return null
      Throws:
      ApplicationException