-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using issue bean methods to simplify the logic
Signed-off-by: Santhosh Gandhe <[email protected]>
- Loading branch information
Showing
3 changed files
with
83 additions
and
47 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
78 changes: 76 additions & 2 deletions
78
...source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBean.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 |
---|---|---|
@@ -1,50 +1,124 @@ | ||
package org.opensearch.dataprepper.plugins.source.jira.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.CREATED; | ||
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.KEY; | ||
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.NAME; | ||
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.PROJECT; | ||
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.UPDATED; | ||
|
||
|
||
@Getter | ||
@Setter | ||
public class IssueBean { | ||
|
||
@JsonIgnore | ||
private final Pattern JiraDateTimePattern = Pattern.compile( | ||
"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}[-+]\\d{4}$"); | ||
@JsonIgnore | ||
private final DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); | ||
|
||
/** | ||
* Expand options that include additional issue details in the response. | ||
*/ | ||
@Getter | ||
@Setter | ||
@JsonProperty("expand") | ||
private String expand = null; | ||
|
||
/** | ||
* The ID of the issue. | ||
*/ | ||
@Getter | ||
@Setter | ||
@JsonProperty("id") | ||
private String id = null; | ||
|
||
/** | ||
* The URL of the issue details. | ||
*/ | ||
@Getter | ||
@Setter | ||
@JsonProperty("self") | ||
private String self = null; | ||
|
||
/** | ||
* The key of the issue. | ||
*/ | ||
@Getter | ||
@Setter | ||
@JsonProperty("key") | ||
private String key = null; | ||
|
||
@Getter | ||
@Setter | ||
@JsonProperty("renderedFields") | ||
private Map<String, Object> renderedFields = null; | ||
|
||
@Getter | ||
@Setter | ||
@JsonProperty("properties") | ||
private Map<String, Object> properties = null; | ||
|
||
@Getter | ||
@Setter | ||
@JsonProperty("names") | ||
private Map<String, String> names = null; | ||
|
||
@Getter | ||
@Setter | ||
@JsonProperty("fields") | ||
private Map<String, Object> fields = null; | ||
|
||
|
||
@JsonIgnore | ||
public String getProject() { | ||
if (fields != null && Objects.nonNull(((Map) fields.get(PROJECT)).get(KEY))) { | ||
return ((Map) fields.get(PROJECT)).get(KEY).toString(); | ||
} | ||
return null; | ||
} | ||
|
||
@JsonIgnore | ||
public String getProjectName() { | ||
if (fields != null && Objects.nonNull(((Map) fields.get(PROJECT)).get(NAME))) { | ||
((Map) fields.get(PROJECT)).get(NAME).toString(); | ||
} | ||
return null; | ||
} | ||
|
||
@JsonIgnore | ||
public long getCreatedTimeMillis() { | ||
return getGivenDateField(CREATED); | ||
} | ||
|
||
@JsonIgnore | ||
public long getUpdatedTimeMillis() { | ||
return getGivenDateField(UPDATED); | ||
} | ||
|
||
@JsonIgnore | ||
private long getGivenDateField(String dateTimeFieldToPull) { | ||
long dateTimeField = 0; | ||
|
||
if (fields != null && Objects.nonNull(fields.get(dateTimeFieldToPull)) && JiraDateTimePattern.matcher(fields.get(dateTimeFieldToPull) | ||
.toString()).matches()) { | ||
String charSequence = fields.get(dateTimeFieldToPull).toString(); | ||
OffsetDateTime offsetDateTime = OffsetDateTime.parse(charSequence, offsetDateTimeFormatter); | ||
new Date(offsetDateTime.toInstant().toEpochMilli()); | ||
dateTimeField = offsetDateTime.toEpochSecond() * 1000; | ||
} | ||
return dateTimeField; | ||
} | ||
|
||
|
||
} |
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