Search in sources :

Example 1 with JsonObjectBuilder

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

the class ProgramActions method createEventProgram.

public ApiResponse createEventProgram(String... orgUnitsIds) {
    JsonObject body = new JsonObjectBuilder(buildProgram("WITHOUT_REGISTRATION", null, orgUnitsIds)).build();
    ApiResponse response = post(body);
    createProgramStage(response.extractUid(), "DEFAULT STAGE");
    return response;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 2 with JsonObjectBuilder

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

the class ProgramActions method addDataElement.

public ApiResponse addDataElement(String programStageId, String dataElementId, boolean isMandatory) {
    JsonObject object = programStageActions.get(programStageId, new QueryParamsBuilder().add("fields=*")).getBody();
    JsonObjectBuilder.jsonObject(object).addOrAppendToArray("programStageDataElements", new JsonObjectBuilder().addProperty("compulsory", String.valueOf(isMandatory)).addObject("dataElement", new JsonObjectBuilder().addProperty("id", dataElementId)).build());
    return programStageActions.update(programStageId, object);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder)

Example 3 with JsonObjectBuilder

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

the class ProgramActions method createProgramStage.

/**
 * Creates a program stage and links it to the program.
 *
 * @param programId
 * @param programStageName
 * @return program stage id
 */
public String createProgramStage(String programId, String programStageName) {
    ApiResponse response = programStageActions.post(new JsonObjectBuilder().addProperty("name", programStageName).addObject("program", new JsonObjectBuilder().addProperty("id", programId)).addProperty("publicAccess", "rwrw----").build());
    response.validate().statusCode(Matchers.is(Matchers.oneOf(201, 200)));
    return response.extractUid();
}
Also used : JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 4 with JsonObjectBuilder

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

the class TrackedEntityTypeActions method addAttribute.

public void addAttribute(String tet, String attribute, boolean mandatory) {
    JsonObject object = this.get(tet).getBodyAsJsonBuilder().addOrAppendToArray("trackedEntityTypeAttributes", new JsonObjectBuilder().addProperty("mandatory", String.valueOf(mandatory)).addObject("trackedEntityAttribute", new JsonObjectBuilder().addProperty("id", attribute)).build()).build();
    this.update(tet, object).validateStatus(200);
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder)

Example 5 with JsonObjectBuilder

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

the class UserActions method grantUserSearchAccessToOrgUnit.

public void grantUserSearchAccessToOrgUnit(String userId, String orgUnitId) {
    JsonObject object = this.get(userId).getBodyAsJsonBuilder().addOrAppendToArray("teiSearchOrganisationUnits", 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)

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