Search in sources :

Example 31 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse 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)

Example 32 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse 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"));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 33 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class UserActions method addUserToUserGroup.

public void addUserToUserGroup(String userId, String userGroupId) {
    ApiResponse response = this.get(userId);
    List<String> userGroups = response.extractList("userGroups.id");
    if (userGroups != null && userGroups.contains(userGroupId)) {
        return;
    }
    JsonObject object = response.getBody();
    JsonObject userGroupAccess = new JsonObject();
    userGroupAccess.addProperty("id", userGroupId);
    object.get("userGroups").getAsJsonArray().add(userGroupAccess);
    this.update(userId, object).validate().statusCode(200);
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 34 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse 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"));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 35 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class MetadataActions method importMetadata.

public MetadataApiResponse importMetadata(JsonObject object, String... queryParams) {
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll(queryParams);
    queryParamsBuilder.addAll("atomicMode=OBJECT", "importReportMode=FULL");
    ApiResponse response = post(object, queryParamsBuilder);
    response.validate().statusCode(200);
    return new MetadataApiResponse(response);
}
Also used : MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse)

Aggregations

ApiResponse (org.hisp.dhis.dto.ApiResponse)145 Test (org.junit.jupiter.api.Test)75 JsonObject (com.google.gson.JsonObject)63 ApiTest (org.hisp.dhis.ApiTest)63 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)48 File (java.io.File)25 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)18 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)18 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)14 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)11 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)11 RestApiActions (org.hisp.dhis.actions.RestApiActions)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 JsonArray (com.google.gson.JsonArray)5 ImportSummary (org.hisp.dhis.dto.ImportSummary)5 LoginActions (org.hisp.dhis.actions.LoginActions)4 MetadataApiResponse (org.hisp.dhis.dto.MetadataApiResponse)4 ArrayList (java.util.ArrayList)3