Search in sources :

Example 11 with PersonnelBusinessService

use of org.mifos.customers.personnel.business.service.PersonnelBusinessService in project head by mifos.

the class PersonnelServiceFacadeWebTier method createPersonnelInformation.

@Override
public UserDetailDto createPersonnelInformation(CreateOrUpdatePersonnelInformation personnel) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    try {
        PersonnelBusinessService personnelBusinessService = new PersonnelBusinessService();
        List<RoleBO> roles = new ArrayList<RoleBO>();
        for (ListElement element : personnel.getRoles()) {
            RoleBO role = personnelBusinessService.getRoleById(new Short(element.getId().shortValue()));
            roles.add(role);
        }
        AddressDto addressDto = personnel.getAddress();
        Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
        OfficeBO office = officeDao.findOfficeById(personnel.getOfficeId());
        Name name = new Name(personnel.getFirstName(), personnel.getMiddleName(), personnel.getSecondLastName(), personnel.getLastName());
        verifyFields(personnel.getUserName(), personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), name.getDisplayName());
        PersonnelBO newPersonnel = new PersonnelBO(PersonnelLevel.fromInt(personnel.getPersonnelLevelId().intValue()), office, personnel.getTitle(), personnel.getPreferredLocale(), personnel.getPassword(), personnel.getUserName(), personnel.getEmailId(), roles, personnel.getCustomFields(), name, personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), personnel.getMaritalStatus(), personnel.getGender(), personnel.getDateOfJoiningMFI().toDate(), personnel.getDateOfJoiningBranch().toDate(), address, Integer.valueOf(user.getUserId()).shortValue(), personnel.getPasswordExpirationDate().toDate(), null);
        transactionHelper.startTransaction();
        this.personnelDao.save(newPersonnel);
        transactionHelper.flushSession();
        newPersonnel.generateGlobalPersonnelNum();
        this.personnelDao.save(newPersonnel);
        transactionHelper.commitTransaction();
        return newPersonnel.toDto();
    } catch (PersistenceException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ValidationException e) {
        transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e.getValues(), e);
    } catch (ServiceException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ValidationException(org.mifos.framework.exceptions.ValidationException) Address(org.mifos.framework.business.util.Address) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) AddressDto(org.mifos.dto.domain.AddressDto) Name(org.mifos.framework.business.util.Name) BusinessRuleException(org.mifos.service.BusinessRuleException) ServiceException(org.mifos.framework.exceptions.ServiceException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with PersonnelBusinessService

use of org.mifos.customers.personnel.business.service.PersonnelBusinessService in project head by mifos.

the class RolesPermissionsAction method getLoggedUsers.

private List<String> getLoggedUsers(HttpServletRequest request) {
    List<String> loggedUsers = new ArrayList<String>();
    ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request, ShutdownManager.class.getName());
    Collection<HttpSession> sessions = shutdownManager.getActiveSessions();
    PersonnelBusinessService personnelBusinessService = new PersonnelBusinessService();
    for (HttpSession session : sessions) {
        UserContext userContextFromSession = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
        if (userContextFromSession == null) {
            continue;
        }
        PersonnelBO personnel;
        try {
            personnel = personnelBusinessService.getPersonnel(userContextFromSession.getId());
        } catch (ServiceException e) {
            continue;
        }
        loggedUsers.add(personnel.getUserName());
    }
    return loggedUsers;
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) ShutdownManager(org.mifos.application.admin.system.ShutdownManager)

Aggregations

PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)12 ArrayList (java.util.ArrayList)6 ServiceException (org.mifos.framework.exceptions.ServiceException)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 Before (org.junit.Before)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 ActivityContext (org.mifos.security.util.ActivityContext)3 UserContext (org.mifos.security.util.UserContext)3 HttpSession (javax.servlet.http.HttpSession)2 Test (org.junit.Test)2 ShutdownManager (org.mifos.application.admin.system.ShutdownManager)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 OfficeBO (org.mifos.customers.office.business.OfficeBO)2 PersonnelLevel (org.mifos.customers.personnel.util.helpers.PersonnelLevel)2 AddressDto (org.mifos.dto.domain.AddressDto)2 Address (org.mifos.framework.business.util.Address)2 AuditLog (org.mifos.framework.components.audit.business.AuditLog)2 AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)2 FieldConfig (org.mifos.framework.components.fieldConfiguration.util.helpers.FieldConfig)2 ValidationException (org.mifos.framework.exceptions.ValidationException)2