Search in sources :

Example 11 with RoleBO

use of org.mifos.security.rolesandpermission.business.RoleBO in project head by mifos.

the class RolesAndPermissionPersistenceIntegrationTest method testGetRoleForGivenId.

@Test
public void testGetRoleForGivenId() throws Exception {
    RoleBO role = legacyRolesPermissionsDao.getRole((short) 1);
    Assert.assertEquals(RoleTestUtil.EXPECTED_ACTIVITIES_FOR_ROLE, role.getActivities().size());
}
Also used : RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) Test(org.junit.Test)

Example 12 with RoleBO

use of org.mifos.security.rolesandpermission.business.RoleBO in project head by mifos.

the class PersonAction method manage.

@TransactionDemarcate(joinToken = true)
public ActionForward manage(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    PersonActionForm actionform = (PersonActionForm) form;
    actionform.clear();
    PersonnelBO personnelInSession = (PersonnelBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    PersonnelBO personnel = this.personnelDao.findPersonnelById(personnelInSession.getPersonnelId());
    List<ValueListElement> titles = this.customerDao.retrieveTitles();
    List<ValueListElement> genders = this.customerDao.retrieveGenders();
    List<ValueListElement> maritalStatuses = this.customerDao.retrieveMaritalStatuses();
    List<ValueListElement> languages = Localization.getInstance().getLocaleForUI();
    List<RoleBO> roles = legacyRolesPermissionsDao.getRoles();
    List<PersonnelLevelEntity> personnelLevels = this.customerDao.retrievePersonnelLevels();
    for (PersonnelLevelEntity personnelLevelEntity : personnelLevels) {
        String messageTextLookup = ApplicationContextProvider.getBean(MessageLookup.class).lookup(personnelLevelEntity.getLookUpValue().getPropertiesKey());
        personnelLevelEntity.setName(messageTextLookup);
    }
    SessionUtils.setCollectionAttribute(PersonnelConstants.TITLE_LIST, titles, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.PERSONNEL_LEVEL_LIST, personnelLevels, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.GENDER_LIST, genders, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.MARITAL_STATUS_LIST, maritalStatuses, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.LANGUAGE_LIST, languages, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.ROLES_LIST, roles, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.ROLEMASTERLIST, roles, request);
    List<CustomFieldDefinitionEntity> customFieldDefs = new ArrayList<CustomFieldDefinitionEntity>();
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, customFieldDefs, request);
    UserContext userContext = getUserContext(request);
    List<PersonnelStatusEntity> statuses = legacyMasterDao.findMasterDataEntitiesWithLocale(PersonnelStatusEntity.class);
    for (PersonnelStatusEntity personnelStatusEntity : statuses) {
        String messageTextLookup = ApplicationContextProvider.getBean(MessageLookup.class).lookup(personnelStatusEntity.getLookUpValue().getPropertiesKey());
        personnelStatusEntity.setName(messageTextLookup);
    }
    SessionUtils.setCollectionAttribute(PersonnelConstants.STATUS_LIST, statuses, request);
    OfficeBO loggedInOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    List<OfficeDetailsDto> officeHierarchy = new OfficePersistence().getChildOffices(loggedInOffice.getSearchId());
    SessionUtils.setCollectionAttribute(PersonnelConstants.OFFICE_LIST, officeHierarchy, request);
    actionform.setPersonnelId(personnel.getPersonnelId().toString());
    if (personnel.getOffice() != null) {
        actionform.setOfficeId(personnel.getOffice().getOfficeId().toString());
    }
    if (personnel.getTitle() != null) {
        actionform.setTitle(personnel.getTitle().toString());
    }
    if (personnel.getLevel() != null) {
        actionform.setLevel(personnel.getLevelEnum().getValue().toString());
    }
    if (personnel.getStatus() != null) {
        actionform.setStatus(personnel.getStatus().getId().toString());
    }
    actionform.setLoginName(personnel.getUserName());
    actionform.setGlobalPersonnelNum(personnel.getGlobalPersonnelNum());
    actionform.setCustomFields(new ArrayList<CustomFieldDto>());
    if (personnel.getPersonnelDetails() != null) {
        PersonnelDetailsEntity personnelDetails = personnel.getPersonnelDetails();
        actionform.setFirstName(personnelDetails.getName().getFirstName());
        actionform.setMiddleName(personnelDetails.getName().getMiddleName());
        actionform.setSecondLastName(personnelDetails.getName().getSecondLastName());
        actionform.setLastName(personnelDetails.getName().getLastName());
        if (personnelDetails.getGender() != null) {
            actionform.setGender(personnelDetails.getGender().toString());
        }
        if (personnelDetails.getMaritalStatus() != null) {
            actionform.setMaritalStatus(personnelDetails.getMaritalStatus().toString());
        }
        actionform.setAddress(personnelDetails.getAddress());
        if (personnelDetails.getDateOfJoiningMFI() != null) {
            actionform.setDateOfJoiningMFI(DateUtils.makeDateAsSentFromBrowser(personnelDetails.getDateOfJoiningMFI()));
        }
        if (personnelDetails.getDob() != null) {
            actionform.setDob(DateUtils.makeDateAsSentFromBrowser(personnelDetails.getDob()));
        }
    }
    actionform.setEmailId(personnel.getEmailId());
    if (personnel.getPreferredLocale() != null) {
        actionform.setPreferredLocale(personnel.getPreferredLocale());
    }
    if (personnel.getPasswordExpirationDate() != null) {
        actionform.setPasswordExpirationDate(DateUtils.makeDateAsSentFromBrowser(personnel.getPasswordExpirationDate()));
    }
    List<RoleBO> selectList = new ArrayList<RoleBO>();
    for (PersonnelRoleEntity personnelRole : personnel.getPersonnelRoles()) {
        selectList.add(personnelRole.getRole());
    }
    SessionUtils.setCollectionAttribute(PersonnelConstants.PERSONNEL_ROLES_LIST, selectList, request);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, personnel, request);
    return mapping.findForward(ActionForwards.manage_success.toString());
}
Also used : PersonnelDetailsEntity(org.mifos.customers.personnel.business.PersonnelDetailsEntity) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) OfficeDetailsDto(org.mifos.dto.domain.OfficeDetailsDto) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) PersonnelStatusEntity(org.mifos.customers.personnel.business.PersonnelStatusEntity) PersonActionForm(org.mifos.customers.personnel.struts.actionforms.PersonActionForm) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelRoleEntity(org.mifos.customers.personnel.business.PersonnelRoleEntity) MessageLookup(org.mifos.application.master.MessageLookup) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) ValueListElement(org.mifos.dto.domain.ValueListElement) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 13 with RoleBO

use of org.mifos.security.rolesandpermission.business.RoleBO in project head by mifos.

the class PersonAction method translateFormToCreatePersonnelInformationDto.

@SuppressWarnings("unchecked")
private CreateOrUpdatePersonnelInformation translateFormToCreatePersonnelInformationDto(HttpServletRequest request, PersonActionForm personActionForm) throws PageExpiredException, InvalidDateException {
    UserContext userContext = getUserContext(request);
    PersonnelLevel level = PersonnelLevel.fromInt(getShortValue(personActionForm.getLevel()));
    PersonnelStatus personnelStatus = PersonnelStatus.ACTIVE;
    if (StringUtils.isNotBlank(personActionForm.getStatus())) {
        personnelStatus = PersonnelStatus.getPersonnelStatus(getShortValue(personActionForm.getStatus()));
    }
    OfficeBO office = (OfficeBO) SessionUtils.getAttribute(PersonnelConstants.OFFICE, request);
    if (office == null) {
        Short officeId = getShortValue(personActionForm.getOfficeId());
        office = this.officeDao.findOfficeById(officeId);
    }
    Integer title = getIntegerValue(personActionForm.getTitle());
    Short preferredLocale = Localization.getInstance().getConfiguredLocaleId();
    preferredLocale = getPerefferedLocale(personActionForm, userContext);
    Date dob = null;
    if (personActionForm.getDob() != null && !personActionForm.getDob().equals("")) {
        dob = DateUtils.getDate(personActionForm.getDob());
    }
    Date dateOfJoiningMFI = null;
    if (personActionForm.getDateOfJoiningMFI() != null && !personActionForm.getDateOfJoiningMFI().equals("")) {
        dateOfJoiningMFI = DateUtils.getDateAsSentFromBrowser(personActionForm.getDateOfJoiningMFI());
    }
    Date passwordExpirationDate = null;
    if (personActionForm.getPasswordExpirationDate() != null && !personActionForm.getPasswordExpirationDate().equals("")) {
        passwordExpirationDate = DateUtils.getDate(personActionForm.getPasswordExpirationDate());
    }
    List<RoleBO> roles = new ArrayList<RoleBO>();
    boolean addFlag = false;
    List<RoleBO> selectList = new ArrayList<RoleBO>();
    List<RoleBO> masterList = (List<RoleBO>) SessionUtils.getAttribute(PersonnelConstants.ROLEMASTERLIST, request);
    if (personActionForm.getPersonnelRoles() != null) {
        for (RoleBO role : masterList) {
            for (String roleId : personActionForm.getPersonnelRoles()) {
                if (roleId != null && role.getId().intValue() == Integer.valueOf(roleId).intValue()) {
                    selectList.add(role);
                    addFlag = true;
                }
            }
        }
    }
    if (addFlag) {
        roles = selectList;
    }
    List<ListElement> roleList = new ArrayList<ListElement>();
    for (RoleBO element : roles) {
        ListElement listElement = new ListElement(new Integer(element.getId()), element.getName());
        roleList.add(listElement);
    }
    Address address = personActionForm.getAddress();
    AddressDto addressDto = new AddressDto(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
    Long id = null;
    if (StringUtils.isNotBlank(personActionForm.getPersonnelId())) {
        id = Long.valueOf(personActionForm.getPersonnelId());
    }
    CreateOrUpdatePersonnelInformation perosonnelInfo = new CreateOrUpdatePersonnelInformation(id, level.getValue(), office.getOfficeId(), title, preferredLocale, personActionForm.getUserPassword(), personActionForm.getLoginName(), personActionForm.getEmailId(), roleList, personActionForm.getCustomFields(), personActionForm.getFirstName(), personActionForm.getMiddleName(), personActionForm.getLastName(), personActionForm.getSecondLastName(), personActionForm.getGovernmentIdNumber(), new DateTime(dob), getIntegerValue(personActionForm.getMaritalStatus()), getIntegerValue(personActionForm.getGender()), new DateTime(dateOfJoiningMFI), new DateTimeService().getCurrentDateTime(), addressDto, personnelStatus.getValue(), new DateTime(passwordExpirationDate));
    return perosonnelInfo;
}
Also used : Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) Date(java.util.Date) DateTime(org.joda.time.DateTime) PersonnelStatus(org.mifos.customers.personnel.util.helpers.PersonnelStatus) CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation) OfficeBO(org.mifos.customers.office.business.OfficeBO) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) List(java.util.List) ArrayList(java.util.ArrayList) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) DateTimeService(org.mifos.framework.util.DateTimeService) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 14 with RoleBO

use of org.mifos.security.rolesandpermission.business.RoleBO in project head by mifos.

the class PersonAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    PersonActionForm personActionForm = (PersonActionForm) form;
    Short officeId = getShortValue(personActionForm.getOfficeId());
    OfficeBO office = this.officeDao.findOfficeById(officeId);
    SessionUtils.setAttribute(PersonnelConstants.OFFICE, office, request);
    personActionForm.clear();
    //Shahid - keeping the previous session objects for the sake of existing tests, once fully converted to spring
    //then we can get rid of the session objects made redundant by the dto
    DefinePersonnelDto definePersonnelDto = this.personnelServiceFacade.retrieveInfoForNewUserDefinition(officeId);
    SessionUtils.setAttribute("definePersonnelDto", definePersonnelDto, request);
    List<ValueListElement> titles = this.customerDao.retrieveTitles();
    List<ValueListElement> genders = this.customerDao.retrieveGenders();
    List<ValueListElement> maritalStatuses = this.customerDao.retrieveMaritalStatuses();
    List<ValueListElement> languages = Localization.getInstance().getLocaleForUI();
    List<RoleBO> roles = legacyRolesPermissionsDao.getRoles();
    List<PersonnelLevelEntity> personnelLevels = this.customerDao.retrievePersonnelLevels();
    SessionUtils.setCollectionAttribute(PersonnelConstants.TITLE_LIST, titles, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.PERSONNEL_LEVEL_LIST, personnelLevels, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.GENDER_LIST, genders, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.MARITAL_STATUS_LIST, maritalStatuses, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.LANGUAGE_LIST, languages, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.ROLES_LIST, roles, request);
    SessionUtils.setCollectionAttribute(PersonnelConstants.ROLEMASTERLIST, roles, request);
    List<CustomFieldDefinitionEntity> customFieldDefs1 = new ArrayList<CustomFieldDefinitionEntity>();
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, customFieldDefs1, request);
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    personActionForm.setCustomFields(customFields);
    if (office.getOfficeLevel() != OfficeLevel.BRANCHOFFICE) {
        for (MasterDataEntity level : personnelLevels) {
            if (level.getId().equals(PersonnelLevel.LOAN_OFFICER.getValue())) {
                personnelLevels.remove(level);
                break;
            }
        }
    }
    personActionForm.setCustomFields(new ArrayList<CustomFieldDto>());
    personActionForm.setDateOfJoiningMFI(DateUtils.makeDateAsSentFromBrowser());
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) DefinePersonnelDto(org.mifos.dto.screen.DefinePersonnelDto) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) PersonActionForm(org.mifos.customers.personnel.struts.actionforms.PersonActionForm) OfficeBO(org.mifos.customers.office.business.OfficeBO) ValueListElement(org.mifos.dto.domain.ValueListElement) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 15 with RoleBO

use of org.mifos.security.rolesandpermission.business.RoleBO in project head by mifos.

the class PersonAction method preview.

@SuppressWarnings("unchecked")
@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    PersonActionForm personActionForm = (PersonActionForm) form;
    UserContext userContext = getUserContext(request);
    personActionForm.setDateOfJoiningBranch(DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    PersonActionForm personActionForm1 = (PersonActionForm) form;
    boolean addFlag = false;
    List<RoleBO> selectList = new ArrayList<RoleBO>();
    if (personActionForm1.getPersonnelRoles() != null) {
        List<RoleBO> masterList = (List<RoleBO>) SessionUtils.getAttribute(PersonnelConstants.ROLEMASTERLIST, request);
        for (RoleBO role : masterList) {
            for (String roleId : personActionForm1.getPersonnelRoles()) {
                if (roleId != null && role.getId().intValue() == Integer.valueOf(roleId).intValue()) {
                    selectList.add(role);
                    addFlag = true;
                }
            }
        }
    }
    if (addFlag) {
        SessionUtils.setCollectionAttribute(PersonnelConstants.PERSONNEL_ROLES_LIST, selectList, request);
    } else {
        SessionUtils.setAttribute(PersonnelConstants.PERSONNEL_ROLES_LIST, null, request);
    }
    return createGroupQuestionnaire.fetchAppliedQuestions(mapping, personActionForm, request, ActionForwards.preview_success);
}
Also used : PersonActionForm(org.mifos.customers.personnel.struts.actionforms.PersonActionForm) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)30 ArrayList (java.util.ArrayList)13 PersistenceException (org.mifos.framework.exceptions.PersistenceException)11 MifosRuntimeException (org.mifos.core.MifosRuntimeException)10 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)9 UserContext (org.mifos.security.util.UserContext)8 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)7 MifosUser (org.mifos.security.MifosUser)7 OfficeBO (org.mifos.customers.office.business.OfficeBO)6 ValueListElement (org.mifos.dto.domain.ValueListElement)6 ServiceException (org.mifos.framework.exceptions.ServiceException)6 List (java.util.List)5 Test (org.junit.Test)5 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 PersonnelLevelEntity (org.mifos.customers.personnel.business.PersonnelLevelEntity)5 PersonActionForm (org.mifos.customers.personnel.struts.actionforms.PersonActionForm)5 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)5 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)4 ListElement (org.mifos.dto.screen.ListElement)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4