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