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());
}
});
}
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);
}
}
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;
}
Aggregations