Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0eab892ccd81511b8d6169c5d74577546b3e705f (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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*******************************************************************************
 * 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.mylar.tasks.core;

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

/**
 * @author Mik Kersten
 * @author Rob Elves
 */
public class RepositoryTaskData extends AttributeContainer implements Serializable {

	private static final long serialVersionUID = 2746931358107812373L;

	public static final String VAL_STATUS_NEW = "NEW";
	
	private String reportID;

	private boolean hasChanges = false;
	
	private String repositoryURL;

	protected String newComment = "";
		
	private List<TaskComment> taskComments = new ArrayList<TaskComment>();

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


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

	/** Whether or not this bug report is saved offline. */
	protected boolean savedOffline = false;

	protected String charset = null;

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

	// private static final RepositoryTaskAttributeFactory attributeFactory =
	// new BugzillaAttributeFactory();

	// /** Parser for dates in the report */
	// private static SimpleDateFormat delta_ts_format = new
	// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	//
	// private static SimpleDateFormat creation_ts_format = new
	// SimpleDateFormat("yyyy-MM-dd HH:mm");

	/** The bugs valid keywords */
	protected List<String> validKeywords;

	/** Description of the bug */
	protected String description;

	/** Creation timestamp */
	protected Date created;

	/** Modification timestamp */
	protected Date lastModified = null;

	protected String repositoryKind;

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

//	/**
//	 * TODO: move?
//	 */
//	public static boolean isResolvedStatus(String status) {
//		if (status != null) {
//			return status.equals(VAL_STATUS_RESOLVED) || status.equals(VAL_STATUS_CLOSED)
//					|| status.equals(VAL_STATUS_VERIFIED);
//		} else {
//			return false;
//		}
//	}

	public String getLabel() {
		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);
		// return
		// getAttributeValue(BugzillaReportElement.REPORTER.getKeyString());
	}

	/**
	 * 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);
		// return
		// getAttributeValue(BugzillaReportElement.SHORT_DESC.getKeyString());
	}

	public void setSummary(String summary) {
		throw new NullPointerException("not impelmented");
		// setAttributeValue(RepositoryTaskAttribute.SHORT_DESC, summary);
		// setAttributeValue(BugzillaReportElement.SHORT_DESC.getKeyString(),
		// summary);
	}

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

	public boolean isLocallyCreated() {
		return false;
	}

//	public boolean isResolved() {
//		return isResolvedStatus(getStatus());
//	}

	/**
	 * 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);
		// return getAttributeValues(BugzillaReportElement.CC.getKeyString());
	}

	public void removeCC(String email) {
		removeAttributeValue(RepositoryTaskAttribute.USER_CC, email);
		// removeAttributeValue(BugzillaReportElement.CC.getKeyString(), email);
	}

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

	/**
	 * Get the new comment that is to be added to the bug
	 */
	public String getNewComment() {
		return newComment;
	}

	/**
	 * Set the new comment that will be added to the bug
	 */
	public void setNewComment(String newComment) {
		this.newComment = newComment;
	}

	public void addComment(TaskComment taskComment) {
		TaskComment preceding = null;
		if (taskComments.size() > 0) {
			// if there are some comments, get the last comment and set the next
			// value to be the new comment
			preceding = taskComments.get(taskComments.size() - 1);
			preceding.setNext(taskComment);
		}
		taskComment.setPrevious(preceding);
		taskComments.add(taskComment);
	}

	public List<TaskComment> getComments() {
		return taskComments;
	}
	
	public void setDescription(String description) {
		RepositoryTaskAttribute attribute = getDescriptionAttribute();
		if(attribute != null) {
			attribute.setValue(description);
		}
	}

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

	public RepositoryTaskAttribute getDescriptionAttribute() {
		RepositoryTaskAttribute attribute = getAttribute(RepositoryTaskAttribute.DESCRIPTION);
		if (attribute != null) {
			return attribute;
		} else {
			List<TaskComment> coms = this.getComments();
			if (coms != null && coms.size() > 0) {
				return coms.get(0).getAttribute(RepositoryTaskAttribute.COMMENT_TEXT);
			}
		}
		return null;
	}
	
	public void addAttachment(RepositoryAttachment attachment) {
		attachments.add(attachment);
	}

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

	public String getId() {
		return reportID;
	}

	/**
	 * @return the server for this report
	 */
	public String getRepositoryUrl() {
		return repositoryURL;
	}

	public boolean hasLocalChanges() {
		return hasChanges;
	}

	public void setHasLocalChanges(boolean b) {
		hasChanges = b;
	}

	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);
		}
	}

}

Back to the top