Search in sources :

Example 31 with ActivityEntity

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

the class RolesPermissionsAction method getActivities.

private List<ActivityEntity> getActivities(List<ActivityEntity> activityList, Map<String, String> activities) {
    List<ActivityEntity> newActivityList = new ArrayList<ActivityEntity>();
    List<Short> ids = new ArrayList<Short>();
    Set<String> keys = activities.keySet();
    for (String string : keys) {
        /*
             * We need to collect the id's of all the checked activities when we
             * created the ui. We have given unique name to leaf activities and
             * "chekbox" to non leaf activities .Now we are trying to get the
             * id's of checked leafs only
             */
        if (!activities.get(string).equalsIgnoreCase("checkbox") && !activities.get(string).equalsIgnoreCase("")) {
            Short activityId = Short.parseShort(activities.get(string));
            ids.add(activityId);
        }
    }
    for (ActivityEntity activityEntity : activityList) {
        if (ids.contains(activityEntity.getId())) {
            newActivityList.add(activityEntity);
        }
    }
    return newActivityList;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) ArrayList(java.util.ArrayList)

Example 32 with ActivityEntity

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

the class ActivityTag method getActivities.

List<ActivityEntity> getActivities(List<ActivityEntity> activityList, Map<String, String> activities) {
    List<ActivityEntity> newActivityList = new ArrayList<ActivityEntity>();
    List<Short> ids = new ArrayList<Short>();
    Set<String> keys = activities.keySet();
    for (String string : keys) {
        /*
             * We need to collect the id's of all the checked activities when we
             * created the ui. We have given unique name to leaf activities and
             * "chekbox" to non leaf activities .Now we are trying to get the
             * id's of checked leafs only
             */
        if (!activities.get(string).equalsIgnoreCase("checkbox") && !activities.get(string).equalsIgnoreCase("")) {
            Short activityId = Short.parseShort(activities.get(string));
            ids.add(activityId);
        }
    }
    for (ActivityEntity activityEntity : activityList) {
        if (ids.contains(activityEntity.getId())) {
            newActivityList.add(activityEntity);
        }
    }
    return newActivityList;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) ArrayList(java.util.ArrayList)

Example 33 with ActivityEntity

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

the class ActivityTag method doEndTag.

@SuppressWarnings("unchecked")
@Override
public int doEndTag() throws JspException {
    RoleTempleteBuilder builder = new RoleTempleteBuilder();
    List<ActivityEntity> activities;
    try {
        activities = (List<ActivityEntity>) SessionUtils.getAttribute(RolesAndPermissionConstants.ACTIVITYLIST, (HttpServletRequest) pageContext.getRequest());
        activities = filterActivities(activities);
        RoleBO role = (RoleBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, (HttpServletRequest) pageContext.getRequest());
        RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) pageContext.getSession().getAttribute("rolesPermissionsActionForm");
        if (rolesPermissionsActionForm != null && rolesPermissionsActionForm.getActivities().size() > 0) {
            List<ActivityEntity> flitered = filterActivities(getActivities(activities, rolesPermissionsActionForm.getActivities()));
            Set<Short> activitySet = convertToIdSet(flitered);
            builder.setCurrentActivites(activitySet);
        } else if (role != null) {
            List<ActivityEntity> flitered = filterActivities(new ArrayList<ActivityEntity>(role.getActivities()));
            Set<Short> activitySet = convertToIdSet(flitered);
            builder.setCurrentActivites(activitySet);
        }
        Map<Short, ActivityRestrictionDto> activityRestrictionDtoMap = rolesPermissionsActionForm.getActivityRestrictionDtoMap();
        if (activityRestrictionDtoMap == null) {
            activityRestrictionDtoMap = new HashMap<Short, ActivityRestrictionDto>();
        }
        builder.setActivityRestrictionDtoMap(activityRestrictionDtoMap);
        SessionUtils.getAttribute(Constants.BUSINESS_KEY, (HttpServletRequest) pageContext.getRequest());
        StringBuilder sb = builder.getRolesTemplete(activities);
        pageContext.getOut().print(sb.toString());
    } catch (IOException e) {
        throw new JspException(e);
    } catch (PageExpiredException e1) {
        throw new JspException(e1);
    }
    return EVAL_PAGE;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Set(java.util.Set) HashSet(java.util.HashSet) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) RoleTempleteBuilder(org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder) JspException(javax.servlet.jsp.JspException) ArrayList(java.util.ArrayList) List(java.util.List) ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 34 with ActivityEntity

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

the class LegacyRolesPermissionsDao method updateLookUpValue.

public void updateLookUpValue(Short activityId, String inputCategoryName) {
    ActivityEntity activityEntity = null;
    try {
        activityEntity = getPersistentObject(ActivityEntity.class, activityId);
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }
    if (activityEntity != null) {
        LookUpValueEntity lookUpValueEntity = activityEntity.getDescriptionLookupValues();
        ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValue(lookUpValueEntity, inputCategoryName);
    }
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MessageLookup(org.mifos.application.master.MessageLookup) SystemException(org.mifos.framework.exceptions.SystemException) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException) ServiceException(org.mifos.framework.exceptions.ServiceException) SecurityException(org.mifos.framework.exceptions.SecurityException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Example 35 with ActivityEntity

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

the class LegacyRolesPermissionsDao method createActivityEntity.

private ActivityEntity createActivityEntity(short parentActivity, int lookUpId) throws ServiceException, ActivityGeneratorException, PersistenceException {
    ActivityEntity parentActivityEntity;
    if (parentActivity != 0) {
        parentActivityEntity = getPersistentObject(ActivityEntity.class, parentActivity);
    } else {
        parentActivityEntity = null;
    }
    LookUpValueEntity lookupValueEntity = getPersistentObject(LookUpValueEntity.class, lookUpId);
    ActivityEntity activityEntity = new ActivityEntity((short) calculateDynamicActivityId(), parentActivityEntity, lookupValueEntity);
    createOrUpdate(activityEntity);
    return activityEntity;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Aggregations

ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)42 PersistenceException (org.mifos.framework.exceptions.PersistenceException)13 MifosRuntimeException (org.mifos.core.MifosRuntimeException)12 Test (org.junit.Test)10 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)9 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)9 ArrayList (java.util.ArrayList)8 UserContext (org.mifos.security.util.UserContext)8 HibernateException (org.hibernate.HibernateException)7 ActivityGeneratorException (org.mifos.security.activity.ActivityGeneratorException)7 ApplicationException (org.mifos.framework.exceptions.ApplicationException)6 ServiceException (org.mifos.framework.exceptions.ServiceException)6 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)6 HibernateProcessException (org.mifos.framework.exceptions.HibernateProcessException)5 SystemException (org.mifos.framework.exceptions.SystemException)5 IOException (java.io.IOException)4 MessageLookup (org.mifos.application.master.MessageLookup)4 SecurityException (org.mifos.framework.exceptions.SecurityException)4 List (java.util.List)3 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)3