Search in sources :

Example 1 with FieldConfigurationEntity

use of org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity 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 2 with FieldConfigurationEntity

use of org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity in project head by mifos.

the class ClientCustActionForm method validateSpouseNames.

@SuppressWarnings({ "unchecked" })
private void validateSpouseNames(ActionErrors errors, HttpServletRequest request) {
    boolean mandatorySpouseType = false;
    Map<Short, List<FieldConfigurationEntity>> entityMandatoryFieldMap = (Map<Short, List<FieldConfigurationEntity>>) request.getSession().getServletContext().getAttribute(Constants.FIELD_CONFIGURATION);
    List<FieldConfigurationEntity> mandatoryfieldList = entityMandatoryFieldMap.get(EntityType.CLIENT.getValue());
    for (FieldConfigurationEntity fieldConfigurationEntity : mandatoryfieldList) {
        if (HiddenMandatoryFieldNamesConstants.SPOUSE_FATHER_INFORMATION.equals(fieldConfigurationEntity.getFieldName())) {
            if (fieldConfigurationEntity.isMandatory()) {
                mandatorySpouseType = true;
                break;
            }
        }
    }
    // issue 2929: when the spouse/father fields are hidden, then the values are null instead empty string - this need to be fixed here
    if (spouseName.getFirstName() == null) {
        spouseName.setFirstName("");
    }
    if (spouseName.getMiddleName() == null) {
        spouseName.setMiddleName("");
    }
    if (spouseName.getSecondLastName() == null) {
        spouseName.setSecondLastName("");
    }
    if (spouseName.getLastName() == null) {
        spouseName.setLastName("");
    }
    if (spouseName.getNameType() == null && (mandatorySpouseType || !StringUtils.isBlank(spouseName.getFirstName()) || !StringUtils.isBlank(spouseName.getMiddleName()) || !StringUtils.isBlank(spouseName.getSecondLastName()) || !StringUtils.isBlank(spouseName.getLastName()))) {
        errors.add(CustomerConstants.SPOUSE_TYPE, new ActionMessage(CustomerConstants.ERRORS_MANDATORY, getLocalizedMessage("Customer.SpouseType")));
    }
    if (mandatorySpouseType && StringUtils.isBlank(spouseName.getFirstName())) {
        errors.add(CustomerConstants.SPOUSE_FIRST_NAME, new ActionMessage(CustomerConstants.ERRORS_MANDATORY, getLocalizedMessage("Customer.SpouseFirstName")));
    }
    if (mandatorySpouseType && StringUtils.isBlank(spouseName.getLastName())) {
        errors.add(CustomerConstants.SPOUSE_LAST_NAME, new ActionMessage(CustomerConstants.ERRORS_MANDATORY, getLocalizedMessage("Customer.SpouseLastName")));
    }
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) FieldConfigurationEntity(org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with FieldConfigurationEntity

use of org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity in project head by mifos.

the class LoanAccountActionFormTest method testShouldValidateIfPurposeOfLoanIsValid.

public void testShouldValidateIfPurposeOfLoanIsValid() throws Exception {
    FieldConfigurationEntity fieldConfigMock = createMock(FieldConfigurationEntity.class);
    expect(fieldConfigMock.getFieldName()).andReturn(LoanConstants.PURPOSE_OF_LOAN);
    replay(fieldConfigMock);
    form.setClientDetails(asList(LOAN_ACCOUNT_DETAILS_WITH_VALID_PURPOSE));
    form.setClients(asList("1"));
    form.validatePurposeOfLoanForGlim(actionErrors, asList(fieldConfigMock));
    Assert.assertEquals(0, actionErrors.size());
    verify(fieldConfigMock);
}
Also used : FieldConfigurationEntity(org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity)

Example 4 with FieldConfigurationEntity

use of org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity in project head by mifos.

the class LoanAccountActionFormTest method testShouldAddErrorIfPurposeOfLoanIsNull.

public void testShouldAddErrorIfPurposeOfLoanIsNull() throws Exception {
    FieldConfigurationEntity fieldConfigMock = createMock(FieldConfigurationEntity.class);
    expect(fieldConfigMock.getFieldName()).andReturn(LoanConstants.PURPOSE_OF_LOAN);
    replay(fieldConfigMock);
    form.setClientDetails(asList(LOAN_ACCOUNT_DETAILS_WITH_PURPOSE_NULL));
    form.setClients(asList("1"));
    form.validatePurposeOfLoanForGlim(actionErrors, asList(fieldConfigMock));
    Assert.assertEquals(1, actionErrors.size());
    verify(fieldConfigMock);
}
Also used : FieldConfigurationEntity(org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity)

Example 5 with FieldConfigurationEntity

use of org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity in project head by mifos.

the class MultipleLoanAccountsCreationActionForm method isPurposeOfLoanMandatory.

/**
     * Returns true or false depending on whether the purpose of the loan is
     * mandatory or not
     */
private boolean isPurposeOfLoanMandatory(HttpServletRequest request) {
    logger.debug("Checking if purpose of loan is Mandatory");
    Map<Short, List<FieldConfigurationEntity>> entityMandatoryFieldMap = (Map<Short, List<FieldConfigurationEntity>>) request.getSession().getServletContext().getAttribute(Constants.FIELD_CONFIGURATION);
    List<FieldConfigurationEntity> mandatoryfieldList = entityMandatoryFieldMap.get(EntityType.LOAN.getValue());
    boolean isMandatory = false;
    for (FieldConfigurationEntity entity : mandatoryfieldList) {
        if (entity.getFieldName().equalsIgnoreCase(LoanConstants.PURPOSE_OF_LOAN)) {
            isMandatory = true;
            logger.debug("Returning true");
            break;
        }
    }
    logger.debug("Returning " + isMandatory);
    return isMandatory;
}
Also used : FieldConfigurationEntity(org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

FieldConfigurationEntity (org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity)13 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ActionMessage (org.apache.struts.action.ActionMessage)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 UserContext (org.mifos.security.util.UserContext)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 MandatoryHiddenFieldsDto (org.mifos.dto.domain.MandatoryHiddenFieldsDto)1