Example usage for org.joda.time LocalDateTime getSecondOfMinute

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

Introduction

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

Prototype

public int getSecondOfMinute() 

Source Link

Document

Get the second of minute field value.

Usage

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);
    if (emailCampaign == null) {
        throw new EmailCampaignNotFound(campaignId);
    }/*from  w  w w  . j  a  va 2  s.com*/
    LocalDateTime nextTriggerDate = emailCampaign.getNextTriggerDate();
    emailCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    //calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
            emailCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means next run time is in the past calculate a new future date
        nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
                emailCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    emailCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.emailCampaignRepository.saveAndFlush(emailCampaign);
}

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override//from   w w w.j a  v a  2s  . c  o m
public CommandProcessingResult activateEmailCampaign(Long campaignId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();

    this.emailCampaignValidator.validateActivation(command.json());

    final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);

    if (emailCampaign == null) {
        throw new EmailCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate activationDate = command.localDateValueOfParameterNamed("activationDate");

    emailCampaign.activate(currentUser, fmt, activationDate);

    this.emailCampaignRepository.saveAndFlush(emailCampaign);

    if (emailCampaign.isDirect()) {
        insertDirectCampaignIntoEmailOutboundTable(emailCampaign.getParamValue(),
                emailCampaign.getEmailSubject(), emailCampaign.getEmailMessage(),
                emailCampaign.getCampaignName(), emailCampaign.getId());
    } else {
        if (emailCampaign.isSchedule()) {

            /**
             * if recurrence start date is in the future calculate
             * next trigger date if not use recurrence start date us next trigger
             * date when activating
             */
            LocalDate nextTriggerDate = null;
            if (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
                nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
                        emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
            } else {
                nextTriggerDate = emailCampaign.getRecurrenceStartDate();
            }
            // to get time of tenant
            final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime();

            final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":"
                    + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
            final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
            final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

            emailCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
            this.emailCampaignRepository.saveAndFlush(emailCampaign);
        }
    }

    /*
      if campaign is direct insert campaign message into scheduledemail outbound table
      else if its a schedule create a job process for it
     */
    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withEntityId(emailCampaign.getId()) //
            .build();
}

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override/*from  w  ww . j a  v  a2 s  . co  m*/
public CommandProcessingResult reactivateEmailCampaign(final Long campaignId, JsonCommand command) {

    this.emailCampaignValidator.validateActivation(command.json());

    final AppUser currentUser = this.context.authenticatedUser();

    final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);

    if (emailCampaign == null) {
        throw new EmailCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate reactivationDate = command.localDateValueOfParameterNamed("activationDate");
    emailCampaign.reactivate(currentUser, fmt, reactivationDate);
    if (emailCampaign.isSchedule()) {

        /**
         * if recurrence start date is in the future calculate
         * next trigger date if not use recurrence start date us next trigger date when activating
         */
        LocalDate nextTriggerDate = null;
        if (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
            nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
                    emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
        } else {
            nextTriggerDate = emailCampaign.getRecurrenceStartDate();
        }
        // to get time of tenant
        final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime();

        final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":"
                + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
        final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

        emailCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
        this.emailCampaignRepository.saveAndFlush(emailCampaign);
    }

    return new CommandProcessingResultBuilder() //
            .withEntityId(emailCampaign.getId()) //
            .build();

}

From source file:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);
    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }/*from w ww .j a  v  a2 s . com*/
    LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate();
    smsCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    //calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
            smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means next run time is in the past calculate a new future date
        nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                smsCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    smsCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.smsCampaignRepository.saveAndFlush(smsCampaign);
}

From source file:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override//from w  ww.  j a  v  a  2 s.co  m
public CommandProcessingResult activateSmsCampaign(Long campaignId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();

    this.smsCampaignValidator.validateActivation(command.json());

    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);

    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate activationDate = command.localDateValueOfParameterNamed("activationDate");

    smsCampaign.activate(currentUser, fmt, activationDate);

    this.smsCampaignRepository.saveAndFlush(smsCampaign);

    if (smsCampaign.isDirect()) {
        insertDirectCampaignIntoSmsOutboundTable(smsCampaign.getParamValue(), smsCampaign.getMessage(),
                smsCampaign.getCampaignName());
    } else {
        if (smsCampaign.isSchedule()) {

            /**
             * if recurrence start date is in the future calculate
             * next trigger date if not use recurrence start date us next trigger
             * date when activating
             */
            LocalDate nextTriggerDate = null;
            if (smsCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
                nextTriggerDate = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                        smsCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
            } else {
                nextTriggerDate = smsCampaign.getRecurrenceStartDate();
            }
            // to get time of tenant
            final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();

            final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":"
                    + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
            final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
            final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

            smsCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
            this.smsCampaignRepository.saveAndFlush(smsCampaign);
        }
    }

    /*
      if campaign is direct insert campaign message into sms outbound table
      else if its a schedule create a job process for it
     */
    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withEntityId(smsCampaign.getId()) //
            .build();
}

From source file:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override/*from w  ww . ja  v a  2s.  com*/
public CommandProcessingResult reactivateSmsCampaign(final Long campaignId, JsonCommand command) {

    this.smsCampaignValidator.validateActivation(command.json());

    final AppUser currentUser = this.context.authenticatedUser();

    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);

    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate reactivationDate = command.localDateValueOfParameterNamed("activationDate");
    smsCampaign.reactivate(currentUser, fmt, reactivationDate);
    if (smsCampaign.isSchedule()) {

        /**
         * if recurrence start date is in the future calculate
         * next trigger date if not use recurrence start date us next trigger
         * date when activating
         */
        LocalDate nextTriggerDate = null;
        if (smsCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
            nextTriggerDate = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                    smsCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
        } else {
            nextTriggerDate = smsCampaign.getRecurrenceStartDate();
        }
        // to get time of tenant
        final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();

        final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":"
                + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
        final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

        smsCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
        this.smsCampaignRepository.saveAndFlush(smsCampaign);
    }

    return new CommandProcessingResultBuilder() //
            .withEntityId(smsCampaign.getId()) //
            .build();

}

From source file:org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateTimeXMLGregorianCalendarAdapter.java

License:Apache License

public static XMLGregorianCalendar print(final LocalDateTime dateTime) {
    if (dateTime == null)
        return null;

    final XMLGregorianCalendarImpl xgc = new XMLGregorianCalendarImpl();
    xgc.setYear(dateTime.getYear());//from ww w  . j a va  2  s. c  o m
    xgc.setMonth(dateTime.getMonthOfYear());
    xgc.setDay(dateTime.getDayOfMonth());
    xgc.setHour(dateTime.getHourOfDay());
    xgc.setMinute(dateTime.getMinuteOfHour());
    xgc.setSecond(dateTime.getSecondOfMinute());
    xgc.setMillisecond(dateTime.getMillisOfSecond());

    return xgc;
}

From source file:org.apache.isis.schema.utils.jaxbadapters.XmlCalendarFactory.java

License:Apache License

public static XMLGregorianCalendar create(LocalDateTime localDateTime) {
    return localDateTime != null ? withTypeFactoryDo(dtf -> dtf.newXMLGregorianCalendar(localDateTime.getYear(),
            localDateTime.getMonthOfYear(), localDateTime.getDayOfMonth(), localDateTime.getHourOfDay(),
            localDateTime.getMinuteOfHour(), localDateTime.getSecondOfMinute(),
            localDateTime.getMillisOfSecond(), DatatypeConstants.FIELD_UNDEFINED)) : null;
}

From source file:org.assertj.jodatime.api.LocalDateTimeAssert.java

License:Apache License

/**
 * Returns true if both datetime are in the same year, month and day of month, hour, minute and second, false
 * otherwise./*from  www.j a va2 s.  com*/
 * 
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year, month and day of month, hour, minute and second, false
 *         otherwise.
 */
private static boolean areEqualIgnoringMillis(LocalDateTime actual, LocalDateTime other) {
    return areEqualIgnoringSeconds(actual, other) && actual.getSecondOfMinute() == other.getSecondOfMinute();
}

From source file:org.broadleafcommerce.core.offer.service.processor.AbstractBaseProcessor.java

License:Apache License

/**
 * Removes all out of date offers.  If an offer does not have a start date, or the start
 * date is a later date, that offer will be removed.  Offers without a start date should
 * not be processed.  If the offer has a end date that has already passed, that offer
 * will be removed.  Offers without a end date will be processed if the start date
 * is prior to the transaction date.//from w  w w  . j  a  v a2 s . co  m
 *
 * @param offers
 * @return List of Offers with valid dates
 */
protected List<Offer> removeOutOfDateOffers(List<Offer> offers) {
    List<Offer> offersToRemove = new ArrayList<Offer>();
    for (Offer offer : offers) {
        TimeZone timeZone = getOfferTimeZoneProcessor().getTimeZone(offer);

        Calendar current = timeZone == null ? SystemTime.asCalendar() : SystemTime.asCalendar(timeZone);
        Calendar start = null;
        if (offer.getStartDate() != null) {
            LocalDateTime startDate = new LocalDateTime(offer.getStartDate());
            start = timeZone == null ? new GregorianCalendar() : new GregorianCalendar(timeZone);
            start.set(Calendar.YEAR, startDate.getYear());
            start.set(Calendar.MONTH, startDate.getMonthOfYear() - 1);
            start.set(Calendar.DAY_OF_MONTH, startDate.getDayOfMonth());
            start.set(Calendar.HOUR_OF_DAY, startDate.getHourOfDay());
            start.set(Calendar.MINUTE, startDate.getMinuteOfHour());
            start.set(Calendar.SECOND, startDate.getSecondOfMinute());
            start.get(Calendar.HOUR_OF_DAY);//do not delete this line
            start.get(Calendar.MINUTE);
            if (LOG.isTraceEnabled()) {
                LOG.debug("Offer: " + offer.getName() + " timeZone:" + timeZone + " startTime:"
                        + start.getTime() + " currentTime:" + current.getTime());
            }
        }
        Calendar end = null;
        if (offer.getEndDate() != null) {
            LocalDateTime endDate = new LocalDateTime(offer.getEndDate());
            end = timeZone == null ? new GregorianCalendar() : new GregorianCalendar(timeZone);
            end.set(Calendar.YEAR, endDate.getYear());
            end.set(Calendar.MONTH, endDate.getMonthOfYear() - 1);
            end.set(Calendar.DAY_OF_MONTH, endDate.getDayOfMonth());
            end.set(Calendar.HOUR_OF_DAY, endDate.getHourOfDay());
            end.set(Calendar.MINUTE, endDate.getMinuteOfHour());
            end.set(Calendar.SECOND, endDate.getSecondOfMinute());
            end.get(Calendar.HOUR_OF_DAY);//do not delete this line
            end.get(Calendar.MINUTE);
            if (LOG.isTraceEnabled()) {
                LOG.debug("Offer: " + offer.getName() + " endTime:" + start.getTime());
            }
        }
        if ((offer.getStartDate() == null) || (start.after(current))) {
            offersToRemove.add(offer);
        } else if (offer.getEndDate() != null && end.before(current)) {
            offersToRemove.add(offer);
        }
    }
    // remove all offers in the offersToRemove list from original offers list
    for (Offer offer : offersToRemove) {
        offers.remove(offer);
    }
    return offers;

    // return offers;
}