use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class RelationshipsValidationHook method validateRelationship.
public void validateRelationship(ValidationErrorReporter reporter, Relationship relationship) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerBundle bundle = context.getBundle();
boolean isValid = validateMandatoryData(reporter, relationship, bundle.getPreheat().getAll(RelationshipType.class));
// Relationship
if (isValid) {
validateRelationshipLinkToOneEntity(reporter, relationship);
validateRelationshipConstraint(reporter, relationship, bundle);
validateAutoRelationship(reporter, relationship);
validateReferences(reporter, relationship, relationship.getFrom());
validateReferences(reporter, relationship, relationship.getTo());
}
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class RepeatedEventsValidationHook method validate.
@Override
public void validate(ValidationErrorReporter reporter, TrackerImportValidationContext context) {
TrackerBundle bundle = context.getBundle();
Map<Pair<String, String>, List<Event>> eventsByEnrollmentAndNotRepeatableProgramStage = bundle.getEvents().stream().filter(e -> !reporter.isInvalid(e)).filter(e -> !context.getStrategy(e).isDelete()).filter(e -> {
ProgramStage programStage = context.getProgramStage(e.getProgramStage());
return programStage.getProgram().isRegistration() && !programStage.getRepeatable();
}).collect(Collectors.groupingBy(e -> Pair.of(e.getProgramStage(), e.getEnrollment())));
for (Map.Entry<Pair<String, String>, List<Event>> mapEntry : eventsByEnrollmentAndNotRepeatableProgramStage.entrySet()) {
if (mapEntry.getValue().size() > 1) {
for (Event event : mapEntry.getValue()) {
reporter.addError(event, TrackerErrorCode.E1039, mapEntry.getKey().getLeft());
}
}
}
bundle.getEvents().forEach(e -> validateNotMultipleEvents(reporter, context, e));
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class AttributeValidationHook method validateAttributeUniqueness.
protected void validateAttributeUniqueness(ValidationErrorReporter errorReporter, TrackerDto dto, String value, TrackedEntityAttribute trackedEntityAttribute, TrackedEntityInstance trackedEntityInstance, OrganisationUnit organisationUnit) {
checkNotNull(trackedEntityAttribute, TRACKED_ENTITY_ATTRIBUTE_CANT_BE_NULL);
if (Boolean.FALSE.equals(trackedEntityAttribute.isUnique()))
return;
List<UniqueAttributeValue> uniqueAttributeValues = errorReporter.getValidationContext().getBundle().getPreheat().getUniqueAttributeValues();
for (UniqueAttributeValue uniqueAttributeValue : uniqueAttributeValues) {
boolean isTeaUniqueInOrgUnitScope = !trackedEntityAttribute.getOrgunitScope() || Objects.equals(organisationUnit.getUid(), uniqueAttributeValue.getOrgUnitId());
boolean isTheSameTea = Objects.equals(uniqueAttributeValue.getAttributeUid(), trackedEntityAttribute.getUid());
boolean hasTheSameValue = Objects.equals(uniqueAttributeValue.getValue(), value);
boolean isNotSameTei = trackedEntityInstance == null || !Objects.equals(trackedEntityInstance.getUid(), uniqueAttributeValue.getTeiUid());
if (isTeaUniqueInOrgUnitScope && isTheSameTea && hasTheSameValue && isNotSameTei) {
TrackerBundle bundle = errorReporter.getValidationContext().getBundle();
TrackerErrorReport err = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1064).addArg(value).addArg(trackedEntityAttribute.getUid()).build(bundle);
errorReporter.addError(err);
return;
}
}
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class AttributeValidationHook method validateAttrValueType.
protected void validateAttrValueType(ValidationErrorReporter errorReporter, TrackerDto dto, Attribute attr, TrackedEntityAttribute teAttr) {
checkNotNull(attr, ATTRIBUTE_CANT_BE_NULL);
checkNotNull(teAttr, TRACKED_ENTITY_ATTRIBUTE_CANT_BE_NULL);
ValueType valueType = teAttr.getValueType();
TrackerImportValidationContext context = errorReporter.getValidationContext();
String error;
if (valueType.equals(ValueType.ORGANISATION_UNIT)) {
error = context.getOrganisationUnit(attr.getValue()) == null ? " Value " + attr.getValue() + " is not a valid org unit value" : null;
} else if (valueType.equals(ValueType.USERNAME)) {
error = context.usernameExists(attr.getValue()) ? null : " Value " + attr.getValue() + " is not a valid username value";
} else {
// org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
try {
error = teAttrService.validateValueType(teAttr, attr.getValue());
} catch (Exception e) {
error = e.getMessage();
}
}
if (error != null) {
TrackerBundle bundle = context.getBundle();
TrackerErrorReport err = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1007).addArg(valueType.toString()).addArg(error).build(bundle);
errorReporter.addError(err);
}
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EventCategoryOptValidationHookTest method setUp.
@BeforeEach
public void setUp() {
initServices();
hook = new EventCategoryOptValidationHook(i18nManager);
catOption = createCategoryOption('A');
category = createCategory('A', catOption);
catCombo = createCategoryCombo('A', category);
attOptionCombo = createCategoryOptionCombo(catCombo, catOption);
defaultCatCombo = new CategoryCombo();
defaultCatCombo.setName(DEFAULT_CATEGORY_COMBO_NAME);
defaultCatOption = new CategoryOption();
defaultCatOption.setName(DEFAULT_NAME);
defaultCatOptionCombo = createCategoryOptionCombo(defaultCatCombo, defaultCatOption);
program = createProgram('A');
program.setCategoryCombo(catCombo);
event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setProgram(program.getUid());
event.setOccurredAt(EVENT_INSTANT);
User user = createUser('A');
TrackerBundle bundle = TrackerBundle.builder().user(user).build();
when(validationContext.getBundle()).thenReturn(bundle);
when(validationContext.getProgram(program.getUid())).thenReturn(program);
reporter = new ValidationErrorReporter(validationContext);
}
Aggregations