Commit 422db6b4 authored by Greg Messner's avatar Greg Messner
Browse files

Fixed data binding for NoteableType (#149).

parent 46b72ec7
......@@ -37,18 +37,24 @@ public class Note {
}
}
public static enum NotableType {
ISSUE("Issue"), MERGE_REQUEST("MergeRequest"), SNIPPET("Snippet");
public static enum NoteableType {
private String name;
ISSUE, MERGE_REQUEST, SNIPPET;
private static JacksonJsonEnumHelper<NoteableType> enumHelper = new JacksonJsonEnumHelper<>(NoteableType.class, true, true);
NotableType(String name) {
this.name = name;
@JsonCreator
public static NoteableType forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (name);
return (enumHelper.toString(this));
}
}
......@@ -61,7 +67,8 @@ public class Note {
private String fileName;
private Integer id;
private Integer noteableId;
private NotableType noteableType;
private NoteableType noteableType;
private Integer noteableIid;
private Boolean system;
private String title;
private String updatedAt;
......@@ -139,14 +146,22 @@ public class Note {
this.noteableId = noteableId;
}
public NotableType getNoteableType() {
public NoteableType getNoteableType() {
return noteableType;
}
public void setNoteableType(NotableType noteableType) {
public void setNoteableType(NoteableType noteableType) {
this.noteableType = noteableType;
}
public Integer getNoteableIid() {
return noteableIid;
}
public void setNoteableIid(Integer noteableIid) {
this.noteableIid = noteableIid;
}
public Boolean getSystem() {
return system;
}
......
......@@ -31,6 +31,33 @@ public class JacksonJsonEnumHelper<E extends Enum<E>> {
}
}
public JacksonJsonEnumHelper(Class<E> enumType, boolean firstLetterCapitalized, boolean camelCased) {
valuesMap = new HashMap<>();
namesMap = new HashMap<>();
for (E e : enumType.getEnumConstants()) {
char[] chars = e.name().toLowerCase().toCharArray();
StringBuilder nameBuf = new StringBuilder(chars.length);
boolean nextCharIsCapitalized = firstLetterCapitalized;
for (char ch : chars) {
if (ch == '_' && camelCased) {
nextCharIsCapitalized = true;
} else if (nextCharIsCapitalized) {
nextCharIsCapitalized = false;
nameBuf.append(Character.toUpperCase(ch));
} else {
nameBuf.append(ch);
}
}
String name = nameBuf.toString();
valuesMap.put(name, e);
namesMap.put(e, name);
}
}
@JsonCreator
public E forValue(String value) {
return valuesMap.get(value);
......
......@@ -7,6 +7,10 @@ import javax.xml.bind.annotation.XmlAccessorType;
import org.gitlab4j.api.models.Diff;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
@XmlAccessorType(XmlAccessType.FIELD)
public class NoteEvent implements Event {
......@@ -96,7 +100,7 @@ public class NoteEvent implements Event {
public void setMergeRequest(EventMergeRequest mergeRequest) {
this.mergeRequest = mergeRequest;
}
public EventSnippet getSnippet() {
return snippet;
}
......@@ -105,21 +109,24 @@ public class NoteEvent implements Event {
this.snippet = snippet;
}
public enum NoteableType {
COMMIT("Commit"),
ISSUE("Issue"),
MERGE_REQUEST("MergeRequest"),
SNIPPET("Snippet");
public static enum NoteableType {
private String name;
ISSUE, MERGE_REQUEST, SNIPPET, COMMIT;
private static JacksonJsonEnumHelper<NoteableType> enumHelper = new JacksonJsonEnumHelper<>(NoteableType.class, true, true);
@JsonCreator
public static NoteableType forValue(String value) {
return enumHelper.forValue(value);
}
NoteableType(String name) {
this.name = name;
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (name);
return (enumHelper.toString(this));
}
}
......@@ -128,7 +135,7 @@ public class NoteEvent implements Event {
private Integer id;
private String note;
private NoteableType notableType;
private NoteableType noteableType;
private Integer authorId;
private Date createdAt;
private Date updatedAt;
......@@ -158,11 +165,11 @@ public class NoteEvent implements Event {
}
public NoteableType getNoteableType() {
return notableType;
return noteableType;
}
public void setNoteableType(NoteableType notableType) {
this.notableType = notableType;
public void NoteableType(NoteableType notableType) {
this.noteableType = notableType;
}
public Integer getAuthorId() {
......
......@@ -332,6 +332,17 @@ public class TestGitLabApiBeans {
}
}
@Test
public void testMergeRequestNote() {
try {
Note note = makeFakeApiCall(Note.class, "merge-request-note");
assertTrue(compareJson(note, "merge-request-note"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void testNotificationSettings() {
......
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