List of usage examples for org.joda.time LocalDateTime getHourOfDay
public int getHourOfDay()
From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java
License:Apache License
private void updateTriggerDates(Long campaignId) { final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId); if (smsCampaign == null) { throw new SmsCampaignNotFound(campaignId); }/*from ww w .jav a2 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:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java
License:Apache License
@Transactional @Override/* www.j a va2 s .c om*/ 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); } 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:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java
License:Apache License
@Transactional @Override/* w ww .j a v a 2 s. co m*/ 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.isDirect()) { insertDirectCampaignIntoSmsOutboundTable(smsCampaign); } 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); return new CommandProcessingResultBuilder() // .withEntityId(smsCampaign.getId()) // .build(); }
From source file:com.gst.infrastructure.dataqueries.service.GenericDataServiceImpl.java
License:Apache License
@Override public String generateJsonFromGenericResultsetData(final GenericResultsetData grs) { final StringBuffer writer = new StringBuffer(); writer.append("["); final List<ResultsetColumnHeaderData> columnHeaders = grs.getColumnHeaders(); final List<ResultsetRowData> data = grs.getData(); List<String> row; Integer rSize;//from w w w .j ava 2 s . c om final String doubleQuote = "\""; final String slashDoubleQuote = "\\\""; String currColType; String currVal; for (int i = 0; i < data.size(); i++) { writer.append("\n{"); row = data.get(i).getRow(); rSize = row.size(); for (int j = 0; j < rSize; j++) { writer.append(doubleQuote + columnHeaders.get(j).getColumnName() + doubleQuote + ": "); currColType = columnHeaders.get(j).getColumnDisplayType(); final String colType = columnHeaders.get(j).getColumnType(); if (currColType == null && colType.equalsIgnoreCase("INT")) { currColType = "INTEGER"; } if (currColType == null && colType.equalsIgnoreCase("VARCHAR")) { currColType = "VARCHAR"; } if (currColType == null && colType.equalsIgnoreCase("DATE")) { currColType = "DATE"; } currVal = row.get(j); if (currVal != null && currColType != null) { if (currColType.equals("DECIMAL") || currColType.equals("INTEGER")) { writer.append(currVal); } else { if (currColType.equals("DATE")) { final LocalDate localDate = new LocalDate(currVal); writer.append("[" + localDate.getYear() + ", " + localDate.getMonthOfYear() + ", " + localDate.getDayOfMonth() + "]"); } else if (currColType.equals("DATETIME")) { final LocalDateTime localDateTime = new LocalDateTime(currVal); writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthOfYear() + ", " + localDateTime.getDayOfMonth() + " " + localDateTime.getHourOfDay() + ", " + localDateTime.getMinuteOfHour() + ", " + localDateTime.getSecondOfMinute() + ", " + localDateTime.getMillisOfSecond() + "]"); } else { writer.append( doubleQuote + replace(currVal, doubleQuote, slashDoubleQuote) + doubleQuote); } } } else { writer.append("null"); } if (j < (rSize - 1)) { writer.append(",\n"); } } if (i < (data.size() - 1)) { writer.append("},"); } else { writer.append("}"); } } writer.append("\n]"); return writer.toString(); }
From source file:com.helger.datetime.xml.PDTXMLConverter.java
License:Apache License
/** * Get the passed object as {@link XMLGregorianCalendar} with date and time. * * @param aBase/*from w ww. ja v a2s .co m*/ * The source object. May be <code>null</code>. * @return <code>null</code> if the parameter is <code>null</code>. */ @Nullable public static XMLGregorianCalendar getXMLCalendar(@Nullable final LocalDateTime aBase) { return aBase == null ? null : s_aDTFactory.newXMLGregorianCalendar(aBase.getYear(), aBase.getMonthOfYear(), aBase.getDayOfMonth(), aBase.getHourOfDay(), aBase.getMinuteOfHour(), aBase.getSecondOfMinute(), aBase.getMillisOfSecond(), DatatypeConstants.FIELD_UNDEFINED); }
From source file:com.marand.thinkmed.medications.business.impl.TherapyDisplayProvider.java
License:Open Source License
private String getCalculatedIntervalDisplay(final HourMinuteDto startHourMinute, final Integer durationInMinutes, final DateTime therapyEnd) { if (startHourMinute != null) { final LocalDateTime start = new LocalDateTime(1, 1, 1, startHourMinute.getHour(), startHourMinute.getMinute()); String intervalString = hourMinuteToString(startHourMinute) + ""; if (durationInMinutes != null) { final LocalDateTime end = start.plusMinutes(durationInMinutes); final HourMinuteDto endHourMinute = new HourMinuteDto(end.getHourOfDay(), end.getMinuteOfHour()); intervalString += hourMinuteToString(endHourMinute); } else if (therapyEnd != null) { final HourMinuteDto endHourMinute = new HourMinuteDto(therapyEnd.getHourOfDay(), therapyEnd.getMinuteOfHour()); intervalString += hourMinuteToString(endHourMinute); } else {/*from w w w. j a v a 2s . co m*/ intervalString += "..."; } return intervalString; } return null; }
From source file:com.metinkale.prayerapp.vakit.times.Times.java
License:Apache License
@NonNull private LocalDateTime getTimeCal(@Nullable LocalDate date, int time) { if (date == null) { date = LocalDate.now();// ww w .ja v a 2s . co m } if ((time < 0) || (time > 5)) { while (time >= 6) { date = date.plusDays(1); time -= 6; } while (time <= -1) { date = date.minusDays(1); time += 6; } } LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time))); int h = timeCal.getHourOfDay(); if ((time >= 3) && (h < 5)) { timeCal = timeCal.plusDays(1); } return timeCal; }
From source file:com.prayer.vakit.times.Times.java
License:Apache License
public LocalDateTime getTimeCal(LocalDate date, int time) { if (date == null) { date = LocalDate.now();//from ww w .ja v a 2s . c o m } if ((time < 0) || (time > 5)) { while (time >= 6) { date = date.plusDays(1); time -= 6; } while (time <= -1) { date = date.minusDays(1); time += 6; } } LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time))); int h = timeCal.getHourOfDay(); if ((time >= 3) && (h < 5)) { timeCal = timeCal.plusDays(1); } return timeCal; }
From source file:com.restservice.serviceLogic.ResultLogic.java
License:Open Source License
/** * Request handler for getting the count per hour statistic * Additional logic beyond the transactor database connection to insert additional zeros * for dates where no count (row) has been returned * /*w w w.j a va2 s.c o m*/ * @param id * search term index * @return envelope containing a status message and a search result count * per date DTO * @throws SQLException * @throws ExecutionException * @throws InterruptedException */ public Envelope getCountAndNewsPerHour(Long id, String lang) throws SQLException, InterruptedException, ExecutionException { SearchTermsPerQueryPerDate countsPerDay; Envelope env = new Envelope(); countsPerDay = transactor.getCountPerHour(id, lang); // Fill with zeros ArrayList<Integer> newCounts = new ArrayList<Integer>(); ArrayList<LocalDateTime> newDates = new ArrayList<LocalDateTime>(); if (!countsPerDay.getDates().isEmpty()) { ArrayList<LocalDateTime> oldDates = new ArrayList<>(); for (LocalDateTime curDate : countsPerDay.getDates()) { oldDates.add(new LocalDateTime(curDate.getYear(), curDate.getMonthOfYear(), curDate.getDayOfMonth(), curDate.getHourOfDay(), 0)); } newDates.add(oldDates.get(0)); newCounts.add(countsPerDay.getCounts().get(0)); for (int i = 1; i < oldDates.size(); i++) { if (!oldDates.get(i - 1).plusHours(1).equals(oldDates.get(i))) { LocalDateTime startDate = oldDates.get(i - 1); LocalDateTime endDate = oldDates.get(i); while (!startDate.equals(endDate)) { startDate = startDate.plusHours(1); if (startDate.equals(endDate)) { newDates.add(oldDates.get(i)); newCounts.add(countsPerDay.getCounts().get(i)); } else { newCounts.add(0); newDates.add(startDate); } } } else { newDates.add(oldDates.get(i)); newCounts.add(countsPerDay.getCounts().get(i)); } } } countsPerDay.setCounts(newCounts); countsPerDay.setDates(newDates); countsPerDay.updateDateStrings(); // convert to nice output format CountAndNewsPerHour countAndNews = new CountAndNewsPerHour(); for (Integer index = 0; index < countsPerDay.getCounts().size(); index++) { CountPeaksNewsAndDate element = new CountPeaksNewsAndDate(); element.setRawDate(countsPerDay.getDates().get(index)); element.setCount(countsPerDay.getCounts().get(index)); element.setPeak(false); countAndNews.getGraph().add(element); } countAndNews.setQuery(countsPerDay.getQuery()); // find and marks peaks ArrayList<Integer> peakIndices = PeaksUtil.findPeaks24(countAndNews); for (Integer peakIndex : peakIndices) { countAndNews.getGraph().get(peakIndex).setPeak(true); } if (peakIndices.size() > 0) { // create news fetchers HashMap<Integer, Future<ArrayList<NewsItem>>> newsFetchers = new HashMap<Integer, Future<ArrayList<NewsItem>>>(); ExecutorService executor = Executors.newFixedThreadPool(peakIndices.size()); for (Integer peakIndex : peakIndices) { LocalDateTime date = countAndNews.getGraph().get(peakIndex).getRawDate(); newsFetchers.put(peakIndex, executor.submit( new TopNewsFetcherThread(id, date.getDayOfMonth(), date.getMonthOfYear(), date.getYear()))); } // retrieve news fetchers results executor.shutdown(); java.util.Iterator<Entry<Integer, Future<ArrayList<NewsItem>>>> iterator = newsFetchers.entrySet() .iterator(); while (iterator.hasNext()) { Entry<Integer, Future<ArrayList<NewsItem>>> entry = iterator.next(); ArrayList<NewsItem> result = entry.getValue().get(); if (result != null) { for (NewsItem newsitem : result) { countAndNews.getGraph().get(entry.getKey()).getNews().add(newsitem.toShortString()); } } } } env.setData(countAndNews); return env; }
From source file:com.restservice.serviceLogic.ResultLogic.java
License:Open Source License
/** * Request handler for getting the count per hour statistic * //from w w w . j a va 2 s. co m * @param id * search term index * @param lang * iso language code of the language (all languages are selected * if this parameter is null) * * @return envelope containing a status message and the number of * positive/negative tweets per hour * @throws SQLException */ public Envelope getSentimentPerHour(Long id, String lang) throws SQLException { SentimentPerQueryPerDate data; Envelope env = new Envelope(); // TODO: Filling these zeros shouldn't been done three times (twice // here and once in getCountPerHour). Fix it! See ticket #86 data = transactor.getSentimentPerHour(id, lang); ArrayList<LocalDateTime> oldDatesPositive = new ArrayList<>(); ArrayList<Integer> newCountsPositive = new ArrayList<Integer>(); ArrayList<LocalDateTime> newDatesPositive = new ArrayList<LocalDateTime>(); ArrayList<LocalDateTime> oldDatesNegative = new ArrayList<>(); ArrayList<Integer> newCountsNegative = new ArrayList<Integer>(); ArrayList<LocalDateTime> newDatesNegative = new ArrayList<LocalDateTime>(); // Reset minutes, seconds and miliseconds to 0 if (!data.getPositiveCounts().getDates().isEmpty()) { for (LocalDateTime curDate : data.getPositiveCounts().getDates()) { oldDatesPositive.add(new LocalDateTime(curDate.getYear(), curDate.getMonthOfYear(), curDate.getDayOfMonth(), curDate.getHourOfDay(), 0)); } } if (!data.getNegativeCounts().getDates().isEmpty()) { for (LocalDateTime curDate : data.getNegativeCounts().getDates()) { oldDatesNegative.add(new LocalDateTime(curDate.getYear(), curDate.getMonthOfYear(), curDate.getDayOfMonth(), curDate.getHourOfDay(), 0)); } } // Get first date from both (positive or negative) and fill the // other one with leading zero counts if (!oldDatesPositive.isEmpty() && !oldDatesNegative.isEmpty()) { // The first positive date is earlier than the first negative // date if (oldDatesPositive.get(0).compareTo(oldDatesNegative.get(0)) == -1) { LocalDateTime curDate = oldDatesPositive.get(0); while (!curDate.equals(oldDatesNegative.get(0))) { newCountsNegative.add(0); newDatesNegative.add(curDate); curDate = curDate.plusHours(1); } } // The first negative date is earlier than the first positive // date else if (oldDatesPositive.get(0).compareTo(oldDatesNegative.get(0)) == 1) { LocalDateTime curDate = oldDatesNegative.get(0); while (!curDate.equals(oldDatesPositive.get(0))) { newCountsPositive.add(0); newDatesPositive.add(curDate); curDate = curDate.plusHours(1); } } } // Fill hours that have 0 counts for positive tweets if (!oldDatesPositive.isEmpty()) { newDatesPositive.add(oldDatesPositive.get(0)); newCountsPositive.add(data.getPositiveCounts().getCounts().get(0)); for (int i = 1; i < oldDatesPositive.size(); i++) { if (!oldDatesPositive.get(i - 1).plusHours(1).equals(oldDatesPositive.get(i))) { LocalDateTime startDate = oldDatesPositive.get(i - 1); LocalDateTime endDate = oldDatesPositive.get(i); while (!startDate.equals(endDate)) { startDate = startDate.plusHours(1); if (startDate.equals(endDate)) { newDatesPositive.add(oldDatesPositive.get(i)); newCountsPositive.add(data.getPositiveCounts().getCounts().get(i)); } else { newCountsPositive.add(0); newDatesPositive.add(startDate); } } } else { newDatesPositive.add(oldDatesPositive.get(i)); newCountsPositive.add(data.getPositiveCounts().getCounts().get(i)); } } } // Fill hours that have 0 counts for negative tweets if (!oldDatesNegative.isEmpty()) { newDatesNegative.add(oldDatesNegative.get(0)); newCountsNegative.add(data.getNegativeCounts().getCounts().get(0)); for (int i = 1; i < oldDatesNegative.size(); i++) { if (!oldDatesNegative.get(i - 1).plusHours(1).equals(oldDatesNegative.get(i))) { LocalDateTime startDate = oldDatesNegative.get(i - 1); LocalDateTime endDate = oldDatesNegative.get(i); while (!startDate.equals(endDate)) { startDate = startDate.plusHours(1); if (startDate.equals(endDate)) { newDatesNegative.add(oldDatesNegative.get(i)); newCountsNegative.add(data.getNegativeCounts().getCounts().get(i)); } else { newCountsNegative.add(0); newDatesNegative.add(startDate); } } } else { newDatesNegative.add(oldDatesNegative.get(i)); newCountsNegative.add(data.getNegativeCounts().getCounts().get(i)); } } } // Fill negative with zeros when only positive exists if (!newDatesPositive.isEmpty() && newDatesNegative.isEmpty()) { for (LocalDateTime curDate : newDatesPositive) { newCountsNegative.add(0); newDatesNegative.add(curDate); } } // Fill positive with zeros when only negative exists else if (newDatesPositive.isEmpty() && !newDatesNegative.isEmpty()) { for (LocalDateTime curDate : newDatesNegative) { newCountsPositive.add(0); newDatesPositive.add(curDate); } } // Get last date from both (positive or negative) and fill the other // one with trailing zero counts if (!newDatesPositive.isEmpty() && !newDatesNegative.isEmpty()) { // The last positive date is later than the last negative date if (newDatesPositive.get(newDatesPositive.size() - 1) .compareTo(newDatesNegative.get(newDatesNegative.size() - 1)) == -1) { LocalDateTime curDate = newDatesPositive.get(newDatesPositive.size() - 1); while (!curDate.equals(newDatesNegative.get(newDatesNegative.size() - 1))) { newCountsNegative.add(0); newDatesNegative.add(curDate); curDate = curDate.plusHours(1); } } // The last negative date is later than the last positive date else if (newDatesPositive.get(newDatesPositive.size() - 1) .compareTo(newDatesNegative.get(newDatesNegative.size() - 1)) == 1) { LocalDateTime curDate = newDatesNegative.get(newDatesNegative.size() - 1); while (!curDate.equals(newDatesPositive.get(newDatesPositive.size() - 1))) { newCountsPositive.add(0); newDatesPositive.add(curDate); curDate = curDate.plusHours(1); } } } data.getPositiveCounts().setCounts(newCountsPositive); data.getPositiveCounts().setDates(newDatesPositive); data.getPositiveCounts().updateDateStrings(); data.getNegativeCounts().setCounts(newCountsNegative); data.getNegativeCounts().setDates(newDatesNegative); data.getNegativeCounts().updateDateStrings(); env.setData(data); return env; }