|
Lines 23-35
Link Here
|
| 23 |
|
23 |
|
| 24 |
import java.io.File; |
24 |
import java.io.File; |
| 25 |
import java.util.ArrayList; |
25 |
import java.util.ArrayList; |
|
|
26 |
import java.util.Collections; |
| 27 |
import java.util.Date; |
| 28 |
import java.util.HashSet; |
| 26 |
import java.util.List; |
29 |
import java.util.List; |
|
|
30 |
import java.util.Set; |
| 27 |
|
31 |
|
| 28 |
import org.eclipse.core.runtime.CoreException; |
32 |
import org.eclipse.core.runtime.CoreException; |
| 29 |
import org.eclipse.core.runtime.IProgressMonitor; |
33 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 30 |
import org.eclipse.core.runtime.IStatus; |
34 |
import org.eclipse.core.runtime.IStatus; |
| 31 |
import org.eclipse.core.runtime.Status; |
35 |
import org.eclipse.core.runtime.Status; |
| 32 |
import org.eclipse.mylar.context.core.MylarStatusHandler; |
36 |
import org.eclipse.mylar.core.MylarStatusHandler; |
|
|
37 |
import org.eclipse.mylar.internal.tasks.core.RepositoryTaskHandleUtil; |
| 33 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; |
38 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; |
| 34 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; |
39 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; |
| 35 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; |
40 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; |
|
Lines 46-51
Link Here
|
| 46 |
import com.itsolut.mantis.core.exception.InvalidTicketException; |
51 |
import com.itsolut.mantis.core.exception.InvalidTicketException; |
| 47 |
import com.itsolut.mantis.core.model.MantisTicket; |
52 |
import com.itsolut.mantis.core.model.MantisTicket; |
| 48 |
import com.itsolut.mantis.core.model.MantisTicket.Key; |
53 |
import com.itsolut.mantis.core.model.MantisTicket.Key; |
|
|
54 |
import com.itsolut.mantis.core.util.MantisUtils; |
| 49 |
|
55 |
|
| 50 |
/** |
56 |
/** |
| 51 |
* @author Steffen Pingel |
57 |
* @author Steffen Pingel |
|
Lines 55-62
Link Here
|
| 55 |
|
61 |
|
| 56 |
private final static String CLIENT_LABEL = "Mantis (supports connector 0.0.5 only)"; |
62 |
private final static String CLIENT_LABEL = "Mantis (supports connector 0.0.5 only)"; |
| 57 |
|
63 |
|
| 58 |
private List<String> supportedVersions; |
|
|
| 59 |
|
| 60 |
private MantisClientManager clientManager; |
64 |
private MantisClientManager clientManager; |
| 61 |
|
65 |
|
| 62 |
private MantisOfflineTaskHandler offlineTaskHandler = new MantisOfflineTaskHandler(this); |
66 |
private MantisOfflineTaskHandler offlineTaskHandler = new MantisOfflineTaskHandler(this); |
|
Lines 109-127
Link Here
|
| 109 |
return repositoryUrl + IMantisClient.TICKET_URL + taskId; |
113 |
return repositoryUrl + IMantisClient.TICKET_URL + taskId; |
| 110 |
} |
114 |
} |
| 111 |
|
115 |
|
| 112 |
|
|
|
| 113 |
@Override |
116 |
@Override |
| 114 |
public List<String> getSupportedVersions() { |
|
|
| 115 |
if (supportedVersions == null) { |
| 116 |
supportedVersions = new ArrayList<String>(); |
| 117 |
for (Version version : Version.values()) { |
| 118 |
supportedVersions.add(version.toString()); |
| 119 |
} |
| 120 |
} |
| 121 |
return supportedVersions; |
| 122 |
} |
| 123 |
|
| 124 |
@Override |
| 125 |
public IAttachmentHandler getAttachmentHandler() { |
117 |
public IAttachmentHandler getAttachmentHandler() { |
| 126 |
return attachmentHandler; |
118 |
return attachmentHandler; |
| 127 |
} |
119 |
} |
|
Lines 134-140
Link Here
|
| 134 |
@Override |
126 |
@Override |
| 135 |
public void updateTask(TaskRepository repository, AbstractRepositoryTask repositoryTask) throws CoreException { |
127 |
public void updateTask(TaskRepository repository, AbstractRepositoryTask repositoryTask) throws CoreException { |
| 136 |
if (repositoryTask instanceof MantisTask) { |
128 |
if (repositoryTask instanceof MantisTask) { |
| 137 |
String id = AbstractRepositoryTask.getTaskId(repositoryTask.getHandleIdentifier()); |
129 |
String id = RepositoryTaskHandleUtil.getTaskId(repositoryTask.getHandleIdentifier()); |
| 138 |
try { |
130 |
try { |
| 139 |
IMantisClient connection = getClientManager().getRepository(repository); |
131 |
IMantisClient connection = getClientManager().getRepository(repository); |
| 140 |
MantisTicket ticket = connection.getTicket(Integer.parseInt(id)); |
132 |
MantisTicket ticket = connection.getTicket(Integer.parseInt(id)); |
|
Lines 171-197
Link Here
|
| 171 |
|
163 |
|
| 172 |
return Status.OK_STATUS; |
164 |
return Status.OK_STATUS; |
| 173 |
} |
165 |
} |
| 174 |
|
166 |
|
| 175 |
@Override |
167 |
@Override |
| 176 |
public AbstractRepositoryTask createTaskFromExistingKey(TaskRepository repository, String id) throws CoreException { |
168 |
public AbstractRepositoryTask createTaskFromExistingKey(TaskRepository repository, String taskId) throws CoreException { |
| 177 |
int bugId = -1; |
169 |
int bugId = -1; |
| 178 |
try { |
170 |
try { |
| 179 |
bugId = Integer.parseInt(id); |
171 |
bugId = Integer.parseInt(taskId); |
| 180 |
} catch (NumberFormatException e) { |
172 |
} catch (NumberFormatException e) { |
| 181 |
throw new CoreException(new Status(IStatus.ERROR, MantisCorePlugin.PLUGIN_ID, IStatus.OK, |
173 |
throw new CoreException(new Status(IStatus.ERROR, MantisCorePlugin.PLUGIN_ID, IStatus.OK, |
| 182 |
"Invalid ticket id: " + id, e)); |
174 |
"Invalid ticket id: " + taskId, e)); |
| 183 |
} |
175 |
} |
| 184 |
|
176 |
|
| 185 |
String handle = AbstractRepositoryTask.getHandle(repository.getUrl(), bugId); |
|
|
| 186 |
|
| 187 |
MantisTask task; |
177 |
MantisTask task; |
| 188 |
ITask existingTask = taskList.getTask(handle); |
178 |
ITask existingTask = taskList.getTask(repository.getUrl(), taskId); |
| 189 |
if (existingTask instanceof MantisTask) { |
179 |
if (existingTask instanceof MantisTask) { |
| 190 |
task = (MantisTask) existingTask; |
180 |
task = (MantisTask) existingTask; |
| 191 |
} else { |
181 |
} else { |
| 192 |
RepositoryTaskData taskData = offlineTaskHandler.downloadTaskData(repository, bugId); |
182 |
RepositoryTaskData taskData = offlineTaskHandler.downloadTaskData(repository, bugId); |
| 193 |
// if (taskData != null) { |
183 |
// if (taskData != null) { |
| 194 |
task = new MantisTask(handle, getTicketDescription(taskData), true); |
184 |
task = new MantisTask(repository.getUrl(), taskId, getTicketDescription(taskData), true); |
| 195 |
task.setTaskData(taskData); |
185 |
task.setTaskData(taskData); |
| 196 |
taskList.addTask(task); |
186 |
taskList.addTask(task); |
| 197 |
// } else { |
187 |
// } else { |
|
Lines 222-234
Link Here
|
| 222 |
return clientManager; |
212 |
return clientManager; |
| 223 |
} |
213 |
} |
| 224 |
|
214 |
|
| 225 |
public MantisTask createTask(MantisTicket ticket, String handleIdentifier) { |
215 |
public MantisTask createTask(MantisTicket ticket, String repositoryUrl, String taskId) { |
| 226 |
MantisTask task; |
216 |
MantisTask task; |
| 227 |
ITask existingTask = taskList.getTask(handleIdentifier); |
217 |
ITask existingTask = taskList.getTask(repositoryUrl, taskId); |
| 228 |
if (existingTask instanceof MantisTask) { |
218 |
if (existingTask instanceof MantisTask) { |
| 229 |
task = (MantisTask) existingTask; |
219 |
task = (MantisTask) existingTask; |
| 230 |
} else { |
220 |
} else { |
| 231 |
task = new MantisTask(handleIdentifier, getTicketDescription(ticket), true); |
221 |
task = new MantisTask(repositoryUrl, taskId, getTicketDescription(ticket), true); |
| 232 |
taskList.addTask(task); |
222 |
taskList.addTask(task); |
| 233 |
} |
223 |
} |
| 234 |
return task; |
224 |
return task; |
|
Lines 375-378
Link Here
|
| 375 |
return ticket; |
365 |
return ticket; |
| 376 |
} |
366 |
} |
| 377 |
|
367 |
|
|
|
368 |
//TODO: not changed for Mantis yet... |
| 369 |
@Override |
| 370 |
public Set<AbstractRepositoryTask> getChangedSinceLastSync(TaskRepository repository, Set<AbstractRepositoryTask> tasks) throws CoreException { |
| 371 |
if (repository.getSyncTimeStamp() == null) { |
| 372 |
return tasks; |
| 373 |
} |
| 374 |
|
| 375 |
if (!MantisRepositoryConnector.hasChangedSince(repository)) { |
| 376 |
// return an empty list to avoid causing all tasks to synchronized |
| 377 |
return Collections.emptySet(); |
| 378 |
} |
| 379 |
|
| 380 |
Date since = new Date(0); |
| 381 |
try { |
| 382 |
since = MantisUtils.parseDate(Integer.parseInt(repository.getSyncTimeStamp())); |
| 383 |
} catch (NumberFormatException e) { |
| 384 |
} |
| 385 |
|
| 386 |
IMantisClient client; |
| 387 |
try { |
| 388 |
client = getClientManager().getRepository(repository); |
| 389 |
Set<Integer> ids = client.getChangedTickets(since); |
| 390 |
|
| 391 |
Set<AbstractRepositoryTask> result = new HashSet<AbstractRepositoryTask>(); |
| 392 |
if (!ids.isEmpty()) { |
| 393 |
for (AbstractRepositoryTask task : tasks) { |
| 394 |
Integer id = Integer.parseInt(RepositoryTaskHandleUtil.getTaskId(task.getHandleIdentifier())); |
| 395 |
if (ids.contains(id)) { |
| 396 |
result.add(task); |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
return result; |
| 401 |
} catch (Exception e) { |
| 402 |
throw new CoreException(new Status(IStatus.ERROR, MantisCorePlugin.PLUGIN_ID, IStatus.OK, "could not determine changed tasks", e)); |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 378 |
} |
406 |
} |