Search in sources :

Example 6 with ActivityRestrictionDto

use of org.mifos.dto.domain.ActivityRestrictionDto in project head by mifos.

the class RolesPermissionsActionForm method setActivityRestriction.

public void setActivityRestriction(String activtiyRestrictionTypeIdString) throws RolesPermissionException {
    String amountValueString = restrictionsValues.get(activtiyRestrictionTypeIdString);
    if (amountValueString != null && !amountValueString.isEmpty()) {
        Short activtiyRestrictionTypeId = new Short(activtiyRestrictionTypeIdString);
        BigDecimal amountValue = null;
        try {
            amountValue = new BigDecimal(amountValueString);
            if (amountValue.compareTo(BigDecimal.ZERO) > 0) {
                ActivityRestrictionDto activityRestrictionDto = activityRestrictionDtoMap.get(activtiyRestrictionTypeId);
                if (activityRestrictionDto != null) {
                    activityRestrictionDto.setAmountValue(amountValue);
                    activityRestrictionDtoToPersistList.add(activityRestrictionDto);
                } else {
                    // add new restriction for role
                    Short roleId = 0;
                    if (id != null) {
                        roleId = new Short(id);
                    }
                    activityRestrictionDto = new ActivityRestrictionDto(roleId, activtiyRestrictionTypeId, amountValue);
                    activityRestrictionDtoMap.put(activtiyRestrictionTypeId, activityRestrictionDto);
                }
                this.activityRestrictionDtoToPersistList.add(activityRestrictionDto);
            } else {
                invalidActivityRestrictionsValues.add(ActivityRestrictionType.getByValue(activtiyRestrictionTypeId));
            }
        } catch (NumberFormatException e) {
            invalidActivityRestrictionsValues.add(ActivityRestrictionType.getByValue(activtiyRestrictionTypeId));
        }
    }
}
Also used : ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) BigDecimal(java.math.BigDecimal)

Example 7 with ActivityRestrictionDto

use of org.mifos.dto.domain.ActivityRestrictionDto 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)

Aggregations

ActivityRestrictionDto (org.mifos.dto.domain.ActivityRestrictionDto)7 ArrayList (java.util.ArrayList)4 ActivityRestrictionTypeEntity (org.mifos.security.rolesandpermission.business.ActivityRestrictionTypeEntity)3 RoleActivityRestrictionBO (org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO)3 BigDecimal (java.math.BigDecimal)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)2 RolesPermissionsActionForm (org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JspException (javax.servlet.jsp.JspException)1 MessageLookup (org.mifos.application.master.MessageLookup)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 Money (org.mifos.framework.util.helpers.Money)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1