use of gov.ca.cwds.data.persistence.auth.CwsOffice 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);
}
use of gov.ca.cwds.data.persistence.auth.CwsOffice in project perry by ca-cwds.
the class UserAuthorizationServiceTest method test.
@Test
public void test() {
UserIdDao userIdDao = Mockito.mock(UserIdDao.class);
StaffAuthorityPrivilegeDao staffAuthorityPrivilegeDao = Mockito.mock(StaffAuthorityPrivilegeDao.class);
StaffUnitAuthorityDao staffUnitAuthorityDao = Mockito.mock(StaffUnitAuthorityDao.class);
CwsOfficeDao cwsOfficeDao = Mockito.mock(CwsOfficeDao.class);
AssignmentUnitDao assignmentUnitDao = Mockito.mock(AssignmentUnitDao.class);
StaffPersonDao staffPersonDao = Mockito.mock(StaffPersonDao.class);
UserAuthorizationService userAuthorizationService = new UserAuthorizationService();
userAuthorizationService.setAssignmentUnitDao(assignmentUnitDao);
userAuthorizationService.setCwsOfficeDao(cwsOfficeDao);
userAuthorizationService.setStaffAuthorityPrivilegeDao(staffAuthorityPrivilegeDao);
userAuthorizationService.setUserIdDao(userIdDao);
userAuthorizationService.setStaffUnitAuthorityDao(staffUnitAuthorityDao);
userAuthorizationService.setStaffPersonDao(staffPersonDao);
String racfid = "racfid";
UserId userId = new UserId(null, null, null, STAFF_ID, ID, LOGON_ID, null);
Mockito.when(userIdDao.findActiveByLogonId(racfid)).thenReturn(Collections.singletonList(userId));
Mockito.when(staffAuthorityPrivilegeDao.findSocialWorkerPrivileges(userId.getId())).thenReturn(Collections.emptyList());
StaffPerson staffPerson = new StaffPerson();
staffPerson.setId(STAFF_ID);
staffPerson.setCwsOffice(CWSOFFICE_ID);
Mockito.when(staffPersonDao.findOne(STAFF_ID)).thenReturn(staffPerson);
StaffAuthorityPrivilege staffAuthorityPrivilege = new StaffAuthorityPrivilege(COUNTY_CODE, null, null, null, null, "L", (short) 1, null, null);
Mockito.when(staffAuthorityPrivilegeDao.findByUserId(userId.getId())).thenReturn(Collections.singletonList(staffAuthorityPrivilege));
StaffUnitAuthority staffUnitAuthority = new StaffUnitAuthority("S", null, new Date(), UNIT, STAFF_ID, new Date(), null);
Mockito.when(staffUnitAuthorityDao.findByStaffPersonId(STAFF_ID)).thenReturn(Collections.singletonList(staffUnitAuthority));
AssignmentUnit assignmentUnit = new AssignmentUnit(null, 0, null, COUNTY_CODE, new Date(), CWSOFFICE_ID, null, new Date(), null);
Mockito.when(assignmentUnitDao.findOne(UNIT)).thenReturn(assignmentUnit);
CwsOffice cwsOffice = new CwsOffice(CWSOFFICE_ID, null, null, COUNTY_CWS_CODE, null, null, null, null, null, null, null, null, null, null, null, null, null, COUNTY_CODE, null, null, null);
Mockito.when(cwsOfficeDao.findOne(CWSOFFICE_ID)).thenReturn(cwsOffice);
UserAuthorization userAuthorization = userAuthorizationService.find(racfid);
assert userAuthorization.getUserId().equals(LOGON_ID);
assert userAuthorization.getCwsOffice().equals(cwsOffice);
assert userAuthorization.getStaffPerson().equals(staffPerson);
assert !userAuthorization.getSocialWorker();
assert userAuthorization.getAuthorityPrivilege().size() == 1;
gov.ca.cwds.rest.api.domain.auth.StaffAuthorityPrivilege authorityPrivilege = userAuthorization.getAuthorityPrivilege().iterator().next();
assert authorityPrivilege.getAuthPrivilegeCode().equals("L");
assert authorityPrivilege.getAuthPrivilegeType().equals("1");
assert authorityPrivilege.getCounty().equals("Humboldt");
assert authorityPrivilege.getCountyCode().equals(COUNTY_CODE);
assert authorityPrivilege.getAuthPrivilegeCodeDesc().equals("Staff Person Level of Auth Type");
}
Aggregations