+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client;
-
-import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.Widget;
-import org.sonar.api.web.gwt.client.webservices.*;
-
-import java.util.Arrays;
-
-public abstract class AbstractViewer implements EntryPoint {
-
- public static final String HTML_ROOT_ID = "resource_viewers";
-
- private Resource resource;
- private String renderedResourceKey = "";
- private Panel widgetPanel = null;
- private boolean standAloneMode = true;
-
- public void onModuleLoad() {
- exportJavascript();
- }
-
- /**
- * Export GWT javascript methods to load and control the plugin, must export currently 2 method :
- * I.E for plugin GWT id : foo.bar.MyPlugin, class foo.bar.client.MyPlugin :
- * <p/>
- * $wnd.load_foo_bar_MyPlugin = function() {
- * called to the plugin init from JS
- * obj.@foo.bar.client.MyPlugin::loadContainer()();
- * }
- * $wnd.on_resource_loaded_foo_bar_MyPlugin = function() {
- * called when a resource JSON object has been refreshed within the page
- * obj.@foo.bar.client.MyPlugin::onResourceLoaded()();
- * }
- */
- protected abstract void exportJavascript();
-
- /**
- * When multiple widgets are bound to the same HTML div, this method will indicate
- * If the resource widget is the default one to show when the widget is initialized
- *
- * @param metric the metric for which the widget is shown, cannot be null
- * @param resource the resource bound to the widget
- * @return true or false
- */
- protected abstract boolean isDefault(WSMetrics.Metric metric, Resource resource);
-
- /**
- * Finds if a given metric is in the provided metrics list
- *
- * @param metric the metric to search
- * @param metricsList the metric list
- * @return true or false if not found
- */
- protected boolean isMetricInList(WSMetrics.Metric metric, WSMetrics.Metric... metricsList) {
- return Arrays.asList(metricsList).contains(metric);
- }
-
- /**
- * When multiple widgets are in the same page, this method will indicate if the widget
- * can be shown for the given resource
- *
- * @param resource the resource bound to the page
- * @return true or false
- */
- protected abstract boolean isForResource(Resource resource);
-
-
- public Resource getResource() {
- return resource;
- }
-
- private Resource loadResource() {
- JavaScriptObject resourceJson = getResourceJSONObject();
- if (resourceJson != null) {
- Resource resourceLoaded = ResourcesQuery.parseResources(resourceJson).get(0);
- String currentMetricKey = ResourceDictionary.getViewerMetricKey();
- Boolean isDefaultForMetric = false;
- if (currentMetricKey != null) {
- isDefaultForMetric = isDefault(WSMetrics.get(currentMetricKey), resourceLoaded);
- }
- exportJSBooleanVariable("is_default_for_metric", Utils.widgetGWTIdJSEncode(getGwtId()), isDefaultForMetric);
- exportJSBooleanVariable("is_for_resource", Utils.widgetGWTIdJSEncode(getGwtId()), isForResource(resourceLoaded));
- return resourceLoaded;
- }
- return null;
- }
-
- /**
- * Called when a resource JSON object has been loaded within the page
- */
- public final void onResourceLoaded() {
- resource = loadResource();
- standAloneMode = false;
- }
-
- /**
- * Called to render the widget for the given resource object loaded via the onResourceLoaded() method call
- */
- public final void loadContainer() {
- String resourceKey = ResourceDictionary.getViewerResourceKey();
- if (resourceKey != null) {
- if (!standAloneMode && resource == null) {
- Utils.showError("Unable to find JSON resource object, unable to render widget");
- return;
- } else if (standAloneMode && resource == null) {
- getResourceJsonObject(resourceKey);
- return;
- }
- String currentResourceKey = isANumber(resourceKey) ? resource.getId().toString() : resource.getKey();
- if (!renderedResourceKey.equals(currentResourceKey)) {
- // resource key has changed reload if not in standalone mode
- if (!standAloneMode) {
- resource = loadResource();
- }
-
- if (widgetPanel == null) {
- RootPanel rootPanel = RootPanel.get(HTML_ROOT_ID);
- if (rootPanel == null) {
- Utils.showError("Unable to find root panel " + HTML_ROOT_ID + " in page");
- }
- widgetPanel = new FlowPanel();
- widgetPanel.setStyleName("gwt-ResourceTab");
- String panelId = "tab-" + Utils.widgetGWTIdJSEncode(getGwtId());
- widgetPanel.getElement().setId(panelId);
- registerTab(panelId);
- widgetPanel.setVisible(false);
- rootPanel.add(widgetPanel);
- }
-
- renderedResourceKey = resourceKey;
-
- if (widgetPanel != null) {
- widgetPanel.clear();
- widgetPanel.add(render(resource));
- }
- }
- }
-
- if (widgetPanel != null) {
- widgetPanel.setVisible(true);
- }
- }
-
- private static native void registerTab(Object tabId) /*-{
- $wnd.registeredTabs.push(tabId);
- }-*/;
-
-
- private native void exportJSBooleanVariable(String varPrefix, String encodedGWTId, boolean value)/*-{
- $wnd.config[varPrefix + "_" + encodedGWTId] = value;
- }-*/;
-
- /**
- * Return the GWT id of the widget
- */
- protected abstract String getGwtId();
-
- /**
- * Renders the widget for the current resource
- */
- protected abstract Widget render(Resource resource);
-
- /**
- * Return a JavaScriptObject object containing all the measure available for the current resource key
- *
- * @return the JavaScriptObject instance, should never be null
- */
- protected native JavaScriptObject getResourceJSONObject()/*-{
- return $wnd.config['current_resource'];
- }-*/;
-
-
- private boolean isANumber(String resourceKey) {
- boolean isIdResourceKey = true;
- try {
- Integer.parseInt(resourceKey);
- } catch (NumberFormatException ex) {
- isIdResourceKey = false;
- }
- return isIdResourceKey;
- }
-
- private void getResourceJsonObject(String resourceKey) {
- ResourcesQuery.get(resourceKey).execute(new StandAloneResourceHandler());
- }
-
- public class StandAloneResourceHandler extends BaseQueryCallback<Resources> {
- public void onResponse(Resources resources, JavaScriptObject jsonResponse) {
- resource = resources.firstResource();
- loadContainer();
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-import java.util.Map;
-
-/**
- * @deprecated since 2.5, use {@link org.sonar.wsclient.services.Source} instead.
- */
-@Deprecated
-public class FileSource extends ResponsePOJO {
-
- private Map<Integer, String> sourceLines;
-
- public FileSource(Map<Integer, String> sourceLines) {
- super();
- this.sourceLines = sourceLines;
- }
-
- public Map<Integer, String> getLines() {
- return sourceLines;
- }
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-import java.util.List;
-
-/**
- * @deprecated since 2.5
- */
-@Deprecated
-public class Properties extends ResponsePOJO {
-
- private List<Property> properties;
-
- public Properties(List<Property> properties) {
- this.properties = properties;
- }
-
- public List<Property> getProperties() {
- return properties;
- }
-
- public String get(String key, String defaultValue) {
- for (Property property : properties) {
- if (property.getKey().equals(key)) {
- return property.getValue();
- }
- }
- return defaultValue;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.api.web.gwt.client.Utils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @deprecated since 2.5, use {@link org.sonar.wsclient.services.PropertyQuery} instead.
- */
-@Deprecated
-public final class PropertiesQuery extends Query<Properties> {
-
- private String key;
-
- public PropertiesQuery() {
- }
-
- public PropertiesQuery(String key) {
- this.key = key;
- }
-
- @Override
- public String toString() {
- String url = Utils.getServerApiUrl() + "/properties";
- if (key != null) {
- url += "/" + key;
- }
- return url + "?";
- }
-
- @Override
- public void execute(QueryCallBack<Properties> callback) {
- JsonUtils.requestJson(this.toString(), new JSONHandlerDispatcher<Properties>(callback) {
- @Override
- public Properties parseResponse(JavaScriptObject obj) {
- return new Properties(parseProperties(obj));
- }
-
- private List<Property> parseProperties(JavaScriptObject obj) {
- JSONArray array = new JSONArray(obj);
- List<Property> properties = new ArrayList<Property>();
- for (int i = 0; i < array.size(); i++) {
- JSONObject jsonObject = array.get(i).isObject();
- if (jsonObject != null) {
- properties.add(parseProperty(jsonObject));
- }
- }
- return properties;
- }
-
- private Property parseProperty(JSONObject json) {
- return new Property(JsonUtils.getString(json, "key"), JsonUtils.getString(json, "value"));
- }
- });
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-/**
- * @deprecated since 2.5, use {@link org.sonar.wsclient.services.Property} instead
- */
-@Deprecated
-public class Property extends ResponsePOJO {
-
- private String key;
- private String value;
-
- public Property() {
- }
-
- public Property(String key, String value) {
- this.key = key;
- this.value = value;
- }
-
- public String getKey() {
- return key;
- }
-
- public Property setKey(String key) {
- this.key = key;
- return this;
- }
-
- public String getValue() {
- return value;
- }
-
- public Property setValue(String value) {
- this.value = value;
- return this;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
-import org.sonar.api.web.gwt.client.Utils;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * @deprecated since 2.5, use {@link org.sonar.wsclient.services.SourceQuery} instead
- */
-@Deprecated
-public final class SourcesQuery extends AbstractResourceQuery<FileSource> {
-
- private Integer from;
- private Integer length;
- private boolean color;
-
- public static SourcesQuery get(String resourceKey) {
- return new SourcesQuery(resourceKey);
- }
-
- private SourcesQuery(String resourceKey) {
- super(resourceKey);
- }
-
- public SourcesQuery setFrom(Integer from) {
- this.from = from;
- return this;
- }
-
- public SourcesQuery setLength(Integer length) {
- this.length = length;
- return this;
- }
-
- public SourcesQuery setColor(boolean color) {
- this.color = color;
- return this;
- }
-
- @Override
- public String toString() {
- String url = Utils.getServerApiUrl() + "/sources?resource=" + getResourceKey() + "&";
- if (length > 0) {
- url += "from=" + from + "&to=" + (from + length) + "&";
- }
- if (color) {
- url += "color=true&";
- }
- return url;
- }
-
- @Override
- public void execute(QueryCallBack<FileSource> callback) {
- JsonUtils.requestJson(this.toString(), new JSONHandlerDispatcher<FileSource>(callback) {
- @Override
- public FileSource parseResponse(JavaScriptObject obj) {
- return parseLines(obj);
- }
- });
- }
-
- private FileSource parseLines(JavaScriptObject obj) {
- Map<Integer, String> sourceLines = new TreeMap<Integer, String>();
- FileSource src = new FileSource(sourceLines);
- JSONArray jsonArray = new JSONArray(obj);
- if (jsonArray.size() == 0)
- return src;
- JSONObject sources = jsonArray.get(0).isObject();
- if (sources.size() == 0)
- return src;
- int maxSize = new Double(Math.pow(2, 16)).intValue();
- int currentLine = from == 0 ? 1 : from;
- while (currentLine < maxSize) {
- JSONValue line = sources.get(Integer.toString(currentLine));
- if (line == null) {
- break;
- }
- sourceLines.put(currentLine++, line.isString().stringValue());
- }
- return src;
- }
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-/**
- * @deprecated since 2.5, use {@link org.sonar.wsclient.services.Violation} instead.
- */
-@Deprecated
-public class Violation {
-
- private String message;
- private String priority;
- private int line;
- private Rule rule;
- private Resource resource;
-
- public Violation(String message, String priority, int line, Rule rule, Resource resource) {
- this.message = message;
- this.priority = priority;
- this.line = line;
- this.rule = rule;
- this.resource = resource;
- }
-
- public Violation() {
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String getPriority() {
- return priority;
- }
-
- public void setPriority(String priority) {
- this.priority = priority;
- }
-
- public int getLine() {
- return line;
- }
-
- public void setLine(int line) {
- this.line = line;
- }
-
- public Rule getRule() {
- return rule;
- }
-
- public void setRule(Rule rule) {
- this.rule = rule;
- }
-
- public Resource getResource() {
- return resource;
- }
-
- public void setResource(Resource resource) {
- this.resource = resource;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @deprecated since 2.5
- */
-@Deprecated
-public class Violations extends ResponsePOJO {
- private List<Violation> violations;
- private Map<Integer, List<Violation>> byLines;
-
- public Violations(List<Violation> violations) {
- this.violations = violations;
- }
-
- public Violations() {
- this.violations = new ArrayList<Violation>();
- }
-
- public void add(Violation v) {
- violations.add(v);
- byLines = null;
- }
-
- public List<Violation> getAll() {
- return violations;
- }
-
- public Map<Integer, List<Violation>> getByLines() {
- if (byLines == null) {
- byLines = new HashMap<Integer, List<Violation>>();
- for (Violation violation : violations) {
- List<Violation> lineViolations = byLines.get(violation.getLine());
- if (lineViolations == null) {
- lineViolations = new ArrayList<Violation>();
- byLines.put(violation.getLine(), lineViolations);
- }
- lineViolations.add(violation);
- }
- }
- return byLines;
- }
-
- public String getLevelForLine(Integer line) {
- List<Violation> lineViolations = getByLines().get(line);
- String level = "";
- if (lineViolations != null) {
- for (Violation lineViolation : lineViolations) {
- if ("BLOCKER".equals(lineViolation.getPriority()) || "CRITICAL".equals(lineViolation.getPriority())
- || "MAJOR".equals(lineViolation.getPriority())) {
- level = "error";
-
- } else if (!"error".equals(level)) {
- level = "warning";
- }
- }
- }
- return level;
- }
-
- public int countForLine(Integer line) {
- List<Violation> lineViolations = getByLines().get(line);
- if (lineViolations == null) {
- return 0;
- }
- return lineViolations.size();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.web.gwt.client.webservices;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
-import org.sonar.api.web.gwt.client.Utils;
-
-/**
- * @deprecated since 2.5, use {@link org.sonar.wsclient.services.ViolationQuery} instead.
- */
-@Deprecated
-public final class ViolationsQuery extends AbstractResourceQuery<Violations> {
-
- private String scopes;
- private String qualifiers;
- private String rules;
- private String priorities;
- private Integer depth;
-
- private ViolationsQuery(String resourceKey) {
- super(resourceKey);
- }
-
- public static ViolationsQuery create(String resourceKey) {
- return new ViolationsQuery(resourceKey);
- }
-
- public String getScopes() {
- return scopes;
- }
-
- public ViolationsQuery setScopes(String scopes) {
- this.scopes = scopes;
- return this;
- }
-
- public String getQualifiers() {
- return qualifiers;
- }
-
- public ViolationsQuery setQualifiers(String qualifiers) {
- this.qualifiers = qualifiers;
- return this;
- }
-
- public String getRules() {
- return rules;
- }
-
- public ViolationsQuery setRules(String rules) {
- this.rules = rules;
- return this;
- }
-
- /**
- * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
- */
- @Deprecated
- public String getCategories() {
- return null;
- }
-
- /**
- * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
- */
- @Deprecated
- public ViolationsQuery setCategories(String s) {
- return this;
- }
-
- public Integer getDepth() {
- return depth;
- }
-
- public ViolationsQuery setDepth(Integer depth) {
- this.depth = depth;
- return this;
- }
-
- public String getPriorities() {
- return priorities;
- }
-
- public ViolationsQuery setPriorities(String priorities) {
- this.priorities = priorities;
- return this;
- }
-
- @Override
- public String toString() {
- String url = Utils.getServerApiUrl() + "/violations?resource=" + getResourceKey() + "&";
- if (depth != null) {
- url += "depth=" + depth + "&";
- }
- if (scopes != null) {
- url += "scopes=" + scopes + "&";
- }
- if (qualifiers != null) {
- url += "qualifiers=" + qualifiers + "&";
- }
- if (rules != null) {
- url += "rules=" + rules + "&";
- }
- if (priorities != null) {
- url += "priorities=" + priorities + "&";
- }
- return url;
- }
-
- @Override
- public void execute(final QueryCallBack<Violations> callback) {
- JsonUtils.requestJson(this.toString(), new JSONHandlerDispatcher<Violations>(callback) {
- @Override
- public Violations parseResponse(JavaScriptObject obj) {
- return parseJSON(obj);
- }
- });
- }
-
- private Violations parseJSON(JavaScriptObject obj) {
- Violations result = new Violations();
- JSONArray jsonArray = new JSONArray(obj);
- for (int i = 0; i < jsonArray.size(); i++) {
- JSONObject jsViolation = jsonArray.get(i).isObject();
- if (jsViolation == null) {
- continue;
- }
- JSONString message = jsViolation.get("message").isString();
- JSONString priority = jsViolation.get("priority").isString();
- JSONValue lineJson = jsViolation.get("line");
- int lineIndex = 0;
- if (lineJson != null) {
- lineIndex = (int) lineJson.isNumber().doubleValue();
- }
-
- JSONObject ruleObj = jsViolation.get("rule").isObject();
- Rule rule = new Rule(
- JsonUtils.getString(ruleObj, "key"),
- JsonUtils.getString(ruleObj, "name"));
-
- result.add(new Violation(message.stringValue(), priority.stringValue(), lineIndex, rule, null));
- }
- return result;
- }
-
-}