List of usage examples for java.text DateFormat getInstance
public static final DateFormat getInstance()
From source file:com.expressflow.controller.ProcessController.java
@RequestMapping(value = "/process/{id}", method = RequestMethod.POST) public Process saveProcess(@RequestBody Process process) throws IOException { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (userService.isUserLoggedIn()) { PersistenceManager pm = PMF.get().getPersistenceManager(); try {//from ww w . j a va 2s. com process.setId(process.getId().toUpperCase()); process.setAccessDate(DateFormat.getInstance().parse(process.getAccessDateView())); if (process.getCreationDate() == null) { process.setCreationDate(DateFormat.getInstance().parse(process.getCreationDateView())); } pm.makePersistent(process); return process; } catch (Exception e) { e.printStackTrace(System.err); pm.close(); } finally { pm.close(); } } return null; }
From source file:org.jahia.services.content.ContentIT.java
/** * Test creation / deletion of folder/*from w w w .java 2 s .co m*/ * * @throws RepositoryException */ @Test public void testCreateFolder() throws Exception { JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(); JCRNodeWrapper rootNode = session.getNode(providerRoot); session.checkout(rootNode); final String name = "test" + System.currentTimeMillis(); assertTrue("Root node should be writeable !", rootNode.hasPermission("jcr:addChildNodes")); JCRNodeWrapper testCollection = rootNode.createCollection(name); session.save(); nodes.add(testCollection.getIdentifier()); assertTrue(providerRoot + " : Created folder is not a collection", testCollection.isCollection()); long creationDate = testCollection.getCreationDateAsDate().getTime(); DateFormat dateFormat = DateFormat.getInstance(); assertTrue(providerRoot + " : Creation date invalid value=" + dateFormat.format(new Date(creationDate)) + " expected date in range from " + dateFormat.format(new Date(System.currentTimeMillis() - 10000)) + " to " + dateFormat.format(new Date(System.currentTimeMillis() + 10000)), creationDate < (System.currentTimeMillis() + 10000) && creationDate > System.currentTimeMillis() - 10000); long lastModifiedDate = testCollection.getLastModifiedAsDate().getTime(); assertTrue( providerRoot + " : Modification date invalid value=" + dateFormat.format(new Date(lastModifiedDate)) + " expected date in range from " + dateFormat.format(new Date(System.currentTimeMillis() - 10000)) + " to " + dateFormat.format(new Date(System.currentTimeMillis() + 10000)), lastModifiedDate < (System.currentTimeMillis() + 1000) && lastModifiedDate > System.currentTimeMillis() - 10000); testCollection = session.getNode(providerRoot + "/" + name); }
From source file:org.jsecurity.session.mgt.SimpleSession.java
public void validate() throws InvalidSessionException { //check for stopped: if (isStopped()) { //timestamp is set, so the session is considered stopped: String msg = "Session with id [" + getId() + "] has been " + "explicitly stopped. No further interaction under this session is " + "allowed."; throw new StoppedSessionException(msg, getId()); }/*from w ww . java 2s. c om*/ //check for expiration if (isTimedOut()) { expire(); //throw an exception explaining details of why it expired: Date lastAccessTime = getLastAccessTime(); long timeout = getTimeout(); Serializable sessionId = getId(); DateFormat df = DateFormat.getInstance(); String msg = "Session with id [" + sessionId + "] has expired. " + "Last access time: " + df.format(lastAccessTime) + ". Current time: " + df.format(new Date()) + ". Session timeout is set to " + timeout / MILLIS_PER_SECOND + " seconds (" + timeout / MILLIS_PER_MINUTE + " minutes)"; if (log.isTraceEnabled()) { log.trace(msg); } throw new ExpiredSessionException(msg, sessionId); } }
From source file:org.jahia.services.content.ContentTest.java
/** * Test creation / deletion of folder/*w w w . jav a 2 s . c o m*/ * * @throws RepositoryException */ @Test public void testCreateFolder() throws Exception { JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(); try { JCRNodeWrapper rootNode = session.getNode(providerRoot); session.checkout(rootNode); final String name = "test" + System.currentTimeMillis(); assertTrue("Root node should be writeable !", rootNode.hasPermission("jcr:addChildNodes")); JCRNodeWrapper testCollection = rootNode.createCollection(name); session.save(); nodes.add(testCollection.getIdentifier()); assertTrue(providerRoot + " : Created folder is not a collection", testCollection.isCollection()); long creationDate = testCollection.getCreationDateAsDate().getTime(); DateFormat dateFormat = DateFormat.getInstance(); assertTrue( providerRoot + " : Creation date invalid value=" + dateFormat.format(new Date(creationDate)) + " expected date in range from " + dateFormat.format(new Date(System.currentTimeMillis() - 10000)) + " to " + dateFormat.format(new Date(System.currentTimeMillis() + 10000)), creationDate < (System.currentTimeMillis() + 10000) && creationDate > System.currentTimeMillis() - 10000); long lastModifiedDate = testCollection.getLastModifiedAsDate().getTime(); assertTrue( providerRoot + " : Modification date invalid value=" + dateFormat.format(new Date(lastModifiedDate)) + " expected date in range from " + dateFormat.format(new Date(System.currentTimeMillis() - 10000)) + " to " + dateFormat.format(new Date(System.currentTimeMillis() + 10000)), lastModifiedDate < (System.currentTimeMillis() + 1000) && lastModifiedDate > System.currentTimeMillis() - 10000); testCollection = session.getNode(providerRoot + "/" + name); } finally { session.logout(); } }
From source file:com.orangelabs.rcs.ri.messaging.filetransfer.FileTransferList.java
private String decodeDate(long date) { return DateFormat.getInstance().format(new Date(date)); }
From source file:com.orangelabs.rcs.ri.sharing.video.VideoSharingList.java
/** * Decode date/*from w w w .j a v a 2s . co m*/ * * @param date Date * @return String */ private String decodeDate(long date) { return DateFormat.getInstance().format(new Date(date)); }
From source file:org.drools.guvnor.server.RepositoryAssetOperations.java
private TableDataRow createHistoricalRow(VersionableItem historical) { final DateFormat dateFormatter = DateFormat.getInstance(); TableDataRow tableDataRow = new TableDataRow(); tableDataRow.id = historical.getVersionSnapshotUUID(); tableDataRow.values = new String[5]; tableDataRow.values[0] = Long.toString(historical.getVersionNumber()); tableDataRow.values[1] = historical.getCheckinComment(); tableDataRow.values[2] = dateFormatter.format(historical.getLastModified().getTime()); tableDataRow.values[3] = historical.getStateDescription(); tableDataRow.values[4] = historical.getLastContributor(); return tableDataRow; }
From source file:com.mothsoft.alexis.engine.predictive.OpenNLPMaxentModelExecutorTask.java
private boolean doExecute(final Model model) { final StopWatch stopWatch = new StopWatch(); stopWatch.start();/* w w w . j av a 2 s . c o m*/ boolean result = false; try { logger.info(String.format("Executing model %d", model.getId())); // load model file final File userDirectory = new File(baseDirectory, "" + model.getUserId()); final File modelFile = new File(userDirectory, model.getId() + BIN_GZ_EXT); final AbstractModel maxentModel = new SuffixSensitiveGISModelReader(modelFile).getModel(); final Date now = new Date(); final TimeUnits timeUnits = model.getTimeUnits(); final Timestamp topOfPeriod = new Timestamp(TimeUnits.floor(now, timeUnits).getTime()); final Timestamp endOfPeriod = new Timestamp(topOfPeriod.getTime() + timeUnits.getDuration() - 1); // first position: sum of changes predicted, second position: number // of samples--will calculate a boring old mean... final double[][] changeByPeriod = new double[model.getLookahead()][2]; // initialize for (int i = 0; i < changeByPeriod.length; i++) { changeByPeriod[i][0] = 0.0d; changeByPeriod[i][1] = 0.0d; } // find the most recent point value // FIXME - some sparse data sets may require executing the model on // all documents since that point or applying some sort of // dead-reckoning logic for smoothing final DataSetPoint initial = this.dataSetPointDao.findLastPointBefore(model.getTrainingDataSet(), endOfPeriod); // let's get the corner cases out of the way if (initial == null) { logger.warn("Insufficient data to execute model!"); return false; } // happy path // build consolidated context of events in this period // find current value of training data set for this period final double[] probs = eval(model, topOfPeriod, endOfPeriod, maxentModel); // predict from the last available point, adjusted for time // remaining in period final double y0 = initial.getY(); // map outcomes to periods in the future (at least no earlier than // this period) for (int i = 0; i < probs.length; i++) { // in the form +nU:+/-x, where n is the number of periods, U is // the unit type for the period, +/- is the direction, and x is // a discrete value from Model.OUTCOME_ARRAY final String outcome = maxentModel.getOutcome(i); final Matcher matcher = OUTCOME_PATTERN.matcher(outcome); if (!matcher.matches()) { logger.warn("Can't process outcome: " + outcome + "; skipping"); continue; } final int period = Integer.valueOf(matcher.group(1)); final String units = matcher.group(2); final double percentChange = Double.valueOf(matcher.group(3)); // record the observation and the count of observations changeByPeriod[period][0] += percentChange; changeByPeriod[period][1] += 1.0d; if (logger.isDebugEnabled()) { final double yi = y0 * (1 + percentChange); logger.debug(String.format("Outcome: %s, %s: +%d, change: %f, new value: %f, probability: %f", outcome, units, period, percentChange, yi, probs[i])); } } // build points for predictive data set double yn = y0; // we need to track the points and remove any that were not // predicted by this execution of the model final Timestamp endOfPredictionRange = new Timestamp( topOfPeriod.getTime() + (changeByPeriod.length * timeUnits.getDuration())); final List<DataSetPoint> existingPoints = this.dataSetPointDao .findByTimeRange(model.getPredictionDataSet(), topOfPeriod, endOfPredictionRange); for (int period = 0; period < changeByPeriod.length; period++) { final double totalPercentChange = changeByPeriod[period][0]; final double sampleCount = changeByPeriod[period][1]; double percentChange; if (totalPercentChange == 0.0d || sampleCount == 0.0d) { percentChange = 0.0d; } else { percentChange = totalPercentChange / sampleCount; } // apply adjustments only if the initial point is within the // time period, and only for the first time period boolean applyAdjustment = period == 0 && topOfPeriod.before(initial.getX()); if (applyAdjustment) { final double adjustmentFactor = findAdjustmentFactor(initial.getX(), timeUnits); percentChange = (totalPercentChange / sampleCount) * adjustmentFactor; } // figure out the next value and coerce to a sane number of // decimal places (2); final double newValue = (double) Math.round(yn * (1.0d + percentChange) * 100) / 100; final Timestamp timestamp = new Timestamp( topOfPeriod.getTime() + (period * timeUnits.getDuration())); if (logger.isDebugEnabled()) { logger.debug(String.format("Model %d for data set %d predicted point: (%s, %f)", model.getId(), model.getTrainingDataSet().getId(), DateFormat.getInstance().format(timestamp), newValue)); } DataSetPoint ithPoint = this.dataSetPointDao.findByTimestamp(model.getPredictionDataSet(), timestamp); // conditionally create if (ithPoint == null) { ithPoint = new DataSetPoint(model.getPredictionDataSet(), timestamp, newValue); this.dataSetPointDao.add(ithPoint); } else { // or update ithPoint.setY(newValue); // updated points retained, other existing removed existingPoints.remove(ithPoint); } // store current and use as starting point for next iteration yn = newValue; } // remove stale points from an old model execution for (final DataSetPoint toRemove : existingPoints) { this.dataSetPointDao.remove(toRemove); } result = true; } catch (final Exception e) { logger.warn("Model " + model.getId() + " failed with: " + e, e); result = false; } finally { stopWatch.stop(); logger.info(String.format("Executing model %d took %s", model.getId(), stopWatch.toString())); } return result; }
From source file:org.sakaiproject.news.impl.BasicNewsChannel.java
public Date getPubdateInDateFormat() { if (m_pubdate != null) { try {//ww w . jav a 2s. c om return DateFormat.getInstance().parse(m_pubdate); } catch (ParseException e) { } } return new Date(); }
From source file:org.sakaiproject.news.impl.BasicNewsChannel.java
public Date getLastbuilddateInDateFormat() { if (m_lastbuilddate != null) { try {/*w w w . ja va 2s . c o m*/ return DateFormat.getInstance().parse(m_lastbuilddate); } catch (ParseException e) { } } return new Date(); }