001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 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 */
020 package org.sonar.wsclient.services;
021
022 /**
023 * The web service "dependency" is since Sonar 2.0
024 */
025 public class DependencyQuery extends Query<Dependency> {
026 public static final String BASE_URL = "/api/dependencies";
027
028 private String resourceIdOrKey = null;
029 private String direction = null;
030 private String parentId = null;
031 private String id = null;
032 public static final String INCOMING_DIRECTION = "in";
033 public static final String OUTGOING_DIRECTION = "out";
034
035 public String getResourceIdOrKey() {
036 return resourceIdOrKey;
037 }
038
039 public DependencyQuery setResourceIdOrKey(String resourceIdOrKey) {
040 this.resourceIdOrKey = resourceIdOrKey;
041 return this;
042 }
043
044 public DependencyQuery setResourceId(long resourceId) {
045 this.resourceIdOrKey = String.valueOf(resourceId);
046 return this;
047 }
048
049 public String getDirection() {
050 return direction;
051 }
052
053 public DependencyQuery setDirection(String direction) {
054 this.direction = direction;
055 return this;
056 }
057
058 @Override
059 public String getUrl() {
060 StringBuilder url = new StringBuilder(BASE_URL);
061 url.append('?');
062 appendUrlParameter(url, "resource", resourceIdOrKey);
063 appendUrlParameter(url, "dir", direction);
064 appendUrlParameter(url, "parent", parentId);
065 appendUrlParameter(url, "id", id);
066 return url.toString();
067 }
068
069 public String getParentId() {
070 return parentId;
071 }
072
073 public String getId() {
074 return id;
075 }
076
077 public DependencyQuery setId(String id) {
078 this.id = id;
079 return this;
080 }
081
082 public DependencyQuery setParentId(String parentId) {
083 this.parentId = parentId;
084 return this;
085 }
086
087 @Override
088 public Class<Dependency> getModelClass() {
089 return Dependency.class;
090 }
091
092 /**
093 * Resources that depend upon a resource
094 *
095 * @param resourceIdOrKey the target resource. Can be the primary key (a number) or the logical key (String)
096 */
097 public static DependencyQuery createForIncomingDependencies(String resourceIdOrKey) {
098 DependencyQuery query = new DependencyQuery();
099 query.setResourceIdOrKey(resourceIdOrKey);
100 query.setDirection(INCOMING_DIRECTION);
101 return query;
102 }
103
104 /**
105 * Resources that are depended upon a resource = all the resources that a resource depends upon
106 *
107 * @param resourceIdOrKey the target resource. Can be the primary key (an integer) or the logical key (String)
108 */
109 public static DependencyQuery createForOutgoingDependencies(String resourceIdOrKey) {
110 DependencyQuery query = new DependencyQuery();
111 query.setResourceIdOrKey(resourceIdOrKey);
112 query.setDirection(OUTGOING_DIRECTION);
113 return query;
114 }
115
116 /**
117 * Resources that depend upon or are depended upon a resource. It equals the merge of createForIncomingDependencies(resourceIdOrKey)
118 * and createForOutgoingDependencies(resourceIdOrKey)
119 *
120 * @param resourceIdOrKey the target resource. Can be the primary key (an integer) or the logical key (String)
121 */
122 public static DependencyQuery createForResource(String resourceIdOrKey) {
123 DependencyQuery query = new DependencyQuery();
124 query.setResourceIdOrKey(resourceIdOrKey);
125 return query;
126 }
127
128 public static DependencyQuery createForResource(long resourceId) {
129 DependencyQuery query = new DependencyQuery();
130 query.setResourceId(resourceId);
131 return query;
132 }
133
134 public static DependencyQuery createForSubDependencies(String dependencyId) {
135 DependencyQuery query = new DependencyQuery();
136 query.setParentId(dependencyId);
137 return query;
138 }
139
140 public static DependencyQuery createForId(String id) {
141 DependencyQuery query = new DependencyQuery();
142 query.setId(id);
143 return query;
144 }
145 }