Search in sources :

Example 1 with CwsOffice

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);
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.auth.StaffPerson) StaffAuthorityPrivilege(gov.ca.cwds.rest.api.domain.auth.StaffAuthorityPrivilege) UserAuthorization(gov.ca.cwds.rest.api.domain.auth.UserAuthorization) UserId(gov.ca.cwds.data.persistence.auth.UserId) CwsOffice(gov.ca.cwds.data.persistence.auth.CwsOffice) StaffUnitAuthority(gov.ca.cwds.rest.api.domain.auth.StaffUnitAuthority)

Example 2 with CwsOffice

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");
}
Also used : StaffAuthorityPrivilege(gov.ca.cwds.data.persistence.auth.StaffAuthorityPrivilege) gov.ca.cwds.rest.api.domain.auth(gov.ca.cwds.rest.api.domain.auth) gov.ca.cwds.data.auth(gov.ca.cwds.data.auth) gov.ca.cwds.data.persistence.auth(gov.ca.cwds.data.persistence.auth) CwsOffice(gov.ca.cwds.data.persistence.auth.CwsOffice) Date(java.util.Date) StaffUnitAuthority(gov.ca.cwds.data.persistence.auth.StaffUnitAuthority) Test(org.junit.Test)

Aggregations

CwsOffice (gov.ca.cwds.data.persistence.auth.CwsOffice)2 gov.ca.cwds.data.auth (gov.ca.cwds.data.auth)1 gov.ca.cwds.data.persistence.auth (gov.ca.cwds.data.persistence.auth)1 StaffAuthorityPrivilege (gov.ca.cwds.data.persistence.auth.StaffAuthorityPrivilege)1 StaffPerson (gov.ca.cwds.data.persistence.auth.StaffPerson)1 StaffUnitAuthority (gov.ca.cwds.data.persistence.auth.StaffUnitAuthority)1 UserId (gov.ca.cwds.data.persistence.auth.UserId)1 gov.ca.cwds.rest.api.domain.auth (gov.ca.cwds.rest.api.domain.auth)1 StaffAuthorityPrivilege (gov.ca.cwds.rest.api.domain.auth.StaffAuthorityPrivilege)1 StaffUnitAuthority (gov.ca.cwds.rest.api.domain.auth.StaffUnitAuthority)1 UserAuthorization (gov.ca.cwds.rest.api.domain.auth.UserAuthorization)1 Date (java.util.Date)1 Test (org.junit.Test)1