01: package com.technoetic.xplanner.actions;
02:
03: import java.util.HashSet;
04: import java.util.Iterator;
05: import javax.servlet.http.HttpServletRequest;
06:
07: import net.sf.hibernate.HibernateException;
08: import net.sf.hibernate.Session;
09: import org.apache.struts.Globals;
10: import org.apache.struts.util.MessageResources;
11:
12: import com.technoetic.xplanner.domain.DomainObject;
13: import com.technoetic.xplanner.domain.Iteration;
14: import com.technoetic.xplanner.domain.StoryDisposition;
15: import com.technoetic.xplanner.domain.Task;
16: import com.technoetic.xplanner.domain.TaskDisposition;
17: import com.technoetic.xplanner.domain.UserStory;
18: import com.technoetic.xplanner.security.AuthenticationException;
19: import com.technoetic.xplanner.security.SecurityHelper;
20:
21: public class StoryContinuer extends Continuer {
22: private TaskContinuer taskContinuer;
23:
24: //DEBT 3LAYERCONTEXT remove dependency on request and move this class into the session context.
25: public void init(Session session, HttpServletRequest request)
26: throws AuthenticationException {
27: init(session, (MessageResources) request
28: .getAttribute(Globals.MESSAGES_KEY), SecurityHelper
29: .getRemoteUserId(request));
30: taskContinuer.init(session, (MessageResources) request
31: .getAttribute(Globals.MESSAGES_KEY), currentUserId);
32: }
33:
34: protected void doContinueObject(DomainObject fromObject,
35: DomainObject toParent, DomainObject toObject)
36: throws HibernateException {
37:
38: UserStory fromStory = (UserStory) fromObject;
39: Iteration toIteration = (Iteration) toParent;
40: UserStory toStory = (UserStory) toObject;
41:
42: fromStory.postponeRemainingHours();
43:
44: toStory.setIterationId(toIteration.getId());
45: toStory.setEstimatedHours(fromStory
46: .getTaskBasedRemainingHours());
47: toStory
48: .setDisposition(determineContinuedStoryDisposition(toIteration));
49: toStory.setEstimatedOriginalHours(null);
50: toStory.setTasks(new HashSet());
51: continueTasks(fromStory, toStory,
52: determineTaskDisposition(toIteration));
53: }
54:
55: private TaskDisposition determineTaskDisposition(Iteration iteration) {
56: return iteration.isActive() ? TaskDisposition.ADDED
57: : TaskDisposition.CARRIED_OVER;
58: }
59:
60: private void continueTasks(UserStory fromStory, UserStory toStory,
61: TaskDisposition taskDisposition) throws HibernateException {
62: Iterator taskIterator = fromStory.getTasks().iterator();
63: taskContinuer.setDispositionOfContinuedTasks(taskDisposition);
64: while (taskIterator.hasNext()) {
65: Task task = (Task) taskIterator.next();
66: if (!task.isCompleted()) {
67: taskContinuer.continueObject(task, fromStory, toStory);
68: }
69: }
70: }
71:
72: public StoryDisposition determineContinuedStoryDisposition(
73: Iteration iteration) {
74: return iteration.isActive() ? StoryDisposition.ADDED
75: : StoryDisposition.CARRIED_OVER;
76: }
77:
78: public void setTaskContinuer(TaskContinuer taskContinuer) {
79: this .taskContinuer = taskContinuer;
80: }
81:
82: public TaskContinuer getTaskContinuer() {
83: return taskContinuer;
84: }
85: }
|