use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnInvalidToConstraint.
@Test
void verifyValidationFailsOnInvalidToConstraint() {
RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, TRACKED_ENTITY_INSTANCE);
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().enrollment(CodeGenerator.generateUid()).build()).relationshipType(relType.getUid()).build();
when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, E4010, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Type `to` constraint requires a trackedEntity but a enrollment was found."));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class DefaultTrackerObjectsDeletionService method deleteRelationShips.
@Override
public TrackerTypeReport deleteRelationShips(TrackerBundle bundle) {
TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.RELATIONSHIP);
List<Relationship> relationships = bundle.getRelationships();
for (int idx = 0; idx < relationships.size(); idx++) {
String uid = relationships.get(idx).getRelationship();
TrackerObjectReport objectReport = new TrackerObjectReport(TrackerType.RELATIONSHIP, uid, idx);
org.hisp.dhis.relationship.Relationship relationship = relationshipService.getRelationship(uid);
relationshipService.deleteRelationship(relationship);
typeReport.getStats().incDeleted();
typeReport.addObjectReport(objectReport);
}
return typeReport;
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class StrategyPreProcessor method preProcessRelationships.
public void preProcessRelationships(TrackerBundle bundle) {
for (Relationship relationship : bundle.getRelationships()) {
TrackerImportStrategy importStrategy = bundle.getImportStrategy();
org.hisp.dhis.relationship.Relationship existingRelationship = bundle.getPreheat().getRelationship(TrackerIdScheme.UID, relationship);
if (importStrategy.isCreateAndUpdate()) {
if (existingRelationship == null) {
bundle.setStrategy(relationship, TrackerImportStrategy.CREATE);
} else {
bundle.setStrategy(relationship, TrackerImportStrategy.UPDATE);
}
} else {
bundle.setStrategy(relationship, importStrategy);
}
}
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class DuplicateRelationshipsPreProcessorTest method test_on_identical_rels_1_is_removed.
/*
* Verifies that:
*
* - given 2 identical relationships
*
* - one is removed
*/
@Test
void test_on_identical_rels_1_is_removed() {
String relType = REL_TYPE_NONBIDIRECTIONAL_UID;
String fromTeiUid = CodeGenerator.generateUid();
String toTeiUid = CodeGenerator.generateUid();
Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
preProcessor.process(bundle);
assertThat(bundle.getRelationships(), hasSize(1));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class DuplicateRelationshipsPreProcessorTest method test_on_identical_rels_relType_bi_1_is_removed.
/*
* Verifies that:
*
* - given 2 identical relationships
*
* - and relationship type's bidirectional property = true
*
* - one is removed
*/
@Test
void test_on_identical_rels_relType_bi_1_is_removed() {
String relType = REL_TYPE_BIDIRECTIONAL_UID;
String fromTeiUid = CodeGenerator.generateUid();
String toTeiUid = CodeGenerator.generateUid();
Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(true).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(true).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
preProcessor.process(bundle);
assertThat(bundle.getRelationships(), hasSize(1));
}
Aggregations