|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011 IBM Corporation and others. |
2 |
* Copyright (c) 2011, 2012 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 85-104
Link Here
|
| 85 |
|
85 |
|
| 86 |
private String userId; |
86 |
private String userId; |
| 87 |
private Date deletionDate; |
87 |
private Date deletionDate; |
| 88 |
private Collection<String> tasks; |
|
|
| 89 |
|
88 |
|
| 90 |
public DeletedTasksNotificationJob(String userId, Date deletionDate, Collection<String> tasks) { |
89 |
public DeletedTasksNotificationJob(String userId, Date deletionDate) { |
| 91 |
super("Notyfing task listeners"); |
90 |
super("Notyfing task listeners"); |
| 92 |
this.userId = userId; |
91 |
this.userId = userId; |
| 93 |
this.deletionDate = deletionDate; |
92 |
this.deletionDate = deletionDate; |
| 94 |
this.tasks = tasks; |
|
|
| 95 |
} |
93 |
} |
| 96 |
|
94 |
|
| 97 |
@Override |
95 |
@Override |
| 98 |
protected IStatus run(IProgressMonitor monitor) { |
96 |
protected IStatus run(IProgressMonitor monitor) { |
| 99 |
synchronized (taskListeners) { |
97 |
synchronized (taskListeners) { |
| 100 |
for (TaskModificationListener listener : taskListeners) { |
98 |
for (TaskModificationListener listener : taskListeners) { |
| 101 |
listener.tasksDeleted(userId, tasks, deletionDate); |
99 |
listener.tasksDeleted(userId, deletionDate); |
| 102 |
} |
100 |
} |
| 103 |
} |
101 |
} |
| 104 |
return Status.OK_STATUS; |
102 |
return Status.OK_STATUS; |
|
Lines 137-143
Link Here
|
| 137 |
return createTask(taskName, userId, null, isIdempotent); |
135 |
return createTask(taskName, userId, null, isIdempotent); |
| 138 |
} |
136 |
} |
| 139 |
|
137 |
|
| 140 |
private TaskInfo internalRemoveTask(String userId, String id) throws TaskOperationException { |
138 |
private TaskInfo internalRemoveTask(String userId, String id, Date dateRemoved) throws TaskOperationException { |
| 141 |
TaskInfo task = getTask(userId, id); |
139 |
TaskInfo task = getTask(userId, id); |
| 142 |
if (task == null) |
140 |
if (task == null) |
| 143 |
throw new TaskDoesNotExistException(id); |
141 |
throw new TaskDoesNotExistException(id); |
|
Lines 149-178
Link Here
|
| 149 |
if (!taskDeletions.containsKey(userId)) { |
147 |
if (!taskDeletions.containsKey(userId)) { |
| 150 |
taskDeletions.put(userId, new ArrayList<TaskService.TaskDeletion>()); |
148 |
taskDeletions.put(userId, new ArrayList<TaskService.TaskDeletion>()); |
| 151 |
} |
149 |
} |
| 152 |
taskDeletions.get(userId).add(new TaskDeletion(new Date(), id)); |
150 |
int i = taskDeletions.get(userId).size(); |
|
|
151 |
while(i>0 && taskDeletions.get(userId).get(i-1).deletionDate.after(dateRemoved)){ |
| 152 |
i--; |
| 153 |
} |
| 154 |
taskDeletions.get(userId).add(i, new TaskDeletion(dateRemoved, id)); |
| 153 |
return task; |
155 |
return task; |
| 154 |
} |
156 |
} |
| 155 |
|
157 |
|
| 156 |
public void removeTask(String userId, String id) throws TaskOperationException { |
158 |
public void removeTask(String userId, String id) throws TaskOperationException { |
| 157 |
internalRemoveTask(userId, id); |
159 |
Date date = new Date(); |
| 158 |
Set<String> tasks = new HashSet<String>(); |
160 |
internalRemoveTask(userId, id, date); |
| 159 |
tasks.add(id); |
161 |
notifyDeletionListeners(userId, date); |
| 160 |
notifyDeletionListeners(userId, new Date(), tasks); |
|
|
| 161 |
} |
162 |
} |
| 162 |
|
163 |
|
| 163 |
public void removeCompletedTasks(String userId) { |
164 |
public void removeCompletedTasks(String userId) { |
| 164 |
Set<String> tasks = new HashSet<String>(); |
165 |
Date date = new Date(); |
| 165 |
for (TaskInfo task : getTasks(userId)) { |
166 |
for (TaskInfo task : getTasks(userId)) { |
| 166 |
if (!task.isRunning()) { |
167 |
if (!task.isRunning()) { |
| 167 |
try { |
168 |
try { |
| 168 |
internalRemoveTask(userId, task.getTaskId()); |
169 |
internalRemoveTask(userId, task.getTaskId(), date); |
| 169 |
tasks.add(task.getTaskId()); |
|
|
| 170 |
} catch (TaskOperationException e) { |
170 |
} catch (TaskOperationException e) { |
| 171 |
LogHelper.log(e); |
171 |
LogHelper.log(e); |
| 172 |
} |
172 |
} |
| 173 |
} |
173 |
} |
| 174 |
} |
174 |
} |
| 175 |
notifyDeletionListeners(userId, new Date(), tasks); |
175 |
notifyDeletionListeners(userId, date); |
| 176 |
} |
176 |
} |
| 177 |
|
177 |
|
| 178 |
public TaskInfo createTask(String taskName, String userId, ITaskCanceler taskCanceler, boolean isIdempotent) { |
178 |
public TaskInfo createTask(String taskName, String userId, ITaskCanceler taskCanceler, boolean isIdempotent) { |
|
Lines 191-198
Link Here
|
| 191 |
new TasksNotificationJob(userId, modificationDate).schedule(); |
191 |
new TasksNotificationJob(userId, modificationDate).schedule(); |
| 192 |
} |
192 |
} |
| 193 |
|
193 |
|
| 194 |
private void notifyDeletionListeners(String userId, Date deletionDate, Collection<String> tasks) { |
194 |
private void notifyDeletionListeners(String userId, Date deletionDate) { |
| 195 |
new DeletedTasksNotificationJob(userId, deletionDate, tasks).schedule(); |
195 |
new DeletedTasksNotificationJob(userId, deletionDate).schedule(); |
| 196 |
} |
196 |
} |
| 197 |
|
197 |
|
| 198 |
public TaskInfo getTask(String userId, String id) { |
198 |
public TaskInfo getTask(String userId, String id) { |
|
Lines 256-265
Link Here
|
| 256 |
} |
256 |
} |
| 257 |
} |
257 |
} |
| 258 |
|
258 |
|
| 259 |
public Collection<String> getTasksDeletedSince(String userId, Date deletedSince) { |
259 |
public synchronized Collection<String> getTasksDeletedSince(String userId, Date deletedSince) { |
| 260 |
Set<String> deletedTasks = new HashSet<String>(); |
260 |
Set<String> deletedTasks = new HashSet<String>(); |
| 261 |
List<TaskDeletion> taskDeletionsList = taskDeletions.get(userId); |
261 |
List<TaskDeletion> taskDeletionsList = taskDeletions.get(userId); |
| 262 |
if (taskDeletionsList == null) { |
262 |
if (taskDeletionsList == null || deletedSince==null) { |
| 263 |
return deletedTasks; |
263 |
return deletedTasks; |
| 264 |
} |
264 |
} |
| 265 |
for (int i = taskDeletionsList.size() - 1; i > 0; i--) { |
265 |
for (int i = taskDeletionsList.size() - 1; i > 0; i--) { |