Search in sources :

Example 21 with JsonObjectBuilder

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

the class UserActions method grantUserDataViewAccessToOrgUnit.

public void grantUserDataViewAccessToOrgUnit(String userId, String orgUnitId) {
    JsonObject object = this.get(userId).getBodyAsJsonBuilder().addOrAppendToArray("dataViewOrganisationUnits", 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 22 with JsonObjectBuilder

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

the class SharingActions method setupSharingForUsers.

public void setupSharingForUsers(String type, String id, String... userIds) {
    JsonObject jsonObject = this.get(new QueryParamsBuilder().add("type=" + type).add("id=" + id).build()).getBody();
    for (String userId : userIds) {
        JsonObjectBuilder.jsonObject(jsonObject.getAsJsonObject("object")).addOrAppendToArray("userAccesses", new JsonObjectBuilder().addProperty("id", userId).addProperty("access", "rw------").build());
    }
    this.post(jsonObject, new QueryParamsBuilder().add("type=" + type).add("id=" + id)).validate().statusCode(200);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder)

Example 23 with JsonObjectBuilder

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

the class ProgramActions method addAttribute.

public ApiResponse addAttribute(String programId, String teiAttributeId, boolean isMandatory) {
    JsonObject object = this.get(programId, new QueryParamsBuilder().add("fields=*")).getBodyAsJsonBuilder().addOrAppendToArray("programTrackedEntityAttributes", new JsonObjectBuilder().addProperty("mandatory", String.valueOf(isMandatory)).addObject("trackedEntityAttribute", new JsonObjectBuilder().addProperty("id", teiAttributeId)).build()).build();
    JsonObjectBuilder.jsonObject(object);
    return this.update(programId, object).validateStatus(200);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder)

Example 24 with JsonObjectBuilder

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

the class EnrollmentAttributeTests method shouldUpdateAttributeValue.

@Test
public void shouldUpdateAttributeValue() throws Exception {
    String tei = importTei();
    JsonObject payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(tei).addAttribute(numberAttributeId, "5").array(programId, Constants.ORG_UNIT_IDS[1]);
    trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
    payload = new JsonObjectBuilder(payload).addPropertyByJsonPath("enrollments[0].attributes[0].value", "9").build();
    trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
    trackerActions.getTrackedEntity(tei + "?program=" + programId).validateStatus(200).validate().statusCode(200).body("attributes", hasSize(greaterThanOrEqualTo(1))).body("attributes.attribute", hasItem(numberAttributeId)).body("attributes.value", hasItem("9"));
}
Also used : JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) IdGenerator(org.hisp.dhis.actions.IdGenerator) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 25 with JsonObjectBuilder

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

the class EventsTests method shouldImportToRepeatableStage.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
public void shouldImportToRepeatableStage(Boolean repeatableStage) throws Exception {
    // arrange
    String program = Constants.TRACKER_PROGRAM_ID;
    String programStage = new ProgramStageActions().get("", new QueryParamsBuilder().addAll("filter=program.id:eq:" + program, "filter=repeatable:eq:" + repeatableStage)).extractString("programStages.id[0]");
    TrackerApiResponse response = importTeiWithEnrollment(program);
    String teiId = response.extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    JsonObject event = new EventDataBuilder().setEnrollment(enrollmentId).setTei(teiId).array(Constants.ORG_UNIT_IDS[0], program, programStage).getAsJsonArray("events").get(0).getAsJsonObject();
    JsonObject payload = new JsonObjectBuilder().addArray("events", event, event).build();
    // act
    response = trackerActions.postAndGetJobReport(payload);
    // assert
    if (repeatableStage) {
        response.validateSuccessfulImport().validate().body("stats.created", equalTo(2));
    } else {
        response.validateErrorReport().body("errorCode", hasItem("E1039"));
    }
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) 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) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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