use of gov.ca.cwds.rest.api.domain.auth.StaffAuthorityPrivilege in project perry by ca-cwds.
the class UserAuthorizationService method find.
/**
* {@inheritDoc}
*
* @see CrudsService#find(Serializable)
*/
public UserAuthorization find(Serializable primaryKey) {
final String userId = ((String) primaryKey).trim();
LOGGER.info(userId);
List<UserId> userList = userIdDao.findActiveByLogonId(userId);
if (userList == null || userList.isEmpty()) {
LOGGER.warn("No user id found for {}", primaryKey);
return null;
}
final UserId user = userList.get(0);
String userIdentifier = user.getId();
String staffPersonIdentifier = user.getStaffPersonId();
boolean socialWorker = !staffAuthorityPrivilegeDao.findSocialWorkerPrivileges(userIdentifier).isEmpty();
Set<StaffAuthorityPrivilege> userAuthPrivs = getStaffAuthorityPriveleges(userIdentifier);
Set<StaffUnitAuthority> setStaffUnitAuths = getStaffUnitAuthorities(staffPersonIdentifier);
StaffPerson staffPerson = staffPersonDao.findOne(staffPersonIdentifier);
if (staffPerson == null) {
LOGGER.warn("No staff person found for {}", staffPersonIdentifier);
return null;
}
CwsOffice cwsOffice = cwsOfficeDao.findOne(staffPerson.getCwsOffice());
if (cwsOffice == null) {
LOGGER.warn("No cws office found for {}", staffPerson.getCwsOffice());
return null;
}
return new UserAuthorization(user.getLogonId(), socialWorker, false, true, userAuthPrivs, setStaffUnitAuths, cwsOffice, staffPerson);
}
Aggregations