List of usage examples for org.joda.time MonthDay getDayOfMonth
public int getDayOfMonth()
From source file:app.sunstreak.yourpisd.util.DateHelper.java
License:Open Source License
public static boolean isAprilFools() { MonthDay now = MonthDay.now(); return (now.getDayOfMonth() == 1 || now.getDayOfMonth() == 2) && now.getMonthOfYear() == 4; }
From source file:com.gst.infrastructure.core.api.JodaMonthDayAdapter.java
License:Apache License
@SuppressWarnings("unused") @Override//from w ww . j a v a2 s . c om public JsonElement serialize(final MonthDay src, final Type typeOfSrc, final JsonSerializationContext context) { JsonArray array = null; if (src != null) { array = new JsonArray(); array.add(new JsonPrimitive(src.getMonthOfYear())); array.add(new JsonPrimitive(src.getDayOfMonth())); } return array; }
From source file:com.gst.portfolio.account.domain.AccountTransferStandingInstruction.java
License:Apache License
public static AccountTransferStandingInstruction create(final AccountTransferDetails accountTransferDetails, final String name, final Integer priority, final Integer instructionType, final Integer status, final BigDecimal amount, final LocalDate validFrom, final LocalDate validTill, final Integer recurrenceType, final Integer recurrenceFrequency, final Integer recurrenceInterval, final MonthDay recurrenceOnMonthDay) { Integer recurrenceOnDay = null; Integer recurrenceOnMonth = null; if (recurrenceOnMonthDay != null) { recurrenceOnDay = recurrenceOnMonthDay.getDayOfMonth(); recurrenceOnMonth = recurrenceOnMonthDay.getMonthOfYear(); }/*from w w w . j av a 2 s . co m*/ return new AccountTransferStandingInstruction(accountTransferDetails, name, priority, instructionType, status, amount, validFrom, validTill, recurrenceType, recurrenceFrequency, recurrenceInterval, recurrenceOnDay, recurrenceOnMonth); }
From source file:com.gst.portfolio.account.domain.AccountTransferStandingInstruction.java
License:Apache License
public Map<String, Object> update(JsonCommand command) { final Map<String, Object> actualChanges = new HashMap<>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(STANDING_INSTRUCTION_RESOURCE_NAME); if (StandingInstructionStatus.fromInt(this.status).isDeleted()) { baseDataValidator.reset().parameter(statusParamName).failWithCode("can.not.modify.once.deleted"); }//from w ww . j ava2 s . c om if (command.isChangeInDateParameterNamed(validFromParamName, this.validFrom)) { final LocalDate newValue = command.localDateValueOfParameterNamed(validFromParamName); actualChanges.put(validFromParamName, newValue); this.validFrom = newValue.toDate(); } if (command.isChangeInDateParameterNamed(validTillParamName, this.validTill)) { final LocalDate newValue = command.localDateValueOfParameterNamed(validTillParamName); actualChanges.put(validTillParamName, newValue); this.validTill = newValue.toDate(); } if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName); actualChanges.put(amountParamName, newValue); this.amount = newValue; } if (command.isChangeInIntegerParameterNamed(statusParamName, this.status)) { final Integer newValue = command.integerValueOfParameterNamed(statusParamName); actualChanges.put(statusParamName, newValue); this.status = newValue; } if (command.isChangeInIntegerParameterNamed(priorityParamName, this.priority)) { final Integer newValue = command.integerValueOfParameterNamed(priorityParamName); actualChanges.put(priorityParamName, newValue); this.priority = newValue; } if (command.isChangeInIntegerParameterNamed(instructionTypeParamName, this.instructionType)) { final Integer newValue = command.integerValueOfParameterNamed(instructionTypeParamName); actualChanges.put(instructionTypeParamName, newValue); this.instructionType = newValue; } if (command.isChangeInIntegerParameterNamed(recurrenceTypeParamName, this.recurrenceType)) { final Integer newValue = command.integerValueOfParameterNamed(recurrenceTypeParamName); actualChanges.put(recurrenceTypeParamName, newValue); this.recurrenceType = newValue; } if (command.isChangeInIntegerParameterNamed(recurrenceFrequencyParamName, this.recurrenceFrequency)) { final Integer newValue = command.integerValueOfParameterNamed(recurrenceFrequencyParamName); actualChanges.put(recurrenceFrequencyParamName, newValue); this.recurrenceFrequency = newValue; } if (command.hasParameter(recurrenceOnMonthDayParamName)) { final MonthDay monthDay = command.extractMonthDayNamed(recurrenceOnMonthDayParamName); final String actualValueEntered = command.stringValueOfParameterNamed(recurrenceOnMonthDayParamName); final Integer dayOfMonthValue = monthDay.getDayOfMonth(); if (this.recurrenceOnDay != dayOfMonthValue) { actualChanges.put(recurrenceOnMonthDayParamName, actualValueEntered); this.recurrenceOnDay = dayOfMonthValue; } final Integer monthOfYear = monthDay.getMonthOfYear(); if (this.recurrenceOnMonth != monthOfYear) { actualChanges.put(recurrenceOnMonthDayParamName, actualValueEntered); this.recurrenceOnMonth = monthOfYear; } } if (command.isChangeInIntegerParameterNamed(recurrenceIntervalParamName, this.recurrenceInterval)) { final Integer newValue = command.integerValueOfParameterNamed(recurrenceIntervalParamName); actualChanges.put(recurrenceIntervalParamName, newValue); this.recurrenceInterval = newValue; } validateDependencies(baseDataValidator); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } return actualChanges; }
From source file:com.gst.portfolio.charge.domain.Charge.java
License:Apache License
private Charge(final String name, final BigDecimal amount, final String currencyCode, final ChargeAppliesTo chargeAppliesTo, final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculationType, final boolean penalty, final boolean active, final ChargePaymentMode paymentMode, final MonthDay feeOnMonthDay, final Integer feeInterval, final BigDecimal minCap, final BigDecimal maxCap, final Integer feeFrequency, final GLAccount account, final TaxGroup taxGroup) { this.name = name; this.amount = amount; this.currencyCode = currencyCode; this.chargeAppliesTo = chargeAppliesTo.getValue(); this.chargeTimeType = chargeTime.getValue(); this.chargeCalculation = chargeCalculationType.getValue(); this.penalty = penalty; this.active = active; this.account = account; this.taxGroup = taxGroup; this.chargePaymentMode = paymentMode == null ? null : paymentMode.getValue(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("charges"); if (isMonthlyFee() || isAnnualFee()) { this.feeOnMonth = feeOnMonthDay.getMonthOfYear(); this.feeOnDay = feeOnMonthDay.getDayOfMonth(); }//w w w. j a va2s . c om this.feeInterval = feeInterval; this.feeFrequency = feeFrequency; if (isSavingsCharge()) { // TODO vishwas, this validation seems unnecessary as identical // validation is performed in the write service if (!isAllowedSavingsChargeTime()) { baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType) .failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.savings"); } // TODO vishwas, this validation seems unnecessary as identical // validation is performed in the writeservice if (!isAllowedSavingsChargeCalculationType()) { baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculation) .failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.calculation.type.for.savings"); } if (!(ChargeTimeType.fromInt(getChargeTimeType()).isWithdrawalFee() || ChargeTimeType.fromInt(getChargeTimeType()).isSavingsNoActivityFee()) && ChargeCalculationType.fromInt(getChargeCalculation()).isPercentageOfAmount()) { baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculation) .failWithCodeNoParameterAddedToErrorCode( "savings.charge.calculation.type.percentage.allowed.only.for.withdrawal.or.NoActivity"); } } else if (isLoanCharge()) { if (penalty && (chargeTime.isTimeOfDisbursement() || chargeTime.isTrancheDisbursement())) { throw new ChargeDueAtDisbursementCannotBePenaltyException(name); } if (!penalty && chargeTime.isOverdueInstallment()) { throw new ChargeMustBePenaltyException(name); } // TODO vishwas, this validation seems unnecessary as identical // validation is performed in the write service if (!isAllowedLoanChargeTime()) { baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType) .failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.loan"); } } if (isPercentageOfApprovedAmount()) { this.minCap = minCap; this.maxCap = maxCap; } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } }
From source file:com.gst.portfolio.charge.domain.Charge.java
License:Apache License
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(7); final String localeAsInput = command.locale(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("charges"); final String nameParamName = "name"; if (command.isChangeInStringParameterNamed(nameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(nameParamName); actualChanges.put(nameParamName, newValue); this.name = newValue; }//from w w w .j av a 2 s . c o m final String currencyCodeParamName = "currencyCode"; if (command.isChangeInStringParameterNamed(currencyCodeParamName, this.currencyCode)) { final String newValue = command.stringValueOfParameterNamed(currencyCodeParamName); actualChanges.put(currencyCodeParamName, newValue); this.currencyCode = newValue; } final String amountParamName = "amount"; if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName); actualChanges.put(amountParamName, newValue); actualChanges.put("locale", localeAsInput); this.amount = newValue; } final String chargeTimeParamName = "chargeTimeType"; if (command.isChangeInIntegerParameterNamed(chargeTimeParamName, this.chargeTimeType)) { final Integer newValue = command.integerValueOfParameterNamed(chargeTimeParamName); actualChanges.put(chargeTimeParamName, newValue); actualChanges.put("locale", localeAsInput); this.chargeTimeType = ChargeTimeType.fromInt(newValue).getValue(); if (isSavingsCharge()) { if (!isAllowedSavingsChargeTime()) { baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType) .failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.savings"); } // if charge time is changed to monthly then validate for // feeOnMonthDay and feeInterval if (isMonthlyFee()) { final MonthDay monthDay = command.extractMonthDayNamed("feeOnMonthDay"); baseDataValidator.reset().parameter("feeOnMonthDay").value(monthDay).notNull(); final Integer feeInterval = command.integerValueOfParameterNamed("feeInterval"); baseDataValidator.reset().parameter("feeInterval").value(feeInterval).notNull().inMinMaxRange(1, 12); } } else if (isLoanCharge()) { if (!isAllowedLoanChargeTime()) { baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType) .failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.loan"); } } else if (isClientCharge()) { if (!isAllowedLoanChargeTime()) { baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType) .failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.client"); } } } final String chargeAppliesToParamName = "chargeAppliesTo"; if (command.isChangeInIntegerParameterNamed(chargeAppliesToParamName, this.chargeAppliesTo)) { /* * final Integer newValue = * command.integerValueOfParameterNamed(chargeAppliesToParamName); * actualChanges.put(chargeAppliesToParamName, newValue); * actualChanges.put("locale", localeAsInput); this.chargeAppliesTo * = ChargeAppliesTo.fromInt(newValue).getValue(); */ // AA: Do not allow to change chargeAppliesTo. final String errorMessage = "Update of Charge applies to is not supported"; throw new ChargeParameterUpdateNotSupportedException("charge.applies.to", errorMessage); } final String chargeCalculationParamName = "chargeCalculationType"; if (command.isChangeInIntegerParameterNamed(chargeCalculationParamName, this.chargeCalculation)) { final Integer newValue = command.integerValueOfParameterNamed(chargeCalculationParamName); actualChanges.put(chargeCalculationParamName, newValue); actualChanges.put("locale", localeAsInput); this.chargeCalculation = ChargeCalculationType.fromInt(newValue).getValue(); if (isSavingsCharge()) { if (!isAllowedSavingsChargeCalculationType()) { baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculation) .failWithCodeNoParameterAddedToErrorCode( "not.allowed.charge.calculation.type.for.savings"); } if (!(ChargeTimeType.fromInt(getChargeTimeType()).isWithdrawalFee() || ChargeTimeType.fromInt(getChargeTimeType()).isSavingsNoActivityFee()) && ChargeCalculationType.fromInt(getChargeCalculation()).isPercentageOfAmount()) { baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculation) .failWithCodeNoParameterAddedToErrorCode( "charge.calculation.type.percentage.allowed.only.for.withdrawal.or.noactivity"); } } else if (isClientCharge()) { if (!isAllowedClientChargeCalculationType()) { baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculation) .failWithCodeNoParameterAddedToErrorCode( "not.allowed.charge.calculation.type.for.client"); } } } if (isLoanCharge()) {// validate only for loan charge final String paymentModeParamName = "chargePaymentMode"; if (command.isChangeInIntegerParameterNamed(paymentModeParamName, this.chargePaymentMode)) { final Integer newValue = command.integerValueOfParameterNamed(paymentModeParamName); actualChanges.put(paymentModeParamName, newValue); actualChanges.put("locale", localeAsInput); this.chargePaymentMode = ChargePaymentMode.fromInt(newValue).getValue(); } } if (command.hasParameter("feeOnMonthDay")) { final MonthDay monthDay = command.extractMonthDayNamed("feeOnMonthDay"); final String actualValueEntered = command.stringValueOfParameterNamed("feeOnMonthDay"); final Integer dayOfMonthValue = monthDay.getDayOfMonth(); if (this.feeOnDay != dayOfMonthValue) { actualChanges.put("feeOnMonthDay", actualValueEntered); actualChanges.put("locale", localeAsInput); this.feeOnDay = dayOfMonthValue; } final Integer monthOfYear = monthDay.getMonthOfYear(); if (this.feeOnMonth != monthOfYear) { actualChanges.put("feeOnMonthDay", actualValueEntered); actualChanges.put("locale", localeAsInput); this.feeOnMonth = monthOfYear; } } final String feeInterval = "feeInterval"; if (command.isChangeInIntegerParameterNamed(feeInterval, this.feeInterval)) { final Integer newValue = command.integerValueOfParameterNamed(feeInterval); actualChanges.put(feeInterval, newValue); actualChanges.put("locale", localeAsInput); this.feeInterval = newValue; } final String feeFrequency = "feeFrequency"; if (command.isChangeInIntegerParameterNamed(feeFrequency, this.feeFrequency)) { final Integer newValue = command.integerValueOfParameterNamed(feeFrequency); actualChanges.put(feeFrequency, newValue); actualChanges.put("locale", localeAsInput); this.feeFrequency = newValue; } if (this.feeFrequency != null) { baseDataValidator.reset().parameter("feeInterval").value(this.feeInterval).notNull(); } final String penaltyParamName = "penalty"; if (command.isChangeInBooleanParameterNamed(penaltyParamName, this.penalty)) { final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(penaltyParamName); actualChanges.put(penaltyParamName, newValue); this.penalty = newValue; } final String activeParamName = "active"; if (command.isChangeInBooleanParameterNamed(activeParamName, this.active)) { final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(activeParamName); actualChanges.put(activeParamName, newValue); this.active = newValue; } // allow min and max cap to be only added to PERCENT_OF_AMOUNT for now if (isPercentageOfApprovedAmount()) { final String minCapParamName = "minCap"; if (command.isChangeInBigDecimalParameterNamed(minCapParamName, this.minCap)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(minCapParamName); actualChanges.put(minCapParamName, newValue); actualChanges.put("locale", localeAsInput); this.minCap = newValue; } final String maxCapParamName = "maxCap"; if (command.isChangeInBigDecimalParameterNamed(maxCapParamName, this.maxCap)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maxCapParamName); actualChanges.put(maxCapParamName, newValue); actualChanges.put("locale", localeAsInput); this.maxCap = newValue; } } if (this.penalty && ChargeTimeType.fromInt(this.chargeTimeType).isTimeOfDisbursement()) { throw new ChargeDueAtDisbursementCannotBePenaltyException(this.name); } if (!penalty && ChargeTimeType.fromInt(this.chargeTimeType).isOverdueInstallment()) { throw new ChargeMustBePenaltyException(name); } if (command.isChangeInLongParameterNamed(ChargesApiConstants.glAccountIdParamName, getIncomeAccountId())) { final Long newValue = command.longValueOfParameterNamed(ChargesApiConstants.glAccountIdParamName); actualChanges.put(ChargesApiConstants.glAccountIdParamName, newValue); } if (command.isChangeInLongParameterNamed(ChargesApiConstants.taxGroupIdParamName, getTaxGroupId())) { final Long newValue = command.longValueOfParameterNamed(ChargesApiConstants.taxGroupIdParamName); actualChanges.put(ChargesApiConstants.taxGroupIdParamName, newValue); if (taxGroup != null) { baseDataValidator.reset().parameter(ChargesApiConstants.taxGroupIdParamName) .failWithCode("modification.not.supported"); } } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } return actualChanges; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
private SavingsAccountCharge(final SavingsAccount savingsAccount, final Charge chargeDefinition, final BigDecimal amount, final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation, final LocalDate dueDate, final boolean status, MonthDay feeOnMonthDay, final Integer feeInterval) { this.savingsAccount = savingsAccount; this.charge = chargeDefinition; this.penaltyCharge = chargeDefinition.isPenalty(); this.chargeTime = (chargeTime == null) ? chargeDefinition.getChargeTimeType() : chargeTime.getValue(); if (isOnSpecifiedDueDate()) { if (dueDate == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); }/*from w ww . ja va2 s . c o m*/ } if (isAnnualFee() || isMonthlyFee()) { feeOnMonthDay = (feeOnMonthDay == null) ? chargeDefinition.getFeeOnMonthDay() : feeOnMonthDay; if (feeOnMonthDay == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); } this.feeOnMonth = feeOnMonthDay.getMonthOfYear(); this.feeOnDay = feeOnMonthDay.getDayOfMonth(); } else if (isWeeklyFee()) { if (dueDate == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); } /** * For Weekly fee feeOnDay is ISO standard day of the week. * Monday=1, Tuesday=2 */ this.feeOnDay = dueDate.getDayOfWeek(); } else { this.feeOnDay = null; this.feeOnMonth = null; this.feeInterval = null; } if (isMonthlyFee() || isWeeklyFee()) { this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval; } this.dueDate = (dueDate == null) ? null : dueDate.toDate(); this.chargeCalculation = chargeDefinition.getChargeCalculation(); if (chargeCalculation != null) { this.chargeCalculation = chargeCalculation.getValue(); } BigDecimal chargeAmount = chargeDefinition.getAmount(); if (amount != null) { chargeAmount = amount; } final BigDecimal transactionAmount = new BigDecimal(0); populateDerivedFields(transactionAmount, chargeAmount); if (this.isWithdrawalFee() || this.isSavingsNoActivity()) { this.amountOutstanding = BigDecimal.ZERO; } this.paid = determineIfFullyPaid(); this.status = status; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
public void update(final BigDecimal amount, final LocalDate dueDate, final MonthDay feeOnMonthDay, final Integer feeInterval) { final BigDecimal transactionAmount = BigDecimal.ZERO; if (dueDate != null) { this.dueDate = dueDate.toDate(); if (isWeeklyFee()) { this.feeOnDay = dueDate.getDayOfWeek(); }// w w w. java 2 s .co m } if (feeOnMonthDay != null) { this.feeOnMonth = feeOnMonthDay.getMonthOfYear(); this.feeOnDay = feeOnMonthDay.getDayOfMonth(); } if (feeInterval != null) { this.feeInterval = feeInterval; } if (amount != null) { switch (ChargeCalculationType.fromInt(this.chargeCalculation)) { case INVALID: break; case FLAT: this.amount = amount; break; case PERCENT_OF_AMOUNT: this.percentage = amount; this.amountPercentageAppliedTo = transactionAmount; this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage); this.amountOutstanding = calculateOutstanding(); break; case PERCENT_OF_AMOUNT_AND_INTEREST: this.percentage = amount; this.amount = null; this.amountPercentageAppliedTo = null; this.amountOutstanding = null; break; case PERCENT_OF_INTEREST: this.percentage = amount; this.amount = null; this.amountPercentageAppliedTo = null; this.amountOutstanding = null; break; } } }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(7); final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); if (command.isChangeInLocalDateParameterNamed(dueAsOfDateParamName, getDueLocalDate())) { final String valueAsInput = command.stringValueOfParameterNamed(dueAsOfDateParamName); actualChanges.put(dueAsOfDateParamName, valueAsInput); actualChanges.put(dateFormatParamName, dateFormatAsInput); actualChanges.put(localeParamName, localeAsInput); final LocalDate newValue = command.localDateValueOfParameterNamed(dueAsOfDateParamName); this.dueDate = newValue.toDate(); if (this.isWeeklyFee()) { this.feeOnDay = newValue.getDayOfWeek(); }// w w w.jav a 2 s .c o m } if (command.hasParameter(feeOnMonthDayParamName)) { final MonthDay monthDay = command.extractMonthDayNamed(feeOnMonthDayParamName); final String actualValueEntered = command.stringValueOfParameterNamed(feeOnMonthDayParamName); final Integer dayOfMonthValue = monthDay.getDayOfMonth(); if (this.feeOnDay != dayOfMonthValue) { actualChanges.put(feeOnMonthDayParamName, actualValueEntered); actualChanges.put(localeParamName, localeAsInput); this.feeOnDay = dayOfMonthValue; } final Integer monthOfYear = monthDay.getMonthOfYear(); if (this.feeOnMonth != monthOfYear) { actualChanges.put(feeOnMonthDayParamName, actualValueEntered); actualChanges.put(localeParamName, localeAsInput); this.feeOnMonth = monthOfYear; } } if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName); actualChanges.put(amountParamName, newValue); actualChanges.put(localeParamName, localeAsInput); switch (ChargeCalculationType.fromInt(this.chargeCalculation)) { case INVALID: break; case FLAT: this.amount = newValue; this.amountOutstanding = calculateOutstanding(); break; case PERCENT_OF_AMOUNT: this.percentage = newValue; this.amountPercentageAppliedTo = null; this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage); this.amountOutstanding = calculateOutstanding(); break; case PERCENT_OF_AMOUNT_AND_INTEREST: this.percentage = newValue; this.amount = null; this.amountPercentageAppliedTo = null; this.amountOutstanding = null; break; case PERCENT_OF_INTEREST: this.percentage = newValue; this.amount = null; this.amountPercentageAppliedTo = null; this.amountOutstanding = null; break; } } return actualChanges; }
From source file:fr.nicopico.dashclock.birthday.BirthdayService.java
License:Apache License
@Override protected void onUpdateData(int reason) { if (reason == UPDATE_REASON_SETTINGS_CHANGED) { updatePreferences();/* w ww .ja v a2s . c o m*/ } final Resources res = getResources(); final List<Birthday> birthdays = birthdayRetriever.getContactWithBirthdays(getApplicationContext(), contactGroupId); Configuration config = new Configuration(); config.setToDefaults(); // Disable/enable Android localization if (needToRefreshLocalization || (disableLocalization && !DEFAULT_LANG.equals(Locale.getDefault().getLanguage()))) { if (disableLocalization) { config.locale = new Locale(DEFAULT_LANG); } else { // Restore Android localization //noinspection ConstantConditions config.locale = Resources.getSystem().getConfiguration().locale; } Locale.setDefault(config.locale); getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); } DateTime today = new DateTime(); int upcomingBirthdays = 0; String collapsedTitle = null; String expandedTitle = null; StringBuilder body = new StringBuilder(); for (Birthday birthday : birthdays) { DateTime birthdayEvent; MonthDay birthdayDate = birthday.birthdayDate; try { birthdayEvent = birthdayDate.toDateTime(today); } catch (IllegalFieldValueException e) { if (birthdayDate.getDayOfMonth() == 29 && birthdayDate.getMonthOfYear() == 2) { // Birthday on February 29th (leap year) -> March 1st birthdayEvent = birthdayDate.dayOfMonth().addToCopy(1).toDateTime(today); } else { Log.e(TAG, "Invalid date", e); continue; } } // How many days before the birthday ? int days; if (birthdayEvent.isAfter(today) || birthdayEvent.isEqual(today)) { days = Days.daysBetween(today, birthdayEvent).getDays(); } else { // Next birthday event is next year days = Days.daysBetween(today, birthdayEvent.plusYears(1)).getDays(); } // Should the birthday be displayed ? if (days <= daysLimit) { upcomingBirthdays++; if (upcomingBirthdays == 1) { // A single birthday will be displayed collapsedTitle = birthday.displayName; expandedTitle = res.getString(R.string.single_birthday_title_format, birthday.displayName); } // More than 1 upcoming birthday: display contact name if (upcomingBirthdays > 1) { body.append("\n").append(birthday.displayName).append(", "); } // Age if (!birthday.unknownYear) { int age = today.get(DateTimeFieldType.year()) - birthday.year; body.append(res.getQuantityString(R.plurals.age_format, age, age)); body.append(' '); } // When int daysFormatResId; switch (days) { case 0: daysFormatResId = R.string.when_today_format; break; case 1: daysFormatResId = R.string.when_tomorrow_format; break; default: daysFormatResId = R.string.when_days_format; } body.append(res.getString(daysFormatResId, days)); } else { // All visible birthdays have been processed break; } } if (upcomingBirthdays > 0) { Intent clickIntent = buildClickIntent(birthdays.subList(0, upcomingBirthdays)); if (upcomingBirthdays > 1) { collapsedTitle += " + " + (upcomingBirthdays - 1); } // Display message publishUpdate( new ExtensionData().visible(true).icon(R.drawable.ic_extension_white).status(collapsedTitle) .expandedTitle(expandedTitle).expandedBody(body.toString()).clickIntent(clickIntent)); } else { // Nothing to show publishUpdate(new ExtensionData().visible(false)); } }