01: package com.technoetic.xplanner.actions;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.http.HttpServletResponse;
05:
06: import com.technoetic.xplanner.domain.*;
07: import com.technoetic.xplanner.domain.repository.ObjectRepository;
08: import com.technoetic.xplanner.forms.IterationStatusEditorForm;
09: import com.technoetic.xplanner.history.HistoricalEvent;
10: import com.technoetic.xplanner.history.HistorySupport;
11: import com.technoetic.xplanner.security.SecurityHelper;
12: import com.technoetic.xplanner.util.TimeGenerator;
13:
14: import net.sf.hibernate.Session;
15: import org.apache.commons.lang.StringUtils;
16: import org.apache.struts.action.*;
17: import org.apache.struts.action.ActionMapping;
18:
19: public class CloseIterationAction extends AbstractIterationAction {
20: private TimeGenerator timeGenerator;
21:
22: public void setTimeGenerator(TimeGenerator timeGenerator) {
23: this .timeGenerator = timeGenerator;
24: }
25:
26: public void beforeObjectCommit(Object object, Session session,
27: ActionMapping actionMapping, ActionForm actionForm,
28: HttpServletRequest request, HttpServletResponse reply)
29: throws Exception {
30: Iteration iteration = (Iteration) object;
31: closeIteration(request, session, iteration);
32: String event = HistoricalEvent.ITERATION_CLOSED;
33: HistorySupport.saveEvent(session, iteration, event, null,
34: SecurityHelper.getRemoteUserId(request), timeGenerator
35: .getCurrentTime());
36: }
37:
38: protected ActionForward doExecute(ActionMapping mapping,
39: ActionForm actionForm, HttpServletRequest request,
40: HttpServletResponse response) throws Exception {
41: IterationStatusEditorForm form = (IterationStatusEditorForm) actionForm;
42: if (StringUtils.isEmpty(form.getOid()))
43: return mapping.getInputForward();
44:
45: String iterationId = form.getOid();
46: ObjectRepository objectRepository = getRepository(Iteration.class);
47: Iteration iteration = (Iteration) objectRepository.load(Integer
48: .parseInt(iterationId));
49: if (iteration.isActive()) {
50: iteration.setStatus(IterationStatus.INACTIVE);
51: setTargetObject(request, iteration);
52: }
53: objectRepository.update(iteration);
54: String returnto = request
55: .getParameter(EditObjectAction.RETURNTO_PARAM);
56: ActionForward forward = mapping.findForward("onclose");
57: //DEBT refactor the creation of the url get parameter to reuse what the LinkTag is doing.
58: //DEBT We need to move to encapsulate how the links are built so we eventually "invoke" new screens like functions and not build link by hand
59: return new ActionForward(forward.getPath() + "?iterationId="
60: + iterationId + "&" + returnto + "?oid=" + iterationId
61: + "&fkey=" + iterationId, forward.getRedirect());
62: }
63:
64: public void closeIteration(HttpServletRequest request,
65: Session session, Iteration iteration) throws Exception {
66: iteration.setStatus(IterationStatus.INACTIVE);
67: dataSampler.generateClosingDataSamples(iteration);
68: }
69: }
|