List of usage examples for java.util Calendar before
public boolean before(Object when)
Calendar
represents a time before the time represented by the specified Object
. From source file:org.nuxeo.ecm.core.api.security.ACE.java
/** * Returns the status of this ACE./*from ww w . ja v a 2 s . c om*/ * * @since 7.4 */ public Status getStatus() { Status status = Status.EFFECTIVE; Calendar now = new GregorianCalendar(); if (begin != null && now.before(begin)) { status = Status.PENDING; } if (end != null && now.after(end)) { status = Status.ARCHIVED; } return status; }
From source file:org.egov.tl.web.actions.search.SearchTradeAction.java
public boolean checkForRenewalNotice(final Date dateOfExpiry) { boolean readyForRenewal = false; final Calendar currentDate = Calendar.getInstance(); final Calendar renewalDate = Calendar.getInstance(); renewalDate.setTime(dateOfExpiry);/*from w w w . j a va 2s. com*/ renewalDate.add(Calendar.DATE, Constants.RENEWALTIMEPERIOD); if (renewalDate.before(currentDate) || renewalDate.equals(currentDate)) readyForRenewal = true; return readyForRenewal; }
From source file:com.digitalpebble.stormcrawler.elasticsearch.persistence.CollapsingSpout.java
@Override public void onResponse(SearchResponse response) { long timeTaken = System.currentTimeMillis() - timeStartESQuery; SearchHit[] hits = response.getHits().getHits(); int numBuckets = hits.length; // no more results? if (numBuckets == 0) { lastDate = null;//from w ww . j ava 2 s . c o m lastStartOffset = 0; } // still got some results but paging won't help else if (numBuckets < maxBucketNum) { lastStartOffset = 0; } else { lastStartOffset += numBuckets; } // reset the value for next fetch date if the previous one is too old if (resetFetchDateAfterNSecs != -1) { Calendar diffCal = Calendar.getInstance(); diffCal.setTime(lastDate); diffCal.add(Calendar.SECOND, resetFetchDateAfterNSecs); // compare to now if (diffCal.before(Calendar.getInstance())) { LOG.info("{} lastDate set to null based on resetFetchDateAfterNSecs {}", logIdprefix, resetFetchDateAfterNSecs); lastDate = null; lastStartOffset = 0; } } int alreadyprocessed = 0; int numDocs = 0; synchronized (buffer) { for (SearchHit hit : hits) { Map<String, SearchHits> innerHits = hit.getInnerHits(); // wanted just one per bucket : no inner hits if (innerHits == null) { numDocs++; if (!addHitToBuffer(hit)) { alreadyprocessed++; } continue; } // more than one per bucket SearchHits inMyBucket = innerHits.get("urls_per_bucket"); for (SearchHit subHit : inMyBucket.hits()) { numDocs++; if (!addHitToBuffer(subHit)) { alreadyprocessed++; } } } // Shuffle the URLs so that we don't get blocks of URLs from the // same host or domain if (numBuckets != numDocs) { Collections.shuffle((List) buffer); } } esQueryTimes.addMeasurement(timeTaken); // could be derived from the count of query times above eventCounter.scope("ES_queries").incrBy(1); eventCounter.scope("ES_docs").incrBy(numDocs); eventCounter.scope("already_being_processed").incrBy(alreadyprocessed); LOG.info("{} ES query returned {} hits from {} buckets in {} msec with {} already being processed", logIdprefix, numDocs, numBuckets, timeTaken, alreadyprocessed); // remove lock isInESQuery.set(false); }
From source file:com.adobe.acs.commons.wcm.notifications.impl.SystemNotificationsImpl.java
private boolean isActiveNotification(final SlingHttpServletRequest request, final Resource resource) { if (JcrConstants.JCR_CONTENT.equals(resource.getName()) || REP_POLICY.equals(resource.getName())) { return false; }/* www .j av a 2 s. c o m*/ final PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class); final Page notificationPage = pageManager.getContainingPage(resource); if (notificationPage == null) { log.warn("Trying to get a invalid System Notification page at [ {} ]", resource.getPath()); return false; } else if (this.isDismissed(request, notificationPage)) { // System Notification previously dismissed by the user return false; } // Looks like a valid Notification Page; now check if the properties are valid final ValueMap properties = notificationPage.getProperties(); final boolean enabled = properties.get(PN_ENABLED, false); if (!enabled) { // Disabled return false; } else { final Calendar onTime = properties.get(PN_ON_TIME, Calendar.class); final Calendar offTime = properties.get(PN_OFF_TIME, Calendar.class); if (onTime == null && offTime == null) { // No on time or off time is set, but is enabled so always show return true; } final Calendar now = Calendar.getInstance(); if (onTime != null && now.before(onTime)) { return false; } if (offTime != null && now.after(offTime)) { return false; } return true; } }
From source file:org.openhab.binding.gardena.internal.handler.GardenaThingHandler.java
/** * Converts a Gardena property value to a openHAB state. *//* w w w .j a v a2 s . c o m*/ private State convertToState(Device device, ChannelUID channelUID) throws GardenaException { String abilityName = channelUID.getGroupId(); String propertyName = channelUID.getIdWithoutGroup(); try { String value = device.getAbility(abilityName).getProperty(propertyName).getValueAsString(); if (StringUtils.trimToNull(value) == null || StringUtils.equals(value, "N/A")) { return UnDefType.NULL; } switch (getThing().getChannel(channelUID.getId()).getAcceptedItemType()) { case "String": return new StringType(value); case "Number": if (ABILITY_RADIO.equals(abilityName) && PROPERTY_STATE.equals(propertyName)) { switch (value) { case "poor": return new DecimalType(1); case "good": return new DecimalType(2); case "excellent": return new DecimalType(4); default: return UnDefType.NULL; } } return new DecimalType(value); case "Switch": return Boolean.TRUE.toString().equalsIgnoreCase(value) || "on".equalsIgnoreCase(value) ? OnOffType.ON : OnOffType.OFF; case "DateTime": Calendar cal = DateUtils.parseToCalendar(value); if (cal != null && !cal.before(VALID_DATE_START)) { return new DateTimeType(cal); } else { return UnDefType.NULL; } } } catch (GardenaException e) { logger.warn("Channel '{}' cannot be updated as device does not contain property '{}:{}'", channelUID, abilityName, propertyName); } return null; }
From source file:com.predic8.membrane.core.exchangestore.FileExchangeStore.java
protected void deleteOldFolders() throws IOException { if (this.maxDays < 0) { return; // don't do anything if this feature is deactivated }/*from w ww . j a v a 2 s.co m*/ Calendar threshold = Calendar.getInstance(); threshold.add(Calendar.DAY_OF_MONTH, -maxDays); ArrayList<File> folders3 = new DepthWalker(3).getDirectories(new File(dir)); ArrayList<File> deletion = new ArrayList<File>(); for (File f : folders3) { int day = Integer.parseInt(f.getName()); int mon = Integer.parseInt(f.getParentFile().getName()); int year = Integer.parseInt(f.getParentFile().getParentFile().getName()); Calendar folderTime = Calendar.getInstance(); folderTime.clear(); folderTime.set(year, mon - 1, day); if (folderTime.before(threshold)) { deletion.add(f); } } for (File d : deletion) { FileUtils.deleteDirectory(d); } }
From source file:org.kuali.kfs.sys.batch.Job.java
/** * @deprecated "Implementing institutions likely want to call Job#withinCutoffWindowForDate" */// www .j a v a 2 s.c o m public static boolean isPastCutoffWindow(Date date, Collection<String> runDates) { DateTimeService dTService = SpringContext.getBean(DateTimeService.class); ParameterService parameterService = SpringContext.getBean(ParameterService.class); Calendar jobRunDate = dTService.getCalendar(date); if (parameterService.parameterExists(KfsParameterConstants.FINANCIAL_SYSTEM_BATCH.class, RUN_DATE_CUTOFF_PARM_NM)) { String[] cutOffTime = StringUtils.split(parameterService.getParameterValueAsString( KfsParameterConstants.FINANCIAL_SYSTEM_BATCH.class, RUN_DATE_CUTOFF_PARM_NM), ':'); Calendar runDate = null; for (String runDateStr : runDates) { try { runDate = dTService.getCalendar(dTService.convertToDate(runDateStr)); runDate.add(Calendar.DAY_OF_YEAR, 1); runDate.set(Calendar.HOUR_OF_DAY, Integer.parseInt(cutOffTime[0])); runDate.set(Calendar.MINUTE, Integer.parseInt(cutOffTime[1])); runDate.set(Calendar.SECOND, Integer.parseInt(cutOffTime[2])); } catch (ParseException e) { LOG.error("ParseException occured parsing " + runDateStr, e); } if (jobRunDate.before(runDate)) { return false; } } } return true; }
From source file:org.kuali.ole.sys.batch.Job.java
/** * @deprecated "Implementing institutions likely want to call Job#withinCutoffWindowForDate" *//*from w w w .j a v a 2 s . c o m*/ public static boolean isPastCutoffWindow(Date date, Collection<String> runDates) { DateTimeService dTService = SpringContext.getBean(DateTimeService.class); ParameterService parameterService = SpringContext.getBean(ParameterService.class); Calendar jobRunDate = dTService.getCalendar(date); if (parameterService.parameterExists(OleParameterConstants.FINANCIAL_SYSTEM_BATCH.class, RUN_DATE_CUTOFF_PARM_NM)) { String[] cutOffTime = StringUtils.split(parameterService.getParameterValueAsString( OleParameterConstants.FINANCIAL_SYSTEM_BATCH.class, RUN_DATE_CUTOFF_PARM_NM), ':'); Calendar runDate = null; for (String runDateStr : runDates) { try { runDate = dTService.getCalendar(dTService.convertToDate(runDateStr)); runDate.add(Calendar.DAY_OF_YEAR, 1); runDate.set(Calendar.HOUR_OF_DAY, Integer.parseInt(cutOffTime[0])); runDate.set(Calendar.MINUTE, Integer.parseInt(cutOffTime[1])); runDate.set(Calendar.SECOND, Integer.parseInt(cutOffTime[2])); } catch (ParseException e) { LOG.error("ParseException occured parsing " + runDateStr, e); } if (jobRunDate.before(runDate)) { return false; } } } return true; }
From source file:org.nuxeo.ecm.platform.rendition.service.RenditionCreator.java
protected DocumentModel createRenditionDocument(DocumentModel sourceDocument) { String doctype = sourceDocument.getType(); String renditionMimeType = renditionBlob.getMimeType(); BlobHolder blobHolder = sourceDocument.getAdapter(BlobHolder.class); if (blobHolder == null || (blobHolder instanceof DocumentStringBlobHolder && !(renditionMimeType.startsWith("text/") || renditionMimeType.startsWith("application/xhtml")))) { // We have a document type unable to hold blobs, or // We have a Note or other blob holder that can only hold strings, but the rendition is not a string-related // MIME type. // In either case, we'll have to create a File to hold it. doctype = FILE;//from w w w . ja v a 2 s. co m } boolean isVersionable = sourceDocument.isVersionable(); String liveDocProp = isVersionable ? RENDITION_SOURCE_VERSIONABLE_ID_PROPERTY : RENDITION_SOURCE_ID_PROPERTY; StringBuilder query = new StringBuilder(); query.append("SELECT * FROM Document WHERE ecm:isProxy = 0 AND "); query.append(RENDITION_NAME_PROPERTY); query.append(" = '"); query.append(NXQL.escapeStringInner(renditionName)); query.append("' AND "); if (renditionVariant != null) { query.append(RENDITION_VARIANT_PROPERTY); query.append(" = '"); query.append(NXQL.escapeStringInner(renditionVariant)); query.append("' AND "); } query.append(liveDocProp); query.append(" = '"); query.append(liveDocumentId); query.append("'"); DocumentModelList existingRenditions = session.query(query.toString()); String modificationDatePropertyName = getSourceDocumentModificationDatePropertyName(); Calendar sourceLastModified = (Calendar) sourceDocument.getPropertyValue(modificationDatePropertyName); DocumentModel rendition = null; if (existingRenditions.size() > 0) { rendition = session.getDocument(existingRenditions.get(0).getRef()); if (!isVersionable) { Calendar renditionSourceLastModified = (Calendar) rendition .getPropertyValue(RENDITION_SOURCE_MODIFICATION_DATE_PROPERTY); if (renditionSourceLastModified != null && !renditionSourceLastModified.before(sourceLastModified)) { this.renditionBlob = (Blob) rendition.getPropertyValue("file:content"); return rendition; } } if (rendition.isVersion()) { String sid = rendition.getVersionSeriesId(); rendition = session.getDocument(new IdRef(sid)); } } else { rendition = session.createDocumentModel(null, sourceDocument.getName(), doctype); } rendition.copyContent(sourceDocument); rendition.getContextData().putScopedValue(LifeCycleConstants.INITIAL_LIFECYCLE_STATE_OPTION_NAME, sourceDocument.getCurrentLifeCycleState()); rendition.addFacet(RENDITION_FACET); rendition.setPropertyValue(RENDITION_SOURCE_ID_PROPERTY, sourceDocument.getId()); if (isVersionable) { rendition.setPropertyValue(RENDITION_SOURCE_VERSIONABLE_ID_PROPERTY, liveDocumentId); } if (sourceLastModified != null) { rendition.setPropertyValue(RENDITION_SOURCE_MODIFICATION_DATE_PROPERTY, sourceLastModified); } if (renditionVariant != null) { rendition.setPropertyValue(RENDITION_VARIANT_PROPERTY, renditionVariant); } rendition.setPropertyValue(RENDITION_NAME_PROPERTY, renditionName); return rendition; }
From source file:org.apache.hawq.pxf.plugins.ignite.IgnitePartitionFragmenter.java
/** * Returns list of fragments for Ignite table queries * * @throws UnsupportedOperationException if a partition of unknown type was found * * @return a list of fragments//from w w w. j ava 2 s . c om */ @Override public List<Fragment> getFragments() throws UnsupportedOperationException { if (LOG.isDebugEnabled()) { LOG.debug("getFragments() called; dataSource is '" + inputData.getDataSource() + "'"); } byte[] fragmentMetadata = null; byte[] fragmentUserdata = null; if (partitionType == null) { if (LOG.isDebugEnabled()) { LOG.debug("getFragments() found no partition"); } Fragment fragment = new Fragment(inputData.getDataSource(), replicaHostAddressWrapped, fragmentMetadata, fragmentUserdata); fragments.add(fragment); if (LOG.isDebugEnabled()) { LOG.debug("getFragments() successful"); } return fragments; } switch (partitionType) { case DATE: { if (LOG.isDebugEnabled()) { LOG.debug("getFragments() found DATE partition"); } int currInterval = intervalNum; Calendar fragStart = rangeStart; while (fragStart.before(rangeEnd)) { Calendar fragEnd = (Calendar) fragStart.clone(); switch (intervalType) { case DAY: fragEnd.add(Calendar.DAY_OF_MONTH, currInterval); break; case MONTH: fragEnd.add(Calendar.MONTH, currInterval); break; case YEAR: fragEnd.add(Calendar.YEAR, currInterval); break; } if (fragEnd.after(rangeEnd)) fragEnd = (Calendar) rangeEnd.clone(); fragmentMetadata = new byte[16]; ByteUtils.toLittleEndian(fragmentMetadata, fragStart.getTimeInMillis(), 0, 8); ByteUtils.toLittleEndian(fragmentMetadata, fragEnd.getTimeInMillis(), 8, 8); Fragment fragment = new Fragment(inputData.getDataSource(), replicaHostAddressWrapped, fragmentMetadata, fragmentUserdata); fragments.add(fragment); // Continue the previous fragment fragStart = fragEnd; } break; } case INT: { if (LOG.isDebugEnabled()) { LOG.debug("getFragments() found INT partition"); } int rangeStart = Integer.parseInt(range[0]); int rangeEnd = Integer.parseInt(range[1]); int currInterval = intervalNum; int fragStart = rangeStart; while (fragStart < rangeEnd) { int fragEnd = fragStart + currInterval; if (fragEnd > rangeEnd) { fragEnd = rangeEnd; } fragmentMetadata = new byte[8]; ByteUtils.toLittleEndian(fragmentMetadata, fragStart, 0, 4); ByteUtils.toLittleEndian(fragmentMetadata, fragEnd, 4, 4); Fragment fragment = new Fragment(inputData.getDataSource(), replicaHostAddressWrapped, fragmentMetadata, fragmentUserdata); fragments.add(fragment); // Continue the previous fragment fragStart = fragEnd; } break; } case ENUM: { if (LOG.isDebugEnabled()) { LOG.debug("getFragments() found ENUM partition"); } for (String frag : range) { fragmentMetadata = frag.getBytes(); Fragment fragment = new Fragment(inputData.getDataSource(), replicaHostAddressWrapped, fragmentMetadata, fragmentUserdata); fragments.add(fragment); } break; } default: { throw new UnsupportedOperationException("getFragments() found a partition of unknown type and failed"); } } if (LOG.isDebugEnabled()) { LOG.debug("getFragments() successful"); } return fragments; }