Example usage for org.joda.time LocalDateTime toDate

List of usage examples for org.joda.time LocalDateTime toDate

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime toDate.

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:com.gst.portfolio.calendar.domain.Calendar.java

License:Apache License

public Map<String, Object> update(final JsonCommand command, final Boolean areActiveEntitiesSynced) {

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

    if (command.isChangeInStringParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.TITLE.getValue(), this.title)) {
        final String newValue = command
                .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.TITLE.getValue());
        actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.TITLE.getValue(), newValue);
        this.title = StringUtils.defaultIfEmpty(newValue, null);
    }/*from   w w w  .j  ava2  s . c om*/

    if (command.isChangeInStringParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.DESCRIPTION.getValue(),
            this.description)) {
        final String newValue = command
                .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.DESCRIPTION.getValue());
        actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.DESCRIPTION.getValue(), newValue);
        this.description = StringUtils.defaultIfEmpty(newValue, null);
    }

    if (command.isChangeInStringParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.LOCATION.getValue(),
            this.location)) {
        final String newValue = command
                .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.LOCATION.getValue());
        actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.LOCATION.getValue(), newValue);
        this.location = StringUtils.defaultIfEmpty(newValue, null);
    }

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();
    final String startDateParamName = CALENDAR_SUPPORTED_PARAMETERS.START_DATE.getValue();
    if (command.isChangeInLocalDateParameterNamed(startDateParamName, getStartDateLocalDate())) {

        final String valueAsInput = command.stringValueOfParameterNamed(startDateParamName);
        final LocalDate newValue = command.localDateValueOfParameterNamed(startDateParamName);
        final LocalDate currentDate = DateUtils.getLocalDateOfTenant();

        if (newValue.isBefore(currentDate)) {
            final String defaultUserMessage = "New meeting effective from date cannot be in past";
            throw new CalendarDateException("new.start.date.cannot.be.in.past", defaultUserMessage, newValue,
                    getStartDateLocalDate());
        } else if (isStartDateAfter(newValue) && isStartDateBeforeOrEqual(currentDate)) {
            // new meeting date should be on or after start date or current
            // date
            final String defaultUserMessage = "New meeting effective from date cannot be a date before existing meeting start date";
            throw new CalendarDateException("new.start.date.before.existing.date", defaultUserMessage, newValue,
                    getStartDateLocalDate());
        } else {
            actualChanges.put(startDateParamName, valueAsInput);
            actualChanges.put("dateFormat", dateFormatAsInput);
            actualChanges.put("locale", localeAsInput);
            this.startDate = newValue.toDate();
        }
    }

    final String endDateParamName = CALENDAR_SUPPORTED_PARAMETERS.END_DATE.getValue();
    if (command.isChangeInLocalDateParameterNamed(endDateParamName, getEndDateLocalDate())) {
        final String valueAsInput = command.stringValueOfParameterNamed(endDateParamName);
        actualChanges.put(endDateParamName, valueAsInput);
        actualChanges.put("dateFormat", dateFormatAsInput);
        actualChanges.put("locale", localeAsInput);

        final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName);
        this.endDate = newValue.toDate();
    }

    final String durationParamName = CALENDAR_SUPPORTED_PARAMETERS.DURATION.getValue();
    if (command.isChangeInIntegerSansLocaleParameterNamed(durationParamName, this.duration)) {
        final Integer newValue = command.integerValueSansLocaleOfParameterNamed(durationParamName);
        actualChanges.put(durationParamName, newValue);
        this.duration = newValue;
    }

    // Do not allow to change calendar type
    // TODO: AA Instead of throwing an exception, do not allow meeting
    // calendar type to update.
    final String typeParamName = CALENDAR_SUPPORTED_PARAMETERS.TYPE_ID.getValue();
    if (command.isChangeInIntegerSansLocaleParameterNamed(typeParamName, this.typeId)) {
        final Integer newValue = command.integerValueSansLocaleOfParameterNamed(typeParamName);
        final String defaultUserMessage = "Meeting calendar type update is not supported";
        final String oldMeeingType = CalendarType.fromInt(this.typeId).name();
        final String newMeetingType = CalendarType.fromInt(newValue).name();

        throw new CalendarParameterUpdateNotSupportedException("meeting.type", defaultUserMessage,
                newMeetingType, oldMeeingType);
        /*
         * final Integer newValue =
         * command.integerValueSansLocaleOfParameterNamed(typeParamName);
         * actualChanges.put(typeParamName, newValue); this.typeId =
         * newValue;
         */
    }

    final String repeatingParamName = CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue();
    if (command.isChangeInBooleanParameterNamed(repeatingParamName, this.repeating)) {
        final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(repeatingParamName);
        actualChanges.put(repeatingParamName, newValue);
        this.repeating = newValue;
    }

    // if repeating is false then update recurrence to NULL
    if (!this.repeating)
        this.recurrence = null;

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(CALENDAR_RESOURCE_NAME);

    final CalendarType calendarType = CalendarType.fromInt(this.typeId);
    if (calendarType.isCollection() && !this.repeating) {
        baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue())
                .failWithCodeNoParameterAddedToErrorCode("must.repeat.for.collection.calendar");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    final String newRecurrence = Calendar.constructRecurrence(command, this);
    if (!StringUtils.isBlank(this.recurrence) && !newRecurrence.equalsIgnoreCase(this.recurrence)) {
        /*
         * If active entities like JLG loan or RD accounts are synced to the
         * calendar then do not allow to change meeting frequency
         */

        if (areActiveEntitiesSynced && !CalendarUtils.isFrequencySame(this.recurrence, newRecurrence)) {
            final String defaultUserMessage = "Update of meeting frequency is not supported";
            throw new CalendarParameterUpdateNotSupportedException("meeting.frequency", defaultUserMessage);
        }

        /*
         * If active entities like JLG loan or RD accounts are synced to the
         * calendar then do not allow to change meeting interval
         */

        if (areActiveEntitiesSynced && !CalendarUtils.isIntervalSame(this.recurrence, newRecurrence)) {
            final String defaultUserMessage = "Update of meeting interval is not supported";
            throw new CalendarParameterUpdateNotSupportedException("meeting.interval", defaultUserMessage);
        }

        actualChanges.put("recurrence", newRecurrence);
        this.recurrence = StringUtils.defaultIfEmpty(newRecurrence, null);
    }

    final String remindByParamName = CALENDAR_SUPPORTED_PARAMETERS.REMIND_BY_ID.getValue();
    if (command.isChangeInIntegerSansLocaleParameterNamed(remindByParamName, this.remindById)) {
        final Integer newValue = command.integerValueSansLocaleOfParameterNamed(remindByParamName);
        actualChanges.put(remindByParamName, newValue);
        this.remindById = newValue;
    }

    final String firstRemindarParamName = CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue();
    if (command.isChangeInIntegerSansLocaleParameterNamed(firstRemindarParamName, this.firstReminder)) {
        final Integer newValue = command.integerValueSansLocaleOfParameterNamed(firstRemindarParamName);
        actualChanges.put(firstRemindarParamName, newValue);
        this.firstReminder = newValue;
    }

    final String secondRemindarParamName = CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue();
    if (command.isChangeInIntegerSansLocaleParameterNamed(secondRemindarParamName, this.secondReminder)) {
        final Integer newValue = command.integerValueSansLocaleOfParameterNamed(secondRemindarParamName);
        actualChanges.put(secondRemindarParamName, newValue);
        this.secondReminder = newValue;
    }

    final String timeFormat = command
            .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.Time_Format.getValue());
    final String time = CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue();
    if (command.isChangeInTimeParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue(),
            this.meetingtime, timeFormat)) {
        final String newValue = command
                .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue());
        actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue(), newValue);
        LocalDateTime timeInLocalDateTimeFormat = command.localTimeValueOfParameterNamed(time);
        if (timeInLocalDateTimeFormat != null) {
            this.meetingtime = timeInLocalDateTimeFormat.toDate();
        }

    }

    return actualChanges;
}

From source file:com.gst.portfolio.loanaccount.domain.LoanAccountDomainServiceJpa.java

License:Apache License

@Override
public Map<String, Object> foreCloseLoan(final Loan loan, final LocalDate foreClosureDate,
        final String noteText) {
    this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.LOAN_FORECLOSURE,
            constructEntityMap(BUSINESS_ENTITY.LOAN, loan));
    MonetaryCurrency currency = loan.getCurrency();
    LocalDateTime createdDate = DateUtils.getLocalDateTimeOfTenant();
    final Map<String, Object> changes = new LinkedHashMap<>();
    List<LoanTransaction> newTransactions = new ArrayList<>();

    final List<Long> existingTransactionIds = new ArrayList<>();
    final List<Long> existingReversedTransactionIds = new ArrayList<>();
    existingTransactionIds.addAll(loan.findExistingTransactionIds());
    existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
    final ScheduleGeneratorDTO scheduleGeneratorDTO = null;
    AppUser appUser = getAppUserIfPresent();
    final LoanRepaymentScheduleInstallment foreCloseDetail = loan.fetchLoanForeclosureDetail(foreClosureDate);
    if (loan.isPeriodicAccrualAccountingEnabledOnLoanProduct()
            && (loan.getAccruedTill() == null || !foreClosureDate.isEqual(loan.getAccruedTill()))) {
        loan.reverseAccrualsAfter(foreClosureDate);
        Money[] accruedReceivables = loan.getReceivableIncome(foreClosureDate);
        Money interestPortion = foreCloseDetail.getInterestCharged(currency).minus(accruedReceivables[0]);
        Money feePortion = foreCloseDetail.getFeeChargesCharged(currency).minus(accruedReceivables[1]);
        Money penaltyPortion = foreCloseDetail.getPenaltyChargesCharged(currency).minus(accruedReceivables[2]);
        Money total = interestPortion.plus(feePortion).plus(penaltyPortion);
        if (total.isGreaterThanZero()) {
            LoanTransaction accrualTransaction = LoanTransaction.accrueTransaction(loan, loan.getOffice(),
                    foreClosureDate, total.getAmount(), interestPortion.getAmount(), feePortion.getAmount(),
                    penaltyPortion.getAmount(), appUser);
            LocalDate fromDate = loan.getDisbursementDate();
            if (loan.getAccruedTill() != null) {
                fromDate = loan.getAccruedTill();
            }/*w w  w  .j  a va  2  s. c  o m*/
            createdDate = createdDate.plusSeconds(1);
            newTransactions.add(accrualTransaction);
            loan.addLoanTransaction(accrualTransaction);
            Set<LoanChargePaidBy> accrualCharges = accrualTransaction.getLoanChargesPaid();
            for (LoanCharge loanCharge : loan.charges()) {
                if (loanCharge.isActive() && !loanCharge.isPaid()
                        && (loanCharge.isDueForCollectionFromAndUpToAndIncluding(fromDate, foreClosureDate)
                                || loanCharge.isInstalmentFee())) {
                    final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(accrualTransaction,
                            loanCharge, loanCharge.getAmountOutstanding(currency).getAmount(), null);
                    accrualCharges.add(loanChargePaidBy);
                }
            }
        }
    }

    Money interestPayable = foreCloseDetail.getInterestCharged(currency);
    Money feePayable = foreCloseDetail.getFeeChargesCharged(currency);
    Money penaltyPayable = foreCloseDetail.getPenaltyChargesCharged(currency);
    Money payPrincipal = foreCloseDetail.getPrincipal(currency);
    loan.updateInstallmentsPostDate(foreClosureDate);

    LoanTransaction payment = null;

    if (payPrincipal.plus(interestPayable).plus(feePayable).plus(penaltyPayable).isGreaterThanZero()) {
        final PaymentDetail paymentDetail = null;
        String externalId = null;
        final LocalDateTime currentDateTime = DateUtils.getLocalDateTimeOfTenant();
        payment = LoanTransaction.repayment(loan.getOffice(),
                payPrincipal.plus(interestPayable).plus(feePayable).plus(penaltyPayable), paymentDetail,
                foreClosureDate, externalId, currentDateTime, appUser);
        createdDate = createdDate.plusSeconds(1);
        payment.updateCreatedDate(createdDate.toDate());
        payment.updateLoan(loan);
        newTransactions.add(payment);
    }

    List<Long> transactionIds = new ArrayList<>();
    final ChangedTransactionDetail changedTransactionDetail = loan.handleForeClosureTransactions(payment,
            defaultLoanLifecycleStateMachine(), scheduleGeneratorDTO, appUser);

    /***
     * TODO Vishwas Batch save is giving me a
     * HibernateOptimisticLockingFailureException, looping and saving for
     * the time being, not a major issue for now as this loop is entered
     * only in edge cases (when a payment is made before the latest payment
     * recorded against the loan)
     ***/

    for (LoanTransaction newTransaction : newTransactions) {
        saveLoanTransactionWithDataIntegrityViolationChecks(newTransaction);
        transactionIds.add(newTransaction.getId());
    }
    changes.put("transactions", transactionIds);
    changes.put("eventAmount", payPrincipal.getAmount().negate());

    if (changedTransactionDetail != null) {
        for (Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings()
                .entrySet()) {
            saveLoanTransactionWithDataIntegrityViolationChecks(mapEntry.getValue());
            // update loan with references to the newly created transactions
            loan.getLoanTransactions().add(mapEntry.getValue());
            updateLoanTransaction(mapEntry.getKey(), mapEntry.getValue());
        }
    }

    saveAndFlushLoanWithDataIntegrityViolationChecks(loan);

    if (StringUtils.isNotBlank(noteText)) {
        changes.put("note", noteText);
        final Note note = Note.loanNote(loan, noteText);
        this.noteRepository.save(note);
    }

    postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, false);
    this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.LOAN_FORECLOSURE,
            constructEntityMap(BUSINESS_ENTITY.LOAN_TRANSACTION, payment));
    return changes;

}

From source file:com.gst.portfolio.loanaccount.domain.LoanTransaction.java

License:Apache License

private LoanTransaction(final Loan loan, final Office office, final Integer typeOf, final Date dateOf,
        final BigDecimal amount, final BigDecimal principalPortion, final BigDecimal interestPortion,
        final BigDecimal feeChargesPortion, final BigDecimal penaltyChargesPortion,
        final BigDecimal overPaymentPortion, final boolean reversed, final PaymentDetail paymentDetail,
        final String externalId, final LocalDateTime createdDate, final AppUser appUser) {
    super();/*from w ww  .  ja v  a  2  s  . c  om*/
    this.loan = loan;
    this.typeOf = typeOf;
    this.dateOf = dateOf;
    this.amount = amount;
    this.principalPortion = principalPortion;
    this.interestPortion = interestPortion;
    this.feeChargesPortion = feeChargesPortion;
    this.penaltyChargesPortion = penaltyChargesPortion;
    this.overPaymentPortion = overPaymentPortion;
    this.reversed = reversed;
    this.paymentDetail = paymentDetail;
    this.office = office;
    this.externalId = externalId;
    this.submittedOnDate = DateUtils.getDateOfTenant();
    this.createdDate = createdDate.toDate();
    this.appUser = appUser;
}

From source file:com.gst.portfolio.loanaccount.domain.LoanTransaction.java

License:Apache License

private LoanTransaction(final Loan loan, final Office office, final LoanTransactionType type,
        final BigDecimal amount, final LocalDate date, final String externalId, final LocalDateTime createdDate,
        final AppUser appUser) {
    this.loan = loan;
    this.typeOf = type.getValue();
    this.amount = amount;
    this.dateOf = date.toDateTimeAtStartOfDay().toDate();
    this.externalId = externalId;
    this.office = office;
    this.submittedOnDate = DateUtils.getDateOfTenant();
    this.createdDate = createdDate.toDate();
    this.appUser = appUser;
}

From source file:com.gst.portfolio.loanaccount.domain.LoanTransaction.java

License:Apache License

private LoanTransaction(final Loan loan, final Office office, final LoanTransactionType type,
        final PaymentDetail paymentDetail, final BigDecimal amount, final LocalDate date,
        final String externalId, final LocalDateTime createdDate, final AppUser appUser) {
    this.loan = loan;
    this.typeOf = type.getValue();
    this.paymentDetail = paymentDetail;
    this.amount = amount;
    this.dateOf = date.toDateTimeAtStartOfDay().toDate();
    this.externalId = externalId;
    this.office = office;
    this.submittedOnDate = DateUtils.getDateOfTenant();
    this.createdDate = createdDate.toDate();
    this.appUser = appUser;
}

From source file:com.heisenberg.mongo.MongoCollection.java

License:Apache License

public void writeTimeOpt(BasicDBObject o, String fieldName, LocalDateTime value) {
    if (value != null) {
        o.put(fieldName, value.toDate());
    }//w  ww.j a  v  a  2s.c  om
}

From source file:com.makotogo.mobile.hoursdroid.BillingSummaryFragment.java

License:Apache License

private void processEndDateRequestResult(Intent data) {
    String METHOD = "processEndDateRequestResult(Intent): ";
    Date endDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME);
    long now = System.currentTimeMillis();
    long end = endDate.getTime();
    long begin = (mBeginDate != null) ? mBeginDate.getTime() : DEFAULT_BEGIN_TIME_MILLIS;
    if (begin <= end) {
        // Sanity Check #2 - Begin must be before or equal to End.
        // It is. Set the end date the user chose, at the END of that day
        LocalDateTime ldt = new LocalDateTime(endDate).withHourOfDay(23).withMinuteOfHour(59);
        mEndDate = ldt.toDate();
        // Update the new filter setting
        updateSharedPreferences();/*w  ww  .  j av a 2  s . c  o m*/
    } else {
        String message = "Begin date/time cannot be later than End date/time. Please try again.";
        Log.e(TAG, METHOD + message);
        Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
    }
}

From source file:com.makotogo.mobile.hoursdroid.util.RoundingUtils.java

License:Apache License

/**
 * Calculates a new Date object, and rounds down the seconds and milliseconds to zero
 * to give a nice new value at the minute boundary.
 *
 * @return//  w w w. j av a2  s .  c  o  m
 */
public static Date calculateDateWithRounding() {
    final String METHOD = "calculateDateWithRounding()";
    LocalDateTime localDateTime = new LocalDateTime().withSecondOfMinute(0).withMillisOfSecond(0);
    Date ret = localDateTime.toDate();
    Log.d(TAG, METHOD + "Returning new date: " + ret);
    return ret;
}

From source file:com.pandits.opensource.JodaTimeUtil.java

License:Open Source License

public Date getAdjustedDateInTimeZone(Date date, TimeZone timeZone) {
    LocalDateTime dateTime = createLocalDateTime(date.getTime(), timeZone);
    return dateTime.toDate();
}

From source file:com.sam.moca.server.expression.operators.arith.MinusExpression.java

License:Open Source License

protected MocaValue doOper(MocaValue left, MocaValue right) {
    if (left.getType() == MocaType.DATETIME) {
        if (right.getType() == MocaType.DOUBLE || right.getType() == MocaType.INTEGER) {
            Date d = left.asDate();

            // If the left side is null, return a null result.
            if (d == null) {
                return new MocaValue(MocaType.DATETIME, null);
            }//from  w  w w  . j ava2  s. c o m

            LocalDateTime dt = new LocalDateTime(d);

            int wholeDays = right.asInt();
            double dayPart = right.asDouble() - wholeDays;
            int msDiff = (int) (dayPart * 1000.0 * 3600.0 * 24.0);

            dt = dt.minusDays(wholeDays).minusMillis(msDiff);

            return new MocaValue(MocaType.DATETIME, dt.toDateTime().toDate());
        } else if (right.getType() == MocaType.DATETIME) {
            Date leftDate = left.asDate();
            Date rightDate = right.asDate();

            // If either the left side or the right side is null, return null
            if (leftDate == null || rightDate == null) {
                return new MocaValue(MocaType.DOUBLE, null);
            }

            DateTime leftDt = new DateTime(leftDate);
            DateTime rightDt = new DateTime(rightDate);

            int fullDays = Days.daysBetween(rightDt, leftDt).getDays();

            LocalTime leftTime = new LocalTime(leftDt);
            LocalTime rightTime = new LocalTime(rightDt);

            int ms = leftTime.getMillisOfDay() - rightTime.getMillisOfDay();
            double partial = ((double) ms / (1000.0 * 3600.0 * 24.0));

            if (partial < 0.0 && leftDate.after(rightDate)) {
                partial += 1.0;
            } else if (partial > 0.0 && rightDate.after(leftDate)) {
                partial -= 1.0;
            }

            double daysDiff = (double) fullDays + partial;

            return new MocaValue(MocaType.DOUBLE, daysDiff);
        }
    } else {
        if (left.getType() == MocaType.DOUBLE || right.getType() == MocaType.DOUBLE) {
            return new MocaValue(MocaType.DOUBLE, Double.valueOf(left.asDouble() - right.asDouble()));
        } else {
            return new MocaValue(MocaType.INTEGER, Integer.valueOf(left.asInt() - right.asInt()));
        }
    }
    return null;
}