List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:org.onebusaway.admin.service.bundle.task.FixedRouteDataValidationTask.java
License:Apache License
private void process() throws Exception { _log.info("Creating fixed route data validation report with sourceUrl=" + getSourceUrl()); logger.header(FILENAME,//from www .j av a2s .c om "Mode,Route,Headsign,Direction,# of stops,# of weekday trips,# of Sat trips,# of Sunday trips"); // Use next Wednesday date (including today) to serve as weekday check date. LocalDate firstMon = getFirstDay(DateTimeConstants.MONDAY); LocalDate firstTues = getFirstDay(DateTimeConstants.TUESDAY); LocalDate firstWed = getFirstDay(DateTimeConstants.WEDNESDAY); LocalDate firstThur = getFirstDay(DateTimeConstants.THURSDAY); LocalDate firstFri = getFirstDay(DateTimeConstants.FRIDAY); LocalDate firstSat = getFirstDay(DateTimeConstants.SATURDAY); LocalDate firstSun = getFirstDay(DateTimeConstants.SUNDAY); // Get the service ids for weekdays, Saturdays, and Sundays Set<AgencyAndId> weekdaySvcIds = new HashSet<>(); Set<AgencyAndId> saturdaySvcIds = new HashSet<>(); Set<AgencyAndId> sundaySvcIds = new HashSet<>(); // Check service ids Collection<ServiceCalendar> calendars = _dao.getAllCalendars(); for (ServiceCalendar calendar : calendars) { Date svcStartDate = calendar.getStartDate().getAsDate(); LocalDate jodaStartDate = new LocalDate(svcStartDate); Date svcEndDate = calendar.getEndDate().getAsDate(); LocalDate jodaEndDate = new LocalDate(svcEndDate); if (calendar.getMonday() == 1 && !firstMon.isBefore(jodaStartDate) && !firstMon.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getTuesday() == 1 && !firstTues.isBefore(jodaStartDate) && !firstTues.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getWednesday() == 1 && !firstWed.isBefore(jodaStartDate) && !firstWed.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getThursday() == 1 && !firstThur.isBefore(jodaStartDate) && !firstThur.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getFriday() == 1 && !firstFri.isBefore(jodaStartDate) && !firstFri.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getSaturday() == 1 && !firstSat.isBefore(jodaStartDate) && !firstSat.isAfter(jodaEndDate)) { saturdaySvcIds.add(calendar.getServiceId()); } if (calendar.getSunday() == 1 && !firstSun.isBefore(jodaStartDate) && !firstSun.isAfter(jodaEndDate)) { sundaySvcIds.add(calendar.getServiceId()); } } Map<String, List<String>> reportModes = getReportModes(); Collection<Agency> agencies = _dao.getAllAgencies(); for (String currentMode : reportModes.keySet()) { List<String> currentRoutes = reportModes.get(currentMode); for (Agency agency : agencies) { boolean getAllRoutes = false; // If currentRoutes[0] is agency id, get all the routes for that agency if (currentRoutes.get(0).equals(agency.getId())) { getAllRoutes = true; } List<Route> routes = _dao.getRoutesForAgency(agency); for (Route route : routes) { int[] wkdayTrips = null; int[] satTrips = null; int[] sunTrips = null; Map<String, TripTotals> tripMap = new HashMap<>(); AgencyAndId routeId = route.getId(); if (currentRoutes.contains(routeId.toString()) || getAllRoutes) { List<Trip> trips = _dao.getTripsForRoute(route); for (Trip trip : trips) { List<StopTime> stopTimes = _dao.getStopTimesForTrip(trip); int stopCt = stopTimes.size(); if (stopCt > MAX_STOP_CT) { stopCt = MAX_STOP_CT; } TripTotals tripTotals = null; if (tripMap.containsKey(trip.getTripHeadsign())) { tripTotals = tripMap.get(trip.getTripHeadsign()); } else { tripTotals = new TripTotals(); tripMap.put(trip.getTripHeadsign(), tripTotals); } /* * TODO: if stopCt exceeds array sizes, resize arrays */ if (trip.getDirectionId() == null || trip.getDirectionId().equals("0")) { wkdayTrips = tripTotals.wkdayTrips_0; satTrips = tripTotals.satTrips_0; sunTrips = tripTotals.sunTrips_0; } else { wkdayTrips = tripTotals.wkdayTrips_1; satTrips = tripTotals.satTrips_1; sunTrips = tripTotals.sunTrips_1; } AgencyAndId tripSvcId = trip.getServiceId(); if (weekdaySvcIds.contains(tripSvcId)) { ++wkdayTrips[stopCt]; } else if (saturdaySvcIds.contains(tripSvcId)) { ++satTrips[stopCt]; } else if (sundaySvcIds.contains(tripSvcId)) { ++sunTrips[stopCt]; } tripMap.put(trip.getTripHeadsign(), tripTotals); } String routeName = route.getShortName() + "-" + route.getDesc(); for (String headSign : tripMap.keySet()) { TripTotals tripTotals = tripMap.get(headSign); String dir_0 = "0"; String dir_1 = "1"; for (int i = 0; i < MAX_STOP_CT; ++i) { if (tripTotals.wkdayTrips_0[i] > 0 || tripTotals.satTrips_0[i] > 0 || tripTotals.sunTrips_0[i] > 0) { logger.logCSV(FILENAME, currentMode + "," + routeName + "," + headSign + "," + dir_0 + "," + i + "," + tripTotals.wkdayTrips_0[i] + "," + tripTotals.satTrips_0[i] + "," + tripTotals.sunTrips_0[i]); dir_0 = ""; // Only display direction on its first line headSign = ""; // Only display headsign on its first line routeName = ""; // Only display route on its first line currentMode = ""; // Only display mode on its first line } } for (int i = 0; i < MAX_STOP_CT; ++i) { if (tripTotals.wkdayTrips_1[i] > 0 || tripTotals.satTrips_1[i] > 0 || tripTotals.sunTrips_1[i] > 0) { logger.logCSV(FILENAME, currentMode + "," + routeName + "," + headSign + "," + dir_1 + "," + i + "," + tripTotals.wkdayTrips_1[i] + "," + tripTotals.satTrips_1[i] + "," + tripTotals.sunTrips_1[i]); dir_1 = ""; // Only display direction on its first line headSign = ""; // Only display headsign on its first line routeName = ""; // Only display route on its first line currentMode = ""; // Only display mode on its first line } } } } } } logger.logCSV(FILENAME, ",,,,,,,,"); } _log.info("finished fixed route data validation report"); }
From source file:org.onebusaway.webapp.actions.admin.bundles.CompareBundlesAction.java
License:Apache License
private List<DataValidationMode> buildModes(int buildId) { List<DataValidationMode> modes = new ArrayList<>(); // Check service ids List<ArchivedCalendar> calendars = _gtfsArchiveService.getAllCalendarsByBundleId(buildId); // Get dates for checking trips for days of the week LocalDate startDate = getStartDate(calendars); LocalDate firstMon = getFirstDay(DateTimeConstants.MONDAY, startDate); LocalDate firstTues = getFirstDay(DateTimeConstants.TUESDAY, startDate); LocalDate firstWed = getFirstDay(DateTimeConstants.WEDNESDAY, startDate); LocalDate firstThur = getFirstDay(DateTimeConstants.THURSDAY, startDate); LocalDate firstFri = getFirstDay(DateTimeConstants.FRIDAY, startDate); LocalDate firstSat = getFirstDay(DateTimeConstants.SATURDAY, startDate); LocalDate firstSun = getFirstDay(DateTimeConstants.SUNDAY, startDate); // Get the service ids for weekdays, Saturdays, and Sundays Set<AgencyAndId> weekdaySvcIds = new HashSet<>(); Set<AgencyAndId> saturdaySvcIds = new HashSet<>(); Set<AgencyAndId> sundaySvcIds = new HashSet<>(); for (ArchivedCalendar calendar : calendars) { Date svcStartDate = calendar.getStartDate().getAsDate(); LocalDate jodaStartDate = new LocalDate(svcStartDate); Date svcEndDate = calendar.getEndDate().getAsDate(); LocalDate jodaEndDate = new LocalDate(svcEndDate); if (calendar.getMonday() == 1 && !firstMon.isBefore(jodaStartDate) && !firstMon.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); }/*from w ww . ja va2s . c om*/ if (calendar.getTuesday() == 1 && !firstTues.isBefore(jodaStartDate) && !firstTues.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getWednesday() == 1 && !firstWed.isBefore(jodaStartDate) && !firstWed.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getThursday() == 1 && !firstThur.isBefore(jodaStartDate) && !firstThur.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getFriday() == 1 && !firstFri.isBefore(jodaStartDate) && !firstFri.isAfter(jodaEndDate)) { weekdaySvcIds.add(calendar.getServiceId()); } if (calendar.getSaturday() == 1 && !firstSat.isBefore(jodaStartDate) && !firstSat.isAfter(jodaEndDate)) { saturdaySvcIds.add(calendar.getServiceId()); } if (calendar.getSunday() == 1 && !firstSun.isBefore(jodaStartDate) && !firstSun.isAfter(jodaEndDate)) { sundaySvcIds.add(calendar.getServiceId()); } } // Get all the routes for this build id List<ArchivedRoute> allRoutes = _gtfsArchiveService.getAllRoutesByBundleId(buildId); // Get all the trips for this build id List<ArchivedTrip> allTrips = _gtfsArchiveService.getAllTripsByBundleId(buildId); // Get trip stop countt for all the trips in this build // This call returns a list of arrays of Objects of the form // [String trip_agencyId, String trip_id, int stop_count] List allStopCts = _gtfsArchiveService.getTripStopCounts(buildId); Map<AgencyAndId, Integer> tripStopCounts = new HashMap<>(); for (int i = 0; i < allStopCts.size(); ++i) { Object[] tripStopCt = (Object[]) allStopCts.get(i); String tripAgencyId = (String) tripStopCt[0]; String tripId = (String) tripStopCt[1]; int stopCt = (int) tripStopCt[2]; AgencyAndId agencyAndId = new AgencyAndId(tripAgencyId, tripId); tripStopCounts.put(agencyAndId, stopCt); } Map<String, List<String>> reportModes = getReportModes(); Collection<ArchivedAgency> agencies = _gtfsArchiveService.getAllAgenciesByBundleId(buildId); for (String currentMode : reportModes.keySet()) { DataValidationMode newMode = new DataValidationMode(); newMode.setModeName(currentMode); SortedSet<DataValidationRouteCounts> newModeRouteCts = new TreeSet<DataValidationRouteCounts>(); List<String> agenciesOrRoutes = reportModes.get(currentMode); // Note: currentRoutes entries might be just an agency id for (String agencyOrRoute : agenciesOrRoutes) { // or a route, i.e. <agencyId>_<routeId> //List<ArchivedRoute> routes = null; int idx = agencyOrRoute.indexOf("_"); // check if agency or route id int routeCt = allRoutes.size(); int currentRouteCt = 0; for (ArchivedRoute route : allRoutes) { if (!route.getAgencyId().equals(agencyOrRoute)) { continue; } currentRouteCt++; int[] wkdayTrips = null; int[] satTrips = null; int[] sunTrips = null; Map<String, TripTotals> tripMap = new HashMap<>(); String routeId = route.getAgencyId() + ID_SEPARATOR + route.getId(); DataValidationRouteCounts newRouteCts = new DataValidationRouteCounts(); String routeName = route.getDesc(); if (routeName == null || routeName.equals("null") || routeName.isEmpty()) { routeName = route.getLongName(); } if (routeName == null || routeName.equals("null")) { routeName = ""; } newRouteCts.setRouteName(routeName); String routeNum = route.getShortName(); if (routeNum == null || routeNum.equals("null") || routeNum.isEmpty()) { routeNum = route.getId(); } if (routeNum == null || routeNum.equals("null")) { routeNum = ""; } newRouteCts.setRouteNum(routeNum); // Build DataValidationHeadsignCts SortedSet<DataValidationHeadsignCts> headsignCounts = new TreeSet<>(); int stopCtIdx = 0; for (ArchivedTrip trip : allTrips) { if (trip.getRoute_agencyId().compareTo(route.getAgencyId()) > 0 || (trip.getRoute_agencyId().equals(route.getAgencyId()) && trip.getRoute_id().compareTo(route.getId()) > 0)) { break; } if (!trip.getRoute_agencyId().equals(route.getAgencyId()) || !trip.getRoute_id().equals(route.getId())) { continue; } AgencyAndId tripAgencyAndId = new AgencyAndId(trip.getAgencyId(), trip.getId()); int stopCt = tripStopCounts.get(tripAgencyAndId) != null ? tripStopCounts.get(tripAgencyAndId) : 0; if (stopCt > MAX_STOP_CT) { stopCt = MAX_STOP_CT; } TripTotals tripTotals = null; String tripHeadsign = trip.getTripHeadsign(); tripHeadsign = tripHeadsign == null ? "" : tripHeadsign; if (tripMap.containsKey(tripHeadsign)) { tripTotals = tripMap.get(tripHeadsign); } else { tripTotals = new TripTotals(); tripMap.put(tripHeadsign, tripTotals); } /* * TODO: if stopCt exceeds array sizes, resize arrays */ if (trip.getDirectionId() == null || trip.getDirectionId().equals("0")) { wkdayTrips = tripTotals.wkdayTrips_0; satTrips = tripTotals.satTrips_0; sunTrips = tripTotals.sunTrips_0; } else { wkdayTrips = tripTotals.wkdayTrips_1; satTrips = tripTotals.satTrips_1; sunTrips = tripTotals.sunTrips_1; } AgencyAndId tripSvcId = new AgencyAndId(trip.getServiceId_agencyId(), trip.getServiceId_id()); if (weekdaySvcIds.contains(tripSvcId)) { ++wkdayTrips[stopCt]; } else if (saturdaySvcIds.contains(tripSvcId)) { ++satTrips[stopCt]; } else if (sundaySvcIds.contains(tripSvcId)) { ++sunTrips[stopCt]; } tripMap.put(tripHeadsign, tripTotals); } // End of trips loop. Stop counts by direction for this route have been set. for (String headSign : tripMap.keySet()) { TripTotals tripTotals = tripMap.get(headSign); DataValidationHeadsignCts newHeadsignCt = new DataValidationHeadsignCts(); newHeadsignCt.setHeadsign(headSign); SortedSet<DataValidationDirectionCts> newDirCountSet = new TreeSet<DataValidationDirectionCts>(); DataValidationDirectionCts newDirCt_0 = new DataValidationDirectionCts(); newDirCt_0.setDirection("0"); SortedSet<DataValidationStopCt> stopCounts_0 = new TreeSet<>(); for (int i = 0; i < MAX_STOP_CT; ++i) { if (tripTotals.wkdayTrips_0[i] > 0 || tripTotals.satTrips_0[i] > 0 || tripTotals.sunTrips_0[i] > 0) { DataValidationStopCt stopCt_0 = new DataValidationStopCt(); stopCt_0.setStopCt(i); stopCt_0.setTripCts(new int[] { tripTotals.wkdayTrips_0[i], tripTotals.satTrips_0[i], tripTotals.sunTrips_0[i] }); stopCounts_0.add(stopCt_0); } } if (stopCounts_0.size() > 0) { newDirCt_0.setStopCounts(stopCounts_0); newDirCountSet.add(newDirCt_0); } DataValidationDirectionCts newDirCt_1 = new DataValidationDirectionCts(); newDirCt_1.setDirection("1"); SortedSet<DataValidationStopCt> stopCounts_1 = new TreeSet<>(); for (int i = 0; i < MAX_STOP_CT; ++i) { if (tripTotals.wkdayTrips_1[i] > 0 || tripTotals.satTrips_1[i] > 0 || tripTotals.sunTrips_1[i] > 0) { DataValidationStopCt stopCt_1 = new DataValidationStopCt(); stopCt_1.setStopCt(i); stopCt_1.setTripCts(new int[] { tripTotals.wkdayTrips_1[i], tripTotals.satTrips_1[i], tripTotals.sunTrips_1[i] }); stopCounts_1.add(stopCt_1); } if (stopCounts_1.size() > 0) { newDirCt_1.setStopCounts(stopCounts_1); newDirCountSet.add(newDirCt_1); } } if (newDirCountSet.size() > 0) { newHeadsignCt.setDirCounts(newDirCountSet); headsignCounts.add(newHeadsignCt); } } if (headsignCounts.size() > 0) { newRouteCts.setHeadsignCounts(headsignCounts); newModeRouteCts.add(newRouteCts); } } } if (newModeRouteCts.size() > 0) { newMode.setRoutes(newModeRouteCts); modes.add(newMode); } } return modes; }
From source file:org.onebusaway.webapp.actions.admin.bundles.CompareBundlesAction.java
License:Apache License
/** * Examines all the service calendars for this bundle to determine an appropriate * starting date for the bundle. The problem is that if an agency has two * consecutive service calendars for the same trips, if we simply included all * service calendars, those trips would be counted twice. So the goal is to * determine an appropriate starting date and then only count those service * calendars that are active on that date or within the first week following that * date.//from w w w .j av a 2s . c o m * <p> * The strategy used here is to find the earliest service calendar start date * for each agency, and then take the latest of those start dates to be the * start date for the bundle as a whole. * * @param calendars List of all the ArchivedCalendars for this bundle * @return the date to be used as the bundle starting date */ private LocalDate getStartDate(List<ArchivedCalendar> calendars) { Map<String, LocalDate> agencyStartDates = new HashMap<>(); for (ArchivedCalendar calendar : calendars) { String agencyId = calendar.getServiceId().getAgencyId(); LocalDate start = new LocalDate(calendar.getStartDate().getAsDate().getTime()); LocalDate current = agencyStartDates.get(agencyId); if (current == null || start.isBefore(current)) { agencyStartDates.put(agencyId, start); } } LocalDate agencyStartDate = null; for (LocalDate start : agencyStartDates.values()) { if (agencyStartDate == null) { agencyStartDate = start; } else if (start.isAfter(agencyStartDate)) { agencyStartDate = start; } } if (agencyStartDate == null) { agencyStartDate = new LocalDate(); } return agencyStartDate; }
From source file:org.qi4j.sample.dcicargo.sample_a.infrastructure.wicket.form.DateTextFieldWithPicker.java
License:Apache License
public DateTextFieldWithPicker selectedDate(LocalDate newSelectedDate) { if (earliestDate != null && newSelectedDate.isBefore(earliestDate)) { throw new IllegalArgumentException("Selected date can't be before earliest day."); }//from w ww . jav a 2 s. c o m selectedDate = newSelectedDate; return this; }
From source file:org.squashtest.tm.domain.planning.StandardWorkloadCalendar.java
License:Open Source License
public float getWorkload(LocalDate start, LocalDate end) { if (end.isBefore(start)) { throw new IllegalArgumentException("dashboard.error.date"); }/*w ww . j a v a 2 s . c o m*/ LocalDate lstart = skipWeekendToMonday(start); LocalDate lend = truncateWeekendToLastFriday(end); // the following arises iif both days where in the weekend of the same week if (lend.isBefore(lstart)) { return Days.daysBetween(start, end).getDays() * WEEKEND_DAY_WORKLOAD; } int daysbetween = Days.daysBetween(lstart, lend).getDays() + 1; int adjustedDaysbetween = daysbetween + lstart.getDayOfWeek() - 1; int nbWeekend = adjustedDaysbetween / 7; int nbweekdays = daysbetween - nbWeekend * 2; return nbweekdays * BUSINESS_DAY_WORKLOAD; }
From source file:org.surfnet.cruncher.repository.StatisticsRepositoryImpl.java
License:Apache License
/** * {@inheritDoc}/*from w w w .j a v a 2 s . co m*/ */ @Override public List<LoginData> getLogins(final LocalDate start, final LocalDate end, final String idpEntityId, final String spEntityId) { final List<LoginData> result = new ArrayList<LoginData>(); NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(cruncherJdbcTemplate); String query = "select * from aggregated_log_logins " + "where " + "entryday >= :startDate AND " + "entryday <= :endDate AND " + "(:spEntityId IS NULL OR spentityid = :spEntityId) AND " + "(:idpEntityId IS NULL OR idpentityid = :idpEntityId) " + "order by idpentityid, spentityid, entryday "; Map<String, Object> parameterMap = getParameterMap(start, end, idpEntityId, spEntityId); namedJdbcTemplate.query(query, parameterMap, new RowMapper<Object>() { private Map<LocalDate, Integer> queryResult = new HashMap<LocalDate, Integer>(); private LoginData currentAggregate = null; @Override public Object mapRow(ResultSet rs, int row) throws SQLException { LoginData currentRow = getLoginDataFromRow(rs); /* * aggregate if sp/idp entityid differs from previous record * do not aggregate if on first record * if on last record, aggregate last entries */ if (!currentRow.equals(currentAggregate) && !rs.isFirst()) { //record is different, aggregate previous one and start fresh result.add(aggregateCurrentEntry(currentAggregate, start, end)); queryResult = new HashMap<LocalDate, Integer>(); } queryResult.put(new LocalDate(rs.getDate("entryday")), rs.getInt("entrycount")); currentAggregate = currentRow; if (rs.isLast()) { // aggregate last set result.add(aggregateCurrentEntry(currentAggregate, start, end)); } /* * This is kinda weird, but single row results are stored in * queryResult (hashmap) or aggregated in result (List<loginData) */ return null; } private LoginData aggregateCurrentEntry(final LoginData loginData, final LocalDate start, final LocalDate end) { LocalDate current = start; int total = 0; while (current.isBefore(end.plusDays(1))) { Integer count = queryResult.get(current); if (count == null) { loginData.getData().add(0); } else { loginData.getData().add(count); total += count; } current = current.plusDays(1); } loginData.setTotal(total); loginData.setPointStart(start.toDate().getTime()); loginData.setPointEnd(end.toDate().getTime()); loginData.setPointInterval(POINT_INTERVAL); return loginData; } private LoginData getLoginDataFromRow(ResultSet rs) throws SQLException { LoginData result = new LoginData(); result.setIdpEntityId(rs.getString("idpentityid")); result.setIdpname(rs.getString("idpentityname")); result.setSpEntityId(rs.getString("spentityid")); result.setSpName(rs.getString("spentityname")); return result; } }); return result; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * Sets the date range of this tuningDateField * /* www . j av a 2s.c o m*/ * @param startDate * the start date (included). <code>null</code> for unlimited * @param endDate * the end date (included). <code>null</code> for unlimited * @param errorMessage * the error message */ public void setDateRange(LocalDate startDate, LocalDate endDate, String errorMessage) { if (startDate != null && endDate != null && endDate.isBefore(startDate)) { throw new IllegalArgumentException( "Cannot have a date range with end date " + endDate + " before start date " + startDate); } removeDateRange(); dateRangeValidator = new RangeValidator<LocalDate>(errorMessage, LocalDate.class, startDate, endDate); addValidator(dateRangeValidator); markAsDirty(); }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
protected CalendarItem[] buildDayItems() { LocalDate calendarFirstDay = getCalendarFirstDay(); LocalDate calendarLastDay = getCalendarLastDay(); LocalDate firstDayOfMonth = yearMonthDisplayed.toLocalDate(1); LocalDate lastDayOfMonth = yearMonthDisplayed.toLocalDate(1).dayOfMonth().withMaximumValue(); LocalDate today = LocalDate.now(); int numberOfDays = Days.daysBetween(calendarFirstDay, calendarLastDay).getDays() + 1; LocalDate date = calendarFirstDay; CalendarItem[] calendarItems = new CalendarItem[numberOfDays]; LocalDate currentValue = getLocalDate(); for (int i = 0; i < numberOfDays; i++, date = date.plusDays(1)) { calendarItems[i] = new CalendarItem(); calendarItems[i].setIndex(i);// ww w.j a va2 s. c o m if (date.getMonthOfYear() == yearMonthDisplayed.getMonthOfYear()) { calendarItems[i].setRelativeDateIndex(date.getDayOfMonth()); } else { calendarItems[i].setRelativeDateIndex(-date.getDayOfMonth()); } String calendarItemContent = null; if (cellItemCustomizer != null) { calendarItemContent = cellItemCustomizer.renderDay(date, this); } // fallback to default value if (calendarItemContent == null) { calendarItemContent = Integer.toString(date.getDayOfMonth()); } calendarItems[i].setText(calendarItemContent); StringBuilder style = new StringBuilder(); if (date.equals(today)) { style.append("today "); } if (currentValue != null && date.equals(currentValue)) { style.append("selected "); } if (date.isBefore(firstDayOfMonth)) { style.append("previousmonth "); calendarItems[i].setEnabled(!isPreviousMonthDisabled()); } else if (date.isAfter(lastDayOfMonth)) { style.append("nextmonth "); calendarItems[i].setEnabled(!isNextMonthDisabled()); } else { style.append("currentmonth "); calendarItems[i].setEnabled(isDateEnabled(date)); } if (isWeekend(date)) { style.append("weekend "); } if (cellItemCustomizer != null) { String generatedStyle = cellItemCustomizer.getStyle(date, this); if (generatedStyle != null) { style.append(generatedStyle); style.append(" "); } String tooltip = cellItemCustomizer.getTooltip(date, this); if (tooltip != null) { calendarItems[i].setTooltip(tooltip); } } String computedStyle = style.toString(); if (!computedStyle.isEmpty()) { calendarItems[i].setStyle(computedStyle); } } return calendarItems; }
From source file:org.zkoss.ganttz.timetracker.zoom.TimeTrackerState.java
License:Open Source License
private Collection<DetailItem> createDetails(Interval interval, Iterator<LocalDate> datesGenerator, IDetailItemCreator detailItemCreator) { List<DetailItem> result = new ArrayList<>(); LocalDate current = interval.getStart(); LocalDate end = interval.getFinish(); while (current.isBefore(end)) { result.add(detailItemCreator.create(current.toDateTimeAtStartOfDay())); assert datesGenerator.hasNext(); current = datesGenerator.next(); }//from w ww . j av a 2 s .c o m return result; }
From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.acquisitions.SearchPaymentProcessesAction.java
License:Open Source License
private void fillXlsInfo(Set<PaymentProcess> processes, StyledExcelSpreadsheet spreadsheet, OutputStream outputStream) throws IOException { spreadsheet.newRow();//from w w w. j a v a 2 s .c o m spreadsheet.addCell(processes.size() + " " + getAcquisitionResourceMessage("label.processes")); spreadsheet.newRow(); setHeaders(spreadsheet); TreeSet<PaymentProcess> sortedProcesses = new TreeSet<PaymentProcess>( PaymentProcess.COMPARATOR_BY_YEAR_AND_ACQUISITION_PROCESS_NUMBER); sortedProcesses.addAll(processes); for (PaymentProcess process : sortedProcesses) { spreadsheet.newRow(); spreadsheet.addCell(process.getAcquisitionProcessId()); spreadsheet.addCell(process.getTypeShortDescription()); AcquisitionItemClassification classification = process.getGoodsOrServiceClassification(); spreadsheet.addCell(classification == null ? " " : classification.getLocalizedName()); spreadsheet.addCell(process.getSuppliersDescription()); spreadsheet.addCell(process.getRequest().getRequestItemsSet().size()); spreadsheet.addCell(process.getProcessStateDescription()); DateTime time = new DateTime(); if (process.getPaymentProcessYear().getYear() != time.getYear()) { time = new DateTime(process.getPaymentProcessYear().getYear().intValue(), 12, 31, 23, 59, 59, 0); } spreadsheet.addCell(describeState(process, time)); DateTime date = process.getDateFromLastActivity(); spreadsheet.addCell((date == null) ? "" : date.getDayOfMonth() + "-" + date.getMonthOfYear() + "-" + date.getYear() + " " + date.getHourOfDay() + ":" + date.getMinuteOfHour()); spreadsheet.addCell(process.getRequest().getRequester().getFirstAndLastName()); spreadsheet.addCell(process.getRequest().getRequestingUnit().getName()); final MissionProcess missionProcess = process.getMissionProcess(); spreadsheet.addCell(missionProcess == null ? "" : missionProcess.getProcessNumber()); final Boolean skipSupplierFundAllocation = process.getSkipSupplierFundAllocation(); spreadsheet.addCell(Boolean .toString(skipSupplierFundAllocation != null && skipSupplierFundAllocation.booleanValue())); spreadsheet.addCell(toString(process.getCPVReferences())); final StringBuilder builderAccountingUnit = new StringBuilder(); final StringBuilder builderUnits = new StringBuilder(); for (final Financer financer : process.getFinancersWithFundsAllocated()) { final AccountingUnit accountingUnit = financer.getAccountingUnit(); if (accountingUnit != null) { if (builderAccountingUnit.length() > 0) { builderAccountingUnit.append(", "); } builderAccountingUnit.append(accountingUnit.getName()); } final Unit unit = financer.getUnit(); if (unit != null) { if (builderUnits.length() > 0) { builderUnits.append(", "); } builderUnits.append(unit.getUnit().getAcronym()); } } spreadsheet.addCell(builderAccountingUnit.length() == 0 ? " " : builderAccountingUnit.toString()); spreadsheet.addCell(builderUnits.length() == 0 ? " " : builderUnits.toString()); final Money totalValue = process.getTotalValue(); spreadsheet.addCell((totalValue == null ? Money.ZERO : totalValue).toFormatString()); final StringBuilder fundAllocationNumbers = new StringBuilder(); final StringBuilder commitmentNumbers = new StringBuilder(); final StringBuilder efectiveFundAllocationNumbers = new StringBuilder(); final StringBuilder requestOrderNumber = new StringBuilder(); LocalDate invoiceDate = null; Money invoiceValue = Money.ZERO; if (process instanceof SimplifiedProcedureProcess) { SimplifiedProcedureProcess simplifiedProcedureProcess = (SimplifiedProcedureProcess) process; final AcquisitionRequest acquisitionRequest = simplifiedProcedureProcess.getAcquisitionRequest(); for (PayingUnitTotalBean payingUnitTotal : acquisitionRequest.getTotalAmountsForEachPayingUnit()) { if ((simplifiedProcedureProcess.getFundAllocationPresent()) && (payingUnitTotal.getFinancer().isFundAllocationPresent())) { if (fundAllocationNumbers.length() > 0) { fundAllocationNumbers.append(", "); } fundAllocationNumbers.append(payingUnitTotal.getFinancer().getFundAllocationIds().trim()); } if (commitmentNumbers.length() > 0) { fundAllocationNumbers.append(", "); } String commitmentNumber = payingUnitTotal.getFinancer().getCommitmentNumber(); if (commitmentNumber != null) { commitmentNumber = commitmentNumber.trim(); if (commitmentNumber.length() > 0) { commitmentNumbers.append(commitmentNumber); } } if ((simplifiedProcedureProcess.getEffectiveFundAllocationPresent()) && (payingUnitTotal.getFinancer().isEffectiveFundAllocationPresent())) { if (efectiveFundAllocationNumbers.length() > 0) { efectiveFundAllocationNumbers.append(", "); } efectiveFundAllocationNumbers .append(payingUnitTotal.getFinancer().getEffectiveFundAllocationIds().trim()); } } boolean hasFullInvoice = false; for (final Invoice invoice : acquisitionRequest.getInvoices()) { // final AcquisitionInvoice acquisitionInvoice = (AcquisitionInvoice) invoice; final LocalDate localDate = invoice.getInvoiceDate(); if (invoiceDate == null || invoiceDate.isBefore(localDate)) { invoiceDate = localDate; } hasFullInvoice = true; // if (!hasFullInvoice) { // final String confirmationReport = acquisitionInvoice.getConfirmationReport(); // if (confirmationReport == null) { // hasFullInvoice = true; // } else { // for (int i = 0; i < confirmationReport.length(); ) { // final int ulli = confirmationReport.indexOf("<ul><li>", i); // final int q = confirmationReport.indexOf(" - Quantidade:", ulli); // final int ulliClose = confirmationReport.indexOf("</li></ul>", q); // final String itemDescription = confirmationReport.substring(i + "<ul><li>".length(), q); // final int quantity = Integer.parseInt(confirmationReport.substring(q + " - Quantidade:".length(), ulliClose)); // // invoiceValue = invoiceValue.add(calculate(acquisitionRequest, itemDescription, quantity)); // } // } // } } if (hasFullInvoice) { invoiceValue = totalValue; } final PurchaseOrderDocument purchaseOrderDocument = simplifiedProcedureProcess .getPurchaseOrderDocument(); if (purchaseOrderDocument != null) { requestOrderNumber.append(purchaseOrderDocument.getRequestId()); } } spreadsheet.addCell(fundAllocationNumbers.length() == 0 ? " " : fundAllocationNumbers.toString()); spreadsheet.addCell(commitmentNumbers.length() == 0 ? " " : commitmentNumbers.toString()); spreadsheet.addCell(requestOrderNumber.length() == 0 ? " " : requestOrderNumber.toString()); spreadsheet.addCell( efectiveFundAllocationNumbers.length() == 0 ? " " : efectiveFundAllocationNumbers.toString()); spreadsheet.addCell(invoiceDate == null ? " " : invoiceDate.toString("yyyy-MM-dd")); spreadsheet.addCell(invoiceValue.toFormatString()); DateTime creationDate = process.getCreationDate(); spreadsheet.addCell(creationDate == null ? " " : creationDate.toString("yyyy-MM-dd")); SortedSet<WorkflowLog> executionLogsSet = new TreeSet<WorkflowLog>( WorkflowLog.COMPARATOR_BY_WHEN_REVERSED); executionLogsSet.addAll(process.getExecutionLogsSet()); DateTime approvalDate = getApprovalDate(process, executionLogsSet); spreadsheet.addCell(approvalDate == null ? " " : approvalDate.toString("yyyy-MM-dd")); DateTime authorizationDate = getAuthorizationDate(process, executionLogsSet); spreadsheet.addCell(authorizationDate == null ? " " : authorizationDate.toString("yyyy-MM-dd")); } }