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