public void handleApiCompletion(YRCApiContext ctx) { if (ctx.getInvokeAPIStatus() < 0) { // api call failed // TODO: show exception message } else { if ("getOrganizationList".equals(ctx.getApiName())) { handleSearchApiCompletion(ctx); } else if ("XPXBrandCodesList".equals(ctx.getApiName())) { setModel("BrandCodesList", ctx.getOutputXml().getDocumentElement()); } } super.handleApiCompletion(ctx); }
public void handleApiCompletion(YRCApiContext ctx) { if (ctx.getInvokeAPIStatus() > 0) { if (page.isDisposed()) { YRCPlatformUI.trace("Page is Disposed"); } else { String[] apinames = ctx.getApiNames(); for (int i = 0; i < apinames.length; i++) { String apiname = apinames[i]; if ("getListOfXPEDXMyItemsLists".equals(apiname)) { Element outXml = ctx.getOutputXmls()[i].getDocumentElement(); Element eleMILDtls = YRCXmlUtils.getChildElement(outXml, "XPEDXMyItemsList"); if (null != eleMILDtls) { Element eleShareList = YRCXmlUtils.getChildElement(eleMILDtls, "XPEDXMyItemsListShareList"); if (null != eleShareList) { ArrayList<Element> list = YRCXmlUtils.getChildren(eleShareList, "XPEDXMyItemsListShare"); assignedMap = null; if (null == assignedMap) { assignedMap = new HashMap<String, Element>(); } for (Element eleCustAssignment : list) { String strCustID = eleCustAssignment.getAttribute("CustomerID"); if (!YRCPlatformUI.isVoid(strCustID)) { assignedMap.put(strCustID, eleCustAssignment); } } page.resetTreeAssignedValues(assignedMap); } // Share List setModel("XPEDXMyItemsList", eleMILDtls); strMILCustomerID = eleMILDtls.getAttribute("CustomerID"); if (!YRCPlatformUI.isVoid(strMILCustomerID) && !(Boolean) ctx.getUserData("isCustomerListQueried")) { YRCApiContext apiCtx = new YRCApiContext(); String cmdName = "getCustomerList"; Document docInput = YRCXmlUtils.createFromString( "<Customer CustomerID='" + strMILCustomerID + "' />"); apiCtx.setApiName(cmdName); apiCtx.setInputXml(docInput); apiCtx.setFormId(getFormId()); callApi(apiCtx); } else if (YRCPlatformUI.isVoid(strMILCustomerID)) { YRCPlatformUI.showError("Error", "Unable to retrive the "); } } } else if ("getCustomerList".equals(apiname)) { System.out.println("its inside the api call-->>"); Element outXml = ctx.getOutputXmls()[i].getDocumentElement(); setModel("XPXGetImmediateChildCustomerListService", outXml); String strCustomerKey = YRCXmlUtils.getAttributeValue(outXml, "/CustomerList/Customer/@CustomerKey"); String strCustomerID = YRCXmlUtils.getAttributeValue(outXml, "/CustomerList/Customer/@CustomerID"); String strOrgCode = YRCXmlUtils.getAttributeValue(outXml, "/CustomerList/Customer/@OrganizationCode"); String strSuffixType = YRCXmlUtils.getAttributeValue( outXml, "/CustomerList/Customer/Extn/@ExtnSuffixType"); if (YRCPlatformUI.isVoid(strSuffixType) || !"MC".equals(strSuffixType)) { YRCApiContext apiCtx = new YRCApiContext(); String cmdName = "XPXGetParentCustomerListService"; Document docInput = YRCXmlUtils.createFromString( "<Customer CustomerID='" + strCustomerID + "' OrganizationCode='" + strOrgCode + "'/>"); apiCtx.setApiName(cmdName); apiCtx.setInputXml(docInput); apiCtx.setFormId(getFormId()); callApi(apiCtx); } else { this.getChildList(); // --function used to set the values of child nodes in Tree // structure } } else if ("XPXGetParentCustomerListService".equals(apiname)) { // Set the Global Variable CustomerPath Prefix // XPXGetParentCustomerListService List output will be from Queried_Customer(lower) to // Master_Customer(top) Element outXml = ctx.getOutputXmls()[i].getDocumentElement(); setModel("XPXGetParentCustomerListService", outXml); boolean isFirstCustElement = true; if (outXml != null && outXml.hasChildNodes()) { NodeList childList = outXml.getChildNodes(); for (int j = 0; j < childList.getLength(); j++) { if ((childList.item(j) instanceof Element) && "Customer".equals(childList.item(j).getNodeName())) { Element eleCustomer = (Element) childList.item(j); if (!isFirstCustElement) { if (!YRCPlatformUI.isVoid(strCustomerPathPrefix)) { strCustomerPathPrefix = "|" + strCustomerPathPrefix; } strCustomerPathPrefix = eleCustomer.getAttribute("CustomerID") + strCustomerPathPrefix; } else { // This eats up the first Customer Element in the loop isFirstCustElement = false; } } } } ArrayList listParentCustomers = YRCXmlUtils.getChildren(outXml, "Customer"); int numberOfCustomer = 0; if (!YRCPlatformUI.isVoid(listParentCustomers)) { for (int k = 0; k < listParentCustomers.size(); k++) { Element customerEle = (Element) listParentCustomers.get(k); String CustomerIDValue = YRCXmlUtils.getAttribute(customerEle, "CustomerID"); parentcustomer.add(CustomerIDValue); numberOfCustomer = parentcustomer.size(); } } if (numberOfCustomer == 3) { String strMasterCustomerID = (String) parentcustomer.get(2); YRCApiContext apiCtx = new YRCApiContext(); String cmdName = "getCustomerList"; Document docInput = YRCXmlUtils.createFromString( "<Customer CustomerID='" + strMasterCustomerID + "' />"); apiCtx.setApiName(cmdName); apiCtx.setInputXml(docInput); apiCtx.setFormId(getFormId()); callApi(apiCtx); } else if (numberOfCustomer == 4) { String strMasterCustomerID = (String) parentcustomer.get(3); YRCApiContext apiCtx = new YRCApiContext(); String cmdName = "getCustomerList"; Document docInput = YRCXmlUtils.createFromString( "<Customer CustomerID='" + strMasterCustomerID + "' />"); apiCtx.setApiName(cmdName); apiCtx.setInputXml(docInput); apiCtx.setFormId(getFormId()); callApi(apiCtx); } else if (numberOfCustomer == 2) { String strMasterCustomerID = (String) parentcustomer.get(1); YRCApiContext apiCtx = new YRCApiContext(); String cmdName = "getCustomerList"; Document docInput = YRCXmlUtils.createFromString( "<Customer CustomerID='" + strMasterCustomerID + "' />"); apiCtx.setApiName(cmdName); apiCtx.setInputXml(docInput); apiCtx.setFormId(getFormId()); callApi(apiCtx); } // this.getChildList(); //--function used to set the values of child nodes in Tree // structure } else if ("multiApi".equals(apiname)) { updateAssignFlag = true; updateMyitemsList(); ((XPXUserProfileEditor) YRCDesktopUI.getCurrentPart()).showBusy(false); } // Called for JIRA 4157 else if ("XPXCustomerHierarchyViewService".equals(apiname)) { Element outXml = ctx.getOutputXmls()[i].getDocumentElement(); NodeList XPXCustHierarchyViewNodeList = outXml.getElementsByTagName("XPXCustHierarchyView"); if (XPXCustHierarchyViewNodeList != null && XPXCustHierarchyViewNodeList.getLength() > 0) { for (int k = 0; k < XPXCustHierarchyViewNodeList.getLength(); k++) { Element eleMyItemsList = (Element) XPXCustHierarchyViewNodeList.item(k); String strDivisionID = eleMyItemsList.getAttribute("ExtnCustomerDivision"); if (strDivisionID != "") { divisionHashSet.add(strDivisionID); } } } } else if ("updateXPEDXMyItemsList".equals(apiname)) { Element outXml = ctx.getOutputXmls()[i].getDocumentElement(); Element eleMyItemsList = YRCXmlUtils.getXPathElement(outXml, "/XPEDXMyItemsList"); setModel("getXPEDXMyItemsListDetail", eleMyItemsList); this.getCustomerAssignmentsAfterUpdate(); } } } } // In case of Invoke API failure else if (ctx.getInvokeAPIStatus() == -1) { Element outXml = ctx.getOutputXml().getDocumentElement(); if ("Errors".equals(outXml.getNodeName())) { Element errorEle = (Element) outXml.getElementsByTagName("Error").item(0); if (!YRCPlatformUI.isVoid(errorEle)) { YRCPlatformUI.trace(errorEle.getAttribute("ErrorDescription"), outXml); YRCPlatformUI.showError("Failed!", errorEle.getAttribute("ErrorDescription")); } } } super.handleApiCompletion(ctx); }
private void handleSearchApiCompletion(YRCApiContext ctx) { setModel(ctx.getOutputXml().getDocumentElement()); page.tblResults.setFocus(); }