Commit 13afdbb0 authored by Greg Messner's avatar Greg Messner
Browse files

Mods to support EventsApi (#60).

parent c50c87cd
...@@ -45,12 +45,12 @@ public interface Constants { ...@@ -45,12 +45,12 @@ public interface Constants {
@JsonValue @JsonValue
public String toValue() { public String toValue() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
@Override @Override
public String toString() { public String toString() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
} }
...@@ -67,12 +67,12 @@ public interface Constants { ...@@ -67,12 +67,12 @@ public interface Constants {
@JsonValue @JsonValue
public String toValue() { public String toValue() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
@Override @Override
public String toString() { public String toString() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
} }
...@@ -90,12 +90,12 @@ public interface Constants { ...@@ -90,12 +90,12 @@ public interface Constants {
@JsonValue @JsonValue
public String toValue() { public String toValue() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
@Override @Override
public String toString() { public String toString() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
} }
...@@ -113,12 +113,12 @@ public interface Constants { ...@@ -113,12 +113,12 @@ public interface Constants {
@JsonValue @JsonValue
public String toValue() { public String toValue() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
@Override @Override
public String toString() { public String toString() {
return (name().toLowerCase()); return (enumHelper.toString(this));
} }
} }
...@@ -133,10 +133,14 @@ public interface Constants { ...@@ -133,10 +133,14 @@ public interface Constants {
public static JobScope forValue(String value) { return enumHelper.forValue(value); } public static JobScope forValue(String value) { return enumHelper.forValue(value); }
@JsonValue @JsonValue
public String toValue() { return (name().toLowerCase()); } public String toValue() {
return (enumHelper.toString(this));
}
@Override @Override
public String toString() { return (name().toLowerCase()); } public String toString() {
return (enumHelper.toString(this));
}
} }
/** Enum to use for specifying the state of a merge request update. */ /** Enum to use for specifying the state of a merge request update. */
...@@ -149,10 +153,61 @@ public interface Constants { ...@@ -149,10 +153,61 @@ public interface Constants {
@JsonCreator @JsonCreator
public static StateEvent forValue(String value) { return enumHelper.forValue(value); } public static StateEvent forValue(String value) { return enumHelper.forValue(value); }
@JsonValue @JsonValue
public String toValue() { return (name().toLowerCase()); } public String toValue() {
return (enumHelper.toString(this));
}
@Override @Override
public String toString() { return (name().toLowerCase()); } public String toString() {
return (enumHelper.toString(this));
}
}
/** Enum to use for specifying the event action_type. */
public enum ActionType {
CREATED, UPDATED, CLOSED, REOPENED, PUSHED, COMMENTED, MERGED, JOINED, LEFT, DESTROYED, EXPIRED;
private static JacksonJsonEnumHelper<ActionType> enumHelper = new JacksonJsonEnumHelper<>(ActionType.class);
@JsonCreator
public static ActionType forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (enumHelper.toString(this));
}
}
/** Enum to use for specifying the event target_type. */
public enum TargetType {
ISSUE, MILESTONE, MERGE_REQUEST, NOTE, PROJECT, SNIPPET, USER;
private static JacksonJsonEnumHelper<TargetType> enumHelper = new JacksonJsonEnumHelper<>(TargetType.class, true);
@JsonCreator
public static TargetType forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (enumHelper.toString(this));
}
} }
} }
...@@ -41,6 +41,7 @@ public class GitLabApi { ...@@ -41,6 +41,7 @@ public class GitLabApi {
private UserApi userApi; private UserApi userApi;
private JobApi jobApi; private JobApi jobApi;
private NotesApi notesApi; private NotesApi notesApi;
private EventsApi eventsApi;
private Session session; private Session session;
...@@ -192,6 +193,7 @@ public class GitLabApi { ...@@ -192,6 +193,7 @@ public class GitLabApi {
repositoryFileApi = new RepositoryFileApi(this); repositoryFileApi = new RepositoryFileApi(this);
jobApi = new JobApi(this); jobApi = new JobApi(this);
notesApi = new NotesApi(this); notesApi = new NotesApi(this);
eventsApi = new EventsApi(this);
} }
/** /**
...@@ -401,7 +403,9 @@ public class GitLabApi { ...@@ -401,7 +403,9 @@ public class GitLabApi {
* *
* @return the JobsApi instance owned by this GitLabApi instance * @return the JobsApi instance owned by this GitLabApi instance
*/ */
public JobApi getJobApi() { return (jobApi); } public JobApi getJobApi() {
return (jobApi);
}
/** /**
* Gets the NotesApi instance owned by this GitLabApi instance. The NotesApi is used * Gets the NotesApi instance owned by this GitLabApi instance. The NotesApi is used
...@@ -413,4 +417,13 @@ public class GitLabApi { ...@@ -413,4 +417,13 @@ public class GitLabApi {
return (notesApi); return (notesApi);
} }
/**
* Gets the EventsApi instance owned by this GitLabApi instance. The EventsApi is used
* to perform all events related API calls.
*
* @return the EventsApi instance owned by this GitLabApi instance
*/
public EventsApi getEventsApi() {
return (eventsApi);
}
} }
...@@ -5,6 +5,8 @@ import javax.xml.bind.annotation.XmlAccessType; ...@@ -5,6 +5,8 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.gitlab4j.api.Constants.TargetType;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class Event { public class Event {
...@@ -17,7 +19,7 @@ public class Event { ...@@ -17,7 +19,7 @@ public class Event {
private Integer projectId; private Integer projectId;
private Integer targetId; private Integer targetId;
private String targetTitle; private String targetTitle;
private String targetType; private TargetType targetType;
private String title; private String title;
public String getActionName() { public String getActionName() {
...@@ -84,11 +86,11 @@ public class Event { ...@@ -84,11 +86,11 @@ public class Event {
this.targetTitle = targetTitle; this.targetTitle = targetTitle;
} }
public String getTargetType() { public TargetType getTargetType() {
return targetType; return targetType;
} }
public void setTargetType(String targetType) { public void setTargetType(TargetType targetType) {
this.targetType = targetType; this.targetType = targetType;
} }
......
...@@ -8,15 +8,41 @@ import com.fasterxml.jackson.annotation.JsonCreator; ...@@ -8,15 +8,41 @@ import com.fasterxml.jackson.annotation.JsonCreator;
public class JacksonJsonEnumHelper<E extends Enum<E>> { public class JacksonJsonEnumHelper<E extends Enum<E>> {
private Map<String, E> valuesMap; private Map<String, E> valuesMap;
private Map<E, String> namesMap;
public JacksonJsonEnumHelper(Class<E> enumType) { public JacksonJsonEnumHelper(Class<E> enumType) {
this(enumType, false);
}
public JacksonJsonEnumHelper(Class<E> enumType, boolean firstLetterCapitalized) {
valuesMap = new HashMap<>(); valuesMap = new HashMap<>();
for (E e : enumType.getEnumConstants()) namesMap = new HashMap<>();
valuesMap.put(e.name().toLowerCase(), e);
for (E e : enumType.getEnumConstants()) {
String name = e.name().toLowerCase();
if (firstLetterCapitalized) {
name = name.substring(0, 1).toUpperCase() + name.substring(1);
}
valuesMap.put(name, e);
namesMap.put(e, name);
}
} }
@JsonCreator @JsonCreator
public E forValue(String value) { public E forValue(String value) {
return valuesMap.get(value); return valuesMap.get(value);
} }
/**
* Get the string used by the API for this enum.
*
* @param e the enum value to get the API string for
* @return the string used by the API for this enum
*/
public String toString(E e) {
return (namesMap.get(e));
}
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment