Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
422db6b4
Commit
422db6b4
authored
Mar 05, 2018
by
Greg Messner
Browse files
Fixed data binding for NoteableType (#149).
parent
46b72ec7
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/models/Note.java
View file @
422db6b4
...
@@ -37,18 +37,24 @@ public class Note {
...
@@ -37,18 +37,24 @@ public class Note {
}
}
}
}
public
static
enum
NotableType
{
public
static
enum
NoteableType
{
ISSUE
(
"Issue"
),
MERGE_REQUEST
(
"MergeRequest"
),
SNIPPET
(
"Snippet"
);
private
String
name
;
ISSUE
,
MERGE_REQUEST
,
SNIPPET
;
private
static
JacksonJsonEnumHelper
<
NoteableType
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
NoteableType
.
class
,
true
,
true
);
NotableType
(
String
name
)
{
@JsonCreator
this
.
name
=
name
;
public
static
NoteableType
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
(
name
);
return
(
enumHelper
.
toString
(
this
)
);
}
}
}
}
...
@@ -61,7 +67,8 @@ public class Note {
...
@@ -61,7 +67,8 @@ public class Note {
private
String
fileName
;
private
String
fileName
;
private
Integer
id
;
private
Integer
id
;
private
Integer
noteableId
;
private
Integer
noteableId
;
private
NotableType
noteableType
;
private
NoteableType
noteableType
;
private
Integer
noteableIid
;
private
Boolean
system
;
private
Boolean
system
;
private
String
title
;
private
String
title
;
private
String
updatedAt
;
private
String
updatedAt
;
...
@@ -139,14 +146,22 @@ public class Note {
...
@@ -139,14 +146,22 @@ public class Note {
this
.
noteableId
=
noteableId
;
this
.
noteableId
=
noteableId
;
}
}
public
NotableType
getNoteableType
()
{
public
Not
e
ableType
getNoteableType
()
{
return
noteableType
;
return
noteableType
;
}
}
public
void
setNoteableType
(
NotableType
noteableType
)
{
public
void
setNoteableType
(
Not
e
ableType
noteableType
)
{
this
.
noteableType
=
noteableType
;
this
.
noteableType
=
noteableType
;
}
}
public
Integer
getNoteableIid
()
{
return
noteableIid
;
}
public
void
setNoteableIid
(
Integer
noteableIid
)
{
this
.
noteableIid
=
noteableIid
;
}
public
Boolean
getSystem
()
{
public
Boolean
getSystem
()
{
return
system
;
return
system
;
}
}
...
...
src/main/java/org/gitlab4j/api/utils/JacksonJsonEnumHelper.java
View file @
422db6b4
...
@@ -31,6 +31,33 @@ public class JacksonJsonEnumHelper<E extends Enum<E>> {
...
@@ -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
@JsonCreator
public
E
forValue
(
String
value
)
{
public
E
forValue
(
String
value
)
{
return
valuesMap
.
get
(
value
);
return
valuesMap
.
get
(
value
);
...
...
src/main/java/org/gitlab4j/api/webhook/NoteEvent.java
View file @
422db6b4
...
@@ -7,6 +7,10 @@ import javax.xml.bind.annotation.XmlAccessorType;
...
@@ -7,6 +7,10 @@ import javax.xml.bind.annotation.XmlAccessorType;
import
org.gitlab4j.api.models.Diff
;
import
org.gitlab4j.api.models.Diff
;
import
org.gitlab4j.api.models.User
;
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
)
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
NoteEvent
implements
Event
{
public
class
NoteEvent
implements
Event
{
...
@@ -96,7 +100,7 @@ public class NoteEvent implements Event {
...
@@ -96,7 +100,7 @@ public class NoteEvent implements Event {
public
void
setMergeRequest
(
EventMergeRequest
mergeRequest
)
{
public
void
setMergeRequest
(
EventMergeRequest
mergeRequest
)
{
this
.
mergeRequest
=
mergeRequest
;
this
.
mergeRequest
=
mergeRequest
;
}
}
public
EventSnippet
getSnippet
()
{
public
EventSnippet
getSnippet
()
{
return
snippet
;
return
snippet
;
}
}
...
@@ -105,21 +109,24 @@ public class NoteEvent implements Event {
...
@@ -105,21 +109,24 @@ public class NoteEvent implements Event {
this
.
snippet
=
snippet
;
this
.
snippet
=
snippet
;
}
}
public
enum
NoteableType
{
public
static
enum
NoteableType
{
COMMIT
(
"Commit"
),
ISSUE
(
"Issue"
),
MERGE_REQUEST
(
"MergeRequest"
),
SNIPPET
(
"Snippet"
);
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
)
{
@JsonValue
this
.
name
=
name
;
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
(
name
);
return
(
enumHelper
.
toString
(
this
)
);
}
}
}
}
...
@@ -128,7 +135,7 @@ public class NoteEvent implements Event {
...
@@ -128,7 +135,7 @@ public class NoteEvent implements Event {
private
Integer
id
;
private
Integer
id
;
private
String
note
;
private
String
note
;
private
NoteableType
notableType
;
private
NoteableType
not
e
ableType
;
private
Integer
authorId
;
private
Integer
authorId
;
private
Date
createdAt
;
private
Date
createdAt
;
private
Date
updatedAt
;
private
Date
updatedAt
;
...
@@ -158,11 +165,11 @@ public class NoteEvent implements Event {
...
@@ -158,11 +165,11 @@ public class NoteEvent implements Event {
}
}
public
NoteableType
getNoteableType
()
{
public
NoteableType
getNoteableType
()
{
return
notableType
;
return
not
e
ableType
;
}
}
public
void
set
NoteableType
(
NoteableType
notableType
)
{
public
void
NoteableType
(
NoteableType
notableType
)
{
this
.
notableType
=
notableType
;
this
.
not
e
ableType
=
notableType
;
}
}
public
Integer
getAuthorId
()
{
public
Integer
getAuthorId
()
{
...
...
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
422db6b4
...
@@ -332,6 +332,17 @@ public class TestGitLabApiBeans {
...
@@ -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
@Test
public
void
testNotificationSettings
()
{
public
void
testNotificationSettings
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment