List of usage examples for java.util Date before
public boolean before(Date when)
From source file:com.smartitengineering.cms.spi.impl.content.PersistentRepresentationProviderImpl.java
@Override public Representation getRepresentation(String repName, ContentType contentType, Content content) { if (StringUtils.isBlank(repName) || contentType == null || content == null) { logger.info("Representation name or content type or content is null or blank!"); return null; }/*from w ww . j av a 2s . c om*/ final TemplateId id = new TemplateId(); id.setId(new StringBuilder(content.getContentId().toString()).append(':').append(repName).toString()); PersistentRepresentation cachedRep = readDao.getById(id); boolean update = false; if (cachedRep != null) { update = true; Date cachedDate = cachedRep.getRepresentation().getLastModifiedDate(); RepresentationTemplate template = SmartContentAPI.getInstance().getWorkspaceApi() .getRepresentationTemplate(content.getContentId().getWorkspaceId(), repName); Date lastModified = content.getLastModifiedDate(); if (template != null) { final Date lastModifiedDate = template.getLastModifiedDate(); if (lastModified.before(lastModifiedDate)) { lastModified = lastModifiedDate; } } if (cachedDate.before(lastModified)) { cachedRep = null; } } if (cachedRep == null) { Representation rep = mainProvider.getRepresentation(repName, contentType, content); cachedRep = new PersistentRepresentation(); cachedRep.setId(id); cachedRep.setRepresentation(rep); if (update) { writeDao.update(cachedRep); Event<Representation> event = SmartContentAPI.getInstance().getEventRegistrar() .<Representation>createEvent(EventType.UPDATE, Type.REPRESENTATION, rep); SmartContentAPI.getInstance().getEventRegistrar().notifyEventAsynchronously(event); } else { writeDao.save(cachedRep); Event<Representation> event = SmartContentAPI.getInstance().getEventRegistrar() .<Representation>createEvent(EventType.CREATE, Type.REPRESENTATION, rep); SmartContentAPI.getInstance().getEventRegistrar().notifyEventAsynchronously(event); } } return cachedRep.getRepresentation(); }
From source file:gov.utah.dts.det.ccl.model.view.AlertFollowUpsNeededView.java
public AlertType getAlertType() throws JSONException, ParseException { if (alertType == null) { alertType = AlertType.ALERT;// ww w. j a va 2 s . c om Date now = new Date(); Date latestCorrectionDate = null; for (FindingFollowUpView find : getFindings()) { if (latestCorrectionDate == null || latestCorrectionDate.before(find.getCorrectionDate())) { latestCorrectionDate = find.getCorrectionDate(); } } Date expDt = getFacility().getLicenseExpirationDate(); // if (corrDl == null) { // corrDl = DateUtils.addDays(inspectionDate, 30); // } if (expDt == null) { expDt = DateUtils.addDays(latestCorrectionDate, 60); } Date window = DateUtils.addDays(expDt, -30); //all inspections are required at least 7 days before the expiration date if (latestCorrectionDate.compareTo(window) >= 0 && now.compareTo(DateUtils.addDays(expDt, -14)) >= 0) { //if we had 30 days or less until the license expiration and we are within 14 days of the license expiration alertType = AlertType.RED_ALERT; } else if (latestCorrectionDate.compareTo(window) >= 0 && now.compareTo(DateUtils.addDays(expDt, -21)) >= 0) { //if we had 30 days or less until the license expiration and we are within 21 days of the license expiration alertType = AlertType.ORANGE_ALERT; } else if (now.compareTo(DateUtils.addDays(latestCorrectionDate, 21)) >= 0) { //if we had more than 30 days until the license expiration and we are over 21 days past the correction deadline alertType = AlertType.RED_ALERT; } else if (now.compareTo(DateUtils.addDays(latestCorrectionDate, 14)) >= 0) { //if we had more than 30 days until the license expiration and we are over 14 days past the correction deadline alertType = AlertType.ORANGE_ALERT; } } return alertType; }
From source file:com.qcadoo.model.internal.validators.RangeValidator.java
private boolean validateDateRange(final FieldDefinition fieldDefinition, final Date value, final Entity validatedEntity) { if (from != null && ((!inclusively && !value.after((Date) from)) || (inclusively && value.before((Date) from)))) { addToSmallError(fieldDefinition, validatedEntity); return false; }//from w w w.j av a 2 s . co m if (to != null && ((!inclusively && !value.before((Date) to)) || (inclusively && value.after((Date) to)))) { addToLargeError(fieldDefinition, validatedEntity); return false; } return true; }
From source file:com.ibm.bluemix.smartveggie.dao.SubOutletVendorAllocationDaoImpl.java
@Override public BasicDBObject getVendorForSubOutlet(String vendorUserName) { try {/*from w w w . ja va 2s . co m*/ System.out.println("starting object retrieve.."); DB db = MongodbConnection.getMongoDB(); BasicDBObject query = new BasicDBObject(); query.append("vendorUsername", vendorUserName); System.out.println("Querying for getting vendor suboutlet: " + query); DBCollection col = db.getCollection(ICollectionName.COLLECTION_ALLOC_SUBOUTLETS); DBCursor cursor = col.find(query); BasicDBObject obj = null; while (cursor.hasNext()) { obj = (BasicDBObject) cursor.next(); //Check the date Date currentDate = Calendar.getInstance().getTime(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); String allocationTillString = (String) obj.get("suboutletAllocatedTo"); if (allocationTillString != null) { Date allocEndDate = null; try { allocEndDate = dateFormat.parse(allocationTillString); if (allocEndDate.before(currentDate)) { System.out.println("Suboutlet Allocation already ended...."); //subOutletAvailableList.add(allocation); } else { break; } } catch (Exception e) { e.printStackTrace(); } System.out.println("Retrieved Allocated Vendor suboutlet: " + obj); } } cursor.close(); return obj; } catch (Exception e) { throw e; } }
From source file:org.openmrs.module.kenyaemr.fragment.controller.form.EnterHtmlFormFragmentController.java
/** * Custom server-side validation/*from w ww . j a v a 2s .c om*/ * @param formEncounter the encounter being edited/created * @param formDescriptor the form descriptor * @param visit the associated visit * @return any validation errors */ protected List<FormSubmissionError> extraValidation(Encounter formEncounter, FormDescriptor formDescriptor, Visit visit) { List<FormSubmissionError> validationErrors = new ArrayList<FormSubmissionError>(); EncounterWrapper wrapped = new EncounterWrapper(formEncounter); if (wrapped.getProvider() == null) { validationErrors.add(new FormSubmissionError("general-form-error", "Current user is not a provider and no other provider was specified")); } if (formDescriptor.getAutoCreateVisitTypeUuid() != null) { // Don't do validation against the visit because the encounter can be moved } else if (visit != null) { // If encounter is for a specific visit then check encounter date is valid for that visit. The visit handler // will ensure that the encounter is actually saved into that visit Date formEncounterDateTime = formEncounter.getEncounterDatetime(); if (formEncounterDateTime.before(visit.getStartDatetime())) { validationErrors.add(new FormSubmissionError("general-form-error", "Encounter datetime should be after the visit start date")); } if (visit.getStopDatetime() != null && formEncounterDateTime.after(visit.getStopDatetime())) { validationErrors.add(new FormSubmissionError("general-form-error", "Encounter datetime should be before the visit stop date")); } } return validationErrors; }
From source file:com.venilnoronha.dzone.feed.web.ArticlesRSSController.java
@RequestMapping(value = "/rss/articles", method = RequestMethod.GET) public ModelAndView articlesRssByLastModified(HttpEntity<byte[]> requestEntity, HttpServletRequest request, HttpServletResponse response) throws ParseException { HttpUtils.logUserIP("ArticlesRSS", request); String lastModified = requestEntity.getHeaders().getFirst("If-Modified-Since"); if (lastModified == null) { lastModified = requestEntity.getHeaders().getFirst("If-None-Match"); }//from w w w . j a v a 2s .c o m PageRequest page = new PageRequest(0, feedSize, Direction.DESC, "articleDate"); Page<Article> articlePage; if (lastModified != null) { Date lastModifiedDt = HTTP_FORMAT.parse(lastModified); articlePage = articlesRepository.findByArticleDateBetween(lastModifiedDt, new Date(), page); } else { articlePage = articlesRepository.findAll(page); } Iterator<Article> articlesIter = articlePage.iterator(); List<Article> articles = new ArrayList<>(); Date newLastModified = null; while (articlesIter.hasNext()) { Article article = articlesIter.next(); Date articleDate = article.getArticleDate(); if (newLastModified == null || newLastModified.before(articleDate)) { newLastModified = articleDate; } articles.add(article); } if (articles.isEmpty() && lastModified != null) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return null; } else { response.setHeader("ETag", HTTP_FORMAT.format(newLastModified)); response.setHeader("Last-Modified", HTTP_FORMAT.format(newLastModified)); ModelAndView mav = new ModelAndView(); mav.setView(new ArticlesRSSView(articles)); return mav; } }
From source file:dk.cafeanalog.AnalogDownloader.java
public Opening getCurrentOpening() throws JSONException, ParseException, IOException { if (System.currentTimeMillis() - mLastGet > TIME_BETWEEN_DOWNLOADS || mOpeningsCache == null) { getOpenings();/* w ww . j ava 2 s. c om*/ } Date now = new Date(System.currentTimeMillis()); for (Opening opening : mOpeningsCache) { if (now.after(opening.getOpen()) && now.before(opening.getClose())) { return opening; } } return null; }
From source file:edu.sjsu.cmpe275.project.service.SearchRoomAvailability.java
private boolean isAvailable(Room room, Date checkinDate, Date checkoutDate) { List<Reservation> reservations = room.getReservationList(); if (reservations == null) { return true; }/*w ww . j av a2 s . com*/ //traverse all the reservation to check availability for (Reservation reservation : reservations) { Date inDate = reservation.getCheckinDate(); Date outDate = reservation.getCheckoutDate(); if ((inDate.getTime() == checkinDate.getTime()) || (outDate.getTime() == checkoutDate.getTime()) || (inDate.after(checkinDate) && inDate.before(checkoutDate)) || (outDate.after(checkinDate) && outDate.before(checkoutDate))) { return false; } } return true; }
From source file:de.slub.fedora.oai.OaiHarvester.java
private void harvestLoop() throws URISyntaxException, InterruptedException { while (isRunning()) { Date timestamp = now(); getLastrunParameters();/*w w w.ja v a2 s. co m*/ if (lastrun != null && timestamp.before(lastrun)) { TimeUnit.MILLISECONDS.sleep(interval.getMillis()); continue; } URI uri = buildOaiRequestURI(); HttpGet httpGet = new HttpGet(uri); CloseableHttpClient httpClient = HttpClients.createMinimal(); try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { handleXmlResult(httpEntity.getContent()); writeLastrun(timestamp); } else { logger.warn("Got empty response from OAI service."); } } else { logger.error("Unexpected OAI service response: {} {}", httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } } catch (Exception ex) { logger.error(ex.getMessage()); } finally { if (resumptionTokenIsPresent()) { TimeUnit.SECONDS.sleep(1); } else { TimeUnit.MILLISECONDS.sleep(interval.getMillis()); } } } }
From source file:com.android.loganalysis.item.LogcatItem.java
/** * {@inheritDoc}/*from ww w .j a v a2s . com*/ */ @Override public LogcatItem merge(IItem other) throws ConflictingItemException { if (this == other) { return this; } if (other == null || !(other instanceof LogcatItem)) { throw new ConflictingItemException("Conflicting class types"); } LogcatItem logcat = (LogcatItem) other; Date start = logcat.getStartTime().before(getStartTime()) ? logcat.getStartTime() : getStartTime(); Date stop = logcat.getStopTime().after(getStopTime()) ? logcat.getStopTime() : getStopTime(); Date overlapStart = logcat.getStartTime().after(getStartTime()) ? logcat.getStartTime() : getStartTime(); Date overlapStop = logcat.getStopTime().before(getStopTime()) ? logcat.getStopTime() : getStopTime(); // Make sure that all events in the overlapping span are ItemList mergedEvents = new ItemList(); for (MiscLogcatItem event : getEvents()) { final Date eventTime = event.getEventTime(); if (eventTime.after(overlapStart) && eventTime.before(overlapStop) && !logcat.getEvents().contains(event)) { throw new ConflictingItemException( "Event in first logcat not contained in " + "overlapping portion of other logcat."); } mergedEvents.add(event); } for (MiscLogcatItem event : logcat.getEvents()) { final Date eventTime = event.getEventTime(); if (eventTime.after(overlapStart) && eventTime.before(overlapStop)) { if (!getEvents().contains(event)) { throw new ConflictingItemException( "Event in first logcat not contained in " + "overlapping portion of other logcat."); } } else { mergedEvents.add(event); } } LogcatItem mergedLogcat = new LogcatItem(); mergedLogcat.setStartTime(start); mergedLogcat.setStopTime(stop); mergedLogcat.setAttribute(EVENTS, mergedEvents); return mergedLogcat; }