Search in sources :

Example 6 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class UserActions method grantUserCaptureAccessToOrgUnit.

public void grantUserCaptureAccessToOrgUnit(String userId, String orgUnitId) {
    JsonObject object = this.get(userId).getBodyAsJsonBuilder().addOrAppendToArray("organisationUnits", new JsonObjectBuilder().addProperty("id", orgUnitId).build()).build();
    ApiResponse response = this.update(userId, object);
    response.validate().statusCode(200).body("status", equalTo("OK"));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 7 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class UserActions method grantUserAccessToOrgUnits.

public void grantUserAccessToOrgUnits(String userId, String captureOu, String searchOu, String dataReadOu) {
    JsonObject object = this.get(userId).getBodyAsJsonBuilder().addOrAppendToArray("organisationUnits", new JsonObjectBuilder().addProperty("id", captureOu).build()).addOrAppendToArray("dataViewOrganisationUnits", new JsonObjectBuilder().addProperty("id", dataReadOu).build()).addOrAppendToArray("teiSearchOrganisationUnits", new JsonObjectBuilder().addProperty("id", searchOu).build()).build();
    ApiResponse response = this.update(userId, object);
    response.validate().statusCode(200).body("status", equalTo("OK"));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 8 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class RuleEngineTests method shouldShowErrorsBasedOnValidationStrategy.

@ParameterizedTest
@CsvSource({ "ON_COMPLETE,COMPLETED,true", "ON_COMPLETE,ACTIVE,false", "ON_UPDATE_AND_INSERT,ACTIVE,true" })
public void shouldShowErrorsBasedOnValidationStrategy(String validationStrategy, String eventStatus, boolean shouldFail) {
    String programStage = new ProgramStageActions().get("", new QueryParamsBuilder().addAll("filter=program.id:eq:" + trackerProgramId, "filter=validationStrategy:eq:" + validationStrategy)).extractString("programStages.id[0]");
    JsonObject payload = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, programStage);
    // program rule is triggered for events with date earlier than today
    new JsonObjectBuilder(payload).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].occurredAt", Instant.now().minus(1, ChronoUnit.DAYS).toString()).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].status", eventStatus);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
    if (shouldFail) {
        response.validateErrorReport();
        return;
    }
    response.validateSuccessfulImport();
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ProgramStageActions(org.hisp.dhis.actions.metadata.ProgramStageActions) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class SideEffectsTests method setupData.

private void setupData() throws Exception {
    ProgramStageActions programStageActions = new ProgramStageActions();
    JsonArray array = new FileReaderUtils().read(new File("src/test/resources/tracker/notificationTemplates.json")).get(JsonObject.class).getAsJsonArray("programNotificationTemplates");
    array.forEach(nt -> {
        String programNotificationTemplate = new RestApiActions("/programNotificationTemplates").post(nt.getAsJsonObject()).extractUid();
        JsonObject programStage = JsonObjectBuilder.jsonObject(programStageActions.get(trackerProgramStageId).getBody()).addOrAppendToArray("notificationTemplates", new JsonObjectBuilder().addProperty("id", programNotificationTemplate).build()).build();
        programStageActions.update(trackerProgramStageId, programStage).validate().statusCode(200);
        programStageActions.get(trackerProgramStageId).validate().body("notificationTemplates.id", hasItem(programNotificationTemplate));
    });
}
Also used : JsonArray(com.google.gson.JsonArray) RestApiActions(org.hisp.dhis.actions.RestApiActions) FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) ProgramStageActions(org.hisp.dhis.actions.metadata.ProgramStageActions) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File)

Example 10 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class MetadataPatchTests method before.

@BeforeAll
public void before() {
    dataElementActions = new DataElementActions();
    loginActions = new LoginActions();
    dataElementGroupActions = new RestApiActions("/dataElementGroups");
    sharingActions = new SharingActions();
    loginActions.loginAsAdmin();
    dataElementId = dataElementActions.create(dataElementActions.body("SUM", "AGGREGATE", "TEXT"));
    dataElementGroupId = dataElementGroupActions.create(new JsonObjectBuilder().addProperty("name", DataGenerator.randomString()).addArray("dataElements", new JsonObjectBuilder().addProperty("id", dataElementId).build()).build());
}
Also used : RestApiActions(org.hisp.dhis.actions.RestApiActions) SharingActions(org.hisp.dhis.actions.metadata.SharingActions) DataElementActions(org.hisp.dhis.actions.metadata.DataElementActions) LoginActions(org.hisp.dhis.actions.LoginActions) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)38 JsonObject (com.google.gson.JsonObject)29 Test (org.junit.jupiter.api.Test)18 ApiResponse (org.hisp.dhis.dto.ApiResponse)11 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)9 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ApiTest (org.hisp.dhis.ApiTest)6 File (java.io.File)5 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)5 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)5 JsonArray (com.google.gson.JsonArray)4 IdGenerator (org.hisp.dhis.actions.IdGenerator)4 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)3 EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 RestApiActions (org.hisp.dhis.actions.RestApiActions)2 MetadataActions (org.hisp.dhis.actions.metadata.MetadataActions)2 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)2