List of usage examples for java.sql Timestamp before
public boolean before(Timestamp ts)
From source file:org.apache.ofbiz.base.util.UtilValidate.java
public static boolean isDateBeforeNow(Timestamp date) { Timestamp now = UtilDateTime.nowTimestamp(); if (date != null) { return date.before(now); } else {//from w ww . java2s . c o m return false; } }
From source file:org.openiam.idm.srvc.synch.srcadapter.RDBMSAdapter.java
private Timestamp proccess(SynchConfig config, SynchReviewEntity review, ProvisionService provService, List<LineObject> part, final ValidationScript validationScript, final List<TransformScript> transformScripts, MatchObjectRule matchRule, SynchReviewEntity resultReview, int ctr) throws ClassNotFoundException { Timestamp mostRecentRecord = null; for (LineObject rowObj : part) { log.debug("-RDBMS ADAPTER: SYNCHRONIZING RECORD # ---" + ctr++); log.debug(" - Record update time=" + rowObj.getLastUpdate()); if (mostRecentRecord == null) { mostRecentRecord = rowObj.getLastUpdate(); } else {/* w ww. j ava 2 s. c o m*/ // if current record is newer than what we saved, then update the most recent record value if (mostRecentRecord.before(rowObj.getLastUpdate())) { log.debug("- MostRecentRecord value updated to=" + rowObj.getLastUpdate()); mostRecentRecord.setTime(rowObj.getLastUpdate().getTime()); } } processLineObject(rowObj, config, resultReview, validationScript, transformScripts, matchRule); } return mostRecentRecord; }
From source file:de.cismet.cids.custom.utils.berechtigungspruefung.BerechtigungspruefungHandler.java
/** * DOCUMENT ME!//from ww w. j av a 2 s . co m * * @param user DOCUMENT ME! */ public void deleteOldDateianhangFiles(final User user) { final File directory = new File(BerechtigungspruefungProperties.getInstance().getAnhangAbsPath()); final Date thresholdDate = getThresholdAnhangDate(); // look for all anhang files for (final File file : directory.listFiles()) { if (file.isFile()) { try { final String fileName = file.getName(); final BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class); final Date creationDate = new Date(attr.creationTime().toMillis()); // file older then threshold date (1 month) ? if (creationDate.before(thresholdDate)) { final CidsBean anfrageBean = loadAnfrageBean(user, fileName); // assuring, that the file corresponds to an existing bean This prevents accidental deletion of // non-anhang files (i.e. if AnhangAbsPath was set to a path that contains also other files) if (anfrageBean != null) { final Timestamp anfrageTs = (Timestamp) anfrageBean.getProperty("anfrage_timestamp"); // timestamp filed in the bean agrees with the file creation date ? if (anfrageTs.before(thresholdDate)) { LOG.info("deleting old Anhang file: " + file.getName() + " (date: " + creationDate.toString() + ")"); // now we can delete (hopefully) file.delete(); } } } } catch (final IOException ex) { LOG.warn("could not delete Anhang file: " + file.getName(), ex); } } } }
From source file:org.wso2.bpmn.mysql.DBConnector.java
public void calculateValues() throws SQLException, IOException, ParseException { ResultSet resultSet = null;//from ww w.j av a 2 s. c om try { ConfigLoader configLoader = ConfigLoader.getInstance(); resultSet = statement .executeQuery("select START_TIME_, END_TIME_, DURATION_ FROM ACT_HI_PROCINST WHERE " + "PROC_DEF_ID_ " + "= '" + configLoader.getProcessDefID() + "' AND END_TIME_ IS NOT NULL ORDER BY START_TIME_ ASC"); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("INSTANCE_COUNT__ \t\t"); stringBuffer.append("START_TIME_ \t\t"); stringBuffer.append("END_TIME_ \t\t\t"); stringBuffer.append("DURATION_ \t"); int rowCount = 0; Long totalDuration = 0l; while (resultSet.next()) { Timestamp rowStartTime = resultSet.getTimestamp(1); Timestamp rowStopTime = resultSet.getTimestamp(2); Long duration = resultSet.getLong(3); if (initialStartTime == null) { initialStartTime = rowStartTime; Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(rowStartTime.getTime()); cal.add(Calendar.SECOND, configLoader.getInitialTruncatingTime()); leastCalculationTime = new Timestamp(cal.getTime().getTime()); } if (rowStartTime.before(leastCalculationTime) == true) { continue; } if (startTime == null) { startTime = rowStartTime; } if (stopTime == null) { stopTime = rowStopTime; } if (rowStopTime.after(stopTime)) { stopTime = rowStopTime; } totalDuration += duration; ++rowCount; String resultString = rowCount + "\t\t\t" + rowStartTime.toString() + "\t\t" + rowStopTime + "\t\t" + duration; stringBuffer.append("\n"); stringBuffer.append(resultString); } if (rowCount == 0) { System.out.println("Error : Row count not found : "); } double averageDuration = (double) totalDuration / rowCount; double tps = ((double) rowCount) / calculateTimeDifferenceInSeconds(); String resultValue = "\tstartTime: " + startTime + "\n" + "\tendTime: " + stopTime + "\n" + "\tTotal " + "duration: " + totalDuration + "\n" + "\tAverage duration: " + averageDuration + "\n" + "\tInstance count: " + rowCount + "\n" + "\tTPS: " + tps; stringBuffer.append("\n\n\n\n"); stringBuffer.append(resultValue); FileUtils.writeStringToFile(new File(configLoader.getFilePath()), stringBuffer.toString()); System.out.println("===================Completed Calculation========================"); System.out.println(resultValue); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } } if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:org.kuali.rice.edl.impl.components.NoteConfigComponent.java
/** * Method added for notes editing function. Called by retrieveNoteList method * @param allNotes//from w ww . j a v a 2 s.c o m * @param sortOrder * @return */ private List sortNotes(List allNotes, String sortOrder) { final int returnCode = KewApiConstants.Sorting.SORT_SEQUENCE_DSC.equalsIgnoreCase(sortOrder) ? -1 : 1; try { Collections.sort(allNotes, new Comparator() { public int compare(Object o1, Object o2) { Timestamp date1 = ((Note) o1).getNoteCreateDate(); Timestamp date2 = ((Note) o2).getNoteCreateDate(); if (date1.before(date2)) { return returnCode * -1; } else if (date1.after(date2)) { return returnCode; } else { return 0; } } }); } catch (Throwable e) { LOG.error(e.getMessage(), e); } return allNotes; }
From source file:org.kuali.rice.kim.document.rule.IdentityManagementPersonDocumentRule.java
protected boolean validateActiveDate(String errorPath, Timestamp activeFromDate, Timestamp activeToDate) { // TODO : do not have detail bus rule yet, so just check this for now. boolean valid = true; if (activeFromDate != null && activeToDate != null && activeToDate.before(activeFromDate)) { GlobalVariables.getMessageMap().putError(errorPath, RiceKeyConstants.ERROR_ACTIVE_TO_DATE_BEFORE_FROM_DATE); valid = false;// w w w . ja va2 s . co m } return valid; }
From source file:org.opentaps.common.util.UtilCommon.java
/** * Returns the earliest of the two given <code>Timestamp</code>. * @param ts1 a <code>Timestamp</code> * @param ts2 another <code>Timestamp</code> * @return ts1 if it is before ts2, ts2 otherwise */// w w w . ja v a 2 s .co m public static Timestamp earlierOf(Timestamp ts1, Timestamp ts2) { if (ts1.before(ts2)) { return ts1; } else { return ts2; } }
From source file:org.opentaps.common.util.UtilCommon.java
/** * This method takes the date/time/duration form input and transforms it into an end timestamp. * It uses Java Date formatting capabilities to transform the duration input into an interval. * * @param start Full date, hour, minute and second of the starting time * @param duration The user input for hour such as "1:00" * @param timeZone a <code>TimeZone</code> value * @param locale a <code>Locale</code> value * @return the end <code>Timestamp</code> * @throws IllegalArgumentException If the duration input is unparseable or negative *//* w w w . j av a 2 s . c o m*/ public static Timestamp getEndTimestamp(Timestamp start, String duration, Locale locale, TimeZone timeZone) throws IllegalArgumentException { // return the start timestamp if no duration specified (i.e., duration = 0) if (duration == null || duration.length() == 0) { return start; } Calendar cal = Calendar.getInstance(timeZone, locale); // Turn the duraiton into a date and time with the hour being the duration (note this is input from user, which we require to be in HH:mm form) SimpleDateFormat df = new SimpleDateFormat("HH:mm"); try { cal.setTime(df.parse(duration)); } catch (ParseException e) { throw new IllegalArgumentException( String.format("Duration input must be in %1$s format.", UtilDateTime.getTimeFormat(locale))); } // extract the days, hours and minutes int days = cal.get(Calendar.DAY_OF_YEAR) - 1; int hours = cal.get(Calendar.HOUR_OF_DAY); int minutes = cal.get(Calendar.MINUTE); // set to the start time and add the hours and minutes cal.setTime(start); cal.set(Calendar.DAY_OF_YEAR, days + cal.get(Calendar.DAY_OF_YEAR)); cal.set(Calendar.HOUR_OF_DAY, hours + cal.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, minutes + cal.get(Calendar.MINUTE)); // create the end timestamp Timestamp end = new Timestamp(cal.getTimeInMillis()); // make sure it's after the start timestamp if (end.before(start)) { throw new IllegalArgumentException("Cannot set a negative duration."); } // return our result as a Timestamp return end; }
From source file:org.opentaps.amazon.product.AmazonProductServices.java
/** * Checks the time of the last successful feed processing document download against a configurable threshold and * sends a warning email if the last success was too long in the past (threshold is configurable in the * opentaps.amazon.error.email.productFeedProcessingAgeWarning.thresholdHours property. * @param dctx a <code>DispatchContext</code> value * @param context the service context <code>Map</code> * @return the service response <code>Map</code> */// ww w .ja v a 2s . c o m public static Map<String, Object> checkLastFeedProcessingDocumentDownloadSuccess(DispatchContext dctx, Map<String, Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); TimeZone timeZone = (TimeZone) context.get("timeZone"); GenericValue userLogin = (GenericValue) context.get("userLogin"); if (!AmazonConstants.sendErrorEmails) { String errorLog = UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_NotCheckingLastProcDocSuccessNoEmail", locale); Debug.logInfo(errorLog, MODULE); return ServiceUtil.returnSuccess(); } try { GenericValue amazonProductFeedProcessing = EntityUtil.getFirst( delegator.findAll("AmazonProductFeedProcessing", Arrays.asList("acknowledgeTimestamp DESC"))); if (UtilValidate.isEmpty(amazonProductFeedProcessing)) { String errorLog = UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_NoSuccesfulProcDocs", locale); Debug.logInfo(errorLog, MODULE); return ServiceUtil.returnSuccess(); } Timestamp lastSuccess = amazonProductFeedProcessing.getTimestamp("acknowledgeTimestamp"); Calendar cal = Calendar.getInstance(timeZone, locale); cal.add(Calendar.HOUR, 0 - Math.abs(AmazonConstants.lastProcDocCheckAge)); if (lastSuccess.before(new Timestamp(cal.getTimeInMillis()))) { Map<String, String> emailMap = UtilMisc.toMap("thresholdHours", "" + AmazonConstants.lastProcDocCheckAge); AmazonUtil.sendErrorEmail(dispatcher, userLogin, emailMap, UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_ErrorEmailSubject_ProcDocAgeWarning", AmazonConstants.errorEmailLocale), AmazonConstants.errorEmailScreenUriProcDocAgeWarning); } } catch (GenericEntityException gee) { UtilMessage.createAndLogServiceError(gee, locale, MODULE); } catch (GenericServiceException gse) { UtilMessage.createAndLogServiceError(gse, locale, MODULE); } return ServiceUtil.returnSuccess(); }
From source file:org.kuali.kfs.module.tem.document.service.impl.TravelAuthorizationServiceImpl.java
private boolean matchReimbursements(List<TravelReimbursementDocument> travelReimbursementDocuments, Date tripBeginBufferDate, Date tripEndBufferDate) { Timestamp earliestTripBeginDate = null; Timestamp greatestTripEndDate = null; for (TravelReimbursementDocument document : travelReimbursementDocuments) { Timestamp tripBegin = document.getTripBegin(); Timestamp tripEnd = document.getTripEnd(); if (ObjectUtils.isNull(earliestTripBeginDate) && ObjectUtils.isNull(greatestTripEndDate)) { earliestTripBeginDate = tripBegin; greatestTripEndDate = tripEnd; } else {/*w w w . j a v a 2s.c om*/ earliestTripBeginDate = tripBegin.before(earliestTripBeginDate) ? tripBegin : earliestTripBeginDate; greatestTripEndDate = tripEnd.after(greatestTripEndDate) ? tripEnd : greatestTripEndDate; } } if (doesDatesOverlap(tripBeginBufferDate, tripEndBufferDate, convertToSqlDate(earliestTripBeginDate), convertToSqlDate(greatestTripEndDate))) { return true; } return false; }