1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.web.struts;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21 import org.kuali.ole.module.purap.PurapPropertyConstants;
22 import org.kuali.ole.module.purap.document.RequisitionDocument;
23 import org.kuali.ole.module.purap.document.service.B2BShoppingService;
24 import org.kuali.ole.module.purap.exception.B2BConnectionException;
25 import org.kuali.ole.module.purap.exception.B2BShoppingException;
26 import org.kuali.ole.module.purap.util.cxml.B2BParserHelper;
27 import org.kuali.ole.module.purap.util.cxml.B2BShoppingCart;
28 import org.kuali.ole.sys.OLEConstants;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.rice.core.api.config.property.ConfigurationService;
31 import org.kuali.rice.kns.web.struts.action.KualiAction;
32 import org.kuali.rice.krad.util.GlobalVariables;
33 import org.kuali.rice.krad.util.ObjectUtils;
34
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37 import java.util.List;
38
39 public class B2BAction extends KualiAction {
40 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(B2BAction.class);
41
42 public ActionForward shopCatalogs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
43 B2BForm b2bForm = (B2BForm) form;
44 String url = SpringContext.getBean(B2BShoppingService.class).getPunchOutUrl(GlobalVariables.getUserSession().getPerson());
45
46 if (ObjectUtils.isNull(url)) {
47 throw new B2BConnectionException("Unable to connect to remote site for punchout.");
48 }
49
50 b2bForm.setShopUrl(url);
51 return mapping.findForward(OLEConstants.MAPPING_BASIC);
52 }
53
54 public ActionForward returnFromShopping(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
55 String cXml = request.getParameter("cxml-urlencoded");
56 LOG.info("executeLogic() cXML returned in PunchoutOrderMessage:\n" + cXml);
57
58 B2BShoppingCart cart = B2BParserHelper.getInstance().parseShoppingCartXML(cXml);
59
60 if (cart.isSuccess()) {
61 List requisitions = SpringContext.getBean(B2BShoppingService.class).createRequisitionsFromCxml(cart, GlobalVariables.getUserSession().getPerson());
62 if (requisitions.size() > 1) {
63 request.getSession().setAttribute("multipleB2BRequisitions", "true");
64 }
65 request.setAttribute("forward", SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapPropertyConstants.B2B_PUNCH_BACK_ACTION_FORWARDING_URL));
66 request.getSession().setAttribute("docId", ((RequisitionDocument) requisitions.get(0)).getDocumentNumber());
67 } else {
68 if (LOG.isDebugEnabled()) {
69 LOG.debug("executeLogic() Retrieving shopping cart from cxml was unsuccessful. Error message:" + cart.getStatusText());
70 }
71 throw new B2BShoppingException("Retrieving shopping cart from cxml was unsuccessful. Error message:" + cart.getStatusText());
72 }
73
74 return (mapping.findForward("removeframe"));
75 }
76
77 }
78