List of usage examples for org.apache.commons.lang.time DateFormatUtils formatUTC
public static String formatUTC(Date date, String pattern)
Formats a date/time into a specific pattern using the UTC time zone.
From source file:ddf.catalog.transformer.xml.MetacardMarshallerImpl.java
private String getStringValue(XmlPullParser parser, Attribute attribute, AttributeType.AttributeFormat format, Serializable value) throws IOException, CatalogTransformerException { switch (format) { case STRING://from w ww .j a v a 2 s . c om case BOOLEAN: case SHORT: case INTEGER: case LONG: case FLOAT: case DOUBLE: return value.toString(); case DATE: Date date = (Date) value; return DateFormatUtils.formatUTC(date, DF_PATTERN); case GEOMETRY: return geoToXml(geometryTransformer.transform(attribute), parser); case OBJECT: ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (ObjectOutput output = new ObjectOutputStream(bos)) { output.writeObject(attribute.getValue()); return Base64.getEncoder().encodeToString(bos.toByteArray()); } case BINARY: return Base64.getEncoder().encodeToString((byte[]) value); case XML: return value.toString().replaceAll("[<][?]xml.*[?][>]", ""); default: LOGGER.warn("Unsupported attribute: {}", format); return value.toString(); } }
From source file:de.fhg.iais.asc.workflow.ASCWorkflow.java
/** * Performs the harvesting.//ww w . j a va2 s . c o m * * @param provider The current {@link AscProvider}. * @return An {@link AscProviderIngest} for the new ingest event, non-{@code null}. */ private AscProviderIngest harvest(AscProvider provider) { // Create an ingest event. String eventId = this.config.get(AscConfiguration.INGEST_EVENT, ""); if (StringUtils.isEmpty(eventId) || "*".equals(eventId)) { eventId = String.valueOf(System.currentTimeMillis() / 1000); } final AscProviderIngest ingestEvent = provider.createIngest(eventId); LOG.info("Cleaning up errors from previous runs ..."); this.config.getASCState().displayMessage("Cleaning up errors from previous runs ..."); ingestEvent.removeOldErrors(ErrorSip.SECTION_HARVEST); LOG.info("Harvesting data ..."); LOG.info("Start Harvesting"); this.config.getASCState().displayMessage("Harvesting data ..."); // Read out proxy information if given. String proxyhost = this.config.get(AscConfiguration.OAIPMH_PROXYHOST, ""); Integer proxyport = null; try { proxyport = Integer.parseInt(this.config.get(AscConfiguration.OAIPMH_PROXYPORT, "invalid")); } catch (NumberFormatException ex) { proxyhost = null; proxyport = null; } // Create a harvester. final String oaiSource = this.config.get(AscConfiguration.OAI_SOURCE, ""); final String harvestingformat = this.config.get(AscConfiguration.META_DATA_FORMAT, this.config.get(AscConfiguration.FORMAT, "")); AbstractHarvester harvester = HarvesterFactory.getInstance().getHarvester( this.config.get(AscConfiguration.STRATEGY, ""), oaiSource, harvestingformat, proxyhost, proxyport, this.config.get(AscConfiguration.HARVESTING_FROM_DATE, ""), this.config.get(AscConfiguration.HARVESTING_UNTIL_DATE, ""), this.config, this.config.getASCState(), ingestEvent); if (!oaiSource.isEmpty()) { // If no OAI source is specified, it does not make sense to harvest (and the harvester will throw NullPointerExceptions). StopWatch s = StopWatch.start(); int n = 0; // Create a FileRepositoryWriter. File targetDirectory = ingestEvent.getDirectory(AscDirectory.INBOX); RepositoryWriter writer = new RepositoryWriter(targetDirectory, this.config.get(AscConfiguration.MAX_FILES_EACH, 0), oaiSource, eventId); // Harvest. final String oaiSets = this.config.get(AscConfiguration.OAI_SET, ""); if (StringUtils.isEmpty(oaiSets)) { n = harvester.retrieveAll(writer); } else { String[] sets = oaiSets.split(","); for (int i = 0; i < sets.length; i++) { sets[i] = sets[i].trim(); } for (String set : sets) { n = harvester.retrieveSet(set, writer); } } this.config.getASCState().displayMessage(n + " elements in " + DateFormatUtils.formatUTC(s.stop(), DateFormatUtils.ISO_TIME_NO_T_FORMAT.getPattern())); LOG.info(n + " elements in " + DateFormatUtils.ISO_TIME_NO_T_FORMAT.getPattern()); s.stop("Time used for harvesting"); } else { LOG.info("Skipping harvesting, because oai_source is empty for the current provider"); } return ingestEvent; }
From source file:com.smartitengineering.cms.spi.impl.content.search.ContentSearcherImpl.java
public static String formatDateInSolrFormat(Date date) { return DateFormatUtils.formatUTC(date, SOLR_DATE_FORMAT); }
From source file:org.alfresco.repo.webdav.WebDAV.java
/** * Formats the given date so that it conforms with the WebDAV creation date/time format * //from w w w . j av a 2s. c o m * @param date The date to format * @return The formatted date string */ public static String formatCreationDate(Date date) { return DateFormatUtils.formatUTC(date, CREATION_DATE_FORMAT); }
From source file:org.alfresco.repo.webdav.WebDAV.java
/** * Formats the given date so that it conforms with the WebDAV creation date/time format * //from w w w . ja v a2 s . com * @param ldate long * @return The formatted date string */ public static String formatCreationDate(long ldate) { return DateFormatUtils.formatUTC(ldate, CREATION_DATE_FORMAT); }
From source file:org.bigbluebutton.conference.service.poll.PollService.java
public void savePoll(ArrayList clientSidePoll) { String pollTime = DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"); clientSidePoll.set(6, pollTime);/*from w w w . j av a 2s . c om*/ poll = new Poll(clientSidePoll); application.savePoll(poll); }
From source file:org.codehaus.griffon.runtime.jcouchdb.JsonConverterUtils.java
public static Object toJSON(Object in) { Object value = in;//from w w w.jav a 2s . c o m if (value instanceof java.sql.Date || value instanceof java.sql.Timestamp) { value = new Date(((Date) value).getTime()); } if (value instanceof Date) { value = DateFormatUtils.formatUTC((Date) value, DATE_PATTERN); } return value; }
From source file:org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter.java
private void writeAttributeToXml(Attribute attribute, QName qname, AttributeFormat format, MarshallingContext context, HierarchicalStreamWriter writer) { // Loop to handle multi-valued attributes String name = qname.getPrefix() + ":" + attribute.getName(); for (Serializable value : attribute.getValues()) { String xmlValue = null;/*from ww w . j a va 2 s . c o m*/ switch (format) { case XML: String cdata = (String) value; if (cdata != null && (writer.underlyingWriter() instanceof EnhancedStaxWriter)) { writer.startNode(name); EnhancedStaxWriter eWriter = (EnhancedStaxWriter) writer.underlyingWriter(); eWriter.writeCdata(cdata); writer.endNode(); } break; case GEOMETRY: XmlNode.writeGeometry(name, context, writer, XmlNode.readGeometry((String) value)); break; case BINARY: xmlValue = Base64.getEncoder().encodeToString((byte[]) value); break; case DATE: Date date = (Date) value; xmlValue = DateFormatUtils.formatUTC(date, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); break; case OBJECT: // Probably won't translate at all. break; default: xmlValue = value.toString(); break; } // Write the node if we were able to convert it. if (xmlValue != null) { writer.startNode(name); writer.setValue(xmlValue); writer.endNode(); } } }
From source file:org.dspace.app.cris.discovery.CrisSearchService.java
private <P extends Property<TP>, TP extends PropertiesDefinition> void indexProperty(SolrInputDocument doc, String uuid, String field, P meta, List<String> toIgnoreFields, Map<String, List<DiscoverySearchFilter>> searchFilters, List<String> toProjectionFields, Map<String, DiscoverySortFieldConfiguration> sortFields, List<String> sortFieldsAdded, Set<String> hitHighlightingFields, Set<String> moreLikeThisFields) { AValue value = meta.getValue();//from ww w.j a va 2 s . co m if (value == null || meta.getVisibility() != VisibilityConstants.PUBLIC) { return; } String svalue = meta.toString(); String authority = null; if (value instanceof PointerValue && value.getObject() instanceof ACrisObject) { authority = ResearcherPageUtils.getPersistentIdentifier((ACrisObject) value.getObject()); } if (value instanceof DateValue) { // TODO: make this date format configurable ! svalue = DateFormatUtils.formatUTC(((DateValue) value).getObject(), "yyyy-MM-dd"); } indexProperty(doc, uuid, field, svalue, authority, toIgnoreFields, searchFilters, toProjectionFields, sortFields, sortFieldsAdded, hitHighlightingFields, moreLikeThisFields); }
From source file:org.dspace.app.cris.discovery.CrisSearchService.java
private void indexProperty(SolrInputDocument doc, String uuid, String field, String svalue, String authority, List<String> toIgnoreFields, Map<String, List<DiscoverySearchFilter>> searchFilters, List<String> toProjectionFields, Map<String, DiscoverySortFieldConfiguration> sortFields, List<String> sortFieldsAdded, Set<String> hitHighlightingFields, Set<String> moreLikeThisFields) { if (toIgnoreFields.contains(field)) { return;//w w w .java 2 s . c o m } if ((searchFilters.get(field) != null)) { List<DiscoverySearchFilter> searchFilterConfigs = searchFilters.get(field); for (DiscoverySearchFilter searchFilter : searchFilterConfigs) { String separator = new DSpace().getConfigurationService() .getProperty("discovery.solr.facets.split.char"); if (separator == null) { separator = FILTER_SEPARATOR; } doc.addField(searchFilter.getIndexFieldName(), svalue); doc.addField(searchFilter.getIndexFieldName() + "_keyword", svalue); if (authority != null) { doc.addField(searchFilter.getIndexFieldName() + "_keyword", svalue + AUTHORITY_SEPARATOR + authority); doc.addField(searchFilter.getIndexFieldName() + "_authority", authority); doc.addField(searchFilter.getIndexFieldName() + "_acid", svalue.toLowerCase() + separator + svalue + AUTHORITY_SEPARATOR + authority); } // Add a dynamic fields for auto complete in search doc.addField(searchFilter.getIndexFieldName() + "_ac", svalue.toLowerCase() + separator + svalue); if (searchFilter.getFilterType().equals(DiscoverySearchFilterFacet.FILTER_TYPE_FACET)) { if (searchFilter.getType().equals(DiscoveryConfigurationParameters.TYPE_TEXT)) { // Add a special filter // We use a separator to split up the lowercase // and regular case, this is needed to get our // filters in regular case // Solr has issues with facet prefix and cases if (authority != null) { String facetValue = svalue; doc.addField(searchFilter.getIndexFieldName() + "_filter", facetValue.toLowerCase() + separator + facetValue + AUTHORITY_SEPARATOR + authority); } else { doc.addField(searchFilter.getIndexFieldName() + "_filter", svalue.toLowerCase() + separator + svalue); } } else if (searchFilter.getType().equals(DiscoveryConfigurationParameters.TYPE_DATE)) { Date date = toDate(svalue); if (date != null) { String indexField = searchFilter.getIndexFieldName() + ".year"; doc.addField(searchFilter.getIndexFieldName() + "_keyword", DateFormatUtils.formatUTC(date, "yyyy")); doc.addField(indexField, DateFormatUtils.formatUTC(date, "yyyy")); // Also save a sort value of this year, this // is required for determining the upper & // lower bound year of our facet if (doc.getField(indexField + "_sort") == null) { // We can only add one year so take the // first one doc.addField(indexField + "_sort", DateFormatUtils.formatUTC(date, "yyyy")); } } } else if (searchFilter.getType().equals(DiscoveryConfigurationParameters.TYPE_HIERARCHICAL)) { HierarchicalSidebarFacetConfiguration hierarchicalSidebarFacetConfiguration = (HierarchicalSidebarFacetConfiguration) searchFilter; String[] subValues = svalue.split(hierarchicalSidebarFacetConfiguration.getSplitter()); if (hierarchicalSidebarFacetConfiguration.isSkipFirstNodeLevel() && 1 < subValues.length) { // Remove the first element of our array subValues = (String[]) ArrayUtils.subarray(subValues, 1, subValues.length); } for (int i = 0; i < subValues.length; i++) { StringBuilder valueBuilder = new StringBuilder(); for (int j = 0; j <= i; j++) { valueBuilder.append(subValues[j]); if (j < i) { valueBuilder.append(hierarchicalSidebarFacetConfiguration.getSplitter()); } } String indexValue = valueBuilder.toString().trim(); doc.addField(searchFilter.getIndexFieldName() + "_tax_" + i + "_filter", indexValue.toLowerCase() + separator + indexValue); // We add the field x times that it has // occurred for (int j = i; j < subValues.length; j++) { doc.addField(searchFilter.getIndexFieldName() + "_filter", indexValue.toLowerCase() + separator + indexValue); doc.addField(searchFilter.getIndexFieldName() + "_keyword", indexValue); } } } } } } if ((sortFields.get(field) != null && !sortFieldsAdded.contains(field))) { // Only add sort value once String type = ""; if (sortFields.get(field) != null) { type = sortFields.get(field).getType(); } if (type.equals(DiscoveryConfigurationParameters.TYPE_DATE)) { Date date = toDate(svalue); if (date != null) { doc.addField(field + "_dt", date); } else { log.warn("Error while indexing sort date field, cris: " + uuid + " metadata field: " + field + " date value: " + svalue); } } else { doc.addField(field + "_sort", svalue); } sortFieldsAdded.add(field); } if (hitHighlightingFields.contains(field) || hitHighlightingFields.contains("*")) { doc.addField(field + "_hl", svalue); } if (moreLikeThisFields.contains(field)) { doc.addField(field + "_mlt", svalue); } doc.addField(field, svalue); if (authority != null) { doc.addField(field + "_authority", authority); } if (toProjectionFields.contains(field)) { doc.addField(field + "_stored", svalue + STORE_SEPARATOR + authority); } }