use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class TrackerTest method persistRelationship.
public Relationship persistRelationship(TrackedEntityInstance t1, TrackedEntityInstance t2) {
RelationshipItem from = new RelationshipItem();
from.setTrackedEntityInstance(t1);
RelationshipItem to = new RelationshipItem();
to.setTrackedEntityInstance(t2);
return _persistRelationship(from, to);
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class DefaultTrackerAccessManager method canWrite.
@Override
public List<String> canWrite(User user, Relationship relationship) {
List<String> errors = new ArrayList<>();
RelationshipType relationshipType;
RelationshipItem from;
RelationshipItem to;
// always allow if user == null (internal process) or user is superuser
if (user == null || user.isSuper() || relationship == null) {
return errors;
}
relationshipType = relationship.getRelationshipType();
if (!aclService.canDataWrite(user, relationshipType)) {
errors.add("User has no data write access to relationshipType: " + relationshipType.getUid());
}
from = relationship.getFrom();
to = relationship.getTo();
errors.addAll(canWrite(user, from.getTrackedEntityInstance()));
errors.addAll(canUpdate(user, from.getProgramInstance(), false));
errors.addAll(canUpdate(user, from.getProgramStageInstance(), false));
errors.addAll(canWrite(user, to.getTrackedEntityInstance()));
errors.addAll(canUpdate(user, to.getProgramInstance(), false));
errors.addAll(canUpdate(user, to.getProgramStageInstance(), false));
return errors;
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class RelationshipSMSListener method createRelationshipItem.
private RelationshipItem createRelationshipItem(RelationshipType relType, RelationshipDir dir, Uid objId) {
RelationshipItem relItem = new RelationshipItem();
RelationshipEntity fromEnt = relType.getFromConstraint().getRelationshipEntity();
RelationshipEntity toEnt = relType.getFromConstraint().getRelationshipEntity();
RelationshipEntity relEnt = dir == RelationshipDir.FROM ? fromEnt : toEnt;
switch(relEnt) {
case TRACKED_ENTITY_INSTANCE:
TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(objId.getUid());
if (tei == null) {
throw new SMSProcessingException(SmsResponse.INVALID_TEI.set(objId));
}
relItem.setTrackedEntityInstance(tei);
break;
case PROGRAM_INSTANCE:
ProgramInstance progInst = programInstanceService.getProgramInstance(objId.getUid());
if (progInst == null) {
throw new SMSProcessingException(SmsResponse.INVALID_ENROLL.set(objId));
}
relItem.setProgramInstance(progInst);
break;
case PROGRAM_STAGE_INSTANCE:
ProgramStageInstance stageInst = programStageInstanceService.getProgramStageInstance(objId.getUid());
if (stageInst == null) {
throw new SMSProcessingException(SmsResponse.INVALID_EVENT.set(objId));
}
relItem.setProgramStageInstance(stageInst);
break;
}
return relItem;
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class DeduplicationHelperTest method shouldFailGetDuplicateRelationshipErrorWithDuplicateRelationshipsWithTeis.
@Test
void shouldFailGetDuplicateRelationshipErrorWithDuplicateRelationshipsWithTeis() {
TrackedEntityInstance teiA = getTeiA();
TrackedEntityInstance teiB = getTeiB();
TrackedEntityInstance teiC = getTeiC();
// A->C, B->C
RelationshipItem fromA = new RelationshipItem();
RelationshipItem toA = new RelationshipItem();
RelationshipItem fromB = new RelationshipItem();
RelationshipItem toB = new RelationshipItem();
fromA.setTrackedEntityInstance(teiA);
toA.setTrackedEntityInstance(teiC);
fromB.setTrackedEntityInstance(teiB);
toB.setTrackedEntityInstance(teiC);
Relationship relA = new Relationship();
Relationship relB = new Relationship();
relA.setAutoFields();
relB.setAutoFields();
relA.setRelationshipType(relationshipType);
relB.setRelationshipType(relationshipType);
relA.setFrom(fromA);
relA.setTo(toA);
relB.setFrom(fromB);
relB.setTo(toB);
fromA.setRelationship(relA);
toA.setRelationship(relA);
fromB.setRelationship(relB);
toB.setRelationship(relB);
teiA.getRelationshipItems().add(fromA);
teiB.getRelationshipItems().add(fromB);
assertNotNull(deduplicationHelper.getDuplicateRelationshipError(teiA, teiB.getRelationshipItems().stream().map(RelationshipItem::getRelationship).collect(Collectors.toSet())));
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class DeduplicationHelperTest method testMergeObjectRelationship.
@Test
void testMergeObjectRelationship() throws PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
TrackedEntityInstance original = getTeiA();
TrackedEntityInstance another = getTeiA();
TrackedEntityInstance duplicate = getTeiA();
Relationship anotherBaseRelationship = getRelationship();
RelationshipItem relationshipItemAnotherTo = getRelationshipItem(anotherBaseRelationship, another);
RelationshipItem relationshipItemAnotherFrom = getRelationshipItem(anotherBaseRelationship, duplicate);
Relationship anotherRelationship = getRelationship(relationshipItemAnotherTo, relationshipItemAnotherFrom);
RelationshipItem anotherRelationshipItem = getRelationshipItem(anotherRelationship, duplicate);
duplicate.getRelationshipItems().add(anotherRelationshipItem);
MergeObject mergeObject = deduplicationHelper.generateMergeObject(original, duplicate);
assertTrue(mergeObject.getTrackedEntityAttributes().isEmpty());
assertFalse(mergeObject.getRelationships().isEmpty());
mergeObject.getRelationships().forEach(r -> assertEquals(anotherRelationship.getUid(), r));
Relationship baseRelationship = getRelationship();
RelationshipItem relationshipItemTo = getRelationshipItem(baseRelationship, original);
RelationshipItem relationshipItemFrom = getRelationshipItem(baseRelationship, duplicate);
Relationship relationship = getRelationship(relationshipItemTo, relationshipItemFrom);
RelationshipItem relationshipItem = getRelationshipItem(relationship, duplicate);
duplicate.getRelationshipItems().add(relationshipItem);
mergeObject = deduplicationHelper.generateMergeObject(original, duplicate);
assertEquals(1, mergeObject.getRelationships().size());
}
Aggregations