List of usage examples for org.joda.time LocalDate isAfter
public boolean isAfter(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 w w w.j a va 2 s.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()); }// www. j a v a2 s . com 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 ww .j av a2 s.c om * <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.projectbuendia.client.ui.patientcreation.PatientCreationController.java
License:Apache License
public boolean createPatient(String id, String givenName, String familyName, String age, int ageUnits, int sex, LocalDate admissionDate, LocalDate symptomsOnsetDate, String locationUuid) { // Validate the input. mUi.clearValidationErrors();/*w w w . j a va2s . com*/ boolean hasValidationErrors = false; if (id == null || id.equals("")) { mUi.showValidationError(Ui.FIELD_ID, R.string.patient_validation_missing_id); hasValidationErrors = true; } if (age == null || age.equals("")) { mUi.showValidationError(Ui.FIELD_AGE, R.string.patient_validation_missing_age); hasValidationErrors = true; } if (admissionDate == null) { mUi.showValidationError(Ui.FIELD_ADMISSION_DATE, R.string.patient_validation_missing_admission_date); hasValidationErrors = true; } int ageInt = 0; try { ageInt = Integer.parseInt(age); } catch (NumberFormatException e) { mUi.showValidationError(Ui.FIELD_AGE, R.string.patient_validation_whole_number_age_required); hasValidationErrors = true; } if (ageInt < 0) { mUi.showValidationError(Ui.FIELD_AGE, R.string.patient_validation_negative_age); hasValidationErrors = true; } if (ageUnits != AGE_YEARS && ageUnits != AGE_MONTHS) { mUi.showValidationError(Ui.FIELD_AGE_UNITS, R.string.patient_validation_select_years_or_months); hasValidationErrors = true; } if (sex != SEX_MALE && sex != SEX_FEMALE) { mUi.showValidationError(Ui.FIELD_SEX, R.string.patient_validation_select_gender); hasValidationErrors = true; } if (admissionDate != null && admissionDate.isAfter(LocalDate.now())) { mUi.showValidationError(Ui.FIELD_ADMISSION_DATE, R.string.patient_validation_future_admission_date); hasValidationErrors = true; } if (symptomsOnsetDate != null && symptomsOnsetDate.isAfter(LocalDate.now())) { mUi.showValidationError(Ui.FIELD_SYMPTOMS_ONSET_DATE, R.string.patient_validation_future_onset_date); hasValidationErrors = true; } Utils.logUserAction("add_patient_submitted", "valid", "" + !hasValidationErrors); if (hasValidationErrors) { return false; } AppPatientDelta patientDelta = new AppPatientDelta(); patientDelta.id = Optional.of(id); patientDelta.givenName = Optional.of(Utils.nameOrUnknown(givenName)); patientDelta.familyName = Optional.of(Utils.nameOrUnknown(familyName)); patientDelta.birthdate = Optional.of(getBirthdateFromAge(ageInt, ageUnits)); patientDelta.gender = Optional.of(sex); patientDelta.assignedLocationUuid = Optional.of(Utils.valueOrDefault(locationUuid, Zone.DEFAULT_LOCATION)); patientDelta.admissionDate = Optional.of(admissionDate); patientDelta.firstSymptomDate = Optional.fromNullable(symptomsOnsetDate); mModel.addPatient(mCrudEventBus, patientDelta); return true; }
From source file:org.projectbuendia.client.utils.RelativeDateTimeFormatter.java
License:Apache License
/** Formats a representation of {@code date} relative to {@code anchor}. */ public String format(LocalDate date, LocalDate anchor) { if (date.isAfter(anchor)) { return "in the future"; // TODO/i18n }/*from w ww . j a v a2s . c o m*/ Period period = new Period(date, anchor); int daysAgo = period.toStandardDays().getDays(); return daysAgo > 1 ? daysAgo + " days ago" : // TODO/i18n daysAgo == 1 ? "yesterday" : "today"; // TODO/i18n }
From source file:org.qi4j.sample.dcicargo.sample_a.infrastructure.wicket.form.DateTextFieldWithPicker.java
License:Apache License
public DateTextFieldWithPicker earliestDate(LocalDate newEarliestDate) { if (selectedDate != null && newEarliestDate.isAfter(selectedDate)) { throw new IllegalArgumentException("Earliest date can't be before selected day."); }//from www . j a va2 s. c o m earliestDate = newEarliestDate; // Input field validation - date should be _after_ minimumDate (not the same) LocalDate minimumDate = newEarliestDate.minusDays(1); Date convertedMinimumDate = new DateTime(minimumDate.toDateTime(new LocalTime())).toDate(); add(DateValidator.minimum(convertedMinimumDate)); return this; }
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);//from w w w . j a v a 2 s. co 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.util.Interval.java
License:Open Source License
public Interval(LocalDate startInclusive, LocalDate endExclusive) { Validate.notNull(startInclusive);//w w w. jav a 2 s . co m Validate.notNull(endExclusive); Validate.isTrue(endExclusive.isAfter(startInclusive)); this.startInclusive = startInclusive; this.endExclusive = endExclusive; this.lengthBetween = new Duration(this.startInclusive.toDateTimeAtStartOfDay(), this.endExclusive.toDateTimeAtStartOfDay()); this.daysBetween = Days.daysBetween(this.startInclusive, this.endExclusive); }
From source file:pt.ist.expenditureTrackingSystem.domain.authorizations.DelegatedAuthorization.java
License:Open Source License
private void checkParameters(Authorization authorization, Person delegatedPerson, Unit unit, Boolean canDelegate, LocalDate endDate, Money maxAmount) { if (authorization == null || delegatedPerson == null || canDelegate == null || unit == null) { throw new DomainException(Bundle.EXPENDITURE, "error.authorization.person.and.delegation.are.required"); }/* w w w. ja v a 2 s. c o m*/ if (authorization.getEndDate() != null && ((endDate != null && endDate.isAfter(authorization.getEndDate()) || (authorization.getEndDate() != null && endDate == null)))) { throw new DomainException(Bundle.EXPENDITURE, "error.authorization.cannot.be.delegated.after.your.end.date"); } if (!unit.isSubUnit(authorization.getUnit())) { throw new DomainException(Bundle.EXPENDITURE, "error.unit.is.not.subunit.of.authorization.unit"); } if (maxAmount == null || maxAmount.isGreaterThan(authorization.getMaxAmount())) { throw new DomainException(Bundle.EXPENDITURE, "error.maxAmount.cannot.be.greater.than.authorization.maxAmount"); } }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonAbsencesFromGiaf.java
License:Open Source License
@Override public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger) throws Exception { List<Modification> modifications = new ArrayList<>(); PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery(metadata)); ResultSet result = preparedStatement.executeQuery(); int count = 0; int news = 0; int notImported = 0; int dontExist = 0; Set<Person> importedButInvalid = new HashSet<Person>(); while (result.next()) { count++;/*from w w w . ja va 2 s. co m*/ String numberString = result.getString("emp_num"); Person person = metadata.getPerson(numberString, logger); if (person == null) { logger.debug("Invalid person with number: " + numberString); dontExist++; continue; } PersonProfessionalData personProfessionalData = person.getPersonProfessionalData(); if (personProfessionalData == null) { logger.debug("Empty personProfessionalData: " + numberString); dontExist++; continue; } final GiafProfessionalData giafProfessionalData = personProfessionalData .getGiafProfessionalDataByGiafPersonIdentification(numberString); if (giafProfessionalData == null) { logger.debug("Empty giafProfessionalData: " + numberString); dontExist++; continue; } final String absenceGiafId = result.getString("flt_tip"); final Absence absence = metadata.absence(absenceGiafId); if (absence == null) { logger.debug("Empty absence: " + absenceGiafId + " for person number: " + numberString); importedButInvalid.add(person); } String beginDateString = result.getString("FLT_DT_INIC"); final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null : new LocalDate(Timestamp.valueOf(beginDateString)); if (beginDate == null) { logger.debug("Empty beginDate. Person number: " + numberString + " Absence: " + absenceGiafId); importedButInvalid.add(person); } String endDateString = result.getString("FLT_DT_FIM"); final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null : new LocalDate(Timestamp.valueOf(endDateString)); if (beginDate != null && endDate != null) { if (beginDate.isAfter(endDate)) { logger.debug("BeginDate after endDate. Person number: " + numberString + " begin: " + beginDate + " end: " + endDate); importedButInvalid.add(person); } } String creationDateString = result.getString("data_criacao"); if (Strings.isNullOrEmpty(creationDateString)) { logger.debug("Empty creationDate. Person number: " + numberString + " Absence: " + absenceGiafId); notImported++; continue; } final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString)); String modifiedDateString = result.getString("data_alteracao"); final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null : new DateTime(Timestamp.valueOf(modifiedDateString)); if (!hasPersonAbsence(giafProfessionalData, beginDate, endDate, absence, absenceGiafId, creationDate, modifiedDate)) { modifications.add(new Modification() { @Override public void execute() { new PersonAbsence(giafProfessionalData, beginDate, endDate, absence, absenceGiafId, creationDate, modifiedDate); } }); news++; } } result.close(); preparedStatement.close(); int deleted = 0; int totalInFenix = 0; int repeted = 0; for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) { for (PersonProfessionalExemption personProfessionalExemption : giafProfessionalData .getPersonProfessionalExemptionsSet()) { if (personProfessionalExemption instanceof PersonAbsence && personProfessionalExemption.getAnulationDate() == null) { PersonAbsence personAbsence = (PersonAbsence) personProfessionalExemption; int countThisPersonAbsenceOnGiaf = countThisPersonAbsenceOnGiaf(oracleConnection, personAbsence, logger); if (countThisPersonAbsenceOnGiaf == 0) { personAbsence.setAnulationDate(new DateTime()); deleted++; } else { totalInFenix++; if (countThisPersonAbsenceOnGiaf > 1) { repeted += countThisPersonAbsenceOnGiaf - 1; } } } } } oracleConnection.closeConnection(); log.println("-- Absences --"); log.println("Total GIAF: " + count); log.println("New: " + news); log.println("Deleted: " + deleted); log.println("Not imported: " + notImported); log.println("Imported with errors: " + importedButInvalid.size()); log.println("Repeted: " + repeted); log.println("Invalid persons: " + dontExist); log.println("Total Fnix: " + totalInFenix); log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size())); log.println("Missing in Fnix: " + (count - totalInFenix)); return modifications; }