当前位置: 首页>>代码示例>>Java>>正文


Java ISODateTimeFormat类代码示例

本文整理汇总了Java中org.elasticsearch.common.joda.time.format.ISODateTimeFormat的典型用法代码示例。如果您正苦于以下问题:Java ISODateTimeFormat类的具体用法?Java ISODateTimeFormat怎么用?Java ISODateTimeFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ISODateTimeFormat类属于org.elasticsearch.common.joda.time.format包,在下文中一共展示了ISODateTimeFormat类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intercept

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@Override
public Event intercept(Event event) {
    Map<String, String> headers = event.getHeaders();

    if(headers.containsKey(timestampStr)) {
        String timestamp = headers.get(timestampStr);
        Long millis = Long.parseLong(timestamp);
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        headers.put(timestampStr, fmt.print(millis));

        // elasticsearch sink will look for a timestamp in milliseconds
        headers.put("timestamp", timestamp);
    }

    return event;
}
 
开发者ID:nicolasbaer,项目名称:flume-ng-elasticsearch-serializer-num,代码行数:17,代码来源:KibanaTimeStampInterceptor.java

示例2: getLastDateFromRiver

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Date getLastDateFromRiver(String nvdStreamName) {
	client.admin().indices().prepareRefresh("_river").execute().actionGet();
	GetResponse resp = client
			.prepareGet("_river", riverName().name(), "_meta").execute()
			.actionGet();
	if (resp.isExists()) {
		Map<String, List<?>> nvd = (Map<String, List<?>>) resp.getSourceAsMap()
				.get(NVD_TYPE);

		if (nvd != null) {
			List<?> streams = (List<?>) nvd.get("streams");
			for (Object o : streams) {
				Map<String, String> stream = (Map<String, String>) o;
				String lastUpdate = stream.get("last_update");
				if (lastUpdate != null) { return ISODateTimeFormat
						.dateOptionalTimeParser().parseDateTime(lastUpdate).toDate(); }
				logger.warn("last_update field not present in stream [{}].",
						stream.get("name"));
				return null;
			}
		}
	}
	return null;
}
 
开发者ID:frosenberg,项目名称:elasticsearch-nvd-river,代码行数:26,代码来源:NvdRiver.java

示例3: WildlfyRiver

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
@Inject
public WildlfyRiver(RiverName riverName, RiverSettings settings, Client client, ThreadPool threadPool) {
    super(riverName, settings);
    this.client = client;
    this.threadPool = threadPool;

    logger.info("Creating wildfly metric stream");

    indexName = riverName.name();
    typeName = "metrics";

    //dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");

    timeFormatter = ISODateTimeFormat.dateTimeNoMillis();

}
 
开发者ID:heiko-braun,项目名称:river-metrics,代码行数:18,代码来源:WildlfyRiver.java

示例4: dateFromISOString

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
/**
 * Parse ISO date time formated string into {@link Date} instance.
 * 
 * @param string ISO formatted date string to parse
 * @param silent if true then null is returned instead of {@link IllegalArgumentException} thrown
 * @return parsed date or null
 * @throws IllegalArgumentException in case of bad format
 */
public static Date dateFromISOString(String string, boolean silent) throws IllegalArgumentException {
	if (string == null)
		return null;
	try {
		return ISODateTimeFormat.dateTimeParser().parseDateTime(string).toDate();
	} catch (IllegalArgumentException e) {
		if (!silent)
			throw e;
		else
			return null;
	}
}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:21,代码来源:SearchUtils.java

示例5: readDateParam

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
/**
 * Read request param value as ISO datetime format and return it as millis.
 * 
 * @param params to get param from
 * @param paramKey key of param
 * @return param timestamp value as Long or null
 * @throws IllegalArgumentException if datetime param value is not parseable due bad format
 */
protected Long readDateParam(MultivaluedMap<String, String> params, String paramKey) throws IllegalArgumentException {
	if (params != null && params.containsKey(paramKey)) {
		try {
			String s = SearchUtils.trimToNull(params.getFirst(paramKey));
			if (s == null)
				return null;
			return ISODateTimeFormat.dateTimeParser().parseMillis(s);
		} catch (Exception e) {
			throw new IllegalArgumentException(paramKey);
		}
	}
	return null;
}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:22,代码来源:QuerySettingsParser.java

示例6: dateFromISOString

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
/**
 * Parse ISO date time formatted string into {@link Date} instance.
 * 
 * @param string ISO formatted date string to parse
 * @param silent if true then null is returned instead of {@link IllegalArgumentException} thrown
 * @return parsed date or null
 * @throws IllegalArgumentException in case of bad format
 */
public static Date dateFromISOString(String string, boolean silent) throws IllegalArgumentException {
	if (string == null)
		return null;
	try {
		return ISODateTimeFormat.dateTimeParser().parseDateTime(string).toDate();
	} catch (IllegalArgumentException e) {
		if (!silent)
			throw e;
		else
			return null;
	}
}
 
开发者ID:searchisko,项目名称:searchisko,代码行数:21,代码来源:SearchUtils.java

示例7: readDateParam

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
/**
 * Read request param value as ISO datetime format and return it as millis.
 * 
 * @param params to get param from
 * @param paramKey key of param
 * @return param timestamp value as Long or null
 * @throws IllegalArgumentException if datetime param value is not parsable due bad format
 */
protected Long readDateParam(MultivaluedMap<String, String> params, String paramKey) throws IllegalArgumentException {
	if (params != null && params.containsKey(paramKey)) {
		try {
			String s = SearchUtils.trimToNull(params.getFirst(paramKey));
			if (s == null)
				return null;
			return ISODateTimeFormat.dateTimeParser().parseMillis(s);
		} catch (Exception e) {
			throw new IllegalArgumentException(paramKey);
		}
	}
	return null;
}
 
开发者ID:searchisko,项目名称:searchisko,代码行数:22,代码来源:QuerySettingsParser.java

示例8: processUpdate_PagedByDate

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void processUpdate_PagedByDate() throws Exception {

	// test case with more than one "page" of results from remote system search method with different updated dates
	IRemoteSystemClient remoteClientMock = mock(IRemoteSystemClient.class);
	IESIntegration esIntegrationMock = mockEsIntegrationComponent();
	IDocumentIndexStructureBuilder documentIndexStructureBuilderMock = mock(IDocumentIndexStructureBuilder.class);
	SpaceByLastUpdateTimestampIndexer tested = new SpaceByLastUpdateTimestampIndexer("ORG", false, remoteClientMock,
			esIntegrationMock, documentIndexStructureBuilderMock);

	Client client = Mockito.mock(Client.class);
	BulkRequestBuilder brb = new BulkRequestBuilder(client);

	List<Map<String, Object>> docs = new ArrayList<Map<String, Object>>();
	Map<String, Object> doc1 = addDocumentMock(docs, "ORG-45", "2012-08-14T08:00:10.000-0400");
	Map<String, Object> doc2 = addDocumentMock(docs, "ORG-46", "2012-08-14T08:01:10.000-0400");
	Map<String, Object> doc3 = addDocumentMock(docs, "ORG-47", "2012-08-14T08:02:20.000-0400");
	Date after2 = DateTimeUtils.parseISODateTime("2012-08-14T08:02:20.000-0400");
	List<Map<String, Object>> docs2 = new ArrayList<Map<String, Object>>();
	Map<String, Object> doc4 = addDocumentMock(docs2, "ORG-481", "2012-08-14T08:03:10.000-0400");
	Map<String, Object> doc5 = addDocumentMock(docs2, "ORG-49", "2012-08-14T08:04:10.000-0400");
	Map<String, Object> doc6 = addDocumentMock(docs2, "ORG-154", "2012-08-14T08:05:20.000-0400");
	Date after3 = ISODateTimeFormat.dateTimeParser().parseDateTime("2012-08-14T08:05:20.000-0400").toDate();
	List<Map<String, Object>> docs3 = new ArrayList<Map<String, Object>>();
	Map<String, Object> doc7 = addDocumentMock(docs3, "ORG-4", "2012-08-14T08:06:10.000-0400");
	Map<String, Object> doc8 = addDocumentMock(docs3, "ORG-91", "2012-08-14T08:07:20.000-0400");
	when(
			esIntegrationMock.readDatetimeValue("ORG",
					SpaceByLastUpdateTimestampIndexer.STORE_PROPERTYNAME_LAST_INDEXED_DOC_UPDATE_DATE)).thenReturn(null);
	when(remoteClientMock.getChangedDocuments("ORG", 0, true, null))
			.thenReturn(new ChangedDocumentsResults(docs, 0, 8));
	when(remoteClientMock.getChangedDocuments("ORG", 0, true, after2)).thenReturn(
			new ChangedDocumentsResults(docs2, 0, 5));
	when(remoteClientMock.getChangedDocuments("ORG", 0, true, after3)).thenReturn(
			new ChangedDocumentsResults(docs3, 0, 2));
	when(esIntegrationMock.prepareESBulkRequestBuilder()).thenReturn(brb);
	configureStructureBuilderMockDefaults(documentIndexStructureBuilderMock);

	tested.processUpdate();
	Assert.assertEquals(8, tested.indexingInfo.documentsUpdated);
	Assert.assertEquals(0, tested.indexingInfo.documentsWithError);
	Assert.assertTrue(tested.indexingInfo.fullUpdate);
	verify(esIntegrationMock, times(1)).readDatetimeValue(Mockito.any(String.class), Mockito.any(String.class));
	verify(esIntegrationMock, times(3)).prepareESBulkRequestBuilder();
	verify(remoteClientMock, times(1)).getChangedDocuments("ORG", 0, true, null);
	verify(remoteClientMock, times(1)).getChangedDocuments("ORG", 0, true, after2);
	verify(remoteClientMock, times(1)).getChangedDocuments("ORG", 0, true, after3);
	verify(documentIndexStructureBuilderMock, times(8)).indexDocument(Mockito.any(BulkRequestBuilder.class),
			Mockito.eq("ORG"), Mockito.any(Map.class));
	verify(esIntegrationMock, times(3)).storeDatetimeValue(Mockito.any(String.class), Mockito.any(String.class),
			Mockito.any(Date.class), Mockito.any(BulkRequestBuilder.class));
	verify(esIntegrationMock, times(1)).storeDatetimeValue(Mockito.eq("ORG"),
			Mockito.eq(SpaceByLastUpdateTimestampIndexer.STORE_PROPERTYNAME_LAST_INDEXED_DOC_UPDATE_DATE),
			Mockito.eq(ISODateTimeFormat.dateTimeParser().parseDateTime("2012-08-14T08:02:20.000-0400").toDate()),
			Mockito.any(BulkRequestBuilder.class));
	verify(esIntegrationMock, times(1)).storeDatetimeValue(Mockito.eq("ORG"),
			Mockito.eq(SpaceByLastUpdateTimestampIndexer.STORE_PROPERTYNAME_LAST_INDEXED_DOC_UPDATE_DATE),
			Mockito.eq(ISODateTimeFormat.dateTimeParser().parseDateTime("2012-08-14T08:05:20.000-0400").toDate()),
			Mockito.any(BulkRequestBuilder.class));
	verify(esIntegrationMock, times(1)).storeDatetimeValue(Mockito.eq("ORG"),
			Mockito.eq(SpaceByLastUpdateTimestampIndexer.STORE_PROPERTYNAME_LAST_INDEXED_DOC_UPDATE_DATE),
			Mockito.eq(ISODateTimeFormat.dateTimeParser().parseDateTime("2012-08-14T08:07:20.000-0400").toDate()),
			Mockito.any(BulkRequestBuilder.class));
	verify(esIntegrationMock, times(3)).executeESBulkRequest(Mockito.any(BulkRequestBuilder.class));
	verify(esIntegrationMock, Mockito.atLeastOnce()).isClosed();
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-45", doc1);
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-46", doc2);
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-47", doc3);
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-481", doc4);
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-49", doc5);
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-154", doc6);
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-4", doc7);
	verify(remoteClientMock).getChangedDocumentDetails("ORG", "ORG-91", doc8);
	Mockito.verifyNoMoreInteractions(remoteClientMock);
	Mockito.verifyNoMoreInteractions(esIntegrationMock);

}
 
开发者ID:searchisko,项目名称:elasticsearch-river-remote,代码行数:79,代码来源:SpaceByLastUpdateTimestampIndexerTest.java

示例9: parseISODateTimeWithMinutePrecise

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
/**
 * Parse date string with minute precise - so seconds and milliseconds are set to 0. Used because JQL allows only
 * minute precise queries.
 * 
 * @param dateString to parse
 * @return parsed date rounded to minute precise
 * @throws IllegalArgumentException if date is not parseable
 */
public static Date parseISODateTimeWithMinutePrecise(String dateString) {
	if (Utils.isEmpty(dateString))
		return null;
	return DateTimeUtils.roundDateTimeToMinutePrecise(ISODateTimeFormat.dateTimeParser().parseDateTime(dateString)
			.toDate());
}
 
开发者ID:searchisko,项目名称:elasticsearch-river-remote,代码行数:15,代码来源:DateTimeUtils.java

示例10: parseISODateTime

import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
/**
 * Parse ISO datetime string.
 * 
 * @param dateString to parse
 * @return parsed date
 * @throws IllegalArgumentException if date is not parseable
 */
public static final Date parseISODateTime(String dateString) {
	if (Utils.isEmpty(dateString))
		return null;
	return ISODateTimeFormat.dateTimeParser().parseDateTime(dateString).toDate();
}
 
开发者ID:searchisko,项目名称:elasticsearch-river-remote,代码行数:13,代码来源:DateTimeUtils.java


注:本文中的org.elasticsearch.common.joda.time.format.ISODateTimeFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。