Search in sources :

Example 1 with RelationshipKey

use of org.hisp.dhis.relationship.RelationshipKey in project dhis2-core by dhis2.

the class TrackerIdentifierCollector method collectRelationships.

private void collectRelationships(Map<Class<?>, Set<String>> identifiers, List<Relationship> relationships) {
    relationships.forEach(relationship -> {
        RelationshipKey relationshipKey = RelationshipPreheatKeySupport.getRelationshipKey(relationship);
        addIdentifier(identifiers, Relationship.class, relationshipKey.asString());
        addIdentifier(identifiers, Relationship.class, relationship.getRelationship());
        if (relationship.getFrom() != null) {
            addIdentifier(identifiers, TrackedEntity.class, relationship.getFrom().getTrackedEntity());
            addIdentifier(identifiers, Enrollment.class, relationship.getFrom().getEnrollment());
            addIdentifier(identifiers, Event.class, relationship.getFrom().getEvent());
        }
        if (relationship.getTo() != null) {
            addIdentifier(identifiers, TrackedEntity.class, relationship.getTo().getTrackedEntity());
            addIdentifier(identifiers, Enrollment.class, relationship.getTo().getEnrollment());
            addIdentifier(identifiers, Event.class, relationship.getTo().getEvent());
        }
    });
}
Also used : RelationshipKey(org.hisp.dhis.relationship.RelationshipKey)

Example 2 with RelationshipKey

use of org.hisp.dhis.relationship.RelationshipKey in project dhis2-core by dhis2.

the class TrackerPreheat method putRelationship.

public void putRelationship(TrackerIdScheme identifier, Relationship relationship) {
    if (!relationships.containsKey(identifier)) {
        relationships.put(identifier, new HashMap<>());
    }
    if (Objects.nonNull(relationship)) {
        RelationshipKey relationshipKey = getRelationshipKey(relationship);
        if (relationship.getRelationshipType().isBidirectional()) {
            relationships.get(identifier).put(relationshipKey.inverseKey().asString(), relationship);
        }
        relationships.get(identifier).put(relationshipKey.asString(), relationship);
    }
}
Also used : RelationshipKey(org.hisp.dhis.relationship.RelationshipKey) RelationshipPreheatKeySupport.getRelationshipKey(org.hisp.dhis.tracker.preheat.RelationshipPreheatKeySupport.getRelationshipKey)

Example 3 with RelationshipKey

use of org.hisp.dhis.relationship.RelationshipKey in project dhis2-core by dhis2.

the class TrackerPreheat method getRelationship.

public Relationship getRelationship(TrackerIdScheme identifier, org.hisp.dhis.tracker.domain.Relationship relationship) {
    if (!relationships.containsKey(identifier)) {
        return null;
    }
    RelationshipType relationshipType = get(RelationshipType.class, relationship.getRelationshipType());
    if (Objects.nonNull(relationshipType)) {
        RelationshipKey relationshipKey = getRelationshipKey(relationship);
        RelationshipKey inverseKey = null;
        if (relationshipType.isBidirectional()) {
            inverseKey = relationshipKey.inverseKey();
        }
        return Stream.of(relationshipKey, inverseKey).filter(Objects::nonNull).map(key -> relationships.get(identifier).get(key.asString())).filter(Objects::nonNull).findFirst().orElse(null);
    }
    return null;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Setter(lombok.Setter) Getter(lombok.Getter) CategoryOption(org.hisp.dhis.category.CategoryOption) TrackedEntityProgramOwnerOrgUnit(org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerOrgUnit) HashMap(java.util.HashMap) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerIdScheme(org.hisp.dhis.tracker.TrackerIdScheme) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Event(org.hisp.dhis.tracker.domain.Event) HibernateProxyUtils(org.hisp.dhis.hibernate.HibernateProxyUtils) EnumMap(java.util.EnumMap) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) TreeNode(com.scalified.tree.TreeNode) Collection(java.util.Collection) RelationshipKey(org.hisp.dhis.relationship.RelationshipKey) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) TrackerType(org.hisp.dhis.tracker.TrackerType) RelationshipPreheatKeySupport.getRelationshipKey(org.hisp.dhis.tracker.preheat.RelationshipPreheatKeySupport.getRelationshipKey) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Objects(java.util.Objects) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) Stream(java.util.stream.Stream) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) StringJoiner(java.util.StringJoiner) Optional(java.util.Optional) PeriodType(org.hisp.dhis.period.PeriodType) Relationship(org.hisp.dhis.relationship.Relationship) ArrayMultiTreeNode(com.scalified.tree.multinode.ArrayMultiTreeNode) RelationshipType(org.hisp.dhis.relationship.RelationshipType) Objects(java.util.Objects) RelationshipKey(org.hisp.dhis.relationship.RelationshipKey) RelationshipPreheatKeySupport.getRelationshipKey(org.hisp.dhis.tracker.preheat.RelationshipPreheatKeySupport.getRelationshipKey)

Aggregations

RelationshipKey (org.hisp.dhis.relationship.RelationshipKey)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 TreeNode (com.scalified.tree.TreeNode)1 ArrayMultiTreeNode (com.scalified.tree.multinode.ArrayMultiTreeNode)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 StringJoiner (java.util.StringJoiner)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1