List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:org.sigmah.server.schedule.export.AutoExportJob.java
public void execute(JobExecutionContext executionContext) throws JobExecutionException { final JobDataMap dataMap = executionContext.getJobDetail().getJobDataMap(); final EntityManager em = (EntityManager) dataMap.get("em"); final Log log = (Log) dataMap.get("log"); final Injector injector = (Injector) dataMap.get("injector"); EntityTransaction tx = null;//from www .ja v a 2s.com try { // Open transaction /* * NOTE: it is impossible to use @Transactional for this method * The reason is link{TransactionalInterceptor} gets EntityManager * from the injector which is out of scope */ tx = em.getTransaction(); tx.begin(); final GlobalExportDAO exportDAO = new GlobalExportHibernateDAO(em); final GlobalExportDataProvider dataProvider = injector.getInstance(GlobalExportDataProvider.class); final List<GlobalExportSettings> settings = exportDAO.getGlobalExportSettings(); for (final GlobalExportSettings setting : settings) { /* * Check for auto export schedule */ //skip if no export schedule is specified if (setting.getAutoExportFrequency() == null || setting.getAutoExportFrequency() < 1) continue; final Calendar systemCalendar = Calendar.getInstance(); boolean doExport = false; if ((setting.getAutoExportFrequency() >= 31) && (setting.getAutoExportFrequency() <= 58)) { //Case of Monthly Auto Export if ((setting.getAutoExportFrequency() - 30) == systemCalendar.get(Calendar.DAY_OF_MONTH)) { doExport = true; } } else if ((setting.getAutoExportFrequency() >= 61) && (setting.getAutoExportFrequency() <= 67)) { //Case of Weekly Auto Export if ((setting.getAutoExportFrequency() - 60) == systemCalendar.get(Calendar.DAY_OF_WEEK)) { doExport = true; } } else { //Regular Auto-Export every N-days final Calendar scheduledCalendar = Calendar.getInstance(); Date lastExportDate = setting.getLastExportDate(); if (lastExportDate == null) { lastExportDate = systemCalendar.getTime(); setting.setLastExportDate(lastExportDate); em.merge(setting); } else { scheduledCalendar.setTime(lastExportDate); // add scheduled days to the last exported date scheduledCalendar.add(Calendar.DAY_OF_MONTH, setting.getAutoExportFrequency()); } final Date systemDate = getZeroTimeDate(systemCalendar.getTime()); final Date scheduledDate = getZeroTimeDate(scheduledCalendar.getTime()); if (systemDate.compareTo(scheduledDate) >= 0) { doExport = true; } } if (doExport) { /* * Start auto export */ // persist global export logger final GlobalExport globalExport = new GlobalExport(); globalExport.setOrganization(setting.getOrganization()); globalExport.setDate(systemCalendar.getTime()); em.persist(globalExport); // generate export content final Map<String, List<String[]>> exportData = dataProvider .generateGlobalExportData(setting.getOrganization().getId(), em, setting.getLocale()); // persist export content dataProvider.persistGlobalExportDataAsCsv(globalExport, em, exportData); } } tx.commit(); log.info("Scheduled EXPORT of global exports fired"); } catch (Exception ex) { if (tx != null && tx.isActive()) tx.rollback(); log.error("Scheduled global export job failed : " + ex.getMessage()); ex.printStackTrace(); } }
From source file:com.beanstream.api.ReportingAPI.java
public List<TransactionRecord> query(final Date startDate, final Date endDate, final int startRow, final int endRow, Criteria[] searchCriteria) throws BeanstreamApiException { if (endDate == null || startDate == null) throw new IllegalArgumentException("Start Date and End Date cannot be null!"); if (endDate.compareTo(startDate) < 0) throw new IllegalArgumentException("End Date cannot be less than Start Date!"); if (endRow < startRow) throw new IllegalArgumentException("End Row cannot be less than Start Row!"); if (endRow - startRow > 1000) throw new IllegalArgumentException("You cannot query more than 1000 rows at a time!"); if (searchCriteria == null) searchCriteria = new Criteria[] {}; String url = BeanstreamUrls.getReportsUrl(config.getPlatform(), config.getVersion()); final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_STRING); SearchQuery query = new SearchQuery(dateFormat.format(startDate), dateFormat.format(endDate), startRow, endRow, searchCriteria);/* w ww.j a va2s.c o m*/ connector.setGsonBuilder(getGsonBuilder()); String response = connector.ProcessTransaction(HttpMethod.post, url, query); System.out.println("Response:\n" + response); Records records = getGson().fromJson(response, Records.class); return records.records; }
From source file:org.libreplan.web.orders.ProjectDetailsController.java
public Constraint checkConstraintStartDate() { return new Constraint() { @Override//from w w w . ja v a 2s . c o m public void validate(Component comp, Object value) throws WrongValueException { Date startDate = (Date) value; if ((startDate != null) && (deadline.getValue() != null) && (startDate.compareTo(deadline.getValue()) > 0)) { initDate.setValue(null); getOrder().setInitDate(null); throw new WrongValueException(comp, _("must be lower than end date")); } } }; }
From source file:org.libreplan.web.orders.ProjectDetailsController.java
public Constraint checkConstraintFinishDate() { return new Constraint() { @Override/*from w ww . j a va 2s .c o m*/ public void validate(Component comp, Object value) throws WrongValueException { Date finishDate = (Date) value; if ((finishDate != null) && (initDate.getValue() != null) && (finishDate.compareTo(initDate.getValue()) < 0)) { deadline.setValue(null); getOrder().setDeadline(null); throw new WrongValueException(comp, _("must be after start date")); } } }; }
From source file:com.yukthi.validators.FutureOrTodayValidator.java
@Override public boolean isValid(Date targetDate, ConstraintValidatorContext context) { //if target date is not present, ignore validator if (targetDate == null) { return true; }/*w w w . j a v a 2s. c om*/ //compare target date with today Date today = DateUtils.truncate(new Date(), Calendar.DATE); targetDate = DateUtils.truncate(targetDate, Calendar.DATE); return (targetDate.compareTo(today) >= 0); }
From source file:com.aoyun.serviceOld.GetValForYKPOne.java
/** * @param dateStr//from w w w. j av a 2s. c o m * @return * @throws ParseException */ public boolean isTrue(String dateStr) throws ParseException { Calendar now = Calendar.getInstance(); now.add(Calendar.DAY_OF_YEAR, -Constantz.beforeDate); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String mDateTime = formatter.format(now.getTime()); Date old = formatter.parse(dateStr); Date before = formatter.parse(mDateTime); if (old.compareTo(before) >= 0) { return true; } return false; }
From source file:com.tassadar.multirommgr.Manifest.java
public boolean hasUbuntuReqRecovery(Recovery r) { if (m_ubuntuReqRecovery == null) return true; try {//from ww w . j a va 2 s . com Date my = r.getVersion(); Date req = Recovery.VER_FMT.parse(m_ubuntuReqRecovery); return my.compareTo(req) >= 0; } catch (ParseException e) { e.printStackTrace(); } return true; }
From source file:org.openmrs.module.drughistory.api.impl.DrugEventServiceImpl.java
@Override public void generateDrugEventsFromTrigger(final Person person, final DrugEventTrigger trigger, final Date sinceWhen) { if (trigger == null) { throw new IllegalArgumentException("trigger cannot be null"); }//from www . j a va 2s .com if (trigger.getEventType() == null) { throw new IllegalArgumentException("Trigger's eventType can not be null"); } if (sinceWhen != null && sinceWhen.compareTo(new Date()) > 0) { throw new IllegalArgumentException("Date: " + sinceWhen + " should be earlier than or equal to today"); } dao.generateDrugEventsFromTrigger(person, trigger, sinceWhen); }
From source file:org.onebusaway.aws.monitoring.impl.metrics.AdminServerMetricsImpl.java
@Override public void publishBundleCountMetrics() { double metric = 0; String bundleListUrl = admin_api_url + "bundle/list"; try {// ww w . j av a 2 s . c o m JsonObject bundleList = getJsonObject(bundleListUrl); JsonArray bundles = bundleList.getAsJsonArray("bundles"); for (JsonElement bundleElement : bundles) { if (metric == 0) { try { JsonObject bundle = bundleElement.getAsJsonObject(); Date today = new Date(); Date dateFrom = new SimpleDateFormat("yyyy-MM-dd") .parse(bundle.get("service-date-from").getAsString()); Date dateTo = new SimpleDateFormat("yyyy-MM-dd") .parse(bundle.get("service-date-to").getAsString()); if (dateFrom.compareTo(today) <= 0 && dateTo.compareTo(today) >= 0) { JsonArray files = bundle.getAsJsonArray("files"); double numberOfFiles = files == null ? 0 : files.size(); publishMetric(MetricName.FirstValidBundleFilesCount, StandardUnit.Count, numberOfFiles); } } catch (NullPointerException npe) { _log.error("Unable to retreive the bundle start and end dates for bundle " + metric + 1); } catch (ParseException pe) { _log.error("Unable to parse the bundle start and end dates for bundle " + metric + 1); } } metric++; } publishMetric(MetricName.CurrentBundleCount, StandardUnit.Count, metric); } catch (MalformedURLException mue) { _log.error(mue.getMessage()); return; } catch (IOException ioe) { _log.warn("Error communicating with specified url : " + bundleListUrl); //publishMetric(MetricName.StopMonitoringErrorResponse, StandardUnit.Count, metric); } }
From source file:org.openbravo.client.application.ViewComponent.java
/** * This function returns the last grid configuration change made into a window at any level (at * whole system level or just a for particuar tab or field). * //from w w w. ja va2s . c o m * This value is needed for the eTag calculation, so, if there has been any grid configuration * change, the eTag should change in order to load again the view definition. * * @param window * the window to obtain its last grid configuration change * @return a String with the last grid configuration change */ private String getLastGridConfigurationChange(Window window) { Date lastModification = new Date(0); List<GCSystem> sysConfs = OBDal.getInstance().createQuery(GCSystem.class, "").list(); if (!sysConfs.isEmpty()) { if (lastModification.compareTo(sysConfs.get(0).getUpdated()) < 0) { lastModification = sysConfs.get(0).getUpdated(); } } String tabHql = "select max(updated) from OBUIAPP_GC_Tab where tab.window.id = :windowId"; Query qryTabData = OBDal.getInstance().getSession().createQuery(tabHql); qryTabData.setParameter("windowId", window.getId()); Date tabUpdated = (Date) qryTabData.uniqueResult(); if (tabUpdated != null && lastModification.compareTo(tabUpdated) < 0) { lastModification = tabUpdated; } String fieldHql = "select max(updated) from OBUIAPP_GC_Field where obuiappGcTab.tab.window.id = :windowId"; Query qryFieldData = OBDal.getInstance().getSession().createQuery(fieldHql); qryFieldData.setParameter("windowId", window.getId()); Date fieldUpdated = (Date) qryFieldData.uniqueResult(); if (fieldUpdated != null && lastModification.compareTo(fieldUpdated) < 0) { lastModification = fieldUpdated; } return lastModification.toString(); }