private
def action_plan_to_hash(action_plan)
- hash = {:key => action_plan.key(), :name => action_plan.name(), :status => action_plan.status()}
- hash[:project] = action_plan.projectKey() if action_plan.projectKey() && !action_plan.projectKey().blank?
- hash[:desc] = action_plan.description() if action_plan.description() && !action_plan.description().blank?
- hash[:userLogin] = action_plan.userLogin() if action_plan.userLogin()
- hash[:deadLine] = Api::Utils.format_datetime(action_plan.deadLine()) if action_plan.deadLine()
- hash[:totalIssues] = action_plan.totalIssues() if action_plan.respond_to?('totalIssues')
- hash[:unresolvedIssues] = action_plan.unresolvedIssues() if action_plan.respond_to?('unresolvedIssues')
- hash[:createdAt] = Api::Utils.format_datetime(action_plan.createdAt()) if action_plan.createdAt()
- hash[:updatedAt] = Api::Utils.format_datetime(action_plan.updatedAt()) if action_plan.updatedAt()
- hash
+ ActionPlan.to_hash(action_plan)
end
def error_to_hash(msg)
--- /dev/null
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+class ActionPlan
+
+ def self.to_hash(action_plan)
+ hash = {:key => action_plan.key(), :name => action_plan.name(), :status => action_plan.status()}
+ hash[:project] = action_plan.projectKey() if action_plan.projectKey() && !action_plan.projectKey().blank?
+ hash[:desc] = action_plan.description() if action_plan.description() && !action_plan.description().blank?
+ hash[:userLogin] = action_plan.userLogin() if action_plan.userLogin()
+ hash[:deadLine] = Api::Utils.format_datetime(action_plan.deadLine()) if action_plan.deadLine()
+ hash[:totalIssues] = action_plan.totalIssues() if action_plan.respond_to?('totalIssues')
+ hash[:unresolvedIssues] = action_plan.unresolvedIssues() if action_plan.respond_to?('unresolvedIssues')
+ hash[:createdAt] = Api::Utils.format_datetime(action_plan.createdAt()) if action_plan.createdAt()
+ hash[:updatedAt] = Api::Utils.format_datetime(action_plan.updatedAt()) if action_plan.updatedAt()
+ hash
+ end
+
+end
\ No newline at end of file
return JsonUtils.getString(json, "assignee");
}
+ @CheckForNull
+ public String actionPlan() {
+ return JsonUtils.getString(json, "actionPlan");
+ }
+
public Date creationDate() {
return JsonUtils.getDateTime(json, "creationDate");
}
parseUsers(result, jsonRoot);
parseComponents(result, jsonRoot);
parseProjects(result, jsonRoot);
+ parseActionPlans(result, jsonRoot);
parsePaging(result, jsonRoot);
return result;
}
}
}
+ private void parseActionPlans(Issues result, Map jsonRoot) {
+ List<Map> jsonRules = (List) jsonRoot.get("actionPlans");
+ if (jsonRules != null) {
+ for (Map jsonRule : jsonRules) {
+ result.add(new ActionPlan(jsonRule));
+ }
+ }
+ }
+
List<String> parseTransitions(String json) {
List<String> transitions = new ArrayList<String>();
Map jRoot = (Map) JSONValue.parse(json);
private final Map<String, User> usersByKey = new HashMap<String, User>();
private final Map<String, Component> componentsByKey = new HashMap<String, Component>();
private final Map<String, Component> projectsByKey = new HashMap<String, Component>();
+ private final Map<String, ActionPlan> actionPlansByKey = new HashMap<String, ActionPlan>();
private Paging paging;
private Boolean maxResultsReached;
return projectsByKey.get(issue.projectKey());
}
+ public Collection<ActionPlan> actionPlans() {
+ return actionPlansByKey.values();
+ }
+
+ @CheckForNull
+ public ActionPlan actionPlans(Issue issue) {
+ return actionPlansByKey.get(issue.actionPlan());
+ }
+
public Paging paging() {
return paging;
}
return this;
}
+ Issues add(ActionPlan actionPlan) {
+ actionPlansByKey.put(actionPlan.key(), actionPlan);
+ return this;
+ }
+
Issues addComponent(Component c) {
componentsByKey.put(c.key(), c);
return this;
assertThat(first.message()).isEqualTo("the message");
assertThat(first.effortToFix()).isEqualTo(4.2);
assertThat(first.reporter()).isEqualTo("perceval");
+ assertThat(first.actionPlan()).isEqualTo("9450b10c-e725-48b8-bf01-acdec751c491");
assertThat(first.creationDate()).isNotNull();
assertThat(first.updateDate()).isNotNull();
assertThat(first.closeDate()).isNotNull();
assertThat(component.name()).isEqualTo("Struts");
assertThat(component.longName()).isEqualTo("org.struts");
}
+
+ @Test
+ public void should_parse_action_plans() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-action-plans.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+
+ assertThat(issues.actionPlans()).hasSize(1);
+
+ ActionPlan actionPlan = issues.actionPlans(issues.list().get(0));
+ assertThat(actionPlan.key()).isEqualTo("9450b10c-e725-48b8-bf01-acdec751c491");
+ assertThat(actionPlan.name()).isEqualTo("3.6");
+ assertThat(actionPlan.status()).isEqualTo("OPEN");
+ assertThat(actionPlan.project()).isEqualTo("struts");
+ assertThat(actionPlan.deadLine().getTime()).isEqualTo(1369951200000l);
+ assertThat(actionPlan.createdAt().getTime()).isEqualTo(1369828520000l);
+ assertThat(actionPlan.updatedAt().getTime()).isEqualTo(1369828520000l);
+ }
}
--- /dev/null
+{
+ "issues": [
+ {
+ "key": "ABCDE",
+ "component": "struts:Action.java",
+ "project": "struts",
+ "rule": "squid:CycleBetweenPackages",
+ "severity": "CRITICAL",
+ "status": "OPEN",
+ "actionPlan": "9450b10c-e725-48b8-bf01-acdec751c491",
+ "comments": [
+ {
+ "key": "COMMENT-1",
+ "login": "morgan",
+ "htmlText": "the first comment",
+ "createdAt": "2013-05-18T13:45:34+0200"
+ },
+ {
+ "key": "COMMENT-2",
+ "login": "arthur",
+ "htmlText": "the second comment",
+ "createdAt": "2013-06-19T00:02:03+0100"
+ }
+ ]
+ }
+ ],
+ "rules": [
+ {
+
+ "key": "squid:CycleBetweenPackages",
+ "name": "Avoid cycle between java packages",
+ "desc": "<p>\nWhen several packages are involved in a cycle (package A > package B > package C > package A where \">\" means \"depends upon\"),\nthat means that those packages are highly coupled and that there is no way to reuse/extract one of those packages without importing all the other packages.\nSuch cycle could quickly increase the effort required to maintain an application and to embrace business change.\nSonar not only detect cycles between packages but also determines what is the minimum effort to break those cycles.\nThis rule log a violation on each source file having an outgoing dependency to be but in order to break a cycle.\n</p>\n"
+
+ }
+ ],
+ "components": [
+ {
+ "key": "struts:Action.java",
+ "name": "Action",
+ "qualifier": "CLA",
+ "longName": "org.struts.Action"
+ }
+ ],
+ "projects": [
+ {
+ "key": "struts",
+ "name": "Struts",
+ "qualifier": "TRK",
+ "longName": "org.struts"
+ }
+ ],
+ "actionPlans": [
+ {
+ "key": "9450b10c-e725-48b8-bf01-acdec751c491",
+ "name": "3.6",
+ "status": "OPEN",
+ "project": "struts",
+ "userLogin": "arthur",
+ "deadLine": "2013-05-31T00:00:00+0200",
+ "createdAt": "2013-05-29T13:55:20+0200",
+ "updatedAt": "2013-05-29T13:55:20+0200"
+ }
+ ],
+ "paging": {
+ "pageIndex": 1,
+ "pageSize": 100,
+ "total": 2,
+ "pages": 1
+ },
+ "maxResultsReached": false
+}
\ No newline at end of file
"message": "the message",
"title": "the title",
"reporter": "perceval",
+ "actionPlan": "9450b10c-e725-48b8-bf01-acdec751c491",
"creationDate": "2013-05-18T12:45:34+0200",
"updateDate": "2013-05-18T13:45:34+0200",
"closeDate": "2013-05-18T14:45:34+0200",