1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.commons.crucible.api.model;
18
19 import com.atlassian.theplugin.commons.cfg.ServerId;
20 import org.apache.commons.lang.StringUtils;
21
22
23 public class CustomFilterBean implements CustomFilter {
24 private ServerId serverUid = new ServerId();
25 private String title = "";
26 private State[] state = new State[0];
27 private String author = "";
28 private String moderator = "";
29 private String creator = "";
30 private String reviewer = "";
31 private boolean orRoles;
32 private Boolean complete;
33 private Boolean allReviewersComplete;
34 private String projectKey = "";
35 private boolean enabled;
36 private static final double ID_DISCRIMINATOR = 1002d;
37 private static final int HASHCODE_CONSTANT = 31;
38 private static final int SHIFT_32 = 32;
39 public static final String FILTER_ID = "MANUAL_FILTER_ID";
40 private final String filterName = "Custom";
41 private final String filterUrl = "";
42
43 @Override
44 public boolean equals(Object o) {
45 if (this == o) {
46 return true;
47 }
48 if (o == null || getClass() != o.getClass()) {
49 return false;
50 }
51
52 CustomFilterBean that = (CustomFilterBean) o;
53
54 if (uid != that.uid) {
55 return false;
56 }
57 if (!filterName.equals(that.filterName)) {
58 return false;
59 }
60
61 return true;
62 }
63
64 @Override
65 public int hashCode() {
66 int result;
67 result = (filterName != null ? filterName.hashCode() : 0);
68 result = HASHCODE_CONSTANT * result + (int) (uid ^ (uid >>> SHIFT_32));
69 return result;
70 }
71
72 private transient long uid = System.currentTimeMillis() + (long) (Math.random() * ID_DISCRIMINATOR);
73
74 public String getServerUid() {
75 return serverUid.toString();
76 }
77
78 public void setServerUid(String serverUid) {
79 this.serverUid = new ServerId(serverUid);
80 }
81
82 public CustomFilterBean() {
83 }
84
85 public String getTitle() {
86 return title;
87 }
88
89 public void setTitle(String title) {
90 this.title = title;
91 }
92
93 public State[] getState() {
94 return state;
95 }
96
97 public void setState(State[] state) {
98 this.state = state;
99 }
100
101 public String getAuthor() {
102 return author;
103 }
104
105 public void setAuthor(String author) {
106 this.author = author;
107 }
108
109 public String getModerator() {
110 return moderator;
111 }
112
113 public void setModerator(String moderator) {
114 this.moderator = moderator;
115 }
116
117 public String getCreator() {
118 return creator;
119 }
120
121 public void setCreator(String creator) {
122 this.creator = creator;
123 }
124
125 public String getReviewer() {
126 return reviewer;
127 }
128
129 public void setReviewer(String reviewer) {
130 this.reviewer = reviewer;
131 }
132
133 public Boolean isComplete() {
134 return complete;
135 }
136
137 public void setComplete(Boolean complete) {
138 this.complete = complete;
139 }
140
141 public Boolean isAllReviewersComplete() {
142 return allReviewersComplete;
143 }
144
145 public void setAllReviewersComplete(Boolean allReviewersComplete) {
146 this.allReviewersComplete = allReviewersComplete;
147 }
148
149 public String getProjectKey() {
150 return projectKey;
151 }
152
153 public void setProjectKey(String projectKey) {
154 this.projectKey = projectKey;
155 }
156
157 public boolean isOrRoles() {
158 return orRoles;
159 }
160
161 public void setOrRoles(boolean orRoles) {
162 this.orRoles = orRoles;
163 }
164
165 public boolean isEnabled() {
166 return enabled;
167 }
168
169 public void setEnabled(boolean enabled) {
170 this.enabled = enabled;
171 }
172
173 public String getId() {
174 return FILTER_ID;
175 }
176
177 public String getFilterName() {
178 return filterName;
179 }
180
181 public String getFilterUrl() {
182 return prepareCustomFilterUrl();
183 }
184
185 private String prepareCustomFilterUrl() {
186 StringBuilder url = new StringBuilder();
187
188 addQueryParam(AUTHOR, getAuthor(), url);
189 addQueryParam(CREATOR, getCreator(), url);
190 addQueryParam(MODERATOR, getModerator(), url);
191 addQueryParam(REVIEWER, getReviewer(), url);
192 addQueryParam(PROJECT, getProjectKey(), url);
193 String stateParam = getStates();
194 addQueryParam(STATES, stateParam, url);
195
196 if (isComplete() != null) {
197 addQueryParam(COMPLETE, Boolean.toString(isComplete()), url);
198 }
199 addQueryParam(ORROLES, Boolean.toString(isOrRoles()), url);
200 if (isAllReviewersComplete() != null) {
201 addQueryParam(ALLCOMPLETE, Boolean.toString(isAllReviewersComplete()), url);
202 }
203
204 String urlString = url.toString();
205 return urlString.equals("?") ? "" : urlString;
206 }
207
208 private void addQueryParam(String name, String value, StringBuilder builder) {
209 if (!StringUtils.isEmpty(value)) {
210 if (builder.length() > 0) {
211 builder.append("&");
212 }
213 builder.append(name).append("=").append(value);
214 }
215 }
216
217 public String getStates() {
218 String stateParam = "";
219 if (getState() != null) {
220 for (State s : getState()) {
221 if (stateParam.length() > 0) {
222 stateParam += ",";
223 }
224 stateParam += s.value();
225 }
226 }
227 return stateParam;
228 }
229 }