Search in sources :

Example 6 with RelationshipConstraint

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

the class RelationshipsValidationHookTest method verifyValidationFailsOnFromWithNoDataset.

@Test
void verifyValidationFailsOnFromWithNoDataset() {
    String relationshipUid = "nBx6auGDUHG";
    Relationship relationship = Relationship.builder().relationship(relationshipUid).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().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);
    hasTrackerError(reporter, E4013, RELATIONSHIP, relationship.getUid());
    assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Type `from` constraint is missing trackedEntity."));
}
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)

Example 7 with RelationshipConstraint

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

the class RelationshipSMSListenerTest method setUpInstances.

private void setUpInstances() throws SmsCompressionException {
    user = createUser('U');
    user.setPhoneNumber(ORIGINATOR);
    programInstance = new ProgramInstance();
    programInstance.setAutoFields();
    relationshipType = new RelationshipType();
    relationshipType.setAutoFields();
    RelationshipConstraint relConstraint = new RelationshipConstraint();
    relConstraint.setRelationshipEntity(RelationshipEntity.PROGRAM_INSTANCE);
    relationshipType.setToConstraint(relConstraint);
    relationshipType.setFromConstraint(relConstraint);
    incomingSmsRelationship = createSMSFromSubmission(createRelationshipSubmission());
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) ProgramInstance(org.hisp.dhis.program.ProgramInstance) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 8 with RelationshipConstraint

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

the class PreCheckDataRelationsValidationHookTest method createRelTypeConstraint.

private RelationshipType createRelTypeConstraint(@SuppressWarnings("SameParameterValue") RelationshipEntity from, @SuppressWarnings("SameParameterValue") RelationshipEntity to) {
    RelationshipType relType = new RelationshipType();
    relType.setUid(CodeGenerator.generateUid());
    RelationshipConstraint relationshipConstraintFrom = new RelationshipConstraint();
    relationshipConstraintFrom.setRelationshipEntity(from);
    RelationshipConstraint relationshipConstraintTo = new RelationshipConstraint();
    relationshipConstraintTo.setRelationshipEntity(to);
    relType.setFromConstraint(relationshipConstraintFrom);
    relType.setToConstraint(relationshipConstraintTo);
    return relType;
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 9 with RelationshipConstraint

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

the class RelationshipsValidationHookTest method verifyValidationFailsOnToWithMultipleDataset.

@Test
void verifyValidationFailsOnToWithMultipleDataset() {
    String relationshipUid = "nBx6auGDUHG";
    Relationship relationship = Relationship.builder().relationship(relationshipUid).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).enrollment(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);
    hasTrackerError(reporter, E4001, RELATIONSHIP, relationship.getUid());
    assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Item `to` 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)

Example 10 with RelationshipConstraint

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

the class RelationshipsValidationHookTest method createRelTypeConstraint.

private RelationshipType createRelTypeConstraint(RelationshipEntity from, RelationshipEntity to) {
    RelationshipType relType = new RelationshipType();
    relType.setUid(CodeGenerator.generateUid());
    RelationshipConstraint relationshipConstraintFrom = new RelationshipConstraint();
    relationshipConstraintFrom.setRelationshipEntity(from);
    RelationshipConstraint relationshipConstraintTo = new RelationshipConstraint();
    relationshipConstraintTo.setRelationshipEntity(to);
    relType.setFromConstraint(relationshipConstraintFrom);
    relType.setToConstraint(relationshipConstraintTo);
    return relType;
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

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