-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
(cherry picked from commit a1d05d5)
- Loading branch information
Showing
11 changed files
with
205 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...nt-search/src/main/java/org/elasticsearch/xpack/application/connector/ConnectorUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.application.connector; | ||
|
||
import org.elasticsearch.xcontent.XContentParser; | ||
import org.elasticsearch.xpack.core.common.time.TimeUtils; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
|
||
public class ConnectorUtils { | ||
|
||
/** | ||
* Parses a field from the XContentParser to an Instant. This method should be used for parsing | ||
* all datetime fields related to Connector APIs. It utilizes the parseTimeFieldToInstant method from {@link TimeUtils} | ||
* to parse the date-time string to an Instant. | ||
* | ||
* @param p the XContentParser instance from which to parse the date-time string. | ||
* @param fieldName the name of the field whose value is to be parsed. | ||
*/ | ||
public static Instant parseInstant(XContentParser p, String fieldName) throws IOException { | ||
return TimeUtils.parseTimeFieldToInstant(p, fieldName); | ||
} | ||
|
||
/** | ||
* Parses a nullable field from the XContentParser to an Instant. This method is useful | ||
* when parsing datetime fields that might have null values. | ||
* | ||
* @param p the XContentParser instance from which to parse the date-time string. | ||
* @param fieldName the name of the field whose value is to be parsed. | ||
*/ | ||
public static Instant parseNullableInstant(XContentParser p, String fieldName) throws IOException { | ||
return p.currentToken() == XContentParser.Token.VALUE_NULL ? null : parseInstant(p, fieldName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.