Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8b4be4edef6d0b2a6e987a714e8499d68701886f (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
/*******************************************************************************
 * 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
 *******************************************************************************/
/*
 * Created on 14-Jan-2005
 */
package org.eclipse.mylar.internal.bugzilla.core;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.TaskComment;

/**
 * @author Mik Kersten
 */
public class BugzillaTask extends AbstractRepositoryTask {

	private static final String COMMENT_FORMAT = "yyyy-MM-dd HH:mm";

	private static SimpleDateFormat comment_creation_ts_format = new SimpleDateFormat(COMMENT_FORMAT);

	public BugzillaTask(String handle, String label, boolean newTask) {
		super(handle, label, newTask);
		if (newTask) {
			setSyncState(RepositoryTaskSyncState.INCOMING);
		}
		isDirty = false;
		initFromHandle();
	}

	public BugzillaTask(BugzillaQueryHit hit, boolean newTask) {
		this(hit.getHandleIdentifier(), hit.getDescription(), newTask);
		setPriority(hit.getPriority());
		initFromHandle();
	}

	private void initFromHandle() {
		String id = AbstractRepositoryTask.getTaskId(getHandleIdentifier());
		String repositoryUrl = getRepositoryUrl();
		try {
			String url = BugzillaClient.getBugUrlWithoutLogin(repositoryUrl, Integer.parseInt(id));
			if (url != null) {
				super.setUrl(url);
			}
		} catch (Exception e) {
			MylarStatusHandler.fail(e, "Task initialization failed due to malformed id or URL: "
					+ getHandleIdentifier(), false);
		}
	}

	@Override
	public String getDescription() {
		if (this.isDownloaded() || !super.getDescription().startsWith("<")) {
			return super.getDescription();
		} else {
			if (isSynchronizing()) {
				//return AbstractRepositoryTask.getTaskId(getHandleIdentifier()) + ": <synchronizing>";
				return "<synchronizing>";
			} else {
				//return AbstractRepositoryTask.getTaskId(getHandleIdentifier()) + ": ";
				return "";
			}
		}
	}

	public String getTaskType() {
		if (taskData != null && taskData.getAttribute(BugzillaReportElement.BUG_SEVERITY.getKeyString()) != null) {
			return taskData.getAttribute(BugzillaReportElement.BUG_SEVERITY.getKeyString()).getValue();
		} else {
			return null;
		}
	}

	@Override
	public String toString() {
		return "bugzilla report id: " + getHandleIdentifier();
	}

	@Override
	public String getUrl() {
		// fix for bug 103537 - should login automatically, but dont want to
		// show the login info in the query string
		try {
			return BugzillaClient.getBugUrlWithoutLogin(getRepositoryUrl(), Integer
					.parseInt(AbstractRepositoryTask.getTaskId(handle)));
		} catch (NumberFormatException nfe) {
			return super.getUrl();
		}
	}

	@Override
	public boolean isCompleted() {
		if (taskData != null) {
			if (taskData.getStatus() != null) {
				return taskData.getStatus().equals(IBugzillaConstants.VALUE_STATUS_RESOLVED)
						|| taskData.getStatus().equals(IBugzillaConstants.VALUE_STATUS_CLOSED)
						|| taskData.getStatus().equals(IBugzillaConstants.VALUE_STATUS_VERIFIED);
			} else {
				return false;
			}
		} else {
			return super.isCompleted();
		}
	}

	@Override
	public Date getCompletionDate() {
		try {
			if (taskData != null) {
				if (isCompleted()) {
					// if (taskData.isResolved()) {
					List<TaskComment> taskComments = taskData.getComments();
					if (taskComments != null && !taskComments.isEmpty()) {
						// TODO: fix not to be based on comment
						return comment_creation_ts_format.parse(taskComments.get(taskComments.size() - 1).getCreated());
						// return
						// offlineHandler.getDateForAttributeType(RepositoryTaskAttribute.COMMENT_DATE,
						// (taskComments.get(taskComments.size() -
						// 1).getCreated()));
					}
				}
			}
		} catch (Exception e) {
			//MylarStatusHandler.log(e, "BugzillaTask.getCompletionDate()");
			return null;
		}
		return super.getCompletionDate();
	}

	public String getRepositoryKind() {
		return BugzillaCorePlugin.REPOSITORY_KIND;
	}

	@Override
	public String getPriority() {
		if (taskData != null && taskData.getAttribute(BugzillaReportElement.PRIORITY.getKeyString()) != null) {
			return taskData.getAttribute(BugzillaReportElement.PRIORITY.getKeyString()).getValue();
		} else {
			return super.getPriority();
		}
	}

	@Override
	public String getOwner() {
		if (taskData != null && taskData.getAttribute(BugzillaReportElement.ASSIGNED_TO.getKeyString()) != null) {
			return taskData.getAttribute(BugzillaReportElement.ASSIGNED_TO.getKeyString()).getValue();
		} else {
			return super.getOwner();
		}
	}

}

Back to the top