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