Search in sources :

Example 16 with RoleBO

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

the class PersonAction method get.

@TransactionDemarcate(saveToken = true)
public ActionForward get(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    PersonActionForm personActionForm = (PersonActionForm) form;
    String globalId = request.getParameter("globalPersonnelNum");
    if (globalId == null) {
        globalId = personActionForm.getGlobalPersonnelNum();
    }
    PersonnelInformationDto personnelInformationDto = this.personnelServiceFacade.getPersonnelInformationDto(null, globalId);
    SessionUtils.removeThenSetAttribute("personnelInformationDto", personnelInformationDto, request);
    // John W - for other actions downstream (like edit) business_key set (until all actions refactored)
    PersonnelBO personnelBO = this.personnelDao.findPersonnelById(personnelInformationDto.getPersonnelId());
    SessionUtils.removeThenSetAttribute(Constants.BUSINESS_KEY, personnelBO, request);
    String url = String.format("PersonAction.do?globalPersonnelNum=%s", personnelBO.getGlobalPersonnelNum());
    SessionUtils.removeThenSetAttribute("currentPageUrl", url, 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();
    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> customFieldDefs1 = new ArrayList<CustomFieldDefinitionEntity>();
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, customFieldDefs1, request);
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    personActionForm.setCustomFields(customFields);
    return mapping.findForward(ActionForwards.get_success.toString());
}
Also used : PersonnelInformationDto(org.mifos.dto.screen.PersonnelInformationDto) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) PersonActionForm(org.mifos.customers.personnel.struts.actionforms.PersonActionForm) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MessageLookup(org.mifos.application.master.MessageLookup) ValueListElement(org.mifos.dto.domain.ValueListElement) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 17 with RoleBO

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

the class PersonAction method previewManage.

@SuppressWarnings("unchecked")
@TransactionDemarcate(joinToken = true)
public ActionForward previewManage(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    PersonActionForm actionForm = (PersonActionForm) form;
    boolean addFlag = false;
    List<RoleBO> selectList = new ArrayList<RoleBO>();
    if (actionForm.getPersonnelRoles() != null) {
        List<RoleBO> masterList = (List<RoleBO>) SessionUtils.getAttribute(PersonnelConstants.ROLEMASTERLIST, request);
        for (RoleBO role : masterList) {
            for (String roleId : actionForm.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 mapping.findForward(ActionForwards.previewManage_success.toString());
}
Also used : PersonActionForm(org.mifos.customers.personnel.struts.actionforms.PersonActionForm) 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)

Example 18 with RoleBO

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

the class BirtReportsUploadActionStrutsTest method setupReportEditPermission.

private void setupReportEditPermission(boolean allowReportEdit) throws Exception {
    UserContext userContext = TestUtils.makeUser();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
    request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, ac);
    RoleBO role = legacyRolesPermissionsDao.getRole(userContext.getRoles().iterator().next());
    List<ActivityEntity> roleActivities = new ArrayList<ActivityEntity>(role.getActivities());
    List<ActivityEntity> updatedRoleActivities = new ArrayList<ActivityEntity>();
    for (ActivityEntity ae : roleActivities) {
        if (ae.getId() != SecurityConstants.EDIT_REPORT_INFORMATION || allowReportEdit) {
            updatedRoleActivities.add(ae);
        }
    }
    try {
        StaticHibernateUtil.startTransaction();
        role.update(userContext.getId(), "test", updatedRoleActivities);
        legacyRolesPermissionsDao.save(role);
        StaticHibernateUtil.flushSession();
        for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
            StaticHibernateUtil.getSessionTL().refresh(ae);
        }
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "edit");
    addRequestParameter("reportId", "1");
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 19 with RoleBO

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

the class RolesPermissionsActionStrutsTest method testDeleteFailure.

@Test
public void testDeleteFailure() throws Exception {
    RoleBO roleBO = legacyRolesPermissionsDao.getRole("Admin");
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "preview");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("id", roleBO.getId().toString());
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.preview_success.toString());
    Assert.assertNotNull(request.getAttribute(Constants.CURRENTFLOWKEY));
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "delete");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyActionErrors(new String[] { RolesAndPermissionConstants.KEYROLEASSIGNEDTOPERSONNEL });
    verifyForward(ActionForwards.delete_failure.toString());
    Assert.assertNotNull(request.getAttribute(Constants.CURRENTFLOWKEY));
}
Also used : RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) Test(org.junit.Test)

Example 20 with RoleBO

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

the class RolesPermissionsBusinessServiceIntegrationTest method testGetRoleForGivenId.

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

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