List of usage examples for java.util Date before
public boolean before(Date when)
From source file:com.apigee.sdk.apm.http.impl.client.cache.CachingHttpClient.java
HttpResponse negotiateResponseFromVariants(HttpHost target, HttpRequest request, HttpContext context, Set<HttpCacheEntry> variantEntries) throws IOException, ProtocolException { HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants(request, variantEntries);/*from ww w .j a v a 2 s. c om*/ Date requestDate = getCurrentDate(); HttpResponse backendResponse = backend.execute(target, conditionalRequest, context); Date responseDate = getCurrentDate(); backendResponse.addHeader("Via", generateViaHeader(backendResponse)); if (backendResponse.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_MODIFIED) { return handleBackendResponse(target, conditionalRequest, requestDate, responseDate, backendResponse); } Header resultEtagHeader = backendResponse.getFirstHeader(HeaderConstants.ETAG); if (resultEtagHeader == null) { log.debug("304 response did not contain ETag"); return callBackend(target, request, context); } HttpCacheEntry matchedEntry = null; String resultEtag = resultEtagHeader.getValue(); for (HttpCacheEntry variantEntry : variantEntries) { Header variantEtagHeader = variantEntry.getFirstHeader(HeaderConstants.ETAG); if (variantEtagHeader != null) { String variantEtag = variantEtagHeader.getValue(); if (resultEtag.equals(variantEtag)) { matchedEntry = variantEntry; break; } } } if (matchedEntry == null) { log.debug("304 response did not contain ETag matching one sent in If-None-Match"); return callBackend(target, request, context); } // make sure this cache entry is indeed new enough to update with, // if not force to refresh final Header entryDateHeader = matchedEntry.getFirstHeader("Date"); final Header responseDateHeader = backendResponse.getFirstHeader("Date"); if (entryDateHeader != null && responseDateHeader != null) { try { Date entryDate = DateUtils.parseDate(entryDateHeader.getValue()); Date respDate = DateUtils.parseDate(responseDateHeader.getValue()); if (respDate.before(entryDate)) { // TODO: what to do here? what if the initial request was a // conditional // request. It would get the same result whether it went // through our // cache or not... HttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(request, matchedEntry); return callBackend(target, unconditional, context); } } catch (DateParseException e) { // either backend response or cached entry did not have a valid // Date header, so we can't tell if they are out of order // according to the origin clock; thus we can skip the // unconditional retry recommended in 13.2.6 of RFC 2616. } } cacheUpdates.getAndIncrement(); setResponseStatus(context, CacheResponseStatus.VALIDATED); // SHOULD update cache entry according to rfc HttpCacheEntry responseEntry = matchedEntry; try { responseEntry = responseCache.updateCacheEntry(target, conditionalRequest, matchedEntry, backendResponse, requestDate, responseDate); } catch (IOException ioe) { log.warn("Could not update cache entry", ioe); } HttpResponse resp = responseGenerator.generateResponse(responseEntry); try { resp = responseCache.cacheAndReturnResponse(target, request, resp, requestDate, responseDate); } catch (IOException ioe) { log.warn("Could not cache entry", ioe); } if (suitabilityChecker.isConditional(request) && suitabilityChecker.allConditionalsMatch(request, responseEntry, new Date())) { return responseGenerator.generateNotModifiedResponse(responseEntry); } return resp; }
From source file:edu.cmu.cs.lti.discoursedb.io.mturk.converter.MturkConverterService.java
/** * Maps a discussion forum message to DiscourseDB * // w ww . ja va 2s . co m * @param subj the message subject * @param text the message text * @param forum_uid * @param thread_uid * @param group * @param team * @param author the message author (discoursedb user id number) * @param reply_to the discoursed_db contribution this replies to (or zero) * @param discourse_name * @param dataset_name * @param source_file_name * @param source_column_name * @param source_unique_index * * @returns the contribution Id written to the database */ public Long mapDiscussionPost(String subj, String text, String forum_uid, String thread_uid, String group, String team, long author, String when, long reply_to, String discourse_name, String dataset_name, String source_file_name, String source_column_name, String source_unique_index) { Discourse curDiscourse = discourseService.createOrGetDiscourse(discourse_name); User proxyUser = getProxyUser(author); ContributionTypes mappedType = null; if (reply_to == 0L) { mappedType = ContributionTypes.POST; } else { mappedType = ContributionTypes.RESPONSE; } log.trace("Create Content entity"); Content curContent = contentService.createContent(); curContent.setText(text); curContent.setTitle(subj); curContent.setAuthor(proxyUser); dataSourceService.addSource(curContent, new DataSourceInstance(source_unique_index, source_file_name + "#" + source_column_name + "(content)", DataSourceTypes.BAZAAR, dataset_name)); log.trace("Create Contribution entity"); Contribution curContribution = contributionService.createTypedContribution(mappedType); curContribution.setCurrentRevision(curContent); curContribution.setFirstRevision(curContent); dataSourceService.addSource(curContribution, new DataSourceInstance(source_unique_index, source_file_name + "#" + source_column_name + "(contribution)", DataSourceTypes.BAZAAR, dataset_name)); discussion_source2ddb.put(Long.valueOf(source_unique_index), curContribution.getId()); DiscoursePart thread = discoursepartService.createOrGetDiscoursePartByDataSource(curDiscourse, thread_uid, source_file_name + "#thread_uid", DataSourceTypes.BAZAAR, dataset_name, DiscoursePartTypes.THREAD); DiscoursePart forum = discoursepartService.createOrGetDiscoursePartByDataSource(curDiscourse, forum_uid, source_file_name + "#forum_uid", DataSourceTypes.BAZAAR, dataset_name, DiscoursePartTypes.FORUM); discoursepartService.createDiscoursePartRelation(forum, thread, DiscoursePartRelationTypes.SUBPART); if (!forum.getName().equals("dummy_name") && !forum.getName().equals(forumDpName(forum_uid))) { System.out.println("Changing forum " + forum_uid + " name from " + forum.getName() + " to " + forumDpName(forum_uid) + " in post " + source_unique_index); } forum.setName(forumDpName(forum_uid)); if (reply_to == 0) { if (!thread.getName().equals("dummy_name") && !thread.getName().equals(threadDpName(forum_uid, subj))) { System.out.println("Changing thread " + thread_uid + " name from " + thread.getName() + " to " + threadDpName(forum_uid, subj) + " in post " + source_unique_index); } thread.setName(threadDpName(forum_uid, subj)); } else { Contribution prior = getProxyContributionBySourceId(reply_to); if (prior == null) { System.out.println("What is this in reply to? Post # " + source_unique_index + "Replies to " + reply_to + " text starts with " + text); } else { contributionService.createDiscourseRelation(prior, curContribution, DiscourseRelationTypes.REPLY); } } if (reply_to == 0) { if (group != null) { DiscoursePart grp_dp = discoursepartService.createOrGetTypedDiscoursePart(curDiscourse, groupDpName(group), DiscoursePartTypes.GROUP); discoursepartService.createDiscoursePartRelation(grp_dp, forum, DiscoursePartRelationTypes.SUBPART); //discourses = grp_dp.getDiscourseToDiscourseParts(). } if (team != null && group != null) { DiscoursePart team_dp = discoursepartService.createOrGetTypedDiscoursePart(curDiscourse, teamDpName(group, team), DiscoursePartTypes.TEAM); discoursepartService.createDiscoursePartRelation(team_dp, thread, DiscoursePartRelationTypes.SUBPART); } } discoursepartService.addContributionToDiscoursePart(curContribution, thread); //parse and set creation time for content and contribution try { Date date = forgiving_date_parse(when); curContent.setStartTime(date); curContent.setEndTime(date); curContribution.setStartTime(date); curContribution.setEndTime(date); if (thread.getEndTime() == null || date.after(thread.getEndTime())) { thread.setEndTime(date); } if (thread.getStartTime() == null || date.before(thread.getStartTime())) { thread.setStartTime(date); } } catch (ParseException e) { log.error("Could not parse creation time " + when, e); } return curContribution.getId(); }
From source file:edu.harvard.iq.dvn.core.harvest.HarvesterServiceBean.java
private void createHarvestTimer(HarvestingDataverse dataverse) { if (dataverse.isScheduled()) { long intervalDuration = 0; Calendar initExpiration = Calendar.getInstance(); initExpiration.set(Calendar.MINUTE, 0); initExpiration.set(Calendar.SECOND, 0); if (dataverse.getSchedulePeriod().equals(dataverse.SCHEDULE_PERIOD_DAILY)) { intervalDuration = 1000 * 60 * 60 * 24; initExpiration.set(Calendar.HOUR_OF_DAY, dataverse.getScheduleHourOfDay()); } else if (dataverse.getSchedulePeriod().equals(dataverse.SCHEDULE_PERIOD_WEEKLY)) { intervalDuration = 1000 * 60 * 60 * 24 * 7; initExpiration.set(Calendar.HOUR_OF_DAY, dataverse.getScheduleHourOfDay()); initExpiration.set(Calendar.DAY_OF_WEEK, dataverse.getScheduleDayOfWeek()); } else {/* w ww .j av a2 s. c o m*/ logger.log(Level.WARNING, "Could not set timer for dataverse id, " + dataverse.getId() + ", unknown schedule period: " + dataverse.getSchedulePeriod()); return; } Date initExpirationDate = initExpiration.getTime(); Date currTime = new Date(); if (initExpirationDate.before(currTime)) { initExpirationDate.setTime(initExpiration.getTimeInMillis() + intervalDuration); } logger.log(Level.INFO, "Setting timer for dataverse " + dataverse.getVdc().getName() + ", initial expiration: " + initExpirationDate); // timerService.createTimer(initExpirationDate, intervalDuration, new HarvestTimerInfo(dataverse.getId(), dataverse.getVdc().getName(), dataverse.getSchedulePeriod(), dataverse.getScheduleHourOfDay(), dataverse.getScheduleDayOfWeek())); dvnTimerService.createTimer(initExpirationDate, intervalDuration, new HarvestTimerInfo(dataverse.getId(), dataverse.getVdc().getName(), dataverse.getSchedulePeriod(), dataverse.getScheduleHourOfDay(), dataverse.getScheduleDayOfWeek())); } }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.tasklets.IssuesLastRunExtractorTasklet.java
/** * {@inheritDoc}/*from w w w . j a va2s . c o m*/ * @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext) */ @Override public RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext) throws Exception { final StepContext stepContext = chunkContext.getStepContext(); final String jobName = stepContext.getJobName(); final JobParameters jobParams = stepContext.getStepExecution().getJobParameters(); final Map<String, JobParameter> currParams = new HashMap<String, JobParameter>(jobParams.getParameters()); currParams.remove("run.id"); Date lastJobRun = null; final List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1000); for (final JobInstance jobInstance : jobInstances) { final List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance); for (final JobExecution jobExecution : jobExecutions) { final JobParameters oldJobParams = jobExecution.getJobParameters(); final Map<String, JobParameter> oldParams = new HashMap<String, JobParameter>( oldJobParams.getParameters()); oldParams.remove("run.id"); if (ExitStatus.COMPLETED.equals(jobExecution.getExitStatus()) && oldParams.equals(currParams)) { if (lastJobRun == null || lastJobRun.before(jobExecution.getStartTime())) { lastJobRun = jobExecution.getStartTime(); } } } } if (lastJobRun != null) { stepContext.getStepExecution().getExecutionContext().put("mantis.update.last_job_run", lastJobRun); } stepContext.getStepExecution().getExecutionContext().put("mantis.update.current_job_run", Calendar.getInstance()); return RepeatStatus.FINISHED; }
From source file:eu.europa.esig.dss.validation.policy.SignatureCryptographicConstraint.java
/** * This method carry out the validation of the constraint. * * @return true if the constraint is met, false otherwise. *///from ww w .j a v a 2s . c o m @Override public boolean check() { if (ignore()) { node.addChild(NodeName.STATUS, NodeValue.IGNORED); return true; } if (inform()) { node.addChild(NodeName.STATUS, NodeValue.INFORMATION); node.addChild(NodeName.INFO).setAttribute(AttributeValue.ENCRYPTION_ALGORITHM, encryptionAlgorithm); node.addChild(NodeName.INFO).setAttribute(AttributeValue.DIGEST_ALGORITHM, digestAlgorithm); node.addChild(NodeName.INFO).setAttribute(AttributeValue.PUBLIC_KEY_SIZE, keyLength); return true; } // Encryption algorithm verification: final boolean containsEncryptionAlgorithm = RuleUtils.contains1(encryptionAlgorithm, encryptionAlgorithms); if (!containsEncryptionAlgorithm) { final Pair[] pairs = getParametersAnswer1(); if (fail(MessageTag.ASCCM_ANS_1, pairs)) { return false; } } // Digest algorithm verification: final boolean containsDigestAlgorithm = RuleUtils.contains1(digestAlgorithm, digestAlgorithms); if (!containsDigestAlgorithm) { final Pair[] pairs = getParametersAnswer2(); if (fail(MessageTag.ASCCM_ANS_2, pairs)) { return false; } } // Minimum public key size verification: final String minimumPublicKeySize = minimumPublicKeySizes.get(encryptionAlgorithm); int keyLengthInt = 0; try { keyLengthInt = StringUtils.isBlank(keyLength) || "?".equals(keyLength) ? 0 : Integer.valueOf(keyLength); } catch (NumberFormatException e) { LOG.debug("Unknown key length: '" + keyLength + "'"); } final boolean publicKeyBigEnough = (minimumPublicKeySize != null) && (Integer.valueOf(keyLengthInt) >= Integer.valueOf(minimumPublicKeySize)); if (!publicKeyBigEnough) { final Pair[] pairs = getParametersAnswer3(minimumPublicKeySize); if (fail(MessageTag.ASCCM_ANS_3, pairs)) { return false; } } // Algorithm's expiration date verification: if (!algorithmExpirationDates.isEmpty()) { final String encryptionAlgorithmAndKey = encryptionAlgorithm + keyLength; Date algorithmExpirationDate = algorithmExpirationDates.get(encryptionAlgorithmAndKey); if (algorithmExpirationDate == null) { final Pair[] pairs = getParametersAnswer4(encryptionAlgorithmAndKey); if (fail(MessageTag.ASCCM_ANS_4, pairs)) { return false; } } boolean expiredAlgorithm = algorithmExpirationDate == null ? false : algorithmExpirationDate.before(currentTime); if (expiredAlgorithm) { final Pair[] pairs = getParametersAnswer5(encryptionAlgorithmAndKey, algorithmExpirationDate); if (fail(MessageTag.ASCCM_ANS_5, pairs)) { return false; } } algorithmExpirationDate = algorithmExpirationDates.get(digestAlgorithm); if (algorithmExpirationDate == null) { final Pair[] pairs = getParametersAnswer4(digestAlgorithm); if (fail(MessageTag.ASCCM_ANS_4, pairs)) { return false; } } expiredAlgorithm = algorithmExpirationDate == null ? false : algorithmExpirationDate.before(currentTime); if (expiredAlgorithm) { final Pair[] pairs = getParametersAnswer5(digestAlgorithm, algorithmExpirationDate); if (fail(MessageTag.ASCCM_ANS_5, pairs)) { return false; } } } node.addChild(NodeName.STATUS, NodeValue.OK); return true; }
From source file:com.fdu.jira.plugin.report.timesheet.TimeSheet.java
public void validate(ProjectActionSupport action, Map params) { // nothing to do, all parameters are optional, // and there is no longer restriction for one month period User remoteUser = authenticationContext.getLoggedInUser(); I18nHelper i18nBean = new I18nBean(remoteUser); // startDate before endDate Date startDate = ParameterUtils.getDateParam(params, "startDate", i18nBean.getLocale()); Date endDate = ParameterUtils.getDateParam(params, "endDate", i18nBean.getLocale()); if (startDate == null || endDate == null) { return; // nothing to validate }/*from w w w . j av a 2 s .co m*/ // The end date must be after the start date if (endDate.before(startDate)) { action.addError("endDate", action.getText("report.timesheet.before.startdate")); } // maxPeriod Calendar c = Calendar.getInstance(); c.setTime(startDate); c.add(Calendar.DAY_OF_MONTH, maxPeriod); // The end date must be after the start date if (c.getTime().before(endDate)) { action.addError("endDate", action.getText("report.timesheet.maxperiod")); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopDateField.java
protected boolean checkRange(Date value) { if (updatingInstance) { return true; }/* w ww . j av a 2 s .c o m*/ if (value != null) { Date rangeStart = getRangeStart(); if (rangeStart != null && value.before(rangeStart)) { handleDateOutOfRange(value); return false; } Date rangeEnd = getRangeEnd(); if (rangeEnd != null && value.after(rangeEnd)) { handleDateOutOfRange(value); return false; } } return true; }
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * 2???????????????.//w ww. jav a2 s . c om * @param fromDate1 * @param toDate1 * @param fromDate2 2 * @param toDate2 2 * @return true:??????false:??????? */ public static boolean isDateOverlap(Date fromDate1, Date toDate1, Date fromDate2, Date toDate2) { fromDate1 = truncate(fromDate1, Dates.DAY); toDate1 = truncate(toDate1, Dates.DAY); fromDate2 = truncate(fromDate2, Dates.DAY); toDate2 = truncate(toDate2, Dates.DAY); if ((fromDate1.equals(fromDate2) || toDate1.equals(toDate2) || // ???????? fromDate1.equals(toDate2) || toDate1.equals(fromDate2)) || (fromDate1.before(fromDate2) && toDate1.after(fromDate2)) || // ????????? (fromDate2.before(fromDate1) && toDate2.after(fromDate1))) // ????????? return true; return false; }
From source file:com.lastdaywaiting.example.kalkan.service.SecureManager.java
/** * ? CRL- ?//from w ww.j av a2 s . co m * * @param crlName * @return */ private boolean isNeedLoadCrlObject(String crlName) { if (TypeOfCrlLoaded.NO_LOAD.equals(MAP_OF_LOAD_CRL_LABEL.get(crlName))) { return true; // , ? } else if (TypeOfCrlLoaded.LOADING.equals(MAP_OF_LOAD_CRL_LABEL.get(crlName))) { return false; // , ? ? } else if (TypeOfCrlLoaded.LOADED.equals(MAP_OF_LOAD_CRL_LABEL.get(crlName))) { Date currentDt = new Date(); Date lastLoadedCrl = MAP_OF_LOAD_CRL_TIME.get(crlName); Date checkDt = DateUtils.addHours(lastLoadedCrl, HOURS_OF_RELOAD); if (checkDt.before(currentDt)) { return true; // , ? ??? HOURS_OF_RELOAD ? } else { return false; } } else { throw new RuntimeException("?? ? ?? " + MAP_OF_LOAD_CRL_LABEL.get(crlName)); } }
From source file:org.globus.workspace.cloud.client.util.CumulusParameterConvert.java
public void print_bar() { Calendar now = Calendar.getInstance(); Date nowDt = now.getTime(); if (this.nextUpdate != null && nowDt.before(this.nextUpdate)) { return;/*from www .j a v a 2 s. co m*/ } this.nextUpdate = new Date(nowDt.getTime() + 1000); flush(); }