Search in sources :

Example 46 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class ClientCustActionForm method checkForMandatoryFields.

@SuppressWarnings("unchecked")
@Override
public void checkForMandatoryFields(Short entityId, ActionErrors errors, HttpServletRequest request) {
    Map<Short, List<FieldConfigurationEntity>> entityMandatoryFieldMap = (Map<Short, List<FieldConfigurationEntity>>) request.getSession().getServletContext().getAttribute(Constants.FIELD_CONFIGURATION);
    List<FieldConfigurationEntity> mandatoryfieldList = entityMandatoryFieldMap.get(entityId);
    for (FieldConfigurationEntity fieldConfigurationEntity : mandatoryfieldList) {
        String propertyName = request.getParameter(fieldConfigurationEntity.getLabel());
        UserContext userContext = ((UserContext) request.getSession().getAttribute(LoginConstants.USERCONTEXT));
        if (propertyName != null && !propertyName.equals("") && !propertyName.equalsIgnoreCase("picture")) {
            String propertyValue = request.getParameter(propertyName);
            if (propertyValue == null || propertyValue.equals("")) {
                errors.add(fieldConfigurationEntity.getLabel(), new ActionMessage(FieldConfigurationConstant.EXCEPTION_MANDATORY, FieldConfigurationHelper.getLocalSpecificFieldNames(fieldConfigurationEntity.getLabel(), userContext)));
            }
        } else if (propertyName != null && !propertyName.equals("") && propertyName.equalsIgnoreCase("picture")) {
            try {
                if (getCustomerPicture() == null || getCustomerPicture().read() == -1) {
                    errors.add(fieldConfigurationEntity.getLabel(), new ActionMessage(FieldConfigurationConstant.EXCEPTION_MANDATORY, FieldConfigurationHelper.getLocalSpecificFieldNames(fieldConfigurationEntity.getLabel(), userContext)));
                }
                getCustomerPicture().reset();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) FieldConfigurationEntity(org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) Map(java.util.Map)

Example 47 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class CollectionSheetEntryAction method getUserLocale.

/**
     * used by JSP functions in view.
     */
protected Locale getUserLocale(final HttpServletRequest request) {
    Locale locale = null;
    UserContext userContext = getUserContext(request);
    if (null != userContext) {
        locale = userContext.getCurrentLocale();
    }
    return locale;
}
Also used : Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext)

Example 48 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class LookupOptionsActionForm method getUserLocale.

protected Locale getUserLocale(HttpServletRequest request) {
    Locale locale = null;
    HttpSession session = request.getSession();
    if (session != null) {
        UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
        if (null != userContext) {
            locale = userContext.getCurrentLocale();
        }
    }
    return locale;
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext)

Example 49 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class CenterCustAction method load.

@TransactionDemarcate(saveToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    CenterCustActionForm actionForm = (CenterCustActionForm) form;
    actionForm.clearActionFormFields();
    SessionUtils.removeAttribute(CustomerConstants.CUSTOMER_MEETING, request);
    UserContext userContext = getUserContext(request);
    CenterCreation centerCreationDto = new CenterCreation(actionForm.getOfficeIdValue(), userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
    CenterFormCreationDto centerFormCreation = this.centerServiceFacade.retrieveCenterFormCreationData(centerCreationDto);
    //        SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, new ArrayList<Serializable>(), request);
    SessionUtils.setCollectionAttribute(CustomerConstants.LOAN_OFFICER_LIST, centerFormCreation.getActiveLoanOfficersForBranch(), request);
    SessionUtils.setCollectionAttribute(CustomerConstants.ADDITIONAL_FEES_LIST, centerFormCreation.getAdditionalFees(), request);
    //        actionForm.setCustomFields(centerFormCreation.getCustomFieldViews());
    actionForm.setDefaultFees(centerFormCreation.getDefaultFees());
    DateTime today = new DateTime().toDateMidnight().toDateTime();
    actionForm.setMfiJoiningDate(today.getDayOfMonth(), today.getMonthOfYear(), today.getYear());
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : CenterCustActionForm(org.mifos.customers.center.struts.actionforms.CenterCustActionForm) UserContext(org.mifos.security.util.UserContext) CenterCreation(org.mifos.dto.domain.CenterCreation) CenterFormCreationDto(org.mifos.dto.screen.CenterFormCreationDto) DateTime(org.joda.time.DateTime) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 50 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class RolesPermissionsAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) form;
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    List<ActivityEntity> activities = (List<ActivityEntity>) SessionUtils.getAttribute(RolesAndPermissionConstants.ACTIVITYLIST, request);
    rolesPermissionServiceFacade.updateRole(Short.parseShort(rolesPermissionsActionForm.getId()), userContext.getId(), rolesPermissionsActionForm.getName(), getActivityIds(getActivities(activities, rolesPermissionsActionForm.getActivities())), rolesPermissionsActionForm.getActivityRestrictionDtoToPersistList());
    // MIFOS-3530: update all currently logged users
    for (String loggedUser : getLoggedUsers(request)) {
        this.authenticationAuthorizationServiceFacade.reloadUserDetailsForSecurityContext(loggedUser);
    }
    return mapping.findForward(ActionForwards.update_success.toString());
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ArrayList(java.util.ArrayList) List(java.util.List) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

UserContext (org.mifos.security.util.UserContext)369 MifosUser (org.mifos.security.MifosUser)134 MifosRuntimeException (org.mifos.core.MifosRuntimeException)102 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)81 BusinessRuleException (org.mifos.service.BusinessRuleException)75 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)72 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)65 AccountException (org.mifos.accounts.exceptions.AccountException)55 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 Money (org.mifos.framework.util.helpers.Money)46 LoanBO (org.mifos.accounts.loan.business.LoanBO)45 LocalDate (org.joda.time.LocalDate)44 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)43 ServiceException (org.mifos.framework.exceptions.ServiceException)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)38 CustomerBO (org.mifos.customers.business.CustomerBO)37 MeetingBO (org.mifos.application.meeting.business.MeetingBO)34 Date (java.util.Date)31 CustomerException (org.mifos.customers.exceptions.CustomerException)31