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