List of usage examples for org.joda.time DateTime withMonthOfYear
public DateTime withMonthOfYear(int monthOfYear)
From source file:com.kopysoft.chronos.activities.fragment.JobFragment.java
License:Open Source License
@Override public void onPause() { super.onPause(); Chronos chrono = new Chronos(getActivity()); Job thisJob = chrono.getAllJobs().get(0); /*//from w w w. j a va2 s . c o m EditText dataPayRate; Spinner dataPayPeriodLength; DatePicker dataStartOfPayPeriod; TimePicker dataTimePicker; */ Log.d(TAG, "onPause()"); dataPayRate.clearFocus(); dataPayPeriodLength.clearFocus(); dataStartOfPayPeriod.clearFocus(); dataTimePicker.clearFocus(); try { thisJob.setPayRate(Float.parseFloat(dataPayRate.getText().toString())); Log.d(TAG, "Pay Rate: " + thisJob.getPayRate()); } catch (NumberFormatException e) { Toast.makeText(getActivity(), "Pay Rate format incorrect", Toast.LENGTH_SHORT).show(); } PayPeriodDuration duration = PayPeriodDuration.values()[dataPayPeriodLength.getSelectedItemPosition()]; thisJob.setDuration(duration); DateTime newTime = thisJob.getStartOfPayPeriod(); newTime = newTime.withDayOfMonth(dataStartOfPayPeriod.getDayOfMonth()); newTime = newTime.withMonthOfYear(dataStartOfPayPeriod.getMonth() + 1); newTime = newTime.withYear(dataStartOfPayPeriod.getYear()); newTime = newTime.withHourOfDay(dataTimePicker.getCurrentHour()); newTime = newTime.withMinuteOfHour(dataTimePicker.getCurrentMinute()); thisJob.setStartOfPayPeriod(newTime); chrono.updateJob(thisJob); chrono.close(); }
From source file:com.qcadoo.localization.api.utils.DateUtils.java
License:Open Source License
private static DateTime roundUpDate(final DateTime dateTime, final String dateExpressionPart) { DateTime roundedDate = dateTime; final String[] date = dateExpressionPart.split("-"); if (date.length < 3 || StringUtils.isBlank(date[2])) { final int day = roundedDate.dayOfMonth().getMaximumValue(); roundedDate = roundedDate.withDayOfMonth(day); }/*ww w .j a v a 2s .c o m*/ if (date.length < 2 || StringUtils.isBlank(date[1])) { roundedDate = roundedDate.withMonthOfYear(12); } return roundedDate; }
From source file:com.sonicle.webtop.calendar.bol.ORecurrence.java
License:Open Source License
@Deprecated public void __fillFrom(boolean setRule, EventRecurrence rec, DateTime eventStartDate, DateTime eventEndDate, String eventTimeZone) {/* www .j a va2s . c o m*/ DateTimeZone etz = DateTimeZone.forID(eventTimeZone); setStartDate(eventStartDate); if (StringUtils.equals(rec.getType(), EventRecurrence.TYPE_DAILY)) { setType(rec.getType()); setDailyFreq(rec.getDailyFreq()); } else if (StringUtils.equals(rec.getType(), EventRecurrence.TYPE_DAILY_FERIALI)) { setType(rec.getType()); } else { // Reset fields... setDailyFreq(null); } if (StringUtils.equals(rec.getType(), EventRecurrence.TYPE_WEEKLY)) { setType(rec.getType()); setWeeklyFreq(rec.getWeeklyFreq()); setWeeklyDay_1(LangUtils.coalesce(rec.getWeeklyDay1(), false)); setWeeklyDay_2(LangUtils.coalesce(rec.getWeeklyDay2(), false)); setWeeklyDay_3(LangUtils.coalesce(rec.getWeeklyDay3(), false)); setWeeklyDay_4(LangUtils.coalesce(rec.getWeeklyDay4(), false)); setWeeklyDay_5(LangUtils.coalesce(rec.getWeeklyDay5(), false)); setWeeklyDay_6(LangUtils.coalesce(rec.getWeeklyDay6(), false)); setWeeklyDay_7(LangUtils.coalesce(rec.getWeeklyDay7(), false)); } else { // Reset fields... setWeeklyFreq(null); setWeeklyDay_1(null); setWeeklyDay_2(null); setWeeklyDay_3(null); setWeeklyDay_4(null); setWeeklyDay_5(null); setWeeklyDay_6(null); setWeeklyDay_7(null); } if (StringUtils.equals(rec.getType(), EventRecurrence.TYPE_MONTHLY)) { setType(rec.getType()); setMonthlyFreq(rec.getMonthlyFreq()); setMonthlyDay(rec.getMonthlyDay()); } else { // Reset fields... setMonthlyFreq(null); setMonthlyDay(null); } if (StringUtils.equals(rec.getType(), EventRecurrence.TYPE_YEARLY)) { setType(rec.getType()); setYearlyFreq(rec.getYearlyFreq()); setYearlyDay(rec.getYearlyDay()); setStartDate(eventStartDate.withMonthOfYear(rec.getYearlyFreq()).withDayOfMonth(rec.getYearlyDay())); } else { // Reset fields... setYearlyFreq(null); setYearlyDay(null); } RRule rr = null; if (StringUtils.equals(rec.getEndsMode(), EventRecurrence.ENDS_MODE_NEVER)) { rr = __applyEndNever(etz, setRule); } else if (StringUtils.equals(rec.getEndsMode(), EventRecurrence.ENDS_MODE_REPEAT)) { rr = __applyEndRepeat(rec.getRepeatTimes(), eventStartDate, eventEndDate, etz, setRule); } else if (StringUtils.equals(rec.getEndsMode(), EventRecurrence.ENDS_MODE_UNTIL)) { rr = __applyEndUntil(rec.getUntilDate(), etz, setRule); } else { throw new RuntimeException("Recurrence end-mode unknown or undefined"); } setRule(rr.getValue()); }
From source file:com.thinkbiganalytics.ingest.GetTableDataSupport.java
License:Apache License
protected static Date maxAllowableDateFromUnit(Date fromDate, UnitSizes unit) { DateTime jodaDate = new DateTime(fromDate); switch (unit) { case HOUR:/*from ww w.ja v a 2 s . c o m*/ return jodaDate.hourOfDay().roundFloorCopy().toDate(); case DAY: return jodaDate.withHourOfDay(0).hourOfDay().roundFloorCopy().toDate(); case WEEK: return jodaDate.weekOfWeekyear().roundFloorCopy().toDate(); case MONTH: return jodaDate.monthOfYear().roundFloorCopy().toDate(); case YEAR: return jodaDate.withMonthOfYear(1).withDayOfMonth(1).withHourOfDay(0).hourOfDay().roundFloorCopy() .toDate(); } return fromDate; }
From source file:dk.dma.epd.common.prototype.model.voct.SARISXMLParser.java
License:Apache License
private SARWeatherData getSingleSARWeatherData(Node node) throws XPathExpressionException { Element el = (Element) node; NodeList children = el.getChildNodes(); Node timeEntry = children.item(1); Element timeElement = (Element) timeEntry; NodeList timeNodes = timeElement.getChildNodes(); DateTime windEntryDate = new DateTime(); // Day 0/* ww w.j ava 2 s.c o m*/ windEntryDate = windEntryDate .withDayOfMonth(Integer.parseInt(timeNodes.item(0).getFirstChild().getNodeValue())); // Month 2 windEntryDate = windEntryDate .withMonthOfYear(Integer.parseInt(timeNodes.item(2).getFirstChild().getNodeValue())); // Year 4 windEntryDate = windEntryDate.withYear(Integer.parseInt(timeNodes.item(4).getFirstChild().getNodeValue())); // hour 6 windEntryDate = windEntryDate .withHourOfDay(Integer.parseInt(timeNodes.item(6).getFirstChild().getNodeValue())); // minute 8 windEntryDate = windEntryDate .withMinuteOfHour(Integer.parseInt(timeNodes.item(8).getFirstChild().getNodeValue())); // second 10 windEntryDate = windEntryDate .withSecondOfMinute(Integer.parseInt(timeNodes.item(10).getFirstChild().getNodeValue())); Node windEntry = children.item(3); Element windElements = (Element) windEntry; NodeList windNodes = windElements.getChildNodes(); System.out.println(windElements.getFirstChild().getNodeValue()); for (int k = 0; k < windNodes.getLength(); k++) { System.out.println("k is " + k); Node child2 = windNodes.item(k); System.out.println("Child2 name is " + child2.getNodeName()); if (child2.getNodeType() != Node.TEXT_NODE) { System.out.println("child tag: " + child2.getNodeName()); if (child2.getFirstChild().getNodeType() == Node.TEXT_NODE) { System.out.println("inner child value:" + child2.getFirstChild().getNodeValue()); } } } // System.out.println(node.getChildNodes()); // Get time // System.out.println(getDateFromNodeList(node.getChildNodes().item(1).getChildNodes())); // System.out.println(node.getChildNodes().item(1).getChildNodes().item(0).getChildNodes().item(0).getNodeValue()); // Wind values // System.out.println(node.getChildNodes().item(3)); // for (int i = 0; i < node.getChildNodes().getLength(); i++) { // System.out.println(node.getChildNodes().item(i).getChildNodes().item(1)); // } return null; }
From source file:dk.dma.epd.common.prototype.model.voct.SARISXMLParser.java
License:Apache License
private DateTime getDateFromNodeList(NodeList nodeList) { DateTime returnDate = new DateTime(); if (nodeList.getLength() == 0) { return null; }/*from ww w . j a va 2s . c om*/ if (nodeList.item(0).getNodeName().equals("day")) { // Day returnDate = returnDate .withDayOfMonth(Integer.parseInt(nodeList.item(0).getFirstChild().getNodeValue())); // System.out.println("DAY"); } if (nodeList.item(1).getNodeName().equals("month")) { // Month returnDate = returnDate .withMonthOfYear(Integer.parseInt(nodeList.item(1).getFirstChild().getNodeValue())); // System.out.println("MONTH"); } if (nodeList.item(2).getNodeName().equals("year")) { // Year returnDate = returnDate.withYear(Integer.parseInt(nodeList.item(2).getFirstChild().getNodeValue())); // System.out.println("YEAR"); } if (nodeList.item(3).getNodeName().equals("hour")) { // Hour returnDate = returnDate .withHourOfDay(Integer.parseInt(nodeList.item(3).getFirstChild().getNodeValue())); // System.out.println("HOUR"); } if (nodeList.item(4).getNodeName().equals("minute")) { // Minute returnDate = returnDate .withMinuteOfHour(Integer.parseInt(nodeList.item(4).getFirstChild().getNodeValue())); // System.out.println("MINUTE"); } if (nodeList.item(5).getNodeName().equals("second")) { // Second returnDate = returnDate .withSecondOfMinute(Integer.parseInt(nodeList.item(5).getFirstChild().getNodeValue())); // System.out.println("SECOND"); } return returnDate; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo.java
License:Open Source License
private Map<String, String> checkDate(String precisionURI, Map<String, String[]> qp) { if (precisionURI == null) return Collections.emptyMap(); Map<String, String> errors = new HashMap<String, String>(); Integer year, month, day, hour, minute, second; //just check if the values for the precision parse to integers if (precisionURI.equals(VitroVocabulary.Precision.YEAR.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); } else if (precisionURI.equals(VitroVocabulary.Precision.MONTH.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); } else if (precisionURI.equals(VitroVocabulary.Precision.DAY.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); } else if (precisionURI.equals(VitroVocabulary.Precision.HOUR.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); if (!canParseToNumber(getFieldName() + "-hour", qp)) errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR); } else if (precisionURI.equals(VitroVocabulary.Precision.MINUTE.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); if (!canParseToNumber(getFieldName() + "-hour", qp)) errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR); if (!canParseToNumber(getFieldName() + "-minute", qp)) errors.put(getFieldName() + "-minute", NON_INTEGER_HOUR); } else if (precisionURI.equals(VitroVocabulary.Precision.SECOND.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); if (!canParseToNumber(getFieldName() + "-hour", qp)) errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR); if (!canParseToNumber(getFieldName() + "-minute", qp)) errors.put(getFieldName() + "-minute", NON_INTEGER_HOUR); if (!canParseToNumber(getFieldName() + "-second", qp)) errors.put(getFieldName() + "-second", NON_INTEGER_SECOND); }//from ww w . j a va2s. com //check if we can make a valid date with these integers year = parseToInt(getFieldName() + "-year", qp); if (year == null) year = 1999; month = parseToInt(getFieldName() + "-month", qp); if (month == null) month = 1; day = parseToInt(getFieldName() + "-day", qp); if (day == null) day = 1; hour = parseToInt(getFieldName() + "-hour", qp); if (hour == null) hour = 0; minute = parseToInt(getFieldName() + "-minute", qp); if (minute == null) minute = 0; second = parseToInt(getFieldName() + "-second", qp); if (second == null) second = 0; //initialize to something so that we can be assured not to get //system date dependent behavior DateTime dateTime = new DateTime("1970-01-01T00:00:00Z"); try { dateTime = dateTime.withYear(year); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-year", iae.getLocalizedMessage()); } try { dateTime = dateTime.withMonthOfYear(month); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-month", iae.getLocalizedMessage()); } try { dateTime = dateTime.withDayOfMonth(day); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-day", iae.getLocalizedMessage()); } try { dateTime = dateTime.withHourOfDay(hour); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-hour", iae.getLocalizedMessage()); } try { dateTime = dateTime.withSecondOfMinute(second); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-second", iae.getLocalizedMessage()); } return errors; }
From source file:net.tourbook.chart.ChartComponents.java
License:Open Source License
private void createHistoryUnits(final int firstYear, int lastYear) { /*// w w w. ja v a 2 s.c om * add an additional year because at the year end, a history chart displays also the next * year which caused an outOfBound exception when testing this app at 28.12.2012 */ lastYear += 1; final int numberOfYears = lastYear - firstYear + 1; _historyYears = new int[numberOfYears]; _historyMonths = new int[numberOfYears][12]; _historyDOY = new int[numberOfYears]; int yearIndex = 0; DateTime currentYear = new DateTime().withDate(firstYear - 1, 1, 1); for (int currentYearNo = firstYear; currentYearNo <= lastYear; currentYearNo++) { currentYear = currentYear.plusYears(1); _historyYears[yearIndex] = currentYearNo; int yearDOY = 0; // get number of days for each month for (int monthIndex = 0; monthIndex < 12; monthIndex++) { final int monthDays = currentYear.withMonthOfYear(monthIndex + 1).dayOfMonth().getMaximumValue(); _historyMonths[yearIndex][monthIndex] = monthDays; yearDOY += monthDays; } _historyDOY[yearIndex] = yearDOY; yearIndex++; } }
From source file:net.tourbook.ui.views.calendar.CalendarYearMonthContributionItem.java
License:Open Source License
private void fillMonthComboBox() { DateTime dt = new DateTime(); final int thisMonth = dt.getMonthOfYear(); dt = dt.withMonthOfYear(DateTimeConstants.JANUARY); _cboMonthValues = new ArrayList<Integer>(); _cboMonthKeys = new HashMap<Integer, Integer>(); for (int i = 0; i < 12; i++) { // _cboMonth.add(dt.toString("MMMM")); _cboMonth.add(dt.toString("MMM")); // make the toolbar fit more likely into one line //$NON-NLS-1$ _cboMonthValues.add(dt.getMonthOfYear()); _cboMonthKeys.put(dt.getMonthOfYear(), i); dt = dt.plusMonths(1);/*from w ww . j av a 2s . c o m*/ } _cboMonth.select(thisMonth - 1); }
From source file:org.egov.pgr.elasticsearch.repository.ComplaintIndexRepositoryImpl.java
License:Open Source License
@Override public Map<String, SearchResponse> findAllGrievanceByFilter( final ComplaintDashBoardRequest complaintDashBoardRequest, final BoolQueryBuilder query, final String grouByField) { /**/*from w ww .j a va2 s . c o m*/ * For Current day's complaint count if dates are sent in the request, consider the toDate, else take date range between * current date +1 day */ DateTime fromDate = new DateTime(); if (isNotBlank(complaintDashBoardRequest.getFromDate()) && isNotBlank(complaintDashBoardRequest.getToDate())) fromDate = new DateTime(complaintDashBoardRequest.getFromDate()); // This is size used to fetch those many number of documents int size = 120; if (complaintDashBoardRequest.getSize() >= 0) size = complaintDashBoardRequest.getSize(); DateTime currentYearFromDate = new DateTime(); if (fromDate.getMonthOfYear() < 4) currentYearFromDate = currentYearFromDate.minusYears(1).withMonthOfYear(4).dayOfMonth() .withMinimumValue(); else currentYearFromDate = currentYearFromDate.withMonthOfYear(4).dayOfMonth().withMinimumValue(); final SearchResponse consolidatedResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME) .setQuery(query).setSize(0).addAggregation(getCount("countAggregation", "crn")) .addAggregation(getCountWithGrouping("closedCount", IF_CLOSED, 2)) .addAggregation(getCountWithGrouping("slaCount", IF_SLA, 2)) .addAggregation(getAverageWithFilter(IF_CLOSED, 1, "AgeingInWeeks", COMPLAINT_AGEINGDAYS_FROM_DUE)) .addAggregation(getAverageWithExclusion(SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .addAggregation(getCountBetweenSpecifiedDates("currentYear", CREATED_DATE, currentYearFromDate.toString(formatter), new DateTime().plusDays(1).toString(formatter))) .addAggregation(getCountBetweenSpecifiedDates(TODAY_COMPLAINT_COUNT, CREATED_DATE, new DateTime().toString(formatter), new DateTime().plusDays(1).toString(formatter))) .execute().actionGet(); SearchResponse tableResponse; if (complaintDashBoardRequest.getType().equalsIgnoreCase(DASHBOARD_GROUPING_ALL_WARDS)) tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(AggregationBuilders.terms(ULBWISE).field(CITY_CODE).size(120) .subAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion( GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(AggregationBuilders.topHits(COMPLAINT_RECORD) .addField(CITY_CODE).addField(DISTRICT_NAME).addField(CITY_NAME) .addField(WARD_NAME).setSize(1)) .subAggregation( getCountWithGrouping(GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2).subAggregation( AggregationBuilders.range(GROUP_BY_FIELD_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping( GROUP_BY_FIELD_SLA, IF_SLA, 2))))) .execute().actionGet(); else if (complaintDashBoardRequest.getType().equalsIgnoreCase(DASHBOARD_GROUPING_ALL_LOCALITIES)) tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(AggregationBuilders.terms(ULBWISE).field(CITY_CODE).size(120) .subAggregation(AggregationBuilders.terms(WARDWISE).field(WARD_NUMBER).size(size) .subAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()).subAggregation( getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(AggregationBuilders.topHits(COMPLAINT_RECORD) .addField(CITY_CODE).addField(CITY_DISTRICT_NAME) .addField(CITY_NAME).addField(WARD_NAME) .addField(LOCALITY_NAME).setSize(1)) .subAggregation(getCountWithGrouping( GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING).field( COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping( GROUP_BY_FIELD_SLA, IF_SLA, 2)))))) .execute().actionGet(); else if (complaintDashBoardRequest.getType().equalsIgnoreCase(DASHBOARD_GROUPING_ALL_FUNCTIONARY)) tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(AggregationBuilders.terms(ULBWISE).field(CITY_CODE).size(120) .subAggregation(AggregationBuilders.terms(DEPARTMENTWISE).field(DEPARTMENT_CODE) .size(size) .subAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()).subAggregation( getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(AggregationBuilders.topHits(COMPLAINT_RECORD) .addField(CITY_CODE).addField(CITY_DISTRICT_NAME) .addField(CITY_NAME).addField(DEPARTMENT_NAME) .addField(INITIAL_FUNCTIONARY_MOBILE_NUMBER).setSize(1)) .subAggregation(getCountWithGrouping( GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING).field( COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping( GROUP_BY_FIELD_SLA, IF_SLA, 2)))))) .execute().actionGet(); else tableResponse = elasticsearchTemplate.getClient().prepareSearch(PGR_INDEX_NAME).setQuery(query) .setSize(0) .addAggregation(getCountWithGroupingAndOrder(COMPLAINT_TYPE_WISE, COMPLAINT_TYPE_NAME, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(COMPLAINT_TYPE_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(COMPLAINT_TYPE_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(HOURWISE_COMPLAINT_TYPE_AGEING) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(COMPLAINT_TYPE_SLA, IF_SLA, 2)))) .addAggregation(getCountWithGroupingAndOrder(GROUP_BY_FIELD, grouByField, size, complaintDashBoardRequest.getSortField(), complaintDashBoardRequest.getSortDirection()) .subAggregation(getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation(getCountWithGrouping(GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(GROUP_BY_FIELD_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE) .addRange(ONE_WEEK, 0, 8).addRange(ONE_MONTH, 8, 32) .addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE) .addRange(TWELVE_HOURS, 0, 13).addRange("1day", 13, 25) .addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation( getCountWithGrouping(GROUP_BY_FIELD_SLA, IF_SLA, 2)))) .execute().actionGet(); final HashMap<String, SearchResponse> result = new HashMap<>(); if (grouByField.equals(LOCALITY_NAME)) { final SearchResponse localityMissingResponse = elasticsearchTemplate.getClient() .prepareSearch(PGR_INDEX_NAME).setQuery(query).setSize(0) .addAggregation(AggregationBuilders.missing(NOLOCALITY).field(LOCALITY_NAME) .subAggregation(getAverageWithExclusion(GROUP_BY_FIELD_SATISFACTION_AVERAGE, SATISFACTION_INDEX)) .subAggregation( getCountWithGrouping(GROUP_FIELD_WISE_OPEN_AND_CLOSED_COUNT, IF_CLOSED, 2) .subAggregation(AggregationBuilders.range(GROUP_BY_FIELD_AGEING) .field(COMPLAINT_AGEINGDAYS_FROM_DUE).addRange(ONE_WEEK, 0, 8) .addRange(ONE_MONTH, 8, 32).addRange(THREE_MONTHS, 32, 91) .addUnboundedFrom(REMAINING_MONTHS, 91)) .subAggregation(AggregationBuilders .range(GROUP_BY_FIELD_AGEING_FOR_HOURS) .field(COMPLAINT_AGEING_FROM_DUE).addRange(TWELVE_HOURS, 0, 13) .addRange("1day", 13, 25).addRange(ONE_WEEK, 25, 169) .addUnboundedFrom(REMAINING_HOURS, 169)) .subAggregation(getCountWithGrouping(GROUP_BY_FIELD_SLA, IF_SLA, 2)))) .execute().actionGet(); result.put("noLocality", localityMissingResponse); } result.put("consolidatedResponse", consolidatedResponse); result.put("tableResponse", tableResponse); return result; }