List of usage examples for org.apache.commons.lang.time DateFormatUtils format
public static String format(Date date, String pattern)
Formats a date/time into a specific pattern.
From source file:org.b3log.symphony.service.LivenessMgmtService.java
/** * Increments a field of the specified liveness. * * @param userId the specified user id/*w w w .j a v a 2 s. c o m*/ * @param field the specified field */ @Transactional public void incLiveness(final String userId, final String field) { Stopwatchs.start("Inc liveness"); final String date = DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd"); try { JSONObject liveness = livenessRepository.getByUserAndDate(userId, date); if (null == liveness) { liveness = new JSONObject(); liveness.put(Liveness.LIVENESS_USER_ID, userId); liveness.put(Liveness.LIVENESS_DATE, date); liveness.put(Liveness.LIVENESS_POINT, 0); liveness.put(Liveness.LIVENESS_ACTIVITY, 0); liveness.put(Liveness.LIVENESS_ARTICLE, 0); liveness.put(Liveness.LIVENESS_COMMENT, 0); liveness.put(Liveness.LIVENESS_PV, 0); liveness.put(Liveness.LIVENESS_REWARD, 0); liveness.put(Liveness.LIVENESS_THANK, 0); liveness.put(Liveness.LIVENESS_VOTE, 0); liveness.put(Liveness.LIVENESS_VOTE, 0); livenessRepository.add(liveness); } liveness.put(field, liveness.optInt(field) + 1); livenessRepository.update(liveness.optString(Keys.OBJECT_ID), liveness); } catch (final RepositoryException e) { LOGGER.log(Level.ERROR, "Updates a liveness [" + date + "] field [" + field + "] failed", e); } finally { Stopwatchs.end(); } }
From source file:org.b3log.symphony.service.LivenessQueryService.java
/** * Gets point of current liveness./*from w ww .ja va 2 s . c om*/ * * @param userId the specified user id * @return point */ public int getCurrentLivenessPoint(final String userId) { Stopwatchs.start("Gets liveness"); try { final String date = DateFormatUtils.format(new Date(), "yyyyMMdd"); try { final JSONObject liveness = livenessRepository.getByUserAndDate(userId, date); if (null == liveness) { return 0; } return Liveness.calcPoint(liveness); } catch (final RepositoryException e) { LOGGER.log(Level.ERROR, "Gets current liveness point failed", e); return 0; } } finally { Stopwatchs.end(); } }
From source file:org.b3log.symphony.service.LivenessQueryService.java
/** * Gets the yesterday's liveness.//w ww . j a va2s .c o m * * @param userId the specified user id * @return yesterday's liveness, returns {@code null} if not found */ public JSONObject getYesterdayLiveness(final String userId) { final Date yesterday = DateUtils.addDays(new Date(), -1); final String date = DateFormatUtils.format(yesterday, "yyyyMMdd"); try { return livenessRepository.getByUserAndDate(userId, date); } catch (final RepositoryException e) { LOGGER.log(Level.ERROR, "Gets yesterday's liveness failed", e); return null; } }
From source file:org.bdval.DistributionDifferenceByFeatureMode.java
/** * The SingleQualityMode D&V mode./* w ww . java 2s.co m*/ * * @param options program options. */ @Override public void process(final DAVOptions options) { super.process(options); final ProcessEstimator estimator = new ProcessEstimator(modelIdToModelPrefixMap.size()); for (final String modelId : modelIdToModelPrefixMap.keySet()) { if (excludeModelSet.contains(modelId)) { estimator.unitCompleted(); continue; } final String modelFilenamePrefix = modelIdToModelPrefixMap.get(modelId); final Map<String, String> modelConditionsMap = modelIdToModelConditionsMap.get(modelId); final String datasetName = modelConditionsMap.get("dataset-name"); final String datasetRoot; if (evalDatasetRoot == null) { datasetRoot = modelConditionsMap.get("dataset-root"); } else { datasetRoot = evalDatasetRoot; } final Map<String, String> datasetDetailsMap = localizeDatasetDetailsMap( datasetName2DetailsMap.get(datasetName), datasetRoot); try { loadFilesAndCalculateQuality(options, modelId, modelFilenamePrefix, datasetDetailsMap); } catch (IllegalArgumentException e) { signalQualityCalcObj .writeData("# " + modelId + " error loading table for model: " + e.getMessage()); } catch (IOException e) { signalQualityCalcObj.writeData("# " + modelId + " error reading file: " + e.getMessage()); } finally { // Work completed, estimate time remaining final long estimate = estimator.unitCompleted(); if (estimate == Long.MAX_VALUE) { System.out.println("## Waiting for second data point to estimate time"); } else { final long finishAt = (new Date().getTime()) + estimate; System.out.printf("## Processed model %d of %d, Time remaining %s, finish at %s%n", estimator.getUnitsCompleted(), estimator.getTotalUnits(), ICBStringUtils.millis2hms(estimate), DateFormatUtils.format(finishAt, "HH:mm:ss")); } } } /** Run for a single model. */ /* */ signalQualityCalcObj.close(); }
From source file:org.betaconceptframework.astroboa.engine.jcr.io.Deserializer.java
public CmsRepositoryEntity save(CmsRepositoryEntity entity) { if (entity != null && shouldSaveEntity()) { if (entity instanceof ContentObject) { if (logger.isDebugEnabled()) { logger.debug("\n\nStarting ContentObject Save...{}", DateFormatUtils.format(Calendar.getInstance(), "dd/MM/yyyy HH:mm:ss.SSS")); }/*from w w w . j ava2s .co m*/ long start = System.currentTimeMillis(); //We call ContentServiceImpl as security aspect must run //prior to saving a content object entity = ((ContentServiceImpl) contentService).saveContentObjectInBatchMode((ContentObject) entity, version, updateLastModificationDate, context); if (logger.isDebugEnabled()) { logger.debug("Saving ContentObject from import took {}, {}", DurationFormatUtils.formatDuration(System.currentTimeMillis() - start, "HH:mm:ss.SSSSSS"), DateFormatUtils.format(Calendar.getInstance(), "dd/MM/yyyy HH:mm:ss.SSSSSS")); } if (importReport != null) { ((ImportReportImpl) importReport).addContentObjectsImported(1); } } else if (entity instanceof Topic) { if (shouldSaveEntityTree()) { entity = topicDao.saveTopicTree((Topic) entity, null); } else { entity = topicDao.saveTopic((Topic) entity, null); } if (importReport != null) { ((ImportReportImpl) importReport).addTopicsImported(1); } } else if (entity instanceof Taxonomy) { if (shouldSaveEntityTree()) { entity = taxonomyDao.saveTaxonomyTree((Taxonomy) entity); } else { entity = taxonomyDao.saveTaxonomy((Taxonomy) entity); } if (importReport != null) { ((ImportReportImpl) importReport).addTaxonomiesImported(1); } } else if (entity instanceof RepositoryUser) { entity = repositoryUserDao.saveRepositoryUser((RepositoryUser) entity); if (importReport != null) { ((ImportReportImpl) importReport).addRepositoryUsersImported(1); } } else if (entity instanceof Space) { if (shouldSaveEntityTree()) { entity = spaceDao.saveSpaceTree((Space) entity); } else { entity = spaceDao.saveSpace((Space) entity); } if (importReport != null) { ((ImportReportImpl) importReport).addSpacesImported(1); } } else { logger.warn("Importing of entity {} is not yet supported", entity.toString()); } } return entity; }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.PopulateSimpleCmsProperty.java
private void dispatchPopulate(ValueType definitionValueType, ItemQName propertyAsItem, ValueFactory valueFactory) throws Exception { if (propertyDefinition.isSetDefaultValue() && !propertyHasBeenLoadedAndRemoved) { //Set default value if there are no values at all if (simpleCmsPropertyToBeSaved.hasNoValues() && propertyDefinition.isMandatory()) { simpleCmsPropertyToBeSaved.addSimpleTypeValue(propertyDefinition.getDefaultValue()); }/*w w w . ja v a 2 s . c o m*/ } //Check values are valid ((SimpleCmsPropertyImpl) simpleCmsPropertyToBeSaved).checkValues(); switch (definitionValueType) { case Date: //Special case. Check if provided date is profile.created or profile.created if (StringUtils.equals("profile.created", propertyDefinition.getPath()) && propertyContainerNode.hasProperty("created")) { //Property profile.created already exists and therefore it will not change. //Issue a warning if value provided is not the same with the one existed Calendar providedCreationDate = ((CalendarProperty) simpleCmsPropertyToBeSaved) .getSimpleTypeValue(); Calendar existingCreationDate = propertyContainerNode.getProperty("created").getValue().getDate(); if (providedCreationDate == null || existingCreationDate == null || providedCreationDate.getTimeInMillis() != existingCreationDate.getTimeInMillis()) { logger.warn( "User has provided '{}' as the value of property 'profile.created' but this property already contains value " + "'{}'. Changing the value of this property is not allowed and therefore provided value will be ignored. In fact" + " it will be replaced by the persisted value.", (providedCreationDate == null ? "null" : DateFormatUtils.format(providedCreationDate, "dd/MM/yyy HH:mm") + " " + providedCreationDate.getTimeInMillis()), (existingCreationDate == null ? "null" : DateFormatUtils.format(existingCreationDate, "dd/MM/yyy HH:mm") + " " + existingCreationDate.getTimeInMillis())); } } else if (StringUtils.equals("profile.modified", propertyDefinition.getPath()) && propertyContainerNode.hasProperty("modified")) { //Property profile.modified already exists and therefore it will not change. //Issue a warning if value provided is not the same with the one existed Calendar providedModifiedDate = ((CalendarProperty) simpleCmsPropertyToBeSaved) .getSimpleTypeValue(); Calendar existingModifiedDate = propertyContainerNode.getProperty("modified").getValue().getDate(); if (providedModifiedDate == null || existingModifiedDate == null || providedModifiedDate.getTimeInMillis() != existingModifiedDate.getTimeInMillis()) { logger.warn( "User has provided '{}' as the value of property 'profile.modified' but this property already contains value " + "'{}'. Changing the value of this property is not allowed and therefore provided value will be ignored. Values of this " + " property are provided by Astroboa only.", (providedModifiedDate == null ? "null" : DateFormatUtils.format(providedModifiedDate, "dd/MM/yyy HH:mm") + " " + providedModifiedDate.getTimeInMillis()), (existingModifiedDate == null ? "null" : DateFormatUtils.format(existingModifiedDate, "dd/MM/yyy HH:mm") + " " + existingModifiedDate.getTimeInMillis())); } } else { populateSimpleProperty(valueFactory, definitionValueType, propertyAsItem); } break; case Boolean: case String: case Double: case Long: populateSimpleProperty(valueFactory, definitionValueType, propertyAsItem); break; case ObjectReference: populatePropertyAsContentObject(propertyAsItem); break; case TopicReference: populatePropertyAsTopic(propertyAsItem); break; case Binary: { //If simple cms property corresponds to an unmanaged binary property then //we only care about relativeFileSystemPath. if (propertyDefinition instanceof BinaryPropertyDefinition && ((BinaryPropertyDefinition) propertyDefinition).isBinaryChannelUnmanaged()) { populateBinaryChannelAsUnmanaged(valueFactory, definitionValueType, propertyAsItem); } else { populateBinaryChannel(); } } default: break; } }
From source file:org.betaconceptframework.astroboa.serializer.CmsDefinitionSerializer.java
private <T> void serializeDatePropertyDefinition(SimpleCmsPropertyDefinition<T> simplePropertyDefinition) { CalendarPropertyDefinition calendarDefinition = (CalendarPropertyDefinition) simplePropertyDefinition; serializer.writeAttribute("pattern", calendarDefinition.getPattern()); if (calendarDefinition.isSetDefaultValue()) { serializer.writeAttribute("defaultValue", DateFormatUtils.format( calendarDefinition.getDefaultValue().getTimeInMillis(), calendarDefinition.getPattern())); }//from w ww.jav a 2 s . co m }
From source file:org.betaconceptframework.astroboa.test.engine.service.ContentServiceTest.java
@Test public void testSaveCreationDate() throws ItemNotFoundException, RepositoryException { //Create content objects for test RepositoryUser systemUser = getSystemUser(); ContentObject contentObject = createContentObject(systemUser, "testSaveCreationDate"); contentObject = contentService.save(contentObject, false, true, null); markObjectForRemoval(contentObject); //Retrieve content object node Node contentObjectNode = getSession().getNodeByIdentifier(contentObject.getId()); Calendar creationDate = ((CalendarProperty) contentObject.getCmsProperty("profile.created")) .getSimpleTypeValue();//from ww w. ja v a 2 s .c o m String creationDatePath = DateFormatUtils.format(creationDate, "yyyy/M/d/H/m/s"); Assert.assertTrue(contentObjectNode.getParent().getPath().endsWith(creationDatePath), "Invalid content object creation path " + contentObjectNode.getParent().getPath() + ". It should end with " + creationDatePath); }
From source file:org.betaconceptframework.astroboa.test.engine.service.ContentServiceTest.java
@Test public void testSaveWithProvidedCreationDate() throws ItemNotFoundException, RepositoryException { //Create content objects for test RepositoryUser systemUser = getSystemUser(); ContentObject contentObject = createContentObject(systemUser, "testSaveWithProvidedCreationDate"); Calendar userCreationDate = Calendar.getInstance(); userCreationDate.add(Calendar.YEAR, 1); ((CalendarProperty) contentObject.getCmsProperty("profile.created")).setSimpleTypeValue(userCreationDate); contentObject = contentService.save(contentObject, false, true, null); markObjectForRemoval(contentObject); contentObject = contentService.getContentObject(contentObject.getId(), ResourceRepresentationType.CONTENT_OBJECT_INSTANCE, FetchLevel.ENTITY, CacheRegion.NONE, null, false);/*from w w w .ja v a 2 s . co m*/ //Retrieve content object node Node contentObjectNode = getSession().getNodeByIdentifier(contentObject.getId()); Calendar creationDate = ((CalendarProperty) contentObject.getCmsProperty("profile.created")) .getSimpleTypeValue(); Assert.assertEquals(userCreationDate.getTimeInMillis(), creationDate.getTimeInMillis(), "Invalid creation date. User provided " + DateFormatUtils.format(userCreationDate, "dd/MM/yyy HH:mm:ss") + " " + userCreationDate.getTimeInMillis() + " Persisted value " + DateFormatUtils.format(creationDate, "dd/MM/yyy HH:mm:ss") + " " + creationDate.getTimeInMillis()); String creationDatePath = DateFormatUtils.format(creationDate, "yyyy/M/d/H/m/s"); Assert.assertTrue(contentObjectNode.getParent().getPath().endsWith(creationDatePath), "Invalid content object creation path " + contentObjectNode.getParent().getPath() + ". It should end with " + creationDatePath); }
From source file:org.betaconceptframework.astroboa.test.engine.service.ContentServiceTest.java
@Test public void testUpdateCreationDate() throws ItemNotFoundException, RepositoryException { //Create content objects for test RepositoryUser systemUser = getSystemUser(); ContentObject contentObject = createContentObject(systemUser, "testUpdateCreationDate"); contentObject = contentService.save(contentObject, false, true, null); markObjectForRemoval(contentObject); //reload content object contentObject = contentService.getContentObject(contentObject.getId(), ResourceRepresentationType.CONTENT_OBJECT_INSTANCE, FetchLevel.ENTITY, CacheRegion.NONE, null, false);//from w ww . j a v a2s.c o m Calendar validCreationDate = ((CalendarProperty) contentObject.getCmsProperty("profile.created")) .getSimpleTypeValue(); Calendar userCreationDate = Calendar.getInstance(); userCreationDate.add(Calendar.YEAR, 1); ((CalendarProperty) contentObject.getCmsProperty("profile.created")).setSimpleTypeValue(userCreationDate); TestLogPolicy.setLevelForLogger(Level.FATAL, PopulateSimpleCmsProperty.class.getName()); contentObject = contentService.save(contentObject, false, true, null); TestLogPolicy.setDefaultLevelForLogger(PopulateSimpleCmsProperty.class.getName()); //reload content object contentObject = contentService.getContentObject(contentObject.getId(), ResourceRepresentationType.CONTENT_OBJECT_INSTANCE, FetchLevel.ENTITY, CacheRegion.NONE, null, false); Calendar persistedCreationDate = ((CalendarProperty) contentObject.getCmsProperty("profile.created")) .getSimpleTypeValue(); Assert.assertEquals(validCreationDate.getTimeInMillis(), persistedCreationDate.getTimeInMillis(), "Invalid creation date. Found " + DateFormatUtils.format(validCreationDate, "dd/MM/yyy HH:mm:ss") + " " + validCreationDate.getTimeInMillis() + " but should have been " + DateFormatUtils.format(persistedCreationDate, "dd/MM/yyy HH:mm:ss") + " " + persistedCreationDate.getTimeInMillis()); //Retrieve content object node Node contentObjectNode = getSession().getNodeByIdentifier(contentObject.getId()); String creationDatePath = DateFormatUtils.format(validCreationDate, "yyyy/M/d/H/m/s"); Assert.assertTrue(contentObjectNode.getParent().getPath().endsWith(creationDatePath), "Invalid content object creation path " + contentObjectNode.getParent().getPath() + ". It should end with " + creationDatePath); }