Search in sources :

Example 51 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class EventRuleValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEvents(context.getBundle()).getOrDefault(event.getEvent(), Lists.newArrayList()).stream()).collect(Collectors.toList());
    addIssuesToReporter(reporter, event, programRuleIssues);
}
Also used : ValidationUtils.addIssuesToReporter(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.addIssuesToReporter) Event(org.hisp.dhis.tracker.domain.Event) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Collectors(java.util.stream.Collectors) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue)

Example 52 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter 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);
}
Also used : User(org.hisp.dhis.user.User) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 53 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHookTest method verifyCaptureScopeIsCheckedForTrackedEntityDeletion.

@Test
void verifyCaptureScopeIsCheckedForTrackedEntityDeletion() {
    TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
    when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.DELETE);
    when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(getTEIWithNoProgramInstances());
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateTrackedEntity(reporter, trackedEntity);
    assertFalse(reporter.hasErrors());
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 54 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForEventUsingUpdateStrategyAndUserWithAuthority.

@Test
void verifyValidationSuccessForEventUsingUpdateStrategyAndUserWithAuthority() {
    String enrollmentUid = CodeGenerator.generateUid();
    Event event = Event.builder().enrollment(enrollmentUid).orgUnit(ORG_UNIT_ID).programStage(PS_ID).program(PROGRAM_ID).build();
    when(ctx.getStrategy(event)).thenReturn(TrackerImportStrategy.UPDATE);
    when(ctx.getProgramStage(event.getProgramStage())).thenReturn(programStage);
    ProgramInstance programInstance = getEnrollment(enrollmentUid);
    ProgramStageInstance programStageInstance = getEvent();
    programStageInstance.setProgramInstance(programInstance);
    when(ctx.getProgramStageInstance(event.getEvent())).thenReturn(programStageInstance);
    when(ctx.getProgramInstance(event.getEnrollment())).thenReturn(programInstance);
    when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
    when(aclService.canDataRead(user, program)).thenReturn(true);
    when(aclService.canDataWrite(user, programStage)).thenReturn(true);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    bundle.setUser(changeCompletedEventAuthorisedUser());
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 55 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class PreCheckUpdatableFieldsValidationHookTest method verifyEventValidationFailsWhenUpdateEnrollment.

@Test
void verifyEventValidationFailsWhenUpdateEnrollment() {
    // given
    Event event = validEvent();
    event.setEnrollment("NewEnrollmentId");
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1128, EVENT, event.getUid());
    assertThat(reporter.getReportList().get(0).getErrorMessage(), containsString("enrollment"));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)206 Test (org.junit.jupiter.api.Test)192 Event (org.hisp.dhis.tracker.domain.Event)89 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)48 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)48 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)43 ProgramStage (org.hisp.dhis.program.ProgramStage)38 DataElement (org.hisp.dhis.dataelement.DataElement)25 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)24 Relationship (org.hisp.dhis.tracker.domain.Relationship)23 DataValue (org.hisp.dhis.tracker.domain.DataValue)21 Program (org.hisp.dhis.program.Program)19 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)17 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)16 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 RelationshipType (org.hisp.dhis.relationship.RelationshipType)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11