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