001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.wsclient.issue.internal; 021 022import org.sonar.wsclient.issue.Issue; 023import org.sonar.wsclient.issue.IssueComment; 024import org.sonar.wsclient.issue.WorkDayDuration; 025import org.sonar.wsclient.unmarshallers.JsonUtils; 026 027import javax.annotation.CheckForNull; 028 029import java.util.*; 030 031/** 032 * @since 3.6 033 */ 034public class DefaultIssue implements Issue { 035 036 private final Map json; 037 038 DefaultIssue(Map json) { 039 this.json = json; 040 } 041 042 /** 043 * Unique key 044 */ 045 public String key() { 046 return JsonUtils.getString(json, "key"); 047 } 048 049 public String componentKey() { 050 return JsonUtils.getString(json, "component"); 051 } 052 053 public Long componentId() { 054 return JsonUtils.getLong(json, "componentId"); 055 } 056 057 public String projectKey() { 058 return JsonUtils.getString(json, "project"); 059 } 060 061 public String ruleKey() { 062 return JsonUtils.getString(json, "rule"); 063 } 064 065 public String severity() { 066 return JsonUtils.getString(json, "severity"); 067 } 068 069 @CheckForNull 070 public String message() { 071 return JsonUtils.getString(json, "message"); 072 } 073 074 @CheckForNull 075 public Integer line() { 076 return JsonUtils.getInteger(json, "line"); 077 } 078 079 @CheckForNull 080 public Double effortToFix() { 081 return JsonUtils.getDouble(json, "effortToFix"); 082 } 083 084 @CheckForNull 085 public WorkDayDuration technicalDebt() { 086 Map technicalDebt = (Map) json.get("technicalDebt"); 087 if (technicalDebt != null) { 088 return new DefaultWorkDayDuration(technicalDebt); 089 } 090 return null; 091 } 092 093 public String status() { 094 return JsonUtils.getString(json, "status"); 095 } 096 097 /** 098 * The resolution type. Null if the issue is not resolved. 099 */ 100 @CheckForNull 101 public String resolution() { 102 return JsonUtils.getString(json, "resolution"); 103 } 104 105 @CheckForNull 106 public String reporter() { 107 return JsonUtils.getString(json, "reporter"); 108 } 109 110 /** 111 * Login of assignee. Null if issue is not assigned. 112 */ 113 @CheckForNull 114 public String assignee() { 115 return JsonUtils.getString(json, "assignee"); 116 } 117 118 /** 119 * SCM account 120 */ 121 @CheckForNull 122 public String author() { 123 return JsonUtils.getString(json, "author"); 124 } 125 126 @CheckForNull 127 public String actionPlan() { 128 return JsonUtils.getString(json, "actionPlan"); 129 } 130 131 public Date creationDate() { 132 return JsonUtils.getDateTime(json, "creationDate"); 133 } 134 135 public Date updateDate() { 136 return JsonUtils.getDateTime(json, "updateDate"); 137 } 138 139 @CheckForNull 140 public Date closeDate() { 141 return JsonUtils.getDateTime(json, "closeDate"); 142 } 143 144 @CheckForNull 145 public String attribute(String key) { 146 return attributes().get(key); 147 } 148 149 public Map<String, String> attributes() { 150 Map<String, String> attr = (Map<String,String>) json.get("attr"); 151 if (attr == null) { 152 return Collections.emptyMap(); 153 } 154 return attr; 155 } 156 157 /** 158 * Non-null list of comments 159 */ 160 public List<IssueComment> comments() { 161 List<IssueComment> comments = new ArrayList<IssueComment>(); 162 List<Map> jsonComments = (List<Map>) json.get("comments"); 163 if (jsonComments != null) { 164 for (Map jsonComment : jsonComments) { 165 comments.add(new DefaultIssueComment(jsonComment)); 166 } 167 } 168 return comments; 169 } 170}