Search in sources :

Example 51 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder 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 52 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder 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 53 with QueryParamsBuilder

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

the class MessageConversationsActions method waitForNotification.

public ApiResponse waitForNotification(int expectedCount) {
    boolean isReceived = false;
    int attemptCount = 20;
    ApiResponse response = null;
    while (!isReceived && attemptCount > 0) {
        response = this.get("", new QueryParamsBuilder().add("fields=subject"));
        isReceived = (response.extractList("messageConversations").size() == expectedCount);
        attemptCount--;
    }
    return response;
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 54 with QueryParamsBuilder

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

the class EventValidationTests method setupData.

private void setupData() {
    eventProgramStageId = programActions.programStageActions.get("", new QueryParamsBuilder().add("filter=program.id:eq:" + eventProgramId)).extractString("programStages.id[0]");
    assertNotNull(eventProgramStageId, "Failed to find a program stage");
    trackerProgramStageId = programActions.programStageActions.get("", new QueryParamsBuilder().addAll("filter=program.id:eq:" + trackerProgramId, "filter=repeatable:eq:true")).extractString("programStages.id[0]");
    ouIdWithoutAccess = new OrgUnitActions().createOrgUnit();
    new UserActions().grantCurrentUserAccessToOrgUnit(ouIdWithoutAccess);
    enrollment = trackerActions.postAndGetJobReport(new TeiDataBuilder().buildWithEnrollment(OU_ID, trackerProgramId)).validateSuccessfulImport().extractImportedEnrollments().get(0);
}
Also used : OrgUnitActions(org.hisp.dhis.actions.metadata.OrgUnitActions) TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) UserActions(org.hisp.dhis.actions.UserActions)

Example 55 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder 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

QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)90 JsonObject (com.google.gson.JsonObject)54 Test (org.junit.jupiter.api.Test)51 ApiResponse (org.hisp.dhis.dto.ApiResponse)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 ApiTest (org.hisp.dhis.ApiTest)27 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)21 File (java.io.File)20 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)20 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)14 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)8 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)6 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)5 ProgramActions (org.hisp.dhis.actions.metadata.ProgramActions)4 JsonArray (com.google.gson.JsonArray)3 HashMap (java.util.HashMap)3 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 ImportSummary (org.hisp.dhis.dto.ImportSummary)3