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