Example usage for java.util Date after

List of usage examples for java.util Date after

Introduction

In this page you can find the example usage for java.util Date after.

Prototype

public boolean after(Date when) 

Source Link

Document

Tests if this date is after the specified date.

Usage

From source file:com.vmware.photon.controller.model.adapters.azure.stats.AzureStatsService.java

/**
 * Get the metric definitons from Azure using the Endpoint "/metricDefinitions"
 * The request and response of the API is as described in
 * {@link https://msdn.microsoft.com/en-us/library/azure/dn931939.aspx} Insights REST.
 * @param statsData/* w w  w  .j  a va  2  s .  c o  m*/
 * @throws URISyntaxException
 * @throws IOException
 */
private void getMetricDefinitions(AzureStatsDataHolder statsData) throws URISyntaxException, IOException {
    String azureInstanceId = statsData.computeDesc.id;
    URI uri = UriUtils.buildUri(new URI(AzureConstants.BASE_URI_FOR_REST), azureInstanceId,
            AzureConstants.METRIC_DEFINITIONS_ENDPOINT);
    // Adding a filter to avoid huge data flow on the network
    /*
     * VSYM-656: https://jira-hzn.eng.vmware.com/browse/VSYM-656
     * Remove the filter when Unit of a metric is required.
     */
    uri = UriUtils.extendUriWithQuery(uri, AzureConstants.QUERY_PARAM_API_VERSION,
            AzureConstants.DIAGNOSTIC_SETTING_API_VERSION, AzureConstants.QUERY_PARAM_FILTER,
            AzureConstants.METRIC_DEFINITIONS_MEMORY_FILTER);
    Operation operation = Operation.createGet(uri);
    operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
    operation.addRequestHeader(Operation.AUTHORIZATION_HEADER,
            AzureConstants.AUTH_HEADER_BEARER_PREFIX + statsData.credentials.getToken());
    operation.setCompletion((op, ex) -> {
        if (ex != null) {
            AdapterUtils.sendFailurePatchToProvisioningTask(this, statsData.statsRequest.taskReference, ex);
        }
        MetricDefinitions metricDefinitions = op.getBody(MetricDefinitions.class);
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(AzureConstants.METRIC_TIME_FORMAT);
        if (metricDefinitions.getValues() != null && !metricDefinitions.getValues().isEmpty()) {
            for (MetricAvailability metricAvailability : metricDefinitions.getValues().get(0)
                    .getMetricAvailabilities()) {
                if (metricAvailability.getTimeGrain().equals(AzureConstants.METRIC_TIME_GRAIN_1_MINUTE)) {
                    Location location = metricAvailability.getLocation();
                    Date mostRecentTableDate = null;
                    for (TableInfo tableInfo : location.getTableInfo()) {
                        Date startDate = dateTimeFormatter.parseDateTime(tableInfo.getStartTime()).toDate();
                        if (mostRecentTableDate == null || startDate.after(mostRecentTableDate)) {
                            mostRecentTableDate = startDate;
                            statsData.tableName = tableInfo.getTableName();
                        }
                    }
                    statsData.partitionValue = location.getPartitionKey();
                }
            }
        }
        if (!StringUtils.isEmpty(statsData.tableName)) {
            try {
                getMetrics(statsData);
            } catch (Exception e) {
                AdapterUtils.sendFailurePatchToProvisioningTask(this, statsData.statsRequest.taskReference, e);
            }
        } else {
            // Patch back to the Parent with empty response
            ComputeStatsResponse respBody = new ComputeStatsResponse();
            statsData.statsResponse.computeLink = statsData.computeDesc.documentSelfLink;
            respBody.taskStage = statsData.statsRequest.nextStage;
            respBody.statsList = new ArrayList<>();
            this.sendRequest(Operation.createPatch(statsData.statsRequest.taskReference).setBody(respBody));
        }
    });
    sendRequest(operation);
}

From source file:com.nec.harvest.controller.KoguchiController.java

/**
 * To set editable page/*from   ww  w .j av a 2  s . co m*/
 * 
 * @param currentDate
 *          Current date
 * @param businessDay
 *          The business day
 * @param model
 *          Page model to update attribute EDITABLE
 */
private void pageEditable(Date currentDate, Date businessDay, final Model model) {
    Date getSudo = null;
    try {
        Tighten tighten = tightenService.findByClassifyAndMonth("1");
        getSudo = DateFormatUtil.parse(tighten.getGetSudo(), DateFormat.DATE_WITHOUT_DAY);

        //
        model.addAttribute(EDITABLE, currentDate.after(getSudo));
    } catch (ObjectNotFoundException ex) {
        getSudo = DateUtil.monthsToSubtract(businessDay, 3);

        // 
        model.addAttribute(EDITABLE, currentDate.after(getSudo));
    } catch (IllegalArgumentException | NullPointerException | ParseException ex) {
        logger.warn(ex.getMessage());

        // 
        model.addAttribute(EDITABLE, Boolean.FALSE);
    }
}

From source file:com.surevine.alfresco.webscript.gsa.getallitems.GetAllItemsCommandImpl.java

private void checkSince(Date since) throws GSAInvalidParameterException {
    if (since == null) {
        throw new GSAInvalidParameterException("A start date was not specified", null, 1);
    }// ww w.ja  v a  2s.  com

    if (since.after(new Date())) {
        throw new GSAInvalidParameterException("The specified start date of " + since + " is in the future",
                null, 2);
    }
}

From source file:org.jasig.schedassist.impl.SchedulingAssistantServiceImpl.java

@Override
public VisibleSchedule getVisibleSchedule(final IScheduleVisitor visitor, final IScheduleOwner owner,
        final Date start, final Date end) {
    Validate.notNull(start, "start parameter cannot be null");
    Validate.notNull(end, "start parameter cannot be null");

    Date[] windowBoundaries = calculateOwnerWindowBounds(owner);

    Date localStart = start;//from www .  java 2 s  .  com
    if (start.before(windowBoundaries[0]) || start.after(windowBoundaries[1])) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("ignoring submitted start for getVisibleSchedule: " + start + " (using windowBoundary of "
                    + windowBoundaries[0] + ")");
        }
        localStart = windowBoundaries[0];
    }
    Date localEnd = end;
    if (end.after(windowBoundaries[1])) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("ignoring submitted end for getVisibleSchedule: " + end + " (using windowBoundary of "
                    + windowBoundaries[1] + ")");
        }
        localEnd = windowBoundaries[1];
    }

    Calendar calendar = calendarDao.getCalendar(owner.getCalendarAccount(), localStart, localEnd);
    AvailableSchedule schedule = availableScheduleDao.retrieve(owner);

    VisibleSchedule result = this.visibleScheduleBuilder.calculateVisibleSchedule(localStart, localEnd,
            calendar, schedule, owner, visitor);
    return result;
}

From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.StockBilletterieApp.java

/**
 * Calculate if show is open to book./*from  w  ww  . j  av  a 2  s  .c o m*/
 *
 * @param show the show
 * @return 0 open, 1 to come, -1 passed
 */
private int caculateBookingOpened(ShowDTO show) {
    Date startDate = DateUtils.getDate(show.getStartDate(), true);
    Date endDate = DateUtils.getDate(show.getEndDate(), false);
    Date today = new Date();
    int seanceOpened;

    if (today.before(startDate)) {
        seanceOpened = BOOKING_TO_COME;
    } else if (today.after(endDate)) {
        seanceOpened = BOOKING_PASSED;
    } else {
        seanceOpened = BOOKING_OPENED;
    }

    return seanceOpened;
}

From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBean.java

private boolean isCurrentDateAfterDueDateAndWithinRenewalRange(Date dueDate) {
    Date now = new Date();
    Date boundaryDate = DateUtils.addDays(dueDate, daysAfterDueDateToUseAsBasisForRenewalDate);
    return now.before(boundaryDate) && now.after(dueDate);
}

From source file:info.rmapproject.auth.service.ApiKeyServiceImpl.java

/**
 * Validate an API key/secret combination to ensure the user has access to write to RMap.
 *
 * @param accessKey the access key/*from w  w w.  j av  a 2 s  . c  o m*/
 * @param secret the secret
 * @throws RMapAuthException the RMap Auth exception
 */
public void validateApiKey(String accessKey, String secret) throws RMapAuthException {

    ApiKey apiKey = getApiKeyByKeySecret(accessKey, secret);

    if (apiKey != null) {
        KeyStatus keyStatus = apiKey.getKeyStatus();
        Date keyStartDate = apiKey.getStartDate();
        Date keyEndDate = apiKey.getEndDate();

        Calendar now = Calendar.getInstance();
        now.set(Calendar.HOUR_OF_DAY, 0);
        now.set(Calendar.MINUTE, 0);
        now.set(Calendar.SECOND, 0);
        Date today = now.getTime();
        now.add(Calendar.DATE, -1);
        Date yesterday = now.getTime();

        if (keyStatus != KeyStatus.ACTIVE || (keyStartDate != null && keyStartDate.after(today))
                || (keyEndDate != null && keyEndDate.before(yesterday))) {
            //key not valid! throw exception
            throw new RMapAuthException(ErrorCode.ER_KEY_INACTIVE.getMessage());
        }
    } else {
        throw new RMapAuthException(ErrorCode.ER_ACCESSCODE_SECRET_NOT_FOUND.getMessage());
    }

}

From source file:org.jasig.schedassist.portlet.webflow.FlowHelper.java

/**
 * Verify the startTime argument is within the window; return {@link #NO} if not.
 * /* w  w  w . j a v a  2s  . com*/
 * @param window
 * @param startTime
 * @return {@link #YES} for valid, {@link #NO} for invalid
 */
public String validateChosenStartTime(VisibleWindow window, Date startTime) {
    final Date currentWindowEnd = window.calculateCurrentWindowEnd();
    if (startTime.before(window.calculateCurrentWindowStart()) || startTime.equals(currentWindowEnd)
            || startTime.after(currentWindowEnd)) {
        LOG.debug("selected startTime (" + startTime + ") is no longer within window " + window.getKey());
        return NO;
    }

    return YES;
}

From source file:be.fedict.trust.service.bean.HarvesterMDB.java

private void processHarvestMessage(HarvestMessage harvestMessage) {
    if (null == harvestMessage) {
        return;/*  w  w  w.  j  av a 2 s .  co m*/
    }
    String caName = harvestMessage.getCaName();
    boolean update = harvestMessage.isUpdate();
    String crlFilePath = harvestMessage.getCrlFile();
    File crlFile = new File(crlFilePath);

    LOG.debug("processHarvestMessage - Don't have CA's Serial Number??");
    LOG.debug("issuer: " + caName);
    CertificateAuthorityEntity certificateAuthority = this.certificateAuthorityDAO
            .findCertificateAuthority(caName);
    if (null == certificateAuthority) {
        LOG.error("unknown certificate authority: " + caName);
        deleteCrlFile(crlFile);
        return;
    }
    if (!update && Status.PROCESSING != certificateAuthority.getStatus()) {
        /*
         * Possible that another harvester instance already activated or is
         * processing the CA cache in the meanwhile.
         */
        LOG.debug("CA status not marked for processing");
        deleteCrlFile(crlFile);
        return;
    }

    Date validationDate = new Date();

    X509Certificate issuerCertificate = certificateAuthority.getCertificate();

    Date notAfter = issuerCertificate.getNotAfter();
    if (validationDate.after(notAfter)) {
        LOG.info("will not update CRL cache for expired CA: " + issuerCertificate.getSubjectX500Principal());
        deleteCrlFile(crlFile);
        return;
    }

    FileInputStream crlInputStream;
    try {
        crlInputStream = new FileInputStream(crlFile);
    } catch (FileNotFoundException e) {
        LOG.error("CRL file does not exist: " + crlFilePath);
        return;
    }
    X509CRL crl;
    try {
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", "BC");
        crl = (X509CRL) certificateFactory.generateCRL(crlInputStream);
    } catch (Exception e) {
        LOG.error("BC error: " + e.getMessage(), e);
        deleteCrlFile(crlFile);
        return;
    }

    LOG.debug("checking integrity CRL...");
    boolean crlValid = CrlTrustLinker.checkCrlIntegrity(crl, issuerCertificate, validationDate);
    if (!crlValid) {
        this.auditDAO.logAudit("Invalid CRL for CA=" + caName);
        deleteCrlFile(crlFile);
        return;
    }
    BigInteger crlNumber = getCrlNumber(crl);
    LOG.debug("CRL number: " + crlNumber);

    BigInteger currentCrlNumber = this.certificateAuthorityDAO.findCrlNumber(caName);
    if (null != currentCrlNumber) {
        LOG.debug("CRL number in database: " + currentCrlNumber);
    }
    if (null != currentCrlNumber && currentCrlNumber.compareTo(crlNumber) >= 0
            && certificateAuthority.getStatus() == Status.ACTIVE) {
        // current CRL cache is higher or equal, no update needed
        LOG.debug("current CA cache is new enough.");
        deleteCrlFile(crlFile);
        return;
    }

    List<RevokedCertificateEntity> revokedCertificateEntities = this.certificateAuthorityDAO
            .getRevokedCertificates(caName);
    LOG.debug("number of revoked certificates in database: " + revokedCertificateEntities.size());
    Map<String, RevokedCertificateEntity> revokedCertificatesMap = new HashMap<String, RevokedCertificateEntity>();
    for (RevokedCertificateEntity revokedCertificateEntity : revokedCertificateEntities) {
        String serialNumber = revokedCertificateEntity.getPk().getSerialNumber();
        revokedCertificatesMap.put(serialNumber, revokedCertificateEntity);
    }

    LOG.debug("processing CRL... " + caName);
    boolean isIndirect;
    Enumeration revokedCertificatesEnum;
    try {
        isIndirect = isIndirectCRL(crl);
        revokedCertificatesEnum = getRevokedCertificatesEnum(crl);
    } catch (Exception e) {
        this.auditDAO.logAudit("Failed to parse CRL for CA=" + caName);
        this.failures++;
        throw new RuntimeException(e);
    }

    int entries = 0;
    if (revokedCertificatesEnum.hasMoreElements()) {
        /*
         * Split up persisting the crl entries to avoid memory issues.
         */
        Set<X509CRLEntry> revokedCertsBatch = new HashSet<X509CRLEntry>();
        X500Principal previousCertificateIssuer = crl.getIssuerX500Principal();
        int added = 0;
        while (revokedCertificatesEnum.hasMoreElements()) {

            TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry) revokedCertificatesEnum.nextElement();
            X500Name x500name = new X500Name(previousCertificateIssuer.getName(X500Principal.RFC1779));
            X509CRLEntryObject revokedCertificate = new X509CRLEntryObject(entry, isIndirect, x500name);
            previousCertificateIssuer = revokedCertificate.getCertificateIssuer();

            revokedCertsBatch.add(revokedCertificate);
            added++;
            if (added == BATCH_SIZE) {
                /*
                 * Persist batch
                 */
                this.certificateAuthorityDAO.updateRevokedCertificates(revokedCertsBatch, crlNumber,
                        crl.getIssuerX500Principal(), revokedCertificatesMap);
                entries += revokedCertsBatch.size();
                revokedCertsBatch.clear();
                added = 0;
            }
        }
        /*
         * Persist final batch
         */
        this.certificateAuthorityDAO.updateRevokedCertificates(revokedCertsBatch, crlNumber,
                crl.getIssuerX500Principal(), revokedCertificatesMap);
        entries += revokedCertsBatch.size();

        /*
         * Cleanup redundant CRL entries
         */
        if (null != crlNumber) {
            this.certificateAuthorityDAO.removeOldRevokedCertificates(crlNumber,
                    crl.getIssuerX500Principal().toString());
        }
    }

    deleteCrlFile(crlFile);

    LOG.debug("CRL this update: " + crl.getThisUpdate());
    LOG.debug("CRL next update: " + crl.getNextUpdate());
    certificateAuthority.setStatus(Status.ACTIVE);
    certificateAuthority.setThisUpdate(crl.getThisUpdate());
    certificateAuthority.setNextUpdate(crl.getNextUpdate());
    LOG.debug("cache activated for CA: " + crl.getIssuerX500Principal() + " (entries=" + entries + ")");
}