List of usage examples for java.util Date equals
public boolean equals(Object obj)
From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java
protected boolean applyMisfire(TriggerWrapper tw) { logDebug("Applying misfire on Trigger: ", tw.trigger.getFullName()); long misfireTime = System.currentTimeMillis(); if (getMisfireThreshold() > 0) { misfireTime -= getMisfireThreshold(); }// w w w.j av a 2s . c o m Date tnft = tw.trigger.getNextFireTime(); if (tnft == null || tnft.getTime() > misfireTime) { return false; } Calendar cal = null; if (tw.trigger.getCalendarName() != null) { cal = retrieveCalendar(null, tw.trigger.getCalendarName()); } signaler.notifyTriggerListenersMisfired((Trigger) tw.trigger.clone()); tw.trigger.updateAfterMisfire(cal); if (tw.trigger.getNextFireTime() == null) { tw.state = TriggerWrapper.STATE_COMPLETE; signaler.notifySchedulerListenersFinalized(tw.trigger); removeTrigger(null, tw.trigger.getName(), tw.trigger.getGroup()); } else if (tnft.equals(tw.trigger.getNextFireTime())) { return false; } return true; }
From source file:org.jasig.schedassist.impl.caldav.CaldavCalendarDataDaoImpl.java
/** * This method returns the {@link CalendarWithURI} containing a single {@link VEvent} that * was created with the Scheduling Assistant with the specified {@link IScheduleOwner} as the owner * and the specified start and end times. * /* w ww .j a v a2s .c om*/ * @param owner * @param startTime * @param endTime * @return the matching Scheduling Assistant {@link VEvent}, or null if none for this {@link IScheduleOwner} at the specified times */ protected CalendarWithURI getExistingAppointmentInternal(IScheduleOwner owner, Date startTime, Date endTime) { final DateTime targetStartTime = new DateTime(startTime); final DateTime targetEndTime = new DateTime(endTime); List<CalendarWithURI> calendars = getCalendarsInternal(owner.getCalendarAccount(), startTime, endTime); for (CalendarWithURI calendarWithUri : calendars) { ComponentList componentList = calendarWithUri.getCalendar().getComponents(VEvent.VEVENT); if (componentList.size() != 1) { // scheduling assistant creates calendars with only a single event, short-circuit on calendars with > 1 events continue; } for (Object o : componentList) { VEvent event = (VEvent) o; Date eventStart = event.getStartDate().getDate(); Date eventEnd = event.getEndDate(true).getDate(); Property schedAssistProperty = event .getProperty(SchedulingAssistantAppointment.AVAILABLE_APPOINTMENT); if (!SchedulingAssistantAppointment.TRUE.equals(schedAssistProperty)) { // immediately skip over non-scheduling assistant appointments continue; } // check for version first Property versionProperty = event.getProperty(AvailableVersion.AVAILABLE_VERSION); if (AvailableVersion.AVAILABLE_VERSION_1_2.equals(versionProperty)) { // event has to be (1) an available appointment // with (2) owner recognized as appointment owner and // (3) start and (4) end date have to match if (this.eventUtils.isAttendingAsOwner(event, owner.getCalendarAccount()) && eventStart.equals(targetStartTime) && eventEnd.equals(targetEndTime)) { if (log.isDebugEnabled()) { log.debug("getExistingAppointmentInternal found " + event); } return calendarWithUri; } } } } // not found return null; }
From source file:gui.GW2EventerGui.java
private void runPushService() { Thread t = new Thread() { @Override/* w w w.ja v a 2 s . c o m*/ public void run() { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10 * 1000).build(); HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); HttpGet request = new HttpGet("http://gw2eventer.sourceforge.net/push/"); HttpResponse response; String line = ""; String out = ""; //HashMap result = new HashMap(); String date = ""; String enabled = "false"; String title = ""; String message = ""; while (!this.isInterrupted()) { try { response = client.execute(request); if (response.getStatusLine().toString().contains("200")) { BufferedReader rd = new BufferedReader(new InputStreamReader( response.getEntity().getContent(), Charset.forName("UTF-8"))); line = ""; out = ""; while ((line = rd.readLine()) != null) { out = out + line; } JSONParser parser = new JSONParser(); Object obj; try { obj = parser.parse(out); JSONArray array = (JSONArray) obj; for (int i = 0; i < array.size(); i++) { JSONObject obj2 = (JSONObject) array.get(i); //result.put(obj2.get("version"), obj2.get("changelog")); date = (String) obj2.get("date"); enabled = (String) obj2.get("enabled"); title = (String) obj2.get("title"); message = (String) obj2.get("message"); } if (!date.equals("") && enabled.equals("true")) { try { Date dateData = new Date(Long.parseLong(date)); //long stampNow = dateNow.getTime(); if (!dateData.equals(getLastPushDate())) { setLastPushDate(dateData); //showPushGui(title, message, 100); setPushMessage(title, message); } } catch (java.lang.NumberFormatException ex) { // } } else { clearPushMessage(); } } catch (ParseException ex) { Logger.getLogger(ApiManager.class.getName()).log(Level.SEVERE, null, ex); } request.releaseConnection(); //this.interrupt(); try { Thread.sleep(60000 * 5); } catch (InterruptedException ex) { Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex); } } else { try { request.releaseConnection(); Thread.sleep(20000); } catch (InterruptedException ex) { Logger.getLogger(EventAllReader.class.getName()).log(Level.SEVERE, null, ex); } } } catch (IOException | IllegalStateException ex) { try { Logger.getLogger(EventReader.class.getName()).log(Level.SEVERE, null, ex); request.releaseConnection(); Thread.sleep(20000); } catch (InterruptedException ex1) { Logger.getLogger(EventAllReader.class.getName()).log(Level.SEVERE, null, ex1); this.interrupt(); } } } } }; t.start(); }
From source file:gov.nih.nci.cabig.caaers.api.impl.SAEEvaluationServiceImpl.java
private ValidationErrors validateRepPeriodDates(AdverseEventReportingPeriod rPeriod, List<AdverseEventReportingPeriod> rPeriodList, Date firstCourseDate, Epoch epoch) { ValidationErrors errors = new ValidationErrors(); Date startDate = rPeriod.getStartDate(); Date endDate = rPeriod.getEndDate(); // Check if the start date is equal to or before the end date. if (firstCourseDate != null && startDate != null && (firstCourseDate.getTime() - startDate.getTime() > 0)) { errors.addValidationError("WS_AEMS_014", "Start date of this course/cycle cannot be earlier than the Start date of first course/cycle"); }/*from w ww .ja va 2 s . c om*/ if (startDate != null && endDate != null && (endDate.getTime() - startDate.getTime() < 0)) { errors.addValidationError("WS_AEMS_015", "Course End date cannot be earlier than Start date."); } // Check if the start date is equal to end date. // This is allowed only for Baseline reportingPeriods and not for other // reporting periods. if (epoch != null && !epoch.getName().equals("Baseline")) { if (endDate != null && startDate.equals(endDate)) { errors.addValidationError("WS_AEMS_016", "For Non-Baseline treatment type Start date cannot be equal to End date."); } } // Check if the start date - end date for the reporting Period overlaps // with the date range of an existing Reporting Period. for (AdverseEventReportingPeriod aerp : rPeriodList) { Date sDate = aerp.getStartDate(); Date eDate = aerp.getEndDate(); if (!aerp.getId().equals(rPeriod.getId())) { // CAAERS-7323 - If TAC or otherTreatmentAssignmentDescription of the passed in Reporting Period is different than the Reporting Period in loop, // skip the validation for overlapping reporting period dates if (rPeriod.hasNoCommonTacOrOtherTreatmentAssignmentDescription((aerp))) { continue; } // we should make sure that no existing Reporting Period, start // date falls, in-between these dates. if (startDate != null && endDate != null) { if (DateUtils.compareDate(sDate, startDate) >= 0 && DateUtils.compareDate(sDate, endDate) < 0) { errors.addValidationError("WS_AEMS_017", "Course/cycle cannot overlap with an existing course/cycle."); break; } } else if (startDate != null && DateUtils.compareDate(sDate, startDate) == 0) { errors.addValidationError("WS_AEMS_017", "Course/cycle cannot overlap with an existing course/cycle."); break; } // newly created reporting period start date, should not fall // within any other existing reporting periods if (sDate != null && eDate != null) { if (DateUtils.compareDate(sDate, startDate) <= 0 && DateUtils.compareDate(startDate, eDate) < 0) { errors.addValidationError("WS_AEMS_017", "Course/cycle cannot overlap with an existing course/cycle."); break; } } else if (sDate != null && DateUtils.compareDate(sDate, startDate) == 0) { errors.addValidationError("WS_AEMS_017", "Course/cycle cannot overlap with an existing course/cycle."); break; } } // If the epoch of reportingPeriod is not - Baseline , then it // cannot be earlier than a Baseline if (epoch != null && epoch.getName().equals("Baseline")) { if (aerp.getEpoch() != null && (!aerp.getEpoch().getName().equals("Baseline"))) { if (DateUtils.compareDate(sDate, startDate) < 0) { errors.addValidationError("WS_AEMS_018", "Baseline treatment type cannot start after an existing Non-Baseline treatment type."); return errors; } } } else { if (aerp.getEpoch() != null && aerp.getEpoch().getName().equals("Baseline")) { if (DateUtils.compareDate(startDate, sDate) < 0) { errors.addValidationError("WS_AEMS_019", "Non-Baseline treatment type cannot start before an existing Baseline treatment type."); return errors; } } } // Duplicate Baseline check if (epoch != null && epoch.getName().equals("Baseline")) { // Iterating through the already anything exists with the treatment type Baseline. for (AdverseEventReportingPeriod rp : rPeriodList) { if (rp.getEpoch() != null && rp.getEpoch().getName() != null && rp.getEpoch().getName().equals("Baseline")) { errors.addValidationError("WS_AEMS_085", "A Baseline treatment type already exists"); break; } } } } return errors; }
From source file:org.craftercms.cstudio.alfresco.dm.service.impl.DmWorkflowServiceImpl.java
/** * approve workflows and schedule them as specified in the request * * @param site/*from w ww . j ava 2s. c o m*/ * @param sub * @return call result * @throws ServiceException */ public void goLive(final String site, String sub, final List<DmDependencyTO> submittedItems, String approver, MultiChannelPublishingContext mcpContext) throws ServiceException { List<DmDependencyTO> goLiveItems = new FastList<DmDependencyTO>(); // Don't make go live an item if it is new and to be deleted DmContentService dmContentService = getService(DmContentService.class); for (DmDependencyTO submittedItem : submittedItems) { String uri = submittedItem.getUri(); boolean isNew = dmContentService.isNew(site, uri); if (!(submittedItem.isDeleted() && isNew)) { goLiveItems.add(submittedItem); } } PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class); String user = persistenceManagerService.getCurrentUserName(); // get web project information String assignee = getAssignee(site, sub); ServicesConfig servicesConfig = getService(ServicesConfig.class); final String pathPrefix = servicesConfig.getRepositoryRootPath(site); final Date now = new Date(); // group submitted items into packages by their scheculed date Map<Date, List<DmDependencyTO>> groupedPackages = new FastMap<Date, List<DmDependencyTO>>(); for (DmDependencyTO submittedItem : goLiveItems) { List<String> taskIds = new FastList<String>(); //find all pending workflows //getWorkflowTask(site, null, submittedItem, taskIds); // find out how many workflows pending per submitted items submittedItem.setWorkflowTasks(taskIds); Date scheduledDate = (submittedItem.isNow()) ? null : submittedItem.getScheduledDate(); if (scheduledDate == null || scheduledDate.before(now)) { scheduledDate = now; } List<DmDependencyTO> goLivePackage = groupedPackages.get(scheduledDate); if (goLivePackage == null) goLivePackage = new FastList<DmDependencyTO>(); goLivePackage.add(submittedItem); groupedPackages.put(scheduledDate, goLivePackage); } for (Date scheduledDate : groupedPackages.keySet()) { List<DmDependencyTO> goLivePackage = groupedPackages.get(scheduledDate); if (goLivePackage != null) { // for submit direct, package them together and submit them // together as direct submit if (scheduledDate.equals(now)) { if (goLivePackage.size() == 1) { DmDependencyTO item = goLivePackage.get(0); List<String> tasks = item.getWorkflowTasks(); if (tasks != null && tasks.size() > 1) { // if there is more than one workflow pending approveMultiplePackages(site, null, sub, user, pathPrefix, assignee, null, goLivePackage); } else { approveSinglePackage(site, null, sub, user, pathPrefix, assignee, null, goLivePackage.get(0)); } } else { // more than one independent item approveMultiplePackages(site, null, sub, user, pathPrefix, assignee, null, goLivePackage); } } else { for (DmDependencyTO item : goLivePackage) { approveSinglePackage(site, null, sub, user, pathPrefix, assignee, scheduledDate, item); } } } } invokeListeners(submittedItems, site, Operation.GO_LIVE); }
From source file:edu.byu.mpn.test.DeviceControllerIntegrationTest.java
@Test public void testUpdateDevice() { Date dateRegistered = new Date(); Date dateTimeUpdated = deviceDao.getDeviceById(1).getDateTimeUpdated(); // Tests that correct error responses are returned in cases with invalid devices assertEquals(400, controller.updateDevice(1, "personId", null).getStatus()); assertEquals(400, controller//from w w w.j ava 2 s . c om .updateDevice(1, "personId", new Device(null, "personId", "token", dateTimeUpdated)).getStatus()); assertEquals(400, controller.updateDevice(1, "personId", new Device(1, null, "token", dateTimeUpdated)).getStatus()); assertEquals(400, controller.updateDevice(1, "personId", new Device(1, "personId", null, dateTimeUpdated)) .getStatus()); assertEquals(400, controller.updateDevice(1, "personId", new Device(1, "personId", "token", null)).getStatus()); assertEquals(400, controller .updateDevice(1, "personId", new Device(100, "personId", "token", dateTimeUpdated)).getStatus()); assertEquals(400, controller .updateDevice(100, "personId", new Device(1, "personId", "token", dateTimeUpdated)).getStatus()); assertEquals(403, controller.updateDevice(9, "notMyPersonId", new Device(9, "notMyPersonId", "token9", deviceDao.getDeviceById(9).getDateTimeUpdated())) .getStatus()); assertEquals(404, controller .updateDevice(100, "personId", new Device(100, "personId", "token", dateTimeUpdated)).getStatus()); // Device updated successfully (personId null -> "personId") assertEquals(200, controller .updateDevice(1, "personId", new Device(1, "personId", "valid", dateTimeUpdated)).getStatus()); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } Device device = deviceDao.getDeviceById(1); // When personId is changed, dateRegistered is updated device.setPersonId(null); deviceDao.saveOrUpdateDevice(device, "notme"); device = deviceDao.getDeviceById(device.getId()); device.setPersonId("otherId1"); assertEquals(200, controller.updateDevice(1, "otherId1", device).getStatus()); device = deviceDao.getDeviceById(device.getId()); assertFalse(dateRegistered.equals(device.getDateRegistered())); assertTrue("otherId1".equals(device.getPersonId())); // When device is edited but personId is not changed, dateRegistered stays the same dateRegistered = device.getDateRegistered(); device.setToken("valid2"); device.setDeviceId("notDeviceId1"); assertEquals(200, controller.updateDevice(1, "otherId1", device).getStatus()); assertTrue(dateRegistered.equals(deviceDao.getDeviceById(device.getId()).getDateRegistered())); }
From source file:net.cbtltd.rest.AbstractReservation.java
private static String convertTime(Date time) throws ParseException { if (time == null || time.equals("")) { return ""; }//from ww w.j av a2 s .c o m SimpleDateFormat displayFormat = new SimpleDateFormat("hh:mm aa"); String parsedDate = displayFormat.format(time); return parsedDate; }
From source file:controllers.core.PortfolioEntryPlanningController.java
/** * When edit a package, if the dates (start and end) have changed and the * package contains confirmed allocated actors, then notify their manager. * //from w ww. j ava 2 s . co m * @param oldStartDate * the start date before change * @param oldEndDate * the end date before change * @param planningPackage * the changed planning package */ private void alertManagerDatesHaveChanged(Date oldStartDate, Date oldEndDate, PortfolioEntryPlanningPackage planningPackage) { if ((oldStartDate == null && planningPackage.startDate != null) || (oldStartDate != null && !oldStartDate.equals(planningPackage.startDate)) || (oldEndDate == null && planningPackage.endDate != null) || (oldEndDate != null && !oldEndDate.equals(planningPackage.endDate))) { for (PortfolioEntryResourcePlanAllocatedActor allocatedActor : planningPackage.portfolioEntryResourcePlanAllocatedActors) { if (allocatedActor.isConfirmed && allocatedActor.followPackageDates != null && allocatedActor.followPackageDates) { ActorDao.sendNotification(this.getNotificationManagerService(), this.getI18nMessagesPlugin(), allocatedActor.actor.manager, NotificationCategory.getByCode(Code.PORTFOLIO_ENTRY), controllers.core.routes.ActorController.allocation(allocatedActor.actor.id).url(), "core.portfolio_entry_planning.allocated_actor.edit_confirmed.notification.title", "core.portfolio_entry_planning.allocated_actor.edit_confirmed.notification.message", allocatedActor.actor.getNameHumanReadable()); } } } }
From source file:org.madsonic.service.MediaScannerService.java
private void updateAlbum(MediaFile file, Date lastScanned, Map<String, Integer> albumCount, boolean isVariousArtists) { if (file.getAlbumName() == null && file.getAlbumSetName() == null || file.getArtist() == null || file.getParentPath() == null || !file.isAudio()) { return;/*from w w w . j a va 2 s .c o m*/ } MediaFile parent = mediaFileService.getMediaFile(file.getParentPath()); Album album = albumDao.getAlbumSetForFile(file); if (album == null) { album = albumDao.getAlbumSetForFile(parent); } if (album == null) { album = new Album(); album.setPath(file.getParentPath()); album.setName(file.getAlbumSetName()); album.setNameid3(file.getAlbumName()); album.setArtist(StringUtils.isBlank(file.getAlbumArtist()) ? file.getArtist() : file.getAlbumArtist()); if (isVariousArtists) { album.setArtist("Various Artists"); album.setAlbumartist("Various Artists"); } album.setCreated(file.getChanged()); if (file.getAlbumSetName() == null) { if (parent.getAlbumSetName() != null) { album.setSetName(parent.getAlbumSetName()); album.setName(parent.getAlbumSetName()); } } else { album.setSetName(file.getAlbumSetName()); } } if (album.getCoverArtPath() == null) { parent = mediaFileService.getParentOf(file); if (parent != null) { album.setCoverArtPath(parent.getCoverArtPath()); } } if (album.getYear() < 1) { if (file.getYear() != null) { album.setYear(file.getYear()); } } if (album.getGenre() == null) { album.setGenre(file.getGenre()); } boolean firstEncounter = !lastScanned.equals(album.getLastScanned()); if (firstEncounter) { album.setDurationSeconds(0); album.setSongCount(0); Integer n = albumCount.get(file.getArtist()); albumCount.put(file.getArtist(), n == null ? 1 : n + 1); } if (file.getDurationSeconds() != null) { album.setDurationSeconds(album.getDurationSeconds() + file.getDurationSeconds()); } if (file.isAudio()) { album.setSongCount(album.getSongCount() + 1); } album.setLastScanned(lastScanned); album.setPresent(true); if (file.getAlbumName().toLowerCase().contains(parent.getAlbumName().toLowerCase())) { album.setMediaFileId(parent.getId()); } else { album.setMediaFileId(file.getId()); } album.setGenre(file.getGenre()); if (file.getYear() != null) { album.setYear(file.getYear()); } albumDao.createOrUpdateAlbum(album); if (firstEncounter) { searchService.index(album); } // Update the file's album artist, if necessary. if (!ObjectUtils.equals(album.getArtist(), file.getAlbumArtist())) { file.setAlbumArtist(album.getArtist()); mediaFileDao.createOrUpdateMediaFile(file); } }