Search in sources :

Example 81 with CustomFieldDto

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

the class SavingsActionStrutsTest method getCustomFieldView.

private List<CustomFieldDto> getCustomFieldView() {
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    customFields.add(new CustomFieldDto(new Short("8"), "13", null));
    return customFields;
}
Also used : CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList)

Example 82 with CustomFieldDto

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

the class CenterHierarchyCustomerServiceIntegrationTest method updatingCenterWithDifferentLoanOfficerUpdatesAllChildrenInHierarchyIncludingTheirAssociatedLoansSavingsAndCustomerAccounts.

@Test
public void updatingCenterWithDifferentLoanOfficerUpdatesAllChildrenInHierarchyIncludingTheirAssociatedLoansSavingsAndCustomerAccounts() throws Exception {
    // setup
    String externalId = center.getExternalId();
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(center.getMfiJoiningDate());
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
    CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), otherLoanOfficer.getPersonnelId(), externalId, mfiJoiningDate, address, customFields, customerPositions);
    UserContext userContext = TestUtils.makeUser();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    StaticHibernateUtil.flushAndClearSession();
    // verification
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    group = customerDao.findGroupBySystemId(group.getGlobalCustNum());
    group2 = customerDao.findGroupBySystemId(group2.getGlobalCustNum());
    assertThat(center.getDisplayName(), is(updatedDisplayName));
    assertThat(center.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
    assertThat(group.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
    assertThat(group2.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 83 with CustomFieldDto

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

the class ClientIntegrationTest method getCustomFields.

private List<CustomFieldDto> getCustomFields() {
    List<CustomFieldDto> fields = new ArrayList<CustomFieldDto>();
    fields.add(new CustomFieldDto(Short.valueOf("5"), "value1", CustomFieldType.ALPHA_NUMERIC.getValue()));
    fields.add(new CustomFieldDto(Short.valueOf("6"), "value2", CustomFieldType.ALPHA_NUMERIC.getValue()));
    return fields;
}
Also used : CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList)

Example 84 with CustomFieldDto

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

the class CenterUpdateUsingCustomerServiceIntegrationTest method canUpdateCenterWithDifferentMfiJoiningDateInPastOrFuture.

@Test
public void canUpdateCenterWithDifferentMfiJoiningDateInPastOrFuture() throws Exception {
    // setup
    Short loanOfficerId = center.getPersonnel().getPersonnelId();
    String externalId = center.getExternalId();
    LocalDate dateInPast = new LocalDate(center.getMfiJoiningDate()).minusWeeks(4);
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(dateInPast.toDateMidnight().toDate());
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
    CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), loanOfficerId, externalId, mfiJoiningDate, address, customFields, customerPositions);
    UserContext userContext = TestUtils.makeUser();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    assertThat(center.getMfiJoiningDate(), is(dateInPast.toDateMidnight().toDate()));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) LocalDate(org.joda.time.LocalDate) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 85 with CustomFieldDto

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

the class SavingsServiceFacadeWebTier method updateSavingsAccountDetails.

@Override
public void updateSavingsAccountDetails(Long savingsId, String recommendedOrMandatoryAmount, List<CustomFieldDto> customFields) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
    savingsAccount.updateDetails(userContext);
    Set<AccountCustomFieldEntity> accountCustomFields = savingsAccount.getAccountCustomFields();
    for (CustomFieldDto view : customFields) {
        boolean fieldPresent = false;
        if (CustomFieldType.DATE.getValue().equals(view.getFieldType()) && org.apache.commons.lang.StringUtils.isNotBlank(view.getFieldValue())) {
            try {
                SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, userContext.getPreferredLocale());
                String userfmt = DateUtils.convertToCurrentDateFormat(format.toPattern());
                view.setFieldValue(DateUtils.convertUserToDbFmt(view.getFieldValue(), userfmt));
            } catch (InvalidDateException e) {
                throw new BusinessRuleException(e.getMessage(), e);
            }
        }
        for (AccountCustomFieldEntity customFieldEntity : accountCustomFields) {
            if (customFieldEntity.getFieldId().equals(view.getFieldId())) {
                fieldPresent = true;
                customFieldEntity.setFieldValue(view.getFieldValue());
            }
        }
        if (!fieldPresent) {
            accountCustomFields.add(new AccountCustomFieldEntity(savingsAccount, view.getFieldId(), view.getFieldValue()));
        }
    }
    Money amount = new Money(savingsAccount.getCurrency(), recommendedOrMandatoryAmount);
    try {
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        savingsAccount.update(amount, accountCustomFields);
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) SimpleDateFormat(java.text.SimpleDateFormat) AccountCustomFieldEntity(org.mifos.accounts.business.AccountCustomFieldEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)86 ArrayList (java.util.ArrayList)48 Test (org.junit.Test)36 UserContext (org.mifos.security.util.UserContext)16 Date (java.util.Date)14 Address (org.mifos.framework.business.util.Address)14 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)13 AddressDto (org.mifos.dto.domain.AddressDto)12 List (java.util.List)10 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)10 SimpleDateFormat (java.text.SimpleDateFormat)9 BusinessActivityEntity (org.mifos.application.master.business.BusinessActivityEntity)9 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)8 ApplicableAccountFeeDto (org.mifos.dto.domain.ApplicableAccountFeeDto)8 CustomerPositionDto (org.mifos.dto.domain.CustomerPositionDto)8 CustomFieldDefinitionEntity (org.mifos.application.master.business.CustomFieldDefinitionEntity)7 MeetingBO (org.mifos.application.meeting.business.MeetingBO)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 GroupCustActionForm (org.mifos.customers.group.struts.actionforms.GroupCustActionForm)6 OfficeBO (org.mifos.customers.office.business.OfficeBO)6