Skip to main content
summaryrefslogtreecommitdiffstats
blob: 648f02b9cd705ff0e4eb0d2bf7582957d44542a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.tasks.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

/**
 * This data structure is not to be subclassed but rather used directly to hold
 * repository task data (attribute key, value pairs along with valid options for
 * each attribute).
 * 
 * @author Mik Kersten
 * @author Rob Elves
 */
public final class RepositoryTaskData extends AttributeContainer implements Serializable {

	private static final long serialVersionUID = 2304501248225237699L;

	private boolean hasLocalChanges = false;

	private boolean isNew = false;

	private String reportID;

	private String repositoryURL;

	private String repositoryKind;

	private String taskKind;

	private List<TaskComment> taskComments = new ArrayList<TaskComment>();

	private List<RepositoryAttachment> attachments = new ArrayList<RepositoryAttachment>();

	/** The operation that was selected to do to the bug */
	private RepositoryOperation selectedOperation = null;

	/** The repositoryOperations that can be done on the report */
	private List<RepositoryOperation> repositoryOperations = new ArrayList<RepositoryOperation>();

	public RepositoryTaskData(AbstractAttributeFactory factory, String repositoryKind, String repositoryURL, String id,
			String taskKind) {
		super(factory);
		this.reportID = id;
		this.repositoryKind = repositoryKind;
		this.repositoryURL = repositoryURL;
		this.taskKind = taskKind;
	}

	public String getLabel() {
		if (isNew()) {
			return "<unsubmitted> " + this.getRepositoryUrl();
		} else {
			return getSummary();
		}
	}

	/**
	 * Get the resolution of the bug
	 * 
	 * @return The resolution of the bug
	 */
	public String getResolution() {
		return getAttributeValue(RepositoryTaskAttribute.RESOLUTION);
	}

	/**
	 * Get the status of the bug
	 * 
	 * @return The bugs status
	 */
	public String getStatus() {
		return getAttributeValue(RepositoryTaskAttribute.STATUS);
	}

	public String getLastModified() {
		return getAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED);
	}

	public void setSelectedOperation(RepositoryOperation o) {
		selectedOperation = o;
	}

	public RepositoryOperation getSelectedOperation() {
		return selectedOperation;
	}

	/**
	 * Get all of the repositoryOperations that can be done to the bug
	 * 
	 * @return The repositoryOperations that can be done to the bug
	 */
	public List<RepositoryOperation> getOperations() {
		return repositoryOperations;
	}

	/**
	 * Get the person who reported the bug
	 * 
	 * @return The person who reported the bug
	 */
	public String getReporter() {
		return getAttributeValue(RepositoryTaskAttribute.USER_REPORTER);
	}

	/**
	 * Get an operation from the bug based on its display name
	 * 
	 * @param displayText
	 *            The display text for the operation
	 * @return The operation that has the display text
	 */
	public RepositoryOperation getOperation(String displayText) {
		Iterator<RepositoryOperation> itr = repositoryOperations.iterator();
		while (itr.hasNext()) {
			RepositoryOperation o = itr.next();
			String opName = o.getOperationName();
			opName = opName.replaceAll("</.*>", "");
			opName = opName.replaceAll("<.*>", "");
			if (opName.equals(displayText))
				return o;
		}
		return null;
	}

	/**
	 * Get the summary for the bug
	 * 
	 * @return The bugs summary
	 */
	public String getSummary() {
		return getAttributeValue(RepositoryTaskAttribute.SUMMARY);
	}

	public void setSummary(String summary) {
		setAttributeValue(RepositoryTaskAttribute.SUMMARY, summary);
	}

	public String getProduct() {
		return getAttributeValue(RepositoryTaskAttribute.PRODUCT);
	}

	/**
	 * true if this is a new, unsubmitted task false otherwise
	 */
	public boolean isNew() {
		return isNew;
	}

	public void setNew(boolean isNew) {
		this.isNew = isNew;
	}

	/**
	 * Get the date that the bug was created
	 * 
	 * @return The bugs creation date
	 */
	public String getCreated() {
		return getAttributeValue(RepositoryTaskAttribute.DATE_CREATION);
	}

	/**
	 * Get the keywords for the bug
	 * 
	 * @return The keywords for the bug
	 */
	public List<String> getKeywords() {

		// get the selected keywords for the bug
		StringTokenizer st = new StringTokenizer(getAttributeValue(RepositoryTaskAttribute.KEYWORDS), ",", false);
		List<String> keywords = new ArrayList<String>();
		while (st.hasMoreTokens()) {
			String s = st.nextToken().trim();
			keywords.add(s);
		}

		return keywords;
	}

	/**
	 * Add an operation to the bug
	 * 
	 * @param o
	 *            The operation to add
	 */
	public void addOperation(RepositoryOperation o) {
		repositoryOperations.add(o);
	}

	public List<String> getCC() {
		return getAttributeValues(RepositoryTaskAttribute.USER_CC);
	}

	public void removeCC(String email) {
		removeAttributeValue(RepositoryTaskAttribute.USER_CC, email);
	}

	public String getAssignedTo() {
		return getAttributeValue(RepositoryTaskAttribute.USER_ASSIGNED);
	}

	/**
	 * Get the new comment that is to be added to the bug
	 */
	public String getNewComment() {
		RepositoryTaskAttribute attribute = getAttribute(RepositoryTaskAttribute.COMMENT_NEW);
		return (attribute != null) ? attribute.getValue() : "";
	}

	/**
	 * Set the new comment that will be added to the bug
	 */
	public void setNewComment(String newComment) {
		setAttributeValue(RepositoryTaskAttribute.COMMENT_NEW, newComment);
	}

	public void addComment(TaskComment taskComment) {
		taskComments.add(taskComment);
	}

	public List<TaskComment> getComments() {
		return taskComments;
	}

	public void setDescription(String description) {
		setAttributeValue(RepositoryTaskAttribute.DESCRIPTION, description);
	}

	public String getDescription() {
		RepositoryTaskAttribute attribute = getDescriptionAttribute();
		return (attribute != null) ? attribute.getValue() : "";
	}

	public RepositoryTaskAttribute getDescriptionAttribute() {
		RepositoryTaskAttribute attribute = getAttribute(RepositoryTaskAttribute.DESCRIPTION);
		// TODO: Remove the following after 1.0 release as we now just have a
		// summary attribute
		if (attribute == null) {
			List<TaskComment> coms = this.getComments();
			if (coms != null && coms.size() > 0) {
				return coms.get(0).getAttribute(RepositoryTaskAttribute.COMMENT_TEXT);
			}
		}
		return attribute;
	}

	public void addAttachment(RepositoryAttachment attachment) {
		attachments.add(attachment);
	}

	public List<RepositoryAttachment> getAttachments() {
		return attachments;
	}

	public String getId() {
		return reportID;
	}

	public String getTaskKey() {
		RepositoryTaskAttribute attr = getAttribute(RepositoryTaskAttribute.TASK_KEY);
		if (attr != null) {
			return attr.getValue();
		}
		return getId();
	}
	
	/**
	 * @return the server for this report
	 */
	public String getRepositoryUrl() {
		return repositoryURL;
	}

	@Deprecated
	public boolean hasLocalChanges() {
		return hasLocalChanges;
	}

	@Deprecated
	public void setHasLocalChanges(boolean b) {
		hasLocalChanges = b;
	}

	@Override
	public List<String> getAttributeValues(String key) {
		RepositoryTaskAttribute attribute = getAttribute(key);
		if (attribute != null) {
			return attribute.getValues();
		}
		return new ArrayList<String>();
	}

	public void removeAttributeValue(String key, String value) {
		RepositoryTaskAttribute attrib = getAttribute(key);
		if (attrib != null) {
			attrib.removeValue(value);
		}
	}

	public String getRepositoryKind() {
		return repositoryKind;
	}

	@Override
	public void setAttributeFactory(AbstractAttributeFactory factory) {
		super.setAttributeFactory(factory);
		for (TaskComment taskComment : taskComments) {
			taskComment.setAttributeFactory(factory);
		}
		for (RepositoryAttachment attachment : attachments) {
			attachment.setAttributeFactory(factory);
		}
	}

	public String getTaskKind() {
		return taskKind;
	}

	public void setRepositoryURL(String repositoryURL) {
		this.repositoryURL = repositoryURL;
	}
	
//	public final String getHandleIdentifier() {
//		return RepositoryTaskHandleUtil.getHandle(getRepositoryUrl(), getId());
//	}
}

Back to the top