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 comments; private Map fieldMap; private Issue issue; public IssueWrapper(Issue issue) { this.issue = issue; fieldMap = new HashMap(); comments = new ArrayList(); 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 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 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(); } }