IssueWrapper.java
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package pl.itcrowd.youtrack.api;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import pl.itcrowd.youtrack.api.defaults.Fields;
import pl.itcrowd.youtrack.api.rest.Comment;
import pl.itcrowd.youtrack.api.rest.Field;
import pl.itcrowd.youtrack.api.rest.Issue;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class IssueWrapper implements Serializable {
private static final Log log = LogFactory.getLog(IssueWrapper.class);
private List<Comment> comments;
private Map<String, Field> fieldMap;
private Issue issue;
public IssueWrapper(Issue issue)
{
this.issue = issue;
fieldMap = new HashMap<String, Field>();
comments = new ArrayList<Comment>();
for (Object o : issue.getFieldOrComment()) {
if (o instanceof Field) {
Field field = (Field) o;
fieldMap.put(field.getName().toLowerCase(), field);
} else if (o instanceof Comment) {
comments.add((Comment) o);
} else {
log.warn("Object " + o + " is not Field nor Coment");
}
}
}
public List<Comment> getComments()
{
return Collections.unmodifiableList(comments);
}
public Field getField(String field)
{
return fieldMap.get(field);
}
public String getFieldValue(String fieldName)
{
Field field = getField(fieldName.toLowerCase());
if (field == null) {
return null;
}
List<Field.Value> values = field.getValues();
return values.isEmpty() ? null : values.get(0).getContent();
}
public String getFieldValue(Fields field)
{
return getFieldValue(field.name());
}
public String getId()
{
return issue.getId();
}
}