01: package com.technoetic.xplanner.actions;
02:
03: import java.util.Collection;
04: import javax.servlet.http.HttpServletRequest;
05: import javax.servlet.http.HttpServletResponse;
06:
07: import net.sf.hibernate.Session;
08: import org.apache.struts.action.ActionForm;
09: import org.apache.struts.action.ActionMapping;
10:
11: import com.technoetic.xplanner.domain.Iteration;
12: import com.technoetic.xplanner.domain.UserStory;
13: import com.technoetic.xplanner.domain.repository.ObjectRepository;
14: import com.technoetic.xplanner.forms.AbstractEditorForm;
15: import com.technoetic.xplanner.forms.UserStoryEditorForm;
16:
17: public class EditStoryAction extends EditObjectAction {
18: public static final String CONTINUED = "continued";
19: public static final String MOVED = "moved";
20: public static final String OPERATION_PARAM_KEY = "operation";
21: public static final String ACTION_KEY = "action";
22:
23: public void beforeObjectCommit(Object object, Session session,
24: ActionMapping actionMapping, ActionForm actionForm,
25: HttpServletRequest request, HttpServletResponse reply)
26: throws Exception {
27: UserStory story = (UserStory) object;
28: ObjectRepository iterationRepository = getRepository(Iteration.class);
29: int iterationId = story.getIterationId();
30: Iteration iteration = (Iteration) iterationRepository
31: .load(iterationId);
32: Collection userStories = iteration.getUserStories();
33: userStories.add(story);
34: iteration.modifyStoryOrder(DomainOrderer
35: .buildStoryIdNewOrderArray(userStories));
36: String action = request.getParameter(ACTION_KEY);
37: }
38:
39: protected void populateForm(AbstractEditorForm form,
40: ActionMapping actionMapping, HttpServletRequest request)
41: throws Exception {
42: super .populateForm(form, actionMapping, request);
43: if (form.getOid() == null) {
44: UserStoryEditorForm storyForm = (UserStoryEditorForm) form;
45: int iterationId = Integer.parseInt(request
46: .getParameter("fkey"));
47: ObjectRepository iterationRepository = getRepository(Iteration.class);
48: Iteration iteration = (Iteration) iterationRepository
49: .load(iterationId);
50: storyForm.setDispositionName(iteration
51: .determineNewStoryDisposition().getName());
52: storyForm.setOrderNo(iteration.getUserStories().size() + 1);
53: }
54: }
55:
56: }
|