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);
}
}
}
}
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")));
}
}
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);
}
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);
}
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;
}
Aggregations