Search in sources :

Example 6 with OrgUnit

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

the class TrackedEntityInstanceAclReadTests method setupUser.

/**
 * Takes a User object and retrieves information about the users from the
 * api. Updates the password of the user to allow access.
 *
 * @param user to setup
 */
private void setupUser(User user) {
    userActions.updateUserPassword(user.getUid(), user.getPassword());
    new LoginActions().loginAsUser(user.getUsername(), user.getPassword());
    // Get User information from /me
    ApiResponse apiResponse = new RestApiActions("/me").get();
    String asString = apiResponse.getAsString();
    Me me = apiResponse.as(Me.class);
    // Add userGroups
    user.setGroups(me.getUserGroups().stream().map(UserGroup::getId).collect(Collectors.toList()));
    // Add search-scope ous
    user.setSearchScope(me.getTeiSearchOrganisationUnits().stream().map(OrgUnit::getId).collect(Collectors.toList()));
    // Add capture-scope ous
    user.setCaptureScope(me.getOrganisationUnits().stream().map(OrgUnit::getId).collect(Collectors.toList()));
    // Add hasAllAuthority if user has ALL authority
    user.setAllAuthority(me.getAuthorities().contains("ALL"));
    // Setup map to decide what data can and cannot be read.
    setupAccessMap(user);
}
Also used : OrgUnit(org.hisp.dhis.dto.OrgUnit) RestApiActions(org.hisp.dhis.actions.RestApiActions) Me(org.hisp.dhis.dto.Me) LoginActions(org.hisp.dhis.actions.LoginActions) ApiResponse(org.hisp.dhis.dto.ApiResponse) UserGroup(org.hisp.dhis.dto.UserGroup)

Example 7 with OrgUnit

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

the class OrgUnitActions method createOrgUnitWithParent.

public String createOrgUnitWithParent(String parentId, int level) {
    OrgUnit orgUnit = generateDummy();
    orgUnit.setLevel(level);
    orgUnit.setParent(parentId);
    return create(orgUnit);
}
Also used : OrgUnit(org.hisp.dhis.dto.OrgUnit)

Example 8 with OrgUnit

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

the class OrgUnitsTest method shouldUpdate.

@Test
public void shouldUpdate() {
    OrgUnit orgUnit = orgUnitActions.generateDummy();
    // create
    ApiResponse response = orgUnitActions.post(orgUnit);
    String uid = response.extractUid();
    assertNotNull(uid, "Org unit uid was not returned");
    response = orgUnitActions.get(uid);
    String lastUpdatedDate = response.extractString("lastUpdated");
    // update
    orgUnit.setName(orgUnit.getName() + " updated");
    orgUnit.setShortName(orgUnit.getShortName() + " updated");
    orgUnit.setOpeningDate("2017-09-10T00:00:00.000");
    response = orgUnitActions.update(uid, orgUnit);
    assertEquals(200, response.statusCode(), "Org unit wasn't updated");
    // validate
    response = orgUnitActions.get(uid);
    response.validate().statusCode(200).body("shortName", equalTo(orgUnit.getShortName())).body("name", equalTo(orgUnit.getName())).body("openingDate", equalTo(orgUnit.getOpeningDate())).body("lastUpdated", not(equalTo(lastUpdatedDate)));
}
Also used : OrgUnit(org.hisp.dhis.dto.OrgUnit) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Aggregations

OrgUnit (org.hisp.dhis.dto.OrgUnit)8 ApiResponse (org.hisp.dhis.dto.ApiResponse)3 ApiTest (org.hisp.dhis.ApiTest)2 Test (org.junit.jupiter.api.Test)2 LoginActions (org.hisp.dhis.actions.LoginActions)1 RestApiActions (org.hisp.dhis.actions.RestApiActions)1 Me (org.hisp.dhis.dto.Me)1 UserGroup (org.hisp.dhis.dto.UserGroup)1