List of usage examples for java.util Calendar after
public boolean after(Object when)
Calendar
represents a time after the time represented by the specified Object
. From source file:com.androidrocks.bex.provider.BooksUpdater.java
private boolean bookCoverUpdated(BooksStore.Book book, ImageUtilities.ExpiringBitmap expiring) { expiring.lastModified = null;/*from ww w. ja v a2s .co m*/ final HttpGet get = new HttpGet(book.getImageUrl(BooksStore.ImageSize.TINY)); HttpEntity entity = null; try { final HttpResponse response = HttpManager.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = response.getEntity(); final Header header = response.getFirstHeader("Last-Modified"); if (header != null) { final Calendar calendar = GregorianCalendar.getInstance(); try { calendar.setTime(mLastModifiedFormat.parse(header.getValue())); expiring.lastModified = calendar; return calendar.after(book.getLastModified()); } catch (ParseException e) { return false; } } } } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + book, e); } finally { if (entity != null) { try { entity.consumeContent(); } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + book, e); } } } return false; }
From source file:org.jahia.services.content.rules.ImageService.java
public void addThumbnail(AddedNodeFact imageNode, String name, int size, boolean square, KnowledgeHelper drools) throws Exception { long timer = System.currentTimeMillis(); if (imageNode.getNode().hasNode(name)) { JCRNodeWrapper node = imageNode.getNode().getNode(name); Calendar thumbDate = node.getProperty("jcr:lastModified").getDate(); Calendar contentDate = imageNode.getNode().getNode("jcr:content").getProperty("jcr:lastModified") .getDate();/*ww w. j a va 2s. c o m*/ if (contentDate.after(thumbDate)) { AddedNodeFact thumbNode = new AddedNodeFact(node); File f = getThumbFile(imageNode, size, square, drools); if (f == null) { return; } drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_DATA, f, drools)); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_LASTMODIFIED, new GregorianCalendar(), drools)); } } else { File f = getThumbFile(imageNode, size, square, drools); if (f == null) { return; } AddedNodeFact thumbNode = new AddedNodeFact(imageNode, name, "jnt:resource", drools); if (thumbNode.getNode() != null) { drools.insert(thumbNode); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_DATA, f, drools)); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_MIMETYPE, imageNode.getMimeType(), drools)); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_LASTMODIFIED, new GregorianCalendar(), drools)); } } if (logger.isDebugEnabled()) { logger.debug("{}px thumbnail for node {} created in {} ms", new Object[] { size, imageNode.getNode().getPath(), System.currentTimeMillis() - timer }); } }
From source file:es.emergya.ui.plugins.admin.AdminRoles.java
@Override public boolean needsUpdating() { final Calendar lastUpdated2 = RolConsultas.lastUpdated(); if (lastUpdated2 == null && this.roles.getTotalSize() != 0) { return true; }// w ww . j av a 2s. c o m return lastUpdated2.after(super.lastUpdated); }
From source file:com.sean.takeastand.storage.ScheduleEditor.java
public void editStartTime(boolean alarmToday, AlarmSchedule alarmSchedule) { int UID = alarmSchedule.getUID(); Calendar startTime = alarmSchedule.getStartTime(); cancelDailyRepeatingAlarm(UID); setDailyRepeatingAlarm(UID, Utils.calendarToTimeString(startTime)); scheduleDatabaseAdapter.updateStartTime(UID, Utils.calendarToTimeString(startTime)); if (alarmToday && alarmSchedule.getActivated()) { Log.i(TAG, "alarmToday and activated"); FixedAlarmSchedule fixedAlarmSchedule = new FixedAlarmSchedule(alarmSchedule); Calendar endTime = alarmSchedule.getEndTime(); Calendar rightNow = Calendar.getInstance(); if (startTime.before(rightNow) && endTime.after(rightNow)) { ScheduledRepeatingAlarm scheduledRepeatingAlarm = new ScheduledRepeatingAlarm(mContext, fixedAlarmSchedule); //Update cancels the original alarm, so image needs to be set again scheduledRepeatingAlarm.updateAlarm(); Utils.setImageStatus(mContext, Constants.SCHEDULE_RUNNING); } else {//from ww w . j a va 2 s. c o m if (UID == Utils.getRunningScheduledAlarm(mContext)) { new ScheduledRepeatingAlarm(mContext, fixedAlarmSchedule).cancelAlarm(); } } } }
From source file:com.linuxbox.enkive.imap.mongo.MongoImapAccountCreator.java
@Override public void addImapMessages(String username, Date fromDate, Date toDate) throws MessageSearchException { Calendar startTime = Calendar.getInstance(); startTime.setTime(fromDate);/*from ww w .j a v a 2 s. c o m*/ Calendar endTime = Calendar.getInstance(); endTime.setTime(toDate); while (startTime.before(endTime)) { Calendar endOfMonth = (Calendar) startTime.clone(); endOfMonth.set(Calendar.DAY_OF_MONTH, endOfMonth.getActualMaximum(Calendar.DAY_OF_MONTH)); if (endOfMonth.after(endTime)) endOfMonth = (Calendar) endTime.clone(); // Need to get all messages to add Set<String> messageIdsToAdd = getMailboxMessageIds(username, startTime.getTime(), endOfMonth.getTime()); // Need to add messages // Get top UID, add from there if (!messageIdsToAdd.isEmpty()) { // Need to check if folder exists, if not create it and add to // user // mailbox list DBObject mailboxObject = getMessagesFolder(username, startTime.getTime()); @SuppressWarnings("unchecked") HashMap<String, String> mailboxMsgIds = (HashMap<String, String>) mailboxObject .get(MongoEnkiveImapConstants.MESSAGEIDS); TreeMap<String, String> sortedMsgIds = new TreeMap<String, String>(); sortedMsgIds.putAll(mailboxMsgIds); long i = 0; if (!sortedMsgIds.isEmpty()) i = Long.valueOf(sortedMsgIds.lastKey()); for (String msgId : messageIdsToAdd) { i++; mailboxMsgIds.put(((Long.toString(i))), msgId); } mailboxObject.put(MongoEnkiveImapConstants.MESSAGEIDS, mailboxMsgIds); imapCollection.findAndModify(new BasicDBObject("_id", mailboxObject.get("_id")), mailboxObject); } startTime.set(Calendar.DAY_OF_MONTH, 1); startTime.add(Calendar.MONTH, 1); } }
From source file:org.paxle.crawler.ftp.impl.FtpUrlConnection.java
@Override public long getLastModified() { if (!this.client.isConnected()) return 0l; long lastModTimestamp = 0l; try {//from w w w. j a v a2 s.co m if (this.isDirectory) { Calendar lastMod = null; FTPFile[] files = client.listFiles(path); for (FTPFile nextFile : files) { Calendar fileDate = nextFile.getTimestamp(); lastMod = (lastMod == null || fileDate.after(lastMod)) ? fileDate : lastMod; } if (lastMod != null) { lastModTimestamp = lastMod.getTimeInMillis(); } } else { FTPFile file = this.findFile(); if (file != null) { lastModTimestamp = file.getTimestamp().getTimeInMillis(); } } } catch (IOException e) { e.printStackTrace(); } return lastModTimestamp; }
From source file:es.emergya.ui.plugins.admin.AdminSquads.java
@Override public boolean needsUpdating() { final Calendar lastUpdated2 = PatrullaConsultas.lastUpdated(); if (lastUpdated2 == null && this.squads.getTotalSize() != 0) { return true; }//from w ww .java 2s. co m return lastUpdated2.after(super.lastUpdated); }
From source file:org.apache.archiva.policies.AbstractUpdatePolicy.java
@Override public void applyPolicy(String policySetting, Properties request, File localFile) throws PolicyViolationException, PolicyConfigurationException { if (!StringUtils.equals(request.getProperty("filetype"), "artifact")) { // Only process artifact file types. return;//from w w w . j a va 2 s . co m } String version = request.getProperty("version", ""); boolean isSnapshotVersion = false; if (StringUtils.isNotBlank(version)) { isSnapshotVersion = VersionUtil.isSnapshot(version); } if (!options.contains(policySetting)) { // Not a valid code. throw new PolicyConfigurationException("Unknown " + getUpdateMode() + " policy setting [" + policySetting + "], valid settings are [" + StringUtils.join(options.iterator(), ",") + "]"); } if (ALWAYS.equals(policySetting)) { // Skip means ok to update. log.debug("OK to update, {} policy set to ALWAYS.", getUpdateMode()); return; } // Test for mismatches. if (!isSnapshotVersion && isSnapshotPolicy()) { log.debug("OK to update, snapshot policy does not apply for non-snapshot versions."); return; } if (isSnapshotVersion && !isSnapshotPolicy()) { log.debug("OK to update, release policy does not apply for snapshot versions."); return; } if (NEVER.equals(policySetting)) { // Reject means no. throw new PolicyViolationException("NO to update, " + getUpdateMode() + " policy set to NEVER."); } if (!localFile.exists()) { // No file means it's ok. log.debug("OK to update {}, local file does not exist.", getUpdateMode()); return; } if (ONCE.equals(policySetting)) { // File exists, but policy is once. throw new PolicyViolationException( "NO to update " + getUpdateMode() + ", policy is ONCE, and local file exist."); } if (DAILY.equals(policySetting)) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -1); Calendar fileCal = Calendar.getInstance(); fileCal.setTimeInMillis(localFile.lastModified()); if (cal.after(fileCal)) { // Its ok. return; } else { throw new PolicyViolationException("NO to update " + getUpdateMode() + ", policy is DAILY, local file exist, and has been updated within the last day."); } } if (HOURLY.equals(policySetting)) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, -1); Calendar fileCal = Calendar.getInstance(); fileCal.setTimeInMillis(localFile.lastModified()); if (cal.after(fileCal)) { // Its ok. return; } else { throw new PolicyViolationException("NO to update " + getUpdateMode() + ", policy is HOURLY, local file exist, and has been updated within the last hour."); } } throw new PolicyConfigurationException("Unable to process " + getUpdateMode() + " policy of [" + policySetting + "], please file a bug report."); }
From source file:com.redhat.rhn.domain.common.ResetPassword.java
/** * @return true {@literal if CREATED < (now - expiration-hours)} *//*from w w w . j a v a 2 s. c o m*/ public boolean isExpired() { Calendar now = Calendar.getInstance(); Calendar expireDate = Calendar.getInstance(); expireDate.setTime(getCreated() == null ? new Date() : getCreated()); expireDate.add(Calendar.HOUR, Config.get().getInt(PASSWORD_TOKEN_EXPIRATION, PASSWORD_TOKEN_EXPIRATION_DEFAULT)); return now.after(expireDate); }
From source file:biz.varkon.shelvesom.provider.apparel.ApparelUpdater.java
private boolean apparelCoverUpdated(ApparelStore.Apparel apparel, ImageUtilities.ExpiringBitmap expiring) { expiring.lastModified = null;/* w w w . j a v a 2 s . co m*/ final String tinyThumbnail = Preferences.getImageURLForUpdater(apparel); if (tinyThumbnail != null && !tinyThumbnail.equals("")) { HttpGet get = null; try { get = new HttpGet(Preferences.getImageURLForUpdater(apparel)); } catch (NullPointerException npe) { android.util.Log.e(LOG_TAG, "Could not check modification image for " + apparel, npe); } HttpEntity entity = null; try { final HttpResponse response = HttpManager.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = response.getEntity(); final Header header = response.getFirstHeader("Last-Modified"); if (header != null) { final Calendar calendar = Calendar.getInstance(); try { calendar.setTime(mLastModifiedFormat.parse(header.getValue())); expiring.lastModified = calendar; return calendar.after(apparel.getLastModified()); } catch (ParseException e) { return false; } } } } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + apparel, e); } catch (IllegalArgumentException iae) { android.util.Log.e(LOG_TAG, "Null get value for " + apparel, iae); } finally { if (entity != null) { try { entity.consumeContent(); } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + apparel, e); } } } } return false; }