Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1f7107724a54eb242c2a84231fe5a94fd657855e (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
/*******************************************************************************
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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:
 *     Mylar project committers - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.internal.trac;

import org.eclipse.mylar.internal.trac.TracAttributeFactory.Attribute;
import org.eclipse.mylar.internal.trac.core.ITracClient;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.Task;

/**
 * @author Steffen Pingel
 */
public class TracTask extends AbstractRepositoryTask {

	public enum PriorityLevel {
		BLOCKER, CRITICAL, MAJOR, MINOR, TRIVIAL;

		@Override
		public String toString() {
			switch (this) {
			case BLOCKER:
				return "P1";
			case CRITICAL:
				return "P2";
			case MAJOR:
				return "P3";
			case MINOR:
				return "P4";
			case TRIVIAL:
				return "P5";
			default:
				return "P5";
			}
		}

		public static PriorityLevel fromPriority(String priority) {
			if (priority == null)
				return null;
			if (priority.equals("blocker"))
				return BLOCKER;
			if (priority.equals("critical"))
				return CRITICAL;
			if (priority.equals("major"))
				return MAJOR;
			if (priority.equals("minor"))
				return MINOR;
			if (priority.equals("trivial"))
				return TRIVIAL;
			return null;
		}
	}

	public enum Kind {
		DEFECT, ENHANCEMENT, TASK;

		@Override
		public String toString() {
			switch (this) {
			case DEFECT:
				return "Defect";
			case ENHANCEMENT:
				return "Enhancement";
			case TASK:
				return "Task";
			default:
				return "";
			}
		}

		public static Kind fromType(String type) {
			if (type == null)
				return null;
			if (type.equals("defect"))
				return DEFECT;
			if (type.equals("enhancement"))
				return ENHANCEMENT;
			if (type.equals("task"))
				return TASK;
			return null;
		}

	}

	public enum Status {
		NEW, ASSIGNED, REOPENED, CLOSED;

		@Override
		public String toString() {
			switch (this) {
			case NEW:
				return "New";
			case ASSIGNED:
				return "Assigned";
			case REOPENED:
				return "Reopened";
			case CLOSED:
				return "Closed";
			default:
				return "";
			}
		}

		public static Status fromStatus(String status) {
			if (status == null)
				return null;
			if (status.equals("new"))
				return NEW;
			if (status.equals("assigned"))
				return ASSIGNED;
			if (status.equals("reopened"))
				return REOPENED;
			if (status.equals("closed"))
				return CLOSED;
			return null;
		}

	}

	public TracTask(String handle, String label, boolean newTask) {
		super(handle, label, newTask);

		setUrl(AbstractRepositoryTask.getRepositoryUrl(handle) + ITracClient.TICKET_URL
				+ AbstractRepositoryTask.getTaskId(handle));
	}

	@Override
	public boolean isCompleted() {
		if (taskData != null) {
			return isCompleted(taskData.getStatus());
		} else {
			return super.isCompleted();
		}
	}

	@Override
	public String getRepositoryKind() {
		return TracUiPlugin.REPOSITORY_KIND;
	}

	@Override
	public String getPriority() {
		if (taskData != null && taskData.getAttribute(Attribute.PRIORITY.getTracKey()) != null) {
			return getMylarPriority(taskData.getAttributeValue(Attribute.PRIORITY.getTracKey()));
		} else {
			return super.getPriority();
		}
	}

	@Override
	public String getOwner() {
		if (taskData != null && taskData.getAttribute(RepositoryTaskAttribute.USER_OWNER) != null) {
			return taskData.getAttributeValue(RepositoryTaskAttribute.USER_OWNER);
		} else {
			return super.getOwner();
		}
	}

	// TODO use priority attributes from repository instead of hard coded enum
	public static String getMylarPriority(String tracPriority) {
		if (tracPriority != null) {
			PriorityLevel priority = PriorityLevel.fromPriority(tracPriority);
			if (priority != null) {
				return priority.toString();
			}
		}
		return Task.PriorityLevel.P3.toString();
	}

	public static boolean isCompleted(String tracStatus) {
		TracTask.Status status = TracTask.Status.fromStatus(tracStatus);
		return status == TracTask.Status.CLOSED;
	}

}

Back to the top