Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/main/java/org/gitlab/api/jackson/InstantDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.gitlab.api.jackson;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.format.FormatStyle;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Stream;

/**
* A spezialized {@link Instant} deserializer that can parse different formats.
*/
public class InstantDeserializer extends StdDeserializer<Instant> {

private static final DateTimeFormatter LOCAL_DATE_TIME_FORMATTER_WITH_SPACE_SEPARATOR = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.appendLiteral(' ')
.append(DateTimeFormatter.ISO_LOCAL_TIME)
.toFormatter(Locale.getDefault(Locale.Category.FORMAT));

public InstantDeserializer() {
super(Instant.class);
}

@Override
public Instant deserialize(JsonParser parser, DeserializationContext context) throws IOException {
if (JsonToken.VALUE_NULL.equals(parser.getCurrentToken())) {
return null;
}

final String text = parser.getText();

if (null == text || text.trim().isEmpty()) {
return null;
}

return getFormatters()
.map(formatter -> {
try {
return formatter.parse(text, Instant::from);
} catch (DateTimeParseException e) {
return null;
}
})
.filter(Objects::nonNull)
.findFirst()
.orElseThrow(() -> new JsonParseException("Unable to parse instant \"" + text + "\"", parser.getCurrentLocation()));
}

private static Stream<DateTimeFormatter> getFormatters() {
return Stream.of(
// English (Standard) Formats
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.LONG).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.LONG).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.LONG).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).withLocale(Locale.ENGLISH),
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT).withLocale(Locale.ENGLISH),

// ISO Formats
LOCAL_DATE_TIME_FORMATTER_WITH_SPACE_SEPARATOR,
DateTimeFormatter.ISO_LOCAL_DATE_TIME,
DateTimeFormatter.ISO_DATE_TIME
);
}

}
272 changes: 260 additions & 12 deletions src/main/java/org/gitlab/api/models/GitlabPipeline.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,70 @@
package org.gitlab.api.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gitlab.api.jackson.InstantDeserializer;

import java.time.Instant;

public class GitlabPipeline {
public static final String URL = "/pipelines";


@JsonProperty("id")
private Integer id;

@JsonProperty("ref")
private String ref;

@JsonProperty("sha")
private String sha;

@JsonProperty("ref")
private String ref;

@JsonProperty("status")
private String status;

@JsonProperty("web_url")
private String webUrl;

@JsonProperty("before_sha")
private String beforeSha;

@JsonProperty("tag")
private boolean tag;

@JsonProperty("yaml_errors")
private String yamlErrors;

@JsonProperty("user")
private GitlabUser user;

@JsonProperty("created_at")
@JsonDeserialize(using = InstantDeserializer.class)
private Instant createdAt;

@JsonProperty("updated_at")
@JsonDeserialize(using = InstantDeserializer.class)
private Instant updatedAt;

@JsonProperty("started_at")
@JsonDeserialize(using = InstantDeserializer.class)
private Instant startedAt;

@JsonProperty("finished_at")
@JsonDeserialize(using = InstantDeserializer.class)
private Instant finishedAt;

@JsonProperty("committed_at")
@JsonDeserialize(using = InstantDeserializer.class)
private Instant committedAt;

@JsonProperty("duration")
private int duration;

@JsonProperty("coverage")
private String coverage;

@JsonProperty("detailed_status")
private DetailedStatus detailedStatus;

public Integer getId() {
return id;
}
Expand All @@ -26,14 +73,6 @@ public void setId(Integer id) {
this.id = id;
}

public String getRef() {
return ref;
}

public void setRef(String ref) {
this.ref = ref;
}

public String getSha() {
return sha;
}
Expand All @@ -42,11 +81,220 @@ public void setSha(String sha) {
this.sha = sha;
}

public String getRef() {
return ref;
}

public void setRef(String ref) {
this.ref = ref;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getWebUrl() {
return webUrl;
}

public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
}

public String getBeforeSha() {
return beforeSha;
}

public void setBeforeSha(String beforeSha) {
this.beforeSha = beforeSha;
}

public boolean isTag() {
return tag;
}

public void setTag(boolean tag) {
this.tag = tag;
}

public String getYamlErrors() {
return yamlErrors;
}

public void setYamlErrors(String yamlErrors) {
this.yamlErrors = yamlErrors;
}

public GitlabUser getUser() {
return user;
}

public void setUser(GitlabUser user) {
this.user = user;
}

public Instant getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

public Instant getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}

public Instant getStartedAt() {
return startedAt;
}

public void setStartedAt(Instant startedAt) {
this.startedAt = startedAt;
}

public Instant getFinishedAt() {
return finishedAt;
}

public void setFinishedAt(Instant finishedAt) {
this.finishedAt = finishedAt;
}

public Instant getCommittedAt() {
return committedAt;
}

public void setCommittedAt(Instant committedAt) {
this.committedAt = committedAt;
}

public int getDuration() {
return duration;
}

public void setDuration(int duration) {
this.duration = duration;
}

public String getCoverage() {
return coverage;
}

public void setCoverage(String coverage) {
this.coverage = coverage;
}

public DetailedStatus getDetailedStatus() {
return detailedStatus;
}

public void setDetailedStatus(DetailedStatus detailedStatus) {
this.detailedStatus = detailedStatus;
}

public static class DetailedStatus {

private String icon;

private String text;

private String label;

private String group;

private String tooltip;

@JsonProperty("has_details")
private String hasDetails;

@JsonProperty("details_path")
private String detailsPath;

private String illustration;

private String favicon;

public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public String getTooltip() {
return tooltip;
}

public void setTooltip(String tooltip) {
this.tooltip = tooltip;
}

public String getHasDetails() {
return hasDetails;
}

public void setHasDetails(String hasDetails) {
this.hasDetails = hasDetails;
}

public String getDetailsPath() {
return detailsPath;
}

public void setDetailsPath(String detailsPath) {
this.detailsPath = detailsPath;
}

public String getIllustration() {
return illustration;
}

public void setIllustration(String illustration) {
this.illustration = illustration;
}

public String getFavicon() {
return favicon;
}

public void setFavicon(String favicon) {
this.favicon = favicon;
}

}

}
Loading