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:org.jasig.portlet.announcements.mvc.servlet.ApproveAjaxController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    Long annId = Long.valueOf(request.getParameter("annId"));
    Boolean approval = Boolean.valueOf(request.getParameter("approval"));
    Announcement ann = announcementService.getAnnouncement(annId);

    Date startDisplay = ann.getStartDisplay();
    Date endDisplay = ann.getEndDisplay();
    if (endDisplay == null) {
        // Unspecified end date means the announcement does not expire;  we 
        // will substitute a date in the future each time this item is 
        // evaluated.
        long aYearFromNow = System.currentTimeMillis() + Announcement.MILLISECONDS_IN_A_YEAR;
        endDisplay = new Date(aYearFromNow);
    }//  ww  w . j  a v a2s.  c o m

    Date now = new Date();
    int status = 3;
    /**
     * Scheduled = 0
     * Expired   = 1
     * Showing   = 2
     * Pending   = 3
     */
    if (startDisplay.after(now) && endDisplay.after(now) && approval) {
        status = 0;
    } else if (startDisplay.before(now) && endDisplay.after(now) && approval) {
        status = 2;
    } else if (endDisplay.before(now)) {
        status = 1;
    }

    ann.setPublished(approval);
    cacheManager.getCacheManager().getCache("guestAnnouncementCache").flush();

    announcementService.addOrSaveAnnouncement(ann);

    return new ModelAndView("ajaxApprove", "status", status);

}

From source file:com.emc.ecs.sync.target.AtmosTarget.java

private boolean dataChanged(SyncObject obj, Map<String, Metadata> targetSystemMeta) {
    Date srcMtime = obj.getMetadata().getModificationTime();
    Date dstMtime = parseDate(targetSystemMeta.get("mtime"));

    return srcMtime != null && dstMtime != null && srcMtime.after(dstMtime);
}

From source file:org.jasig.portlet.announcements.controller.ApproveAjaxController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    Long annId = Long.valueOf(request.getParameter("annId"));
    Boolean approval = Boolean.valueOf(request.getParameter("approval"));
    Announcement ann = announcementService.getAnnouncement(annId);

    Date startDisplay = ann.getStartDisplay();
    Date endDisplay = ann.getEndDisplay();
    if (endDisplay == null) {
        // Unspecified end date means the announcement does not expire;  we 
        // will substitute a date in the future each time this item is 
        // evaluated.
        long aYearFromNow = System.currentTimeMillis() + Announcement.MILLISECONDS_IN_A_YEAR;
        endDisplay = new Date(aYearFromNow);
    }/*  w  ww.  ja  v a 2 s.  co  m*/

    Date now = new Date();
    int status = 3;
    /**
     * Scheduled = 0
     * Expired   = 1
     * Showing   = 2
     * Pending   = 3
     */
    if (startDisplay.after(now) && endDisplay.after(now) && approval) {
        status = 0;
    } else if (startDisplay.before(now) && endDisplay.after(now) && approval) {
        status = 2;
    } else if (endDisplay.before(now)) {
        status = 1;
    }

    ann.setPublished(approval);
    cm.getCacheManager().getCache("guestAnnouncementCache").flush();

    announcementService.addOrSaveAnnouncement(ann);

    return new ModelAndView("ajaxApprove", "status", status);

}

From source file:uk.ac.bbsrc.tgac.miso.core.manager.ERASubmissionManager.java

public String prettifySubmissionMetadata(Submission submission) throws SubmissionException {
    StringBuilder sb = new StringBuilder();
    try {/*from   w w w.  j ava2  s.  c  o  m*/
        Collection<File> files = misoFileManager.getFiles(Submission.class, submission.getName());

        Date latestDate = null;

        //get latest submitted xmls
        try {
            for (File f : files) {
                if (f.getName().contains("submission_")) {
                    String d = f.getName().substring(f.getName().lastIndexOf("_") + 1,
                            f.getName().lastIndexOf("."));
                    Date test = df.parse(d);
                    if (latestDate == null || test.after(latestDate)) {
                        latestDate = test;
                    }
                }
            }
        } catch (ParseException e) {
            log.error("No timestamped submission metadata documents. Falling back to simple names: "
                    + e.getMessage());
        }

        String dateStr = "";
        if (latestDate != null) {
            dateStr = "_" + df.format(latestDate);
        }

        InputStream in = null;
        for (File f : files) {
            if (f.getName().contains("submission" + dateStr)) {
                in = ERASubmissionManager.class.getResourceAsStream("/submission/xsl/eraSubmission.xsl");
                if (in != null) {
                    String xsl = LimsUtils.inputStreamToString(in);
                    sb.append(SubmissionUtils.xslTransform(SubmissionUtils.transform(f, true), xsl));
                }
            }
        }

        for (File f : files) {
            if (f.getName().contains("study" + dateStr)) {
                in = ERASubmissionManager.class.getResourceAsStream("/submission/xsl/eraStudy.xsl");
                if (in != null) {
                    String xsl = LimsUtils.inputStreamToString(in);
                    sb.append(SubmissionUtils.xslTransform(SubmissionUtils.transform(f, true), xsl));
                }
            }
        }

        for (File f : files) {
            if (f.getName().contains("sample" + dateStr)) {
                in = ERASubmissionManager.class.getResourceAsStream("/submission/xsl/eraSample.xsl");
                if (in != null) {
                    String xsl = LimsUtils.inputStreamToString(in);
                    sb.append(SubmissionUtils.xslTransform(SubmissionUtils.transform(f, true), xsl));
                }
            }
        }

        for (File f : files) {
            if (f.getName().contains("experiment" + dateStr)) {
                in = ERASubmissionManager.class.getResourceAsStream("/submission/xsl/eraExperiment.xsl");
                if (in != null) {
                    String xsl = LimsUtils.inputStreamToString(in);
                    sb.append(SubmissionUtils.xslTransform(SubmissionUtils.transform(f, true), xsl));
                }
            }
        }

        for (File f : files) {
            if (f.getName().contains("run" + dateStr)) {
                in = ERASubmissionManager.class.getResourceAsStream("/submission/xsl/eraRun.xsl");
                if (in != null) {
                    String xsl = LimsUtils.inputStreamToString(in);
                    sb.append(SubmissionUtils.xslTransform(SubmissionUtils.transform(f, true), xsl));
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    }

    return sb.toString();
}

From source file:org.ala.harvester.FlickrHarvester.java

/**
 * @see org.ala.harvester.Harvester#start()
 *///w w w .ja va2  s.  co  m
@Override
public void start(int infosourceId) throws Exception {

    //get licences maps
    Map<String, Licence> licences = getLicencesMap();
    documentMapper.setLicencesMap(licences);

    int totalIndexed = 0;
    Date endDate = new Date();
    Date finalStartDate = DateUtils.parseDate("2004-01-01", new String[] { "yyyy-MM-dd" });
    if (System.getProperty("startDate") != null) {
        endDate = DateUtils.parseDate(System.getProperty("startDate"), new String[] { "yyyy-MM-dd" });
    }
    if (System.getProperty("endDate") != null) {
        finalStartDate = DateUtils.parseDate(System.getProperty("endDate"), new String[] { "yyyy-MM-dd" });
    }

    Date startDate = DateUtils.addDays(endDate, -1);
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    // page through the images month-by-month
    while (startDate.after(finalStartDate)) {
        logger.info("Harvesting time period: " + df.format(startDate) + " to " + df.format(endDate));
        totalIndexed += indexTimePeriod(infosourceId, endDate, startDate);
        endDate = startDate;
        startDate = DateUtils.addDays(endDate, -1);
    }
    logger.info("Total harvested: " + totalIndexed);
}

From source file:jp.go.nict.langrid.management.web.view.component.validator.DateScopeValidator.java

@Override
protected void onValidate(IValidatable<Date> arg0) {
    Date fromDate = null;
    if (dateTextField.getInput().length() == 0) {
        return;//from   w ww  .  ja v a  2  s.  co m
    }
    try {
        fromDate = DateUtil.parseDateTextWithSlash(dateTextField.getInput());
    } catch (ParseException e) {
        LogWriter.writeError("Validator", e, DateScopeValidator.class);
        Map<String, String> param = new HashMap<String, String>();
        param.put("$label", MessageManager.getMessage("startDate", dateTextField.getLocale()));
        dateTextField.error(MessageManager.getMessage("message.error.date.InValid", param));
        return;
    }
    if (DateUtils.isSameDay(fromDate, arg0.getValue())) {
        return;
    }
    if (fromDate.after(arg0.getValue())) {
        error(arg0);
    }
}

From source file:com.celements.blog.plugin.BlogPlugin.java

private void filterRightsAndSubscription(List<Article> articles, String blogArticleSpace, String language,
        boolean withUnsubscribed, boolean withUndecided, boolean withSubscribed, boolean subscribableOnly,
        boolean checkRights, XWikiContext context) throws XWikiException {
    List<Article> deleteArticles = new ArrayList<Article>();
    XWikiDocument spaceBlogDoc = getBlogService().getBlogPageByBlogSpace(blogArticleSpace);
    if (spaceBlogDoc == null) {
        LOGGER.debug("Missing Blog Configuration! (Blog space: '" + blogArticleSpace + "')");
        deleteArticles.addAll(articles);
    } else {/*  www. ja v a2  s .c o m*/
        Document origBlogDoc = spaceBlogDoc.newDocument(context);
        for (Iterator<Article> artIter = articles.iterator(); artIter.hasNext();) {
            Article article = (Article) artIter.next();
            try {
                XWikiDocument articleDoc = context.getWiki().getDocument(article.getDocumentReference(),
                        context);
                DocumentReference blogDocRef = getBlogService().getBlogDocRefByBlogSpace(
                        articleDoc.getDocumentReference().getLastSpaceReference().getName());
                LOGGER.debug("articleDoc='" + articleDoc + "', " + blogDocRef);
                Document blogDoc = context.getWiki().getDocument(blogDocRef, context).newDocument(context);
                boolean hasRight = false;
                boolean hasEditOnBlog = false;
                if (checkRights || !blogDoc.hasProgrammingRights()) {
                    LOGGER.info("'" + article.getDocName() + "' - Checking rights. Reason: " + "checkRights='"
                            + checkRights + "' || !programming='" + !blogDoc.hasProgrammingRights() + "'");
                    Date publishdate = article.getPublishDate(language);
                    if ((publishdate != null) && (publishdate.after(new Date()))) {
                        if (blogDoc.hasAccessLevel("edit")) {
                            hasRight = true;
                        }
                    } else if (blogDoc.hasAccessLevel("view")) {
                        hasRight = true;
                    }
                    LOGGER.debug("'" + articleDoc.getSpace() + "' != '" + blogArticleSpace
                            + "' && origBlogDoc.hasAccessLevel('edit') => '"
                            + origBlogDoc.hasAccessLevel("edit") + "'");
                    if (!articleDoc.getSpace().equals(blogArticleSpace) && origBlogDoc.hasAccessLevel("edit")) {
                        hasEditOnBlog = true;
                    }
                } else {
                    LOGGER.info("'" + article.getDocName() + "' - Saved with programming rights "
                            + "and not checking for rights.");
                    hasRight = true;
                    hasEditOnBlog = true;
                }

                LOGGER.info("'" + article.getDocName() + "' - hasRight: '" + hasRight + "' "
                        + "hasEditOnBlog: '" + hasEditOnBlog + "'");
                if (hasRight) {
                    if (!articleDoc.getSpace().equals(blogArticleSpace)) {
                        Boolean isSubscribed = article.isSubscribed();

                        if (isSubscribed == null) {
                            if (!withUndecided || !hasEditOnBlog) {
                                LOGGER.info("'" + article.getDocName() + "' - Removed reason: from "
                                        + "subscribed blog && isUndecided && (!withUndecided='" + !withUndecided
                                        + "' || !hasEditOnBlog='" + !hasEditOnBlog + "')");
                                deleteArticles.add(article);
                            }
                        } else {
                            if (!isSubscribed && (!withUnsubscribed || !hasEditOnBlog)) {
                                LOGGER.info("'" + article.getDocName() + "' - Removed reason: from "
                                        + "subscribed blog && isDecided && ((!isSubscribed='" + !isSubscribed
                                        + "' && !withUnsubscribed='" + !withUnsubscribed + "') || "
                                        + "!hasEditOnBlog='" + !hasEditOnBlog + "')");
                                deleteArticles.add(article);
                            } else if (isSubscribed && !withSubscribed) {
                                LOGGER.info("'" + article.getDocName() + "' - Removed reason: from "
                                        + "subscribed blog && isDecided && (isSubscribed='" + isSubscribed
                                        + "' && !withSubscribed='" + !withSubscribed + "')");
                                deleteArticles.add(article);
                            }
                        }
                    } else if (subscribableOnly) {
                        LOGGER.info("'" + article.getDocName() + "' - Removed reason: from own "
                                + "blog, but subscribableOnly='" + subscribableOnly + "'");
                        deleteArticles.add(article);
                    }
                } else {
                    LOGGER.info("'" + article.getDocName() + "' - Removed reason: has no rights");
                    deleteArticles.add(article);
                }
            } catch (XWikiException exp) {
                LOGGER.error("filterRightsAndSubscription: Failed to check rights on: "
                        + article.getDocumentReference(), exp);
            }
        }
    }
    for (Iterator<Article> delIter = deleteArticles.iterator(); delIter.hasNext();) {
        articles.remove(delIter.next());
    }
}

From source file:com.wlami.mibox.client.metadata.MetadataWorker.java

/**
 * Synchronizes the file system state with the metadata.<br/>
 * <br/>/*  w  w w  . ja  va 2  s. c  om*/
 * First checks whether file system lastModified date is later than the
 * metadata. In this case the hashes are updated.
 * 
 * @param f
 *            Referende to the filesystem file.
 * @param mFile
 *            Reference to the metadata file.
 */
private void synchronizeFileMetadata(final File f, final MFile mFile) {
    // Check whether the file has been modified since the last meta sync
    log.debug("Start synchronization for file [{}]", f.getAbsolutePath());
    final Date filesystemLastModified = new Date(f.lastModified());
    if ((mFile.getLastModified() == null) || (filesystemLastModified.after(mFile.getLastModified()))) {
        // The file has been modified, so we have to update metadata
        log.debug("File newer than last modification date. Calculating file and chunk hashes for [{}]",
                f.getName());
        try {
            RequestContainer<ChunkUploadRequest> uploadContainer = new RequestContainer<>();
            // create two digests. One is for the whole file. The other
            // is for the chunks and gets reseted after each chunk.
            MessageDigest fileDigest = MessageDigest.getInstance(HashUtil.SHA_256_MESSAGE_DIGEST, "BC");
            MessageDigest chunkDigest = MessageDigest.getInstance(HashUtil.SHA_256_MESSAGE_DIGEST, "BC");
            FileInputStream fileInputStream = new FileInputStream(f);
            int readBytes = 0;
            int currentChunk = 0;
            int chunkSize = mFile.getChunkSize();
            // Read the file until EOF == -1
            byte[] currentBytes = new byte[chunkSize];
            while ((readBytes = fileInputStream.read(currentBytes)) != -1) {
                fileDigest.update(currentBytes, 0, readBytes);
                chunkDigest.update(currentBytes, 0, readBytes);
                // If we have finished the chunk
                MChunk chunk;
                // Check whether we have the chunk data already
                if (mFile.getChunks().size() > currentChunk) {
                    // We found the chunk
                    chunk = mFile.getChunks().get(currentChunk);
                } else {
                    // There is no chunk and we create a new one.
                    chunk = new MChunk(currentChunk);
                    mFile.getChunks().add(chunk);
                    chunk.setMFile(mFile);
                }
                String newChunkHash = HashUtil.digestToString(chunkDigest.digest());
                if (!newChunkHash.equals(chunk.getDecryptedChunkHash())) {
                    chunk.setDecryptedChunkHash(newChunkHash);
                    log.debug("New Chunk [{}] finished with hash [{}]", currentChunk, newChunkHash);
                    // Create Upload request
                    uploadContainer.add(createUploadRequest(chunk, f, uploadContainer));
                }
                currentChunk++;
            }
            mFile.setFileHash(HashUtil.digestToString(fileDigest.digest()));
            mFile.setLastModified(filesystemLastModified);
            // Define a callback which is executed when all chunks have been
            // uploaded.
            uploadContainer.setAllChildrenCompletedCallback(createUploadContainerFinishedCallback(f, mFile));
            transportProvider.addUploadContainer(uploadContainer);
        } catch (NoSuchAlgorithmException e) {
            log.error("No SHA availabe", e);
        } catch (IOException | NoSuchProviderException e) {
            log.error("", e);
        }
    } else {
        log.debug("The file has not been modified [{}]", f.getName());
    }
}

From source file:goo.TeaTimer.TimerActivity.java

/** {@inheritDoc} */
@Override//from  w  w  w . ja v  a  2  s .  c  o  m
public void onResume() {
    super.onResume();

    // check the timestamp from the last update and start the timer.
    // assumes the data has already been loaded?   
    mLastTime = mSettings.getInt("LastTime", 0);

    mTimerAnimation.setIndex(mSettings.getInt("DrawingIndex", 0));
    int state = mSettings.getInt("State", 0);

    switch (state) {
    case RUNNING:
        long timeStamp = mSettings.getLong("TimeStamp", -1);

        Date now = new Date();
        Date then = new Date(timeStamp);

        // We still have a timer running!
        if (then.after(now)) {
            int delta = (int) (then.getTime() - now.getTime());
            timerStart(delta, false);
            mCurrentState = RUNNING;
            // All finished
        } else {
            clearTime();
            enterState(STOPPED);
        }
        break;

    case STOPPED:
        enterState(STOPPED);
        break;

    case PAUSED:
        mTime = mSettings.getInt("CurrentTime", 0);
        onUpdateTime();
        enterState(PAUSED);
        break;
    }
}

From source file:de.uniwue.info6.webapp.lists.ExGroupTableBean.java

/**
 *
 *
 * @param group/*  ww  w .j a v a2 s . c  om*/
 * @return
 */
public boolean showGroup(ExerciseGroup group) {
    Date start = group.getStartTime();
    if (start != null) {
        if (start.after(new Date())) {
            return false;
        }
    }
    return true;
}