1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package edu.sampleu.travel.web.action; |
17 | |
|
18 | |
import java.util.Iterator; |
19 | |
|
20 | |
import javax.servlet.http.HttpServletRequest; |
21 | |
import javax.servlet.http.HttpServletResponse; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.apache.struts.action.ActionForm; |
25 | |
import org.apache.struts.action.ActionForward; |
26 | |
import org.apache.struts.action.ActionMapping; |
27 | |
import org.kuali.rice.core.util.RiceConstants; |
28 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
29 | |
import org.kuali.rice.kns.exception.ValidationException; |
30 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
31 | |
import org.kuali.rice.kns.util.GlobalVariables; |
32 | |
import org.kuali.rice.kns.util.KNSConstants; |
33 | |
import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase; |
34 | |
|
35 | |
import edu.sampleu.travel.bo.TravelAccount; |
36 | |
import edu.sampleu.travel.document.TravelDocument2; |
37 | |
import edu.sampleu.travel.web.form.TravelDocumentForm2; |
38 | |
|
39 | 0 | public class TravelDocumentAction2 extends KualiTransactionalDocumentActionBase { |
40 | |
|
41 | |
public ActionForward insertAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
42 | 0 | TravelDocumentForm2 travelForm = (TravelDocumentForm2) form; |
43 | 0 | TravelAccount travAcct = (TravelAccount) KNSServiceLocator.getBusinessObjectService().retrieve(travelForm.getTravelAccount()); |
44 | |
|
45 | 0 | if (travAcct == null) { |
46 | 0 | GlobalVariables.getMessageMap().putError("travelAccount.number", RiceKeyConstants.ERROR_CUSTOM, "Invalid travel account number"); |
47 | 0 | throw new ValidationException("Invalid travel account number"); |
48 | |
} |
49 | |
|
50 | 0 | boolean containsNewAcct = false; |
51 | 0 | for (Iterator<TravelAccount> travAcctIter = ((TravelDocument2) travelForm.getDocument()).getTravelAccounts().iterator(); travAcctIter.hasNext();) { |
52 | 0 | if (travAcctIter.next().getNumber().equals(travAcct.getNumber())) { |
53 | 0 | containsNewAcct = true; |
54 | 0 | break; |
55 | |
} |
56 | |
} |
57 | 0 | if (!containsNewAcct) { |
58 | 0 | ((TravelDocument2) travelForm.getDocument()).getTravelAccounts().add(travAcct); |
59 | |
} |
60 | 0 | travelForm.setTravelAccount(new TravelAccount()); |
61 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
62 | |
} |
63 | |
|
64 | |
public ActionForward deleteAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
65 | |
|
66 | 0 | TravelDocumentForm2 travelForm = (TravelDocumentForm2) form; |
67 | 0 | String strIndex = StringUtils.substringBetween((String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE), |
68 | |
KNSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL); |
69 | 0 | if (StringUtils.isNotBlank(strIndex)) { |
70 | 0 | ((TravelDocument2) travelForm.getDocument()).getTravelAccounts().remove(Integer.parseInt(strIndex)); |
71 | |
} |
72 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
73 | |
} |
74 | |
|
75 | |
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
76 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
77 | |
} |
78 | |
} |