Пример #1
0
  public Map<String, Object> update(JsonCommand command) {

    final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(1);
    final String firstnameParamName = "planCode";
    if (command.isChangeInStringParameterNamed(firstnameParamName, this.planCode)) {
      final String newValue = command.stringValueOfParameterNamed(firstnameParamName);
      actualChanges.put(firstnameParamName, newValue);
      this.planCode = StringUtils.defaultIfEmpty(newValue, null);
    }
    final String descriptionParamName = "planDescription";
    if (command.isChangeInStringParameterNamed(descriptionParamName, this.description)) {
      final String newValue = command.stringValueOfParameterNamed(descriptionParamName);
      actualChanges.put(firstnameParamName, newValue);
      this.description = StringUtils.defaultIfEmpty(newValue, null);
    }
    final String provisioingSystem = "provisioingSystem";
    if (command.isChangeInStringParameterNamed(provisioingSystem, this.provisionSystem)) {
      final String newValue = command.stringValueOfParameterNamed(provisioingSystem);
      actualChanges.put(provisioingSystem, newValue);
      this.provisionSystem = StringUtils.defaultIfEmpty(newValue, null);
    }

    final String startDateParamName = "startDate";
    if (command.isChangeInLocalDateParameterNamed(
        startDateParamName, new LocalDate(this.startDate))) {
      final LocalDate newValue = command.localDateValueOfParameterNamed(startDateParamName);
      actualChanges.put(startDateParamName, newValue);
      this.startDate = newValue.toDate();
    }

    final String endDateParamName = "endDate";
    if (command.isChangeInLocalDateParameterNamed(endDateParamName, new LocalDate(this.endDate))) {
      final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName);
      actualChanges.put(endDateParamName, newValue);
      if (newValue != null) this.endDate = newValue.toDate();
    }
    final String billRuleParamName = "billRule";
    if (command.isChangeInLongParameterNamed(billRuleParamName, this.billRule)) {
      final Long newValue = command.longValueOfParameterNamed(billRuleParamName);
      actualChanges.put(billRuleParamName, newValue);
      this.billRule = newValue;
    }
    final String statusParamName = "status";
    if (command.isChangeInLongParameterNamed(statusParamName, this.status)) {
      final Long newValue = command.longValueOfParameterNamed(statusParamName);
      actualChanges.put(statusParamName, newValue);
      this.status = newValue;
    }
    final boolean isPrepaid = command.booleanPrimitiveValueOfParameterNamed("isPrepaid");
    final char isPrepaidParamName = isPrepaid ? 'Y' : 'N';
    this.isPrepaid = isPrepaidParamName;

    final boolean allowTopupParamName = command.booleanPrimitiveValueOfParameterNamed("allowTopup");
    this.allowTopup = allowTopupParamName ? 'Y' : 'N';

    final boolean isHwReqParamName = command.booleanPrimitiveValueOfParameterNamed("isHwReq");
    this.isHwReq = isHwReqParamName ? 'Y' : 'N';
    return actualChanges;
  }
Пример #2
0
  public Map<String, Object> update(final JsonCommand command) {
    final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(9);

    if (command.isChangeInIntegerParameterNamed(
        GroupingTypesApiConstants.statusParamName, this.status)) {
      final Integer newValue =
          command.integerValueOfParameterNamed(GroupingTypesApiConstants.statusParamName);
      actualChanges.put(
          GroupingTypesApiConstants.statusParamName, GroupingTypeEnumerations.status(newValue));
      this.status = GroupingTypeStatus.fromInt(newValue).getValue();
    }

    if (command.isChangeInStringParameterNamed(
        GroupingTypesApiConstants.externalIdParamName, this.externalId)) {
      final String newValue =
          command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName);
      actualChanges.put(GroupingTypesApiConstants.externalIdParamName, newValue);
      this.externalId = StringUtils.defaultIfEmpty(newValue, null);
    }

    if (command.isChangeInLongParameterNamed(
        GroupingTypesApiConstants.officeIdParamName, this.office.getId())) {
      final Long newValue =
          command.longValueOfParameterNamed(GroupingTypesApiConstants.officeIdParamName);
      actualChanges.put(GroupingTypesApiConstants.officeIdParamName, newValue);
    }

    if (command.isChangeInLongParameterNamed(
        GroupingTypesApiConstants.staffIdParamName, staffId())) {
      final Long newValue =
          command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
      actualChanges.put(GroupingTypesApiConstants.staffIdParamName, newValue);
    }

    if (command.isChangeInStringParameterNamed(
        GroupingTypesApiConstants.nameParamName, this.name)) {
      final String newValue =
          command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName);
      actualChanges.put(GroupingTypesApiConstants.nameParamName, newValue);
      this.name = StringUtils.defaultIfEmpty(newValue, null);
    }

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();

    if (command.isChangeInLocalDateParameterNamed(
        GroupingTypesApiConstants.activationDateParamName, getActivationLocalDate())) {
      final String valueAsInput =
          command.stringValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName);
      actualChanges.put(GroupingTypesApiConstants.activationDateParamName, valueAsInput);
      actualChanges.put(GroupingTypesApiConstants.dateFormatParamName, dateFormatAsInput);
      actualChanges.put(GroupingTypesApiConstants.localeParamName, localeAsInput);

      final LocalDate newValue =
          command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName);
      this.activationDate = newValue.toDate();
    }

    return actualChanges;
  }
Пример #3
0
  public Map<String, Object> update(final JsonCommand command, final BigDecimal amount) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(7);

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();

    final String dueDateParamName = "dueDate";
    if (command.isChangeInLocalDateParameterNamed(dueDateParamName, getDueLocalDate())) {
      final String valueAsInput = command.stringValueOfParameterNamed(dueDateParamName);
      actualChanges.put(dueDateParamName, valueAsInput);
      actualChanges.put("dateFormat", dateFormatAsInput);
      actualChanges.put("locale", localeAsInput);

      final LocalDate newValue = command.localDateValueOfParameterNamed(dueDateParamName);
      this.dueDate = newValue.toDate();
    }

    final String amountParamName = "amount";
    if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) {
      final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName);
      actualChanges.put(amountParamName, newValue);
      actualChanges.put("locale", localeAsInput);
      switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
          break;
        case FLAT:
          if (isInstalmentFee()) {
            this.amount =
                newValue.multiply(
                    BigDecimal.valueOf(
                        this.loan.repaymentScheduleDetail().getNumberOfRepayments()));
          } else {
            this.amount = newValue;
          }
          this.amountOutstanding = calculateOutstanding();
          break;
        case PERCENT_OF_AMOUNT:
        case PERCENT_OF_AMOUNT_AND_INTEREST:
        case PERCENT_OF_INTEREST:
          this.percentage = newValue;
          this.amountPercentageAppliedTo = amount;
          BigDecimal loanCharge = BigDecimal.ZERO;
          if (isInstalmentFee()) {
            loanCharge =
                this.loan.calculatePerInstallmentChargeAmount(
                    ChargeCalculationType.fromInt(this.chargeCalculation), this.percentage);
          }
          if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
            loanCharge = percentageOf(this.amountPercentageAppliedTo);
          }
          this.amount = minimumAndMaximumCap(loanCharge);
          this.amountOutstanding = calculateOutstanding();
          break;
      }
      this.amountOrPercentage = newValue;
      if (isInstalmentFee()) {
        final Set<LoanInstallmentCharge> chargePerInstallments =
            this.loan.generateInstallmentLoanCharges(this);
        if (this.loanInstallmentCharge.isEmpty()) {
          this.loanInstallmentCharge.addAll(chargePerInstallments);
        } else {
          int index = 0;
          final LoanInstallmentCharge[] loanChargePerInstallments =
              new LoanInstallmentCharge[chargePerInstallments.size()];
          final LoanInstallmentCharge[] loanChargePerInstallmentArray =
              chargePerInstallments.toArray(loanChargePerInstallments);
          for (final LoanInstallmentCharge chargePerInstallment : this.loanInstallmentCharge) {
            chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
          }
        }
      }
    }
    return actualChanges;
  }