public static CollectionsEntity map()

in service/src/main/java/org/apache/fineract/cn/deposit/service/internal/mapper/CollectionsMapper.java [41:75]


    public static CollectionsEntity map(CollectionsRequest collectionsRequest,
                                        ProductInstanceRepository accountRepository,
                                        SubTransactionTypeRepository subTxnRepository){
        CollectionsEntity  entity = new CollectionsEntity();

        if(collectionsRequest.getTxnDate() != null) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MMMM-dd");
            entity.setTransactionDate(LocalDate.parse(collectionsRequest.getTxnDate(), formatter).atStartOfDay());
        }else {
            entity.setTransactionDate(getNow());
        }
        entity.setAmount(BigDecimal.ZERO);
        entity.setTransportFeeAmount(collectionsRequest.getFee());
        entity.setCurrency(collectionsRequest.getCurrency());
        entity.setRemarks(collectionsRequest.getRemarks());
        entity.setAccount(accountRepository.findByAccountIdentifier(collectionsRequest.getAccountId()).orElseThrow(() -> ServiceException.notFound("Account {0} not found.", collectionsRequest.getAccountId())));
        entity.setSubTxnType(subTxnRepository.findByIdentifier(collectionsRequest.getSubtxnId()).orElseThrow(() -> ServiceException.notFound("Sub Txn Type {0} not found.", collectionsRequest.getSubtxnId())));
        entity.setStatus("INIT");
        entity.setCollectionReference(UUID.randomUUID().toString());
        entity.setCreatedBy(getLoginUser());
        entity.setCreatedOn(getNow());
        entity.setLastModifiedBy(getLoginUser());
        entity.setLastModifiedOn(getNow());
        entity.setIndvCollections(collectionsRequest.getIndividualPayments().stream().map(x-> {
            IndividualCollectionsEntity indv = new IndividualCollectionsEntity();
            indv.setCollection(entity);
            indv.setAccount(accountRepository.findByAccountIdentifier(x.getAccountNumber()).orElseThrow(() -> ServiceException.notFound("Account {0} not found.", x.getAccountNumber())));
            indv.setAccountExternalId(x.getAccountNumber());
            indv.setAmount(x.getAmount());
            indv.setIndividualCollectionReference(UUID.randomUUID().toString());
            entity.setAmount(entity.getAmount().add(x.getAmount()));
            return indv;
        }).collect(Collectors.toSet()));
        return entity;
    }