List of usage examples for org.joda.time LocalDateTime parse
public static LocalDateTime parse(String str, DateTimeFormatter formatter)
From source file:org.apache.fineract.infrastructure.scheduledemail.domain.EmailCampaign.java
License:Apache License
public Map<String, Object> update(JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(5); if (command.isChangeInStringParameterNamed(EmailCampaignValidator.campaignName, this.campaignName)) { final String newValue = command.stringValueOfParameterNamed(EmailCampaignValidator.campaignName); actualChanges.put(EmailCampaignValidator.campaignName, newValue); this.campaignName = StringUtils.defaultIfEmpty(newValue, null); }/*from ww w . j av a 2s.c om*/ if (command.isChangeInStringParameterNamed(EmailCampaignValidator.emailMessage, this.emailMessage)) { final String newValue = command.stringValueOfParameterNamed(EmailCampaignValidator.emailMessage); actualChanges.put(EmailCampaignValidator.emailMessage, newValue); this.emailMessage = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(EmailCampaignValidator.paramValue, this.paramValue)) { final String newValue = command.stringValueOfParameterNamed(EmailCampaignValidator.paramValue); actualChanges.put(EmailCampaignValidator.paramValue, newValue); this.paramValue = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInIntegerParameterNamed(EmailCampaignValidator.campaignType, this.campaignType)) { final Integer newValue = command.integerValueOfParameterNamed(EmailCampaignValidator.campaignType); actualChanges.put(EmailCampaignValidator.campaignType, EmailCampaignType.fromInt(newValue)); this.campaignType = EmailCampaignType.fromInt(newValue).getValue(); } if (command.isChangeInLongParameterNamed(EmailCampaignValidator.businessRuleId, (this.businessRuleId != null) ? this.businessRuleId.getId() : null)) { final String newValue = command.stringValueOfParameterNamed(EmailCampaignValidator.businessRuleId); actualChanges.put(EmailCampaignValidator.businessRuleId, newValue); } if (command.isChangeInStringParameterNamed(EmailCampaignValidator.recurrenceParamName, this.recurrence)) { final String newValue = command.stringValueOfParameterNamed(EmailCampaignValidator.recurrenceParamName); actualChanges.put(EmailCampaignValidator.recurrenceParamName, newValue); this.recurrence = StringUtils.defaultIfEmpty(newValue, null); } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); if (command.isChangeInLocalDateParameterNamed(EmailCampaignValidator.recurrenceStartDate, getRecurrenceStartDate())) { final String valueAsInput = command .stringValueOfParameterNamed(EmailCampaignValidator.recurrenceStartDate); actualChanges.put(EmailCampaignValidator.recurrenceStartDate, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); final LocalDateTime newValue = LocalDateTime.parse(valueAsInput, fmt); this.recurrenceStartDate = newValue.toDate(); } return actualChanges; }
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); }// ww w . j av a 2 s . c o m 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 . ja v a 2 s .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 w w . j a v a 2 s .c om*/ 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.domain.SmsCampaign.java
License:Apache License
public static SmsCampaign instance(final AppUser submittedBy, final Report report, final JsonCommand command) { final String campaignName = command.stringValueOfParameterNamed(SmsCampaignValidator.campaignName); final Long campaignType = command.longValueOfParameterNamed(SmsCampaignValidator.campaignType); final String paramValue = command.stringValueOfParameterNamed(SmsCampaignValidator.paramValue); final String message = command.stringValueOfParameterNamed(SmsCampaignValidator.message); LocalDate submittedOnDate = new LocalDate(); if (command.hasParameter(SmsCampaignValidator.submittedOnDateParamName)) { submittedOnDate = command.localDateValueOfParameterNamed(SmsCampaignValidator.submittedOnDateParamName); }// ww w. j a v a 2 s . c o m final String recurrence = command.stringValueOfParameterNamed(SmsCampaignValidator.recurrenceParamName); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); LocalDateTime recurrenceStartDate = new LocalDateTime(); if (SmsCampaignType.fromInt(campaignType.intValue()).isSchedule()) { if (command.hasParameter(SmsCampaignValidator.recurrenceStartDate)) { recurrenceStartDate = LocalDateTime .parse(command.stringValueOfParameterNamed(SmsCampaignValidator.recurrenceStartDate), fmt); } } else { recurrenceStartDate = null; } return new SmsCampaign(campaignName, campaignType.intValue(), report, paramValue, message, submittedOnDate, submittedBy, recurrence, recurrenceStartDate); }
From source file:org.apache.fineract.infrastructure.sms.domain.SmsCampaign.java
License:Apache License
public Map<String, Object> update(JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(5); if (command.isChangeInStringParameterNamed(SmsCampaignValidator.campaignName, this.campaignName)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.campaignName); actualChanges.put(SmsCampaignValidator.campaignName, newValue); this.campaignName = StringUtils.defaultIfEmpty(newValue, null); }/* w ww .ja v a 2 s .c o m*/ if (command.isChangeInStringParameterNamed(SmsCampaignValidator.message, this.message)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.message); actualChanges.put(SmsCampaignValidator.message, newValue); this.message = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(SmsCampaignValidator.paramValue, this.paramValue)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.paramValue); actualChanges.put(SmsCampaignValidator.paramValue, newValue); this.paramValue = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInIntegerParameterNamed(SmsCampaignValidator.campaignType, this.campaignType)) { final Integer newValue = command.integerValueOfParameterNamed(SmsCampaignValidator.campaignType); actualChanges.put(SmsCampaignValidator.campaignType, SmsCampaignType.fromInt(newValue)); this.campaignType = SmsCampaignType.fromInt(newValue).getValue(); } if (command.isChangeInLongParameterNamed(SmsCampaignValidator.runReportId, (this.businessRuleId != null) ? this.businessRuleId.getId() : null)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.runReportId); actualChanges.put(SmsCampaignValidator.runReportId, newValue); } if (command.isChangeInStringParameterNamed(SmsCampaignValidator.recurrenceParamName, this.recurrence)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.recurrenceParamName); actualChanges.put(SmsCampaignValidator.recurrenceParamName, newValue); this.recurrence = StringUtils.defaultIfEmpty(newValue, null); } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); if (command.isChangeInLocalDateParameterNamed(SmsCampaignValidator.recurrenceStartDate, getRecurrenceStartDate())) { final String valueAsInput = command .stringValueOfParameterNamed(SmsCampaignValidator.recurrenceStartDate); actualChanges.put(SmsCampaignValidator.recurrenceStartDate, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); final LocalDateTime newValue = LocalDateTime.parse(valueAsInput, fmt); this.recurrenceStartDate = newValue.toDate(); } return actualChanges; }
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); }/*w w w .j a va 2 s. c om*/ 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/* www . ja v a 2s.com*/ 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 w w . j a va 2s . c om*/ 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.fuin.objects4j.common.LocalDateTimeAdapter.java
License:Open Source License
@Override public final LocalDateTime unmarshal(final String str) { if (str == null) { return null; }/* w ww .j a v a 2s. c o m*/ return LocalDateTime.parse(str, ISODateTimeFormat.dateTimeParser()); }