List of usage examples for org.joda.time LocalDate getDayOfWeek
public int getDayOfWeek()
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(); }//from w ww. j a v a2 s. co 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:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
private LocalDate setDayOfWeek(LocalDate nextDueLocalDate) { if (this.feeOnDay != nextDueLocalDate.getDayOfWeek()) { nextDueLocalDate = nextDueLocalDate.withDayOfWeek(this.feeOnDay); }//from ww w. ja v a2 s.co m return nextDueLocalDate; }
From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private CalendarInstance getCalendarInstance(final JsonCommand command, RecurringDepositAccount account) { CalendarInstance calendarInstance = null; final boolean isCalendarInherited = command .booleanPrimitiveValueOfParameterNamed(isCalendarInheritedParamName); if (isCalendarInherited) { Set<Group> groups = account.getClient().getGroups(); Long groupId = null;/*from www.j av a2 s. c o m*/ if (groups.isEmpty()) { final String defaultUserMessage = "Client does not belong to group/center. Cannot follow group/center meeting frequency."; throw new GeneralPlatformDomainRuleException( "error.msg.recurring.deposit.account.cannot.create.not.belongs.to.any.groups.to.follow.meeting.frequency", defaultUserMessage, account.clientId()); } else if (groups.size() > 1) { final String defaultUserMessage = "Client belongs to more than one group. Cannot support recurring deposit."; throw new GeneralPlatformDomainRuleException( "error.msg.recurring.deposit.account.cannot.create.belongs.to.multiple.groups", defaultUserMessage, account.clientId()); } else { Group group = groups.iterator().next(); Group parent = group.getParent(); Integer entityType = CalendarEntityType.GROUPS.getValue(); if (parent != null) { groupId = parent.getId(); entityType = CalendarEntityType.CENTERS.getValue(); } else { groupId = group.getId(); } CalendarInstance parentCalendarInstance = this.calendarInstanceRepository .findByEntityIdAndEntityTypeIdAndCalendarTypeId(groupId, entityType, CalendarType.COLLECTION.getValue()); if (parentCalendarInstance == null) { final String defaultUserMessage = "Meeting frequency is not attached to the Group/Center to which the client belongs to."; throw new GeneralPlatformDomainRuleException( "error.msg.meeting.frequency.not.attached.to.group.to.which.client.belongs.to", defaultUserMessage, account.clientId()); } calendarInstance = CalendarInstance.from(parentCalendarInstance.getCalendar(), account.getId(), CalendarEntityType.SAVINGS.getValue()); } } else { LocalDate calendarStartDate = account.depositStartDate(); final Integer frequencyType = command .integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName); final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType); final Integer frequency = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName); final Integer repeatsOnDay = calendarStartDate.getDayOfWeek(); final String title = "recurring_savings_" + account.getId(); final Calendar calendar = Calendar.createRepeatingCalendar(title, calendarStartDate, CalendarType.COLLECTION.getValue(), CalendarFrequencyType.from(periodFrequencyType), frequency, repeatsOnDay, null); calendarInstance = CalendarInstance.from(calendar, account.getId(), CalendarEntityType.SAVINGS.getValue()); } if (calendarInstance == null) { final String defaultUserMessage = "No valid recurring details available for recurring depost account creation."; throw new GeneralPlatformDomainRuleException( "error.msg.recurring.deposit.account.cannot.create.no.valid.recurring.details.available", defaultUserMessage, account.clientId()); } return calendarInstance; }
From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Transactional @Override/*from w w w.j a va2 s . c om*/ public CommandProcessingResult modifyRDApplication(final Long accountId, final JsonCommand command) { try { this.depositAccountDataValidator.validateRecurringDepositForUpdate(command.json()); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final Map<String, Object> changes = new LinkedHashMap<>(20); final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler .assembleFrom(accountId, DepositAccountType.RECURRING_DEPOSIT); checkClientOrGroupActive(account); account.modifyApplication(command, changes); account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), DepositAccountType.RECURRING_DEPOSIT.resourceName()); if (!changes.isEmpty()) { updateFDAndRDCommonChanges(changes, command, account); final MathContext mc = MathContext.DECIMAL64; final CalendarInstance calendarInstance = this.calendarInstanceRepository .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); final Calendar calendar = calendarInstance.getCalendar(); final PeriodFrequencyType frequencyType = CalendarFrequencyType .from(CalendarUtils.getFrequency(calendar.getRecurrence())); Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); frequency = frequency == -1 ? 1 : frequency; account.generateSchedule(frequencyType, frequency, calendar); final boolean isPreMatureClosure = false; account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); account.validateApplicableInterestRate(); this.savingAccountRepository.save(account); } // update calendar details if (!account.isCalendarInherited()) { final LocalDate calendarStartDate = account.depositStartDate(); final Integer frequencyType = command .integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName); final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType); final Integer frequency = command .integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName); final Integer repeatsOnDay = calendarStartDate.getDayOfWeek(); CalendarInstance calendarInstance = this.calendarInstanceRepository .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); Calendar calendar = calendarInstance.getCalendar(); calendar.updateRepeatingCalendar(calendarStartDate, CalendarFrequencyType.from(periodFrequencyType), frequency, repeatsOnDay, null); this.calendarInstanceRepository.save(calendarInstance); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(accountId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(accountId) // .with(changes) // .build(); } catch (final DataAccessException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResult(Long.valueOf(-1)); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return new CommandProcessingResult(Long.valueOf(-1)); } }
From source file:com.helger.datetime.holiday.parser.AbstractHolidayParser.java
License:Apache License
/** * Determines if the provided date shall be substituted. * /* w ww .j a va2s. c om*/ * @param aFixed * The date to be checked. May not be <code>null</code>. * @param aMoveCond * The move condition. May not be <code>null</code>. */ protected static final boolean shallBeMoved(@Nonnull final LocalDate aFixed, @Nonnull final MovingCondition aMoveCond) { return aFixed.getDayOfWeek() == XMLUtil.getWeekday(aMoveCond.getSubstitute()); }
From source file:com.helger.datetime.holiday.parser.AbstractHolidayParser.java
License:Apache License
/** * Moves the date using the FixedMoving information * // w w w . ja v a 2 s . co m * @param aMoveCond * @param aDate * @return The moved date */ private static LocalDate _moveDate(final MovingCondition aMoveCond, final LocalDate aDate) { final int nWeekday = XMLUtil.getWeekday(aMoveCond.getWeekday()); final int nDirection = aMoveCond.getWith() == With.NEXT ? 1 : -1; LocalDate aMovedDate = aDate; while (aMovedDate.getDayOfWeek() != nWeekday) { aMovedDate = aMovedDate.plusDays(nDirection); } return aMovedDate; }
From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayBetweenFixedParser.java
License:Apache License
/** * Parses the provided configuration and creates holidays for the provided * year./* w w w . ja v a 2s.c om*/ */ public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) { for (final FixedWeekdayBetweenFixed aFixedWeekdayBetweenFixed : aConfig.getFixedWeekdayBetweenFixed()) { if (!isValid(aFixedWeekdayBetweenFixed, nYear)) continue; final int nExpectedWeekday = XMLUtil.getWeekday(aFixedWeekdayBetweenFixed.getWeekday()); LocalDate aFrom = XMLUtil.create(nYear, aFixedWeekdayBetweenFixed.getFrom()); final LocalDate aTo = XMLUtil.create(nYear, aFixedWeekdayBetweenFixed.getTo()); LocalDate aResult = null; while (!aFrom.isAfter(aTo)) { if (aFrom.getDayOfWeek() == nExpectedWeekday) { aResult = aFrom; break; } aFrom = aFrom.plusDays(1); } if (aResult != null) { final IHolidayType aType = XMLUtil.getType(aFixedWeekdayBetweenFixed.getLocalizedType()); final String sPropertyKey = aFixedWeekdayBetweenFixed.getDescriptionPropertiesKey(); aHolidayMap.add(aResult, new ResourceBundleHoliday(aType, sPropertyKey)); } } }
From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
protected static LocalDate parse(final int nYear, final FixedWeekdayInMonth aFixedWeekdayInMonth) { LocalDate aDate = PDTFactory.createLocalDate(nYear, XMLUtil.getMonth(aFixedWeekdayInMonth.getMonth()), 1); int nDirection = 1; if (aFixedWeekdayInMonth.getWhich() == Which.LAST) { aDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue()); nDirection = -1;/*from w w w . j ava2s. c o m*/ } final int nWeekDay = XMLUtil.getWeekday(aFixedWeekdayInMonth.getWeekday()); while (aDate.getDayOfWeek() != nWeekDay) { aDate = aDate.plusDays(nDirection); } switch (aFixedWeekdayInMonth.getWhich()) { case FIRST: break; case SECOND: aDate = aDate.plusDays(7); break; case THIRD: aDate = aDate.plusDays(14); break; case FOURTH: aDate = aDate.plusDays(21); break; case LAST: break; } return aDate; }
From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayRelativeToFixedParser.java
License:Apache License
/** * Parses the provided configuration and creates holidays for the provided * year./*from w w w . ja v a2 s .com*/ */ public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) { for (final FixedWeekdayRelativeToFixed aFixedWeekdayRelativeToFixed : aConfig .getFixedWeekdayRelativeToFixed()) { if (!isValid(aFixedWeekdayRelativeToFixed, nYear)) continue; // parsing fixed day final int nExpectedWeekday = XMLUtil.getWeekday(aFixedWeekdayRelativeToFixed.getWeekday()); LocalDate aDay = XMLUtil.create(nYear, aFixedWeekdayRelativeToFixed.getDay()); do { // move fixed to first occurrence of weekday aDay = aFixedWeekdayRelativeToFixed.getWhen() == When.AFTER ? aDay.plusDays(1) : aDay.minusDays(1); } while (aDay.getDayOfWeek() != nExpectedWeekday); int nDays = 0; switch (aFixedWeekdayRelativeToFixed.getWhich()) { case FIRST: break; case SECOND: nDays = 7; break; case THIRD: nDays = 14; break; case FOURTH: nDays = 21; break; case LAST: // seems to be unsupported break; } // move day further if it is second, third or fourth weekday aDay = aFixedWeekdayRelativeToFixed.getWhen() == When.AFTER ? aDay.plusDays(nDays) : aDay.minusDays(nDays); final IHolidayType aType = XMLUtil.getType(aFixedWeekdayRelativeToFixed.getLocalizedType()); final String sPropertyKey = aFixedWeekdayRelativeToFixed.getDescriptionPropertiesKey(); aHolidayMap.add(aDay, new ResourceBundleHoliday(aType, sPropertyKey)); } }
From source file:com.helger.datetime.holiday.parser.impl.RelativeToFixedParser.java
License:Apache License
public void parse(final int nYear, final HolidayMap aHolidays, final Holidays aConfig) { for (final RelativeToFixed aRelativeToFixed : aConfig.getRelativeToFixed()) { if (!isValid(aRelativeToFixed, nYear)) continue; LocalDate aFixed = XMLUtil.create(nYear, aRelativeToFixed.getDate()); if (aRelativeToFixed.getWeekday() != null) { // if weekday is set -> move to weekday final int nExpectedWeekday = XMLUtil.getWeekday(aRelativeToFixed.getWeekday()); final int nDirection = (aRelativeToFixed.getWhen() == When.BEFORE ? -1 : 1); do {/* ww w . ja v a 2s . c om*/ aFixed = aFixed.plusDays(nDirection); } while (aFixed.getDayOfWeek() != nExpectedWeekday); } else if (aRelativeToFixed.getDays() != null) { // if number of days set -> move number of days aFixed = aFixed .plusDays(aRelativeToFixed.getWhen() == When.BEFORE ? -aRelativeToFixed.getDays().intValue() : aRelativeToFixed.getDays().intValue()); } final IHolidayType aType = XMLUtil.getType(aRelativeToFixed.getLocalizedType()); final String sPropertyKey = aRelativeToFixed.getDescriptionPropertiesKey(); aHolidays.add(aFixed, new ResourceBundleHoliday(aType, sPropertyKey)); } }