Example usage for org.joda.time LocalDate toDate

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

Introduction

In this page you can find the example usage for org.joda.time LocalDate 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.accounting.journalentry.api.DateParam.java

License:Apache License

public Date getDate(final String parameterName, final String dateFormat, final String localeAsString) {
    final Locale locale = JsonParserHelper.localeFromString(localeAsString);
    final LocalDate localDate = JsonParserHelper.convertFrom(this.dateAsString, parameterName, dateFormat,
            locale);/*from  ww  w. j a  v  a  2 s.c o  m*/
    return localDate.toDate();
}

From source file:com.gst.accounting.journalentry.service.JournalEntryWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private void validateBusinessRulesForJournalEntries(final JournalEntryCommand command) {
    /** check if date of Journal entry is valid ***/
    final LocalDate entryLocalDate = command.getTransactionDate();
    final Date transactionDate = entryLocalDate.toDateTimeAtStartOfDay().toDate();
    // shouldn't be in the future
    final Date todaysDate = new Date();
    if (transactionDate.after(todaysDate)) {
        throw new JournalEntryInvalidException(GL_JOURNAL_ENTRY_INVALID_REASON.FUTURE_DATE, transactionDate,
                null, null);//from www  .j  a  va2s . com
    }
    // shouldn't be before an accounting closure
    final GLClosure latestGLClosure = this.glClosureRepository
            .getLatestGLClosureByBranch(command.getOfficeId());
    if (latestGLClosure != null) {
        if (latestGLClosure.getClosingDate().after(transactionDate)
                || latestGLClosure.getClosingDate().equals(transactionDate)) {
            throw new JournalEntryInvalidException(GL_JOURNAL_ENTRY_INVALID_REASON.ACCOUNTING_CLOSED,
                    latestGLClosure.getClosingDate(), null, null);
        }
    }

    /*** check if credits and debits are valid **/
    final SingleDebitOrCreditEntryCommand[] credits = command.getCredits();
    final SingleDebitOrCreditEntryCommand[] debits = command.getDebits();

    // atleast one debit or credit must be present
    if (credits == null || credits.length <= 0 || debits == null || debits.length <= 0) {
        throw new JournalEntryInvalidException(GL_JOURNAL_ENTRY_INVALID_REASON.NO_DEBITS_OR_CREDITS, null, null,
                null);
    }

    checkDebitAndCreditAmounts(credits, debits);
}

From source file:com.gst.accounting.provisioning.service.ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private Date parseDate(JsonCommand command) {
    LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed("date", command.parsedJson());
    return localDate.toDate();
}

From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java

License:Apache License

private SmsCampaign(final String campaignName, final Integer campaignType, final Integer triggerType,
        final Report businessRuleId, final Long providerId, final String paramValue, final String message,
        final LocalDate submittedOnDate, final AppUser submittedBy, final String recurrence,
        final LocalDateTime localDateTime) {
    this.campaignName = campaignName;
    this.campaignType = campaignType;
    this.triggerType = SmsCampaignTriggerType.fromInt(triggerType).getValue();
    this.businessRuleId = businessRuleId;
    this.providerId = providerId;
    this.paramValue = paramValue;
    this.status = SmsCampaignStatus.PENDING.getValue();
    this.message = message;
    this.submittedOnDate = submittedOnDate.toDate();
    this.submittedBy = submittedBy;
    this.recurrence = recurrence;
    LocalDateTime recurrenceStartDate = new LocalDateTime();
    this.isVisible = true;
    if (localDateTime != null) {
        this.recurrenceStartDate = localDateTime.toDate();
    } else {/*from  w  ww . j  a  v  a2  s .co  m*/
        this.recurrenceStartDate = recurrenceStartDate.toDate();
    }
}

From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java

License:Apache License

public void activate(final AppUser currentUser, final DateTimeFormatter formatter,
        final LocalDate activationLocalDate) {

    if (isActive()) {
        // handle errors if already activated
        final String defaultUserMessage = "Cannot activate campaign. Campaign is already active.";
        final ApiParameterError error = ApiParameterError.parameterError("error.msg.campaign.already.active",
                defaultUserMessage, SmsCampaignValidator.activationDateParamName,
                activationLocalDate.toString(formatter));

        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        dataValidationErrors.add(error);

        throw new PlatformApiDataValidationException(dataValidationErrors);
    }// w ww.j a  v a2 s.  c  om
    this.approvedOnDate = activationLocalDate.toDate();
    this.approvedBy = currentUser;
    this.status = SmsCampaignStatus.ACTIVE.getValue();

    validate();
}

From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java

License:Apache License

public void close(final AppUser currentUser, final DateTimeFormatter dateTimeFormatter,
        final LocalDate closureLocalDate) {
    if (isClosed()) {
        // handle errors if already activated
        final String defaultUserMessage = "Cannot close campaign. Campaign already in closed state.";
        final ApiParameterError error = ApiParameterError.parameterError("error.msg.campaign.already.closed",
                defaultUserMessage, SmsCampaignValidator.statusParamName,
                SmsCampaignStatus.fromInt(this.status).getCode());

        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        dataValidationErrors.add(error);

        throw new PlatformApiDataValidationException(dataValidationErrors);
    }//  w  w  w . ja v a  2  s  .  c o  m
    if (this.triggerType.intValue() == SmsCampaignTriggerType.SCHEDULE.getValue()) {
        this.nextTriggerDate = null;
        this.lastTriggerDate = null;
    }
    this.closedBy = currentUser;
    this.closureDate = closureLocalDate.toDate();
    this.status = SmsCampaignStatus.CLOSED.getValue();
    validateClosureDate();
}

From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java

License:Apache License

public void reactivate(final AppUser currentUser, final DateTimeFormatter dateTimeFormat,
        final LocalDate reactivateLocalDate) {

    if (!isClosed()) {
        // handle errors if already activated
        final String defaultUserMessage = "Cannot reactivate campaign. Campaign must be in closed state.";
        final ApiParameterError error = ApiParameterError.parameterError("error.msg.campaign.must.be.closed",
                defaultUserMessage, SmsCampaignValidator.statusParamName,
                SmsCampaignStatus.fromInt(this.status).getCode());

        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        dataValidationErrors.add(error);

        throw new PlatformApiDataValidationException(dataValidationErrors);
    }/*from  ww  w.  j av a 2  s .  co  m*/

    this.approvedOnDate = reactivateLocalDate.toDate();
    this.status = SmsCampaignStatus.ACTIVE.getValue();
    this.approvedBy = currentUser;
    this.closureDate = null;
    this.isVisible = true;
    this.closedBy = null;

    validateReactivate();
}

From source file:com.gst.infrastructure.core.api.JsonCommand.java

License:Apache License

public Date DateValueOfParameterNamed(final String parameterName) {
    final LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed(parameterName, this.parsedCommand);
    if (localDate == null) {
        return null;
    }/*from   w w  w  .jav  a  2s.c  om*/
    return localDate.toDateTimeAtStartOfDay().toDate();
}

From source file:com.gst.organisation.holiday.domain.Holiday.java

License:Apache License

private Holiday(final String name, final LocalDate fromDate, final LocalDate toDate,
        final LocalDate repaymentsRescheduledTo, final Integer status, final boolean processed,
        final String description, final Set<Office> offices) {
    if (StringUtils.isNotBlank(name)) {
        this.name = name.trim();
    }// w  ww  .  j  ava2 s  .co  m

    if (fromDate != null) {
        this.fromDate = fromDate.toDate();
    }

    if (toDate != null) {
        this.toDate = toDate.toDate();
    }

    if (repaymentsRescheduledTo != null) {
        this.repaymentsRescheduledTo = repaymentsRescheduledTo.toDate();
    }

    this.status = status;
    this.processed = processed;

    if (StringUtils.isNotBlank(name)) {
        this.description = description.trim();
    } else {
        this.description = null;
    }

    if (offices != null) {
        this.offices = offices;
    }
}

From source file:com.gst.organisation.holiday.domain.HolidayRepositoryWrapper.java

License:Apache License

public boolean isHoliday(Long officeId, LocalDate transactionDate) {
    final List<Holiday> holidays = findByOfficeIdAndGreaterThanDate(officeId, transactionDate.toDate());
    return HolidayUtil.isHoliday(transactionDate, holidays);
}