Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5bb9ebacd7cbec15333ec049b5545f177ddc1515 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 Mylyn project committers 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
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.core.deprecated;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;

/**
 * Responsible for retrieving and posting task data to a repository.
 * 
 * @author Mik Kersten
 * @author Rob Elves
 * @author Steffen Pingel
 * @author Frank Becker
 * @since 2.0
 */
@Deprecated
public abstract class AbstractTaskDataHandler {

	/**
	 * Download copy of task data from repository
	 * 
	 * @throws CoreException
	 */
	public abstract RepositoryTaskData getTaskData(TaskRepository repository, String taskId, IProgressMonitor monitor)
			throws CoreException;

	/**
	 * Download task data for each id provided
	 * 
	 * Override getMultiTaskData() to return true and implement this method if connector supports download of multiple
	 * task data in one request.
	 * 
	 * @since 3.0
	 */
	public void getMultiTaskData(TaskRepository repository, Set<String> taskIds, TaskDataCollector collector,
			IProgressMonitor monitor) throws CoreException {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return a reference to the newly created report in the case of new task submission, null otherwise
	 */
	public abstract String postTaskData(TaskRepository repository, RepositoryTaskData taskData, IProgressMonitor monitor)
			throws CoreException;

	/**
	 * @param repositoryUrl
	 * @param repositoryKind
	 * @param taskKind
	 * 		AbstractTask.DEFAULT_KIND or connector specific task kind string
	 * @return
	 */
	public abstract AbstractAttributeFactory getAttributeFactory(String repositoryUrl, String repositoryKind,
			String taskKind);

	/**
	 * Initialize a new task data object with default attributes and values
	 */
	public abstract boolean initializeTaskData(TaskRepository repository, RepositoryTaskData data,
			IProgressMonitor monitor) throws CoreException;

	/**
	 * @since 2.2
	 * @return false if this operation is not supported by the connector, true if initialized
	 */
	public boolean initializeSubTaskData(TaskRepository repository, RepositoryTaskData taskData,
			RepositoryTaskData parentTaskData, IProgressMonitor monitor) throws CoreException {
		return false;
	}

	/**
	 * @param task
	 * 		the parent task, may be null
	 * @param task
	 * 		the parent task data, may be null
	 * @since 2.2
	 */
	public boolean canInitializeSubTaskData(ITask task, RepositoryTaskData parentTaskData) {
		return false;
	}

	public abstract AbstractAttributeFactory getAttributeFactory(RepositoryTaskData taskData);

	/**
	 * @return Task id for any sub tasks referenced by the provided task data
	 */
	public Set<String> getSubTaskIds(RepositoryTaskData taskData) {
		return Collections.emptySet();
	}

	/**
	 * @return true if connector support downloading multiple task data in single request, false otherwise. If true,
	 * 	override and implement getMultiTaskData
	 */
	public boolean canGetMultiTaskData() {
		return false;
	}

	/**
	 * Sets attribute values from <code>sourceTaskData</code> on <code>targetTaskData</code>. Sets the following
	 * attributes:
	 * <ul>
	 * <li>summary
	 * <li>description
	 * </ul>
	 * Other attribute values are only set if they exist on <code>sourceTaskData</code> and <code>targetTaskData</code>.
	 * 
	 * @param sourceTaskData
	 * 		the source task data values are copied from, the connector kind of repository of <code>sourceTaskData</code>
	 * 		can be different from <code>targetTaskData</code>
	 * @param targetTaskData
	 * 		the target task data values are copied to, the connector kind matches the one of this task data handler
	 * @since 2.2
	 */
	public void cloneTaskData(RepositoryTaskData sourceTaskData, RepositoryTaskData targetTaskData) {
		targetTaskData.setSummary(sourceTaskData.getSummary());
		targetTaskData.setDescription(sourceTaskData.getDescription());
		if (sourceTaskData.getConnectorKind().equals(targetTaskData.getConnectorKind())
				&& sourceTaskData.getTaskKind().equals(targetTaskData.getTaskKind())) {
			// task data objects are from the same connector, copy all attributes
			for (RepositoryTaskAttribute sourceAttribute : sourceTaskData.getAttributes()) {
				copyAttributeValue(sourceAttribute, targetTaskData.getAttribute(sourceAttribute.getId()));
			}
		} else {
			// map attributes from common schema
			String[] commonAttributeKeys = new String[] { RepositoryTaskAttribute.KEYWORDS,
					RepositoryTaskAttribute.PRIORITY, RepositoryTaskAttribute.PRODUCT,
					RepositoryTaskAttribute.COMPONENT, RepositoryTaskAttribute.RESOLUTION,
					RepositoryTaskAttribute.USER_ASSIGNED, RepositoryTaskAttribute.USER_CC, };
			for (String key : commonAttributeKeys) {
				RepositoryTaskAttribute sourceAttribute = sourceTaskData.getAttribute(key);
				if (sourceAttribute != null) {
					copyAttributeValue(sourceAttribute, targetTaskData.getAttribute(key));
				}
			}
		}
	}

	private void copyAttributeValue(RepositoryTaskAttribute sourceAttribute, RepositoryTaskAttribute targetAttribute) {
		if (targetAttribute == null) {
			return;
		}

		if (!sourceAttribute.isReadOnly() && !sourceAttribute.isHidden() && !targetAttribute.isHidden()
				&& !targetAttribute.isReadOnly()) {
			targetAttribute.clearValues();
			if (targetAttribute.getOptions().size() > 0) {
				List<String> values = sourceAttribute.getValues();
				for (String value : values) {
					if (targetAttribute.getOptions().contains(value)) {
						targetAttribute.addValue(value);
					}
				}
			} else {
				List<String> values = sourceAttribute.getValues();
				for (String value : values) {
					targetAttribute.addValue(value);
				}
			}
		}
	}

}

Back to the top