Search in sources :

Example 1 with TrackerIdentifierParams

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

the class TrackerImportParamsSerdeTest method testJsonDeserialization.

@Test
void testJsonDeserialization() throws IOException {
    final String json = "" + "{\"importMode\":\"COMMIT\"," + "\"identifiers\":{\"dataElementIdScheme\":{\"idScheme\":\"UID\"}," + "\"orgUnitIdScheme\":{\"idScheme\":\"UID\"}," + "\"programIdScheme\":{\"idScheme\":\"ATTRIBUTE\",\"value\":\"aaaa\"}," + "\"programStageIdScheme\":{\"idScheme\":\"UID\"}," + "\"idScheme\":{\"idScheme\":\"CODE\"}," + "\"categoryOptionComboIdScheme\":{\"idScheme\":\"UID\"}," + "\"categoryOptionIdScheme\":{\"idScheme\":\"UID\"}}," + "\"importStrategy\":\"DELETE\"," + "\"atomicMode\":\"OBJECT\"," + "\"flushMode\":\"OBJECT\"," + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":true," + "\"skipSideEffects\":true," + "\"skipRuleEngine\":true," + "\"trackedEntities\":[]," + "\"enrollments\":[]," + "\"events\":[]," + "\"relationships\":[]," + "\"username\":\"system-process\"}";
    final TrackerImportParams trackerImportParams = renderService.fromJson(json, TrackerImportParams.class);
    assertThat(trackerImportParams.getImportMode(), is(TrackerBundleMode.COMMIT));
    assertThat(trackerImportParams.getImportStrategy(), is(TrackerImportStrategy.DELETE));
    assertThat(trackerImportParams.getAtomicMode(), is(AtomicMode.OBJECT));
    assertThat(trackerImportParams.getFlushMode(), is(FlushMode.OBJECT));
    assertThat(trackerImportParams.getValidationMode(), is(ValidationMode.SKIP));
    assertThat(trackerImportParams.isSkipPatternValidation(), is(true));
    assertThat(trackerImportParams.isSkipSideEffects(), is(true));
    assertThat(trackerImportParams.isSkipRuleEngine(), is(true));
    assertThat(trackerImportParams.getUser(), is(nullValue()));
    TrackerIdentifierParams identifiers = trackerImportParams.getIdentifiers();
    assertThat(identifiers.getIdScheme(), is(TrackerIdentifier.CODE));
    assertThat(identifiers.getProgramIdScheme().getIdScheme(), is(TrackerIdScheme.ATTRIBUTE));
    assertThat(identifiers.getProgramIdScheme().getValue(), is("aaaa"));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 2 with TrackerIdentifierParams

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

the class TrackerImportParamsSerdeTest method testJsonSerialization.

@Test
void testJsonSerialization() throws JSONException {
    TrackerIdentifierParams identifierParams = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.builder().idScheme(TrackerIdScheme.ATTRIBUTE).value("aaaa").build()).build();
    TrackerImportParams trackerImportParams = TrackerImportParams.builder().identifiers(identifierParams).atomicMode(AtomicMode.OBJECT).flushMode(FlushMode.OBJECT).skipRuleEngine(true).importStrategy(TrackerImportStrategy.DELETE).validationMode(ValidationMode.SKIP).build();
    String json = renderService.toJsonAsString(trackerImportParams);
    JSONAssert.assertEquals(json, "" + "{\"importMode\":\"COMMIT\"," + "\"identifiers\":{\"dataElementIdScheme\":{\"idScheme\":\"UID\"}," + "\"orgUnitIdScheme\":{\"idScheme\":\"UID\"}," + "\"programIdScheme\":{\"idScheme\":\"ATTRIBUTE\",\"value\":\"aaaa\"}," + "\"programStageIdScheme\":{\"idScheme\":\"UID\"}," + "\"idScheme\":{\"idScheme\":\"CODE\"}," + "\"categoryOptionComboIdScheme\":{\"idScheme\":\"UID\"}," + "\"categoryOptionIdScheme\":{\"idScheme\":\"UID\"}}," + "\"importStrategy\":\"DELETE\"," + "\"atomicMode\":\"OBJECT\"," + "\"flushMode\":\"OBJECT\"," + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":false," + "\"skipSideEffects\":false," + "\"skipRuleEngine\":true," + "\"trackedEntities\":[]," + "\"enrollments\":[]," + "\"events\":[]," + "\"relationships\":[]," + "\"username\":\"system-process\"}", JSONCompareMode.LENIENT);
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 3 with TrackerIdentifierParams

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

the class EventDataValuesValidationHookTest method succeedsWhenDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode.

@Test
void succeedsWhenDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode() {
    TrackerIdentifierParams params = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.UID).programStageIdScheme(TrackerIdentifier.UID).dataElementIdScheme(TrackerIdentifier.CODE).build();
    when(context.getIdentifiers()).thenReturn(params);
    DataElement dataElement = dataElement();
    dataElement.setCode("DE_424050");
    when(context.getDataElement(dataElement.getCode())).thenReturn(dataElement);
    ProgramStage programStage = programStage(dataElement);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue dataValue = dataValue();
    dataValue.setDataElement("DE_424050");
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.ACTIVE).dataValues(Set.of(dataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 4 with TrackerIdentifierParams

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

the class EventDataValuesValidationHookTest method succeedsWhenMandatoryDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode.

@Test
void succeedsWhenMandatoryDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode() {
    TrackerIdentifierParams params = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.UID).programStageIdScheme(TrackerIdentifier.UID).dataElementIdScheme(TrackerIdentifier.CODE).build();
    when(context.getIdentifiers()).thenReturn(params);
    DataElement dataElement = dataElement();
    dataElement.setCode("DE_424050");
    when(context.getDataElement(dataElement.getCode())).thenReturn(dataElement);
    ProgramStage programStage = programStage(dataElement, true);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue dataValue = dataValue();
    dataValue.setDataElement("DE_424050");
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.COMPLETED).dataValues(Set.of(dataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 5 with TrackerIdentifierParams

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

the class EventDataValuesValidationHookTest method setUpIdentifiers.

private void setUpIdentifiers() {
    TrackerIdentifierParams params = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.UID).programIdScheme(TrackerIdentifier.UID).programStageIdScheme(TrackerIdentifier.UID).dataElementIdScheme(TrackerIdentifier.UID).build();
    when(context.getIdentifiers()).thenReturn(params);
}
Also used : TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams)

Aggregations

TrackerIdentifierParams (org.hisp.dhis.tracker.TrackerIdentifierParams)6 Test (org.junit.jupiter.api.Test)4 DataElement (org.hisp.dhis.dataelement.DataElement)2 ProgramStage (org.hisp.dhis.program.ProgramStage)2 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)2 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)2 TrackerTest (org.hisp.dhis.tracker.TrackerTest)2 DataValue (org.hisp.dhis.tracker.domain.DataValue)2 Event (org.hisp.dhis.tracker.domain.Event)2 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)2