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"));
}
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);
}
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);
}
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"));
}
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"));
}
}
Aggregations