Search in sources :

Example 1 with RelationshipConstraint

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

the class EnrollmentAnalyticsManagerTest method createRelationshipType.

private RelationshipType createRelationshipType(RelationshipEntity toConstraint) {
    RelationshipType relationshipTypeA = rnd.nextObject(RelationshipType.class);
    RelationshipConstraint from = new RelationshipConstraint();
    from.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    RelationshipConstraint to = new RelationshipConstraint();
    to.setRelationshipEntity(toConstraint);
    relationshipTypeA.setFromConstraint(from);
    relationshipTypeA.setToConstraint(to);
    return relationshipTypeA;
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 2 with RelationshipConstraint

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

the class DhisConvenienceTest method createRelationshipType.

public static RelationshipType createRelationshipType(char uniqueCharacter) {
    RelationshipType relationshipType = new RelationshipType();
    relationshipType.setFromToName("from_" + uniqueCharacter);
    relationshipType.setToFromName("to_" + uniqueCharacter);
    relationshipType.setAutoFields();
    relationshipType.setName("RelationshipType_" + relationshipType.getUid());
    relationshipType.setFromConstraint(new RelationshipConstraint());
    relationshipType.setToConstraint(new RelationshipConstraint());
    return relationshipType;
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 3 with RelationshipConstraint

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

the class DhisConvenienceTest method createTeiToEventRelationshipType.

public static RelationshipType createTeiToEventRelationshipType(char uniqueCharacter, Program program, TrackedEntityType trackedEntityType, boolean isBidirectional) {
    RelationshipConstraint teiConstraintA = new RelationshipConstraint();
    teiConstraintA.setProgram(program);
    teiConstraintA.setTrackedEntityType(trackedEntityType);
    teiConstraintA.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    RelationshipConstraint teiConstraintB = new RelationshipConstraint();
    teiConstraintB.setProgram(program);
    teiConstraintB.setTrackedEntityType(trackedEntityType);
    teiConstraintB.setRelationshipEntity(RelationshipEntity.PROGRAM_STAGE_INSTANCE);
    RelationshipType relationshipType = createRelationshipType(uniqueCharacter);
    relationshipType.setName("Tei_to_event_" + uniqueCharacter);
    relationshipType.setBidirectional(isBidirectional);
    relationshipType.setFromConstraint(teiConstraintA);
    relationshipType.setToConstraint(teiConstraintB);
    return relationshipType;
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 4 with RelationshipConstraint

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

the class JacksonRelationshipServiceTest method createRelationshipTypeWithTeiConstraint.

private RelationshipType createRelationshipTypeWithTeiConstraint() {
    RelationshipType relationshipType = new RelationshipType();
    relationshipType.setUid(CodeGenerator.generateUid());
    RelationshipConstraint from = new RelationshipConstraint();
    from.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    from.setTrackedEntityType(new TrackedEntityType("a", "b"));
    RelationshipConstraint to = rnd.nextObject(RelationshipConstraint.class);
    to.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    to.setTrackedEntityType(new TrackedEntityType("b", "c"));
    relationshipType.setFromConstraint(from);
    relationshipType.setToConstraint(to);
    return relationshipType;
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 5 with RelationshipConstraint

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

the class RelationshipsValidationHookTest method verifyValidationFailsOnFromWithMultipleDataset.

@Test
void verifyValidationFailsOnFromWithMultipleDataset() {
    String relationshipUid = "nBx6auGDUHG";
    Relationship relationship = Relationship.builder().relationship(relationshipUid).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).enrollment(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).build();
    RelationshipType relationshipType = new RelationshipType();
    relationshipType.setUid(relationship.getRelationshipType());
    RelationshipConstraint constraint = new RelationshipConstraint();
    constraint.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    relationshipType.setFromConstraint(constraint);
    relationshipType.setToConstraint(constraint);
    when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relationshipType));
    reporter = new ValidationErrorReporter(ctx);
    validationHook.validateRelationship(reporter, relationship);
    assertTrue(reporter.hasErrors());
    assertThat(reporter.getReportList().get(0).getErrorCode(), is(TrackerErrorCode.E4001));
    assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Item `from` for Relationship `nBx6auGDUHG` is invalid: an Item can link only one Tracker entity."));
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) Relationship(org.hisp.dhis.tracker.domain.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

RelationshipConstraint (org.hisp.dhis.relationship.RelationshipConstraint)13 RelationshipType (org.hisp.dhis.relationship.RelationshipType)13 Relationship (org.hisp.dhis.tracker.domain.Relationship)3 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)3 Test (org.junit.jupiter.api.Test)3 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)1