Example usage for org.dom4j Element addAttribute

List of usage examples for org.dom4j Element addAttribute

Introduction

In this page you can find the example usage for org.dom4j Element addAttribute.

Prototype

Element addAttribute(QName qName, String value);

Source Link

Document

Adds the attribute value of the given fully qualified name.

Usage

From source file:com.sap.data.db.dao.StructureUtil.java

private void addElement(Element element, String attributeName, String attributeType, String fieldName,
        String fieldLength) throws NotFoundException {
    Element fieldElement = element.addElement(attributeName);
    fieldElement.addAttribute("name", fieldName.toUpperCase());
    fieldElement.addAttribute("type", attributeType);

    Element fieldNameElement = fieldElement.addElement("column");
    fieldNameElement.addAttribute("name", this.fieldConvert(fieldName.toUpperCase()));
    fieldNameElement.addAttribute("length", fieldLength);
}

From source file:com.servoy.j2db.documentation.QualifiedDocumentationName.java

License:Open Source License

public Element toXML(String elementName) {
    Element root = DocumentHelper.createElement(elementName);
    if (memberName != null) {
        root.addAttribute(ATTR_MEMBER, memberName);
        String argsAsString = argumentsArray2String(argumentsTypes);
        //         if (argsAsString != null) root.addAttribute(ATTR_ARGUMENTSTYPES, argsAsString);
    }/*from   w w  w.  j  ava  2  s .  c o  m*/
    if (className != null)
        root.addAttribute(ATTR_OBJECT, className);
    return root;
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ?()/*from  w  w w .ja va 2  s.c  o m*/
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> querySFProductBySku(DispatchContext dctx, Map<String, Object> context) {

    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "ITEM_QUERY_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element ItemQueryRequest = Body.addElement("ItemQueryRequest");
    Element CompanyCode = ItemQueryRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element SkuNoList = ItemQueryRequest.addElement("SkuNoList");
    List<String> skuNoList = (List<String>) context.get("skuNoList");
    for (String skuNo : skuNoList) {
        Element SkuNo = SkuNoList.addElement("SkuNo");
        SkuNo.setText(skuNo);//??
    }
    String result = "";
    String XMLStr = doc.getRootElement().asXML();
    try {
        result = sendSFRequest(XMLStr);

    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ServiceUtil.returnSuccess(result);
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ??()/* w  ww.j av  a2s .  c om*/
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> SFProductSync(DispatchContext dctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Delegator delegator = dctx.getDelegator();
    String message = verificationProductSyncParameters(context);
    if (!message.equals("success")) {
        return ServiceUtil.returnError(message);
    }
    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "ITEM_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element ItemRequest = Body.addElement("ItemRequest");

    Element CompanyCode = ItemRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element Items = ItemRequest.addElement("Items");
    for (Map<String, Object> productItem : (List<Map<String, Object>>) context.get("items")) {
        Element Item = Items.addElement("Item");

        Element SkuNo = Item.addElement("SkuNo");
        if (UtilValidate.isNotEmpty(productItem.get("skuNo"))) {
            SkuNo.setText(productItem.get("skuNo").toString());//??
        }
        Element ItemName = Item.addElement("ItemName");
        if (UtilValidate.isNotEmpty(productItem.get("itemName"))) {
            ItemName.setText(productItem.get("itemName").toString());//???
        }
        Element ItemColor = Item.addElement("ItemColor");
        if (UtilValidate.isNotEmpty(productItem.get("itemColor"))) {
            ItemColor.setText(productItem.get("itemColor").toString());//
        }
        Element ItemSize = Item.addElement("ItemSize");
        if (UtilValidate.isNotEmpty(productItem.get("itemSize"))) {
            ItemSize.setText(productItem.get("itemSize").toString());//?
        }
        Element Containers = Item.addElement("Containers");
        Element Container = Containers.addElement("Container");

        Element PackUm = Container.addElement("PackUm");
        if (UtilValidate.isNotEmpty(productItem.get("packUm"))) {//??
            PackUm.setText(productItem.get("packUm").toString());
        }
        Element UmDescr = Container.addElement("UmDescr");
        if (UtilValidate.isNotEmpty(productItem.get("umDescr"))) {//??
            UmDescr.setText(productItem.get("umDescr").toString());
        }
    }
    String XMLStr = doc.getRootElement().asXML();

    try {
        String resultStr = sendSFRequest(XMLStr);
        Document resultDocument = (Document) DocumentHelper.parseText(resultStr);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        SFAuditLogFilter.saveRequestContext(delegator, "ITEM_SERVICE", XMLStr, resultStr);
        if (HeadElement.getText().equals("ERR")) {
            Element ErrorElement = ResponseElement.element("Error");
            String code = ErrorElement.attributeValue("code");
            String errorMessage = ErrorElement.getText();
            return ServiceUtil.returnError("ERROR : errorCode={" + code + "} message={" + errorMessage + "}");
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element ItemResponseElement = BodyElement.element("ItemResponse");
            Element ItemsElement = ItemResponseElement.element("Items");
            Element ItemElement = ItemsElement.element("Item");
            Element ResultElement = ItemElement.element("Result");
            result.put("resultCode", ResultElement.getText());
            return result;
        }
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

@SuppressWarnings("unchecked")
/**//from w w w  .  ja v a  2 s  .co  m
 * ?
 * @author sven
 * @param dctx
 * @param context
 * @return
 */
public static Map<String, Object> querySFOutboundListStatuc(DispatchContext dctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Delegator delegator = dctx.getDelegator();
    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "SALE_ORDER_STATUS_QUERY_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element SaleOrderRequest = Body.addElement("SaleOrderStatusRequest");
    Element CompanyCode = SaleOrderRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element SaleOrders = SaleOrderRequest.addElement("SaleOrders");
    Element SaleOrder = SaleOrders.addElement("SaleOrder");
    Element WarehouseCode = SaleOrder.addElement("WarehouseCode");
    WarehouseCode.setText(WAREHOUSE_CODE);//??
    Element ErpOrder = SaleOrder.addElement("ErpOrder");
    Element ShipmentId = SaleOrder.addElement("ShipmentId");
    ErpOrder.setText(context.get("erpOrder").toString());//???
    ShipmentId.setText(context.get("shipmentId").toString());//???
    String XMLStr = doc.getRootElement().asXML();
    try {
        String resultXML = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "SALE_ORDER_STATUS_QUERY_SERVICE", XMLStr, resultXML);
        Document resultDocument = (Document) DocumentHelper.parseText(resultXML);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultXML);
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element SaleOrderStatusResponseElement = BodyElement.element("SaleOrderStatusResponse");
            Element SaleOrderStatusElement = SaleOrderStatusResponseElement.element("SaleOrders");
            Element SaleOrderStatuElement = SaleOrderStatusElement.element("SaleOrder");
            Element ResultElement = SaleOrderStatuElement.element("Result");

            Element HeaderElement = SaleOrderStatuElement.element("Header");
            Element StepsElement = SaleOrderStatuElement.element("Steps");
            Element NoteElement = SaleOrderStatuElement.element("Note");

            result.put("resultCode", ResultElement.getText());
            if (ResultElement.getText().equals("1")) {
                Element StepElement = StepsElement.element("Step");
                Element StatusElement = StepElement.element("Status");
                Element WayBillNoElement = HeaderElement.element("WayBillNo");
                result.put("status", StatusElement.getText());
                if (UtilValidate.isNotEmpty(WayBillNoElement)) {
                    result.put("trackingNumberId", WayBillNoElement.getText());
                }

            } else {
                result.put("note", NoteElement.getText());
            }
            return result;
        }
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ??/*from w  ww  .j a v  a 2s  .  c  o m*/
 * ??????
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> cancelSFOutboundList(DispatchContext dctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Delegator delegator = dctx.getDelegator();
    String message = verificationCancelSFOutboundList(context);
    if (!message.equals("success")) {
        return ServiceUtil.returnError(message);
    }
    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "CANCEL_SALE_ORDER_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element SaleOrderRequest = Body.addElement("CancelSaleOrderRequest");
    Element CompanyCode = SaleOrderRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element SaleOrders = SaleOrderRequest.addElement("SaleOrders");

    Element SaleOrder = SaleOrders.addElement("SaleOrder");
    Element ErpOrder = SaleOrder.addElement("ErpOrder");
    ErpOrder.setText(context.get("erpOrder").toString());//???

    String XMLStr = doc.getRootElement().asXML();
    try {
        String resultXML = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "CANCEL_SALE_ORDER_SERVICE", XMLStr, resultXML);
        Document resultDocument = (Document) DocumentHelper.parseText(resultXML);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultXML);
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element PurchaseOrderResponseElement = BodyElement.element("CancelSaleOrderResponse");
            Element PurchaseOrdersElement = PurchaseOrderResponseElement.element("SaleOrders");
            Element PurchaseOrderElement = PurchaseOrdersElement.element("SaleOrder");
            Element ResultElement = PurchaseOrderElement.element("Result");
            result.put("resultCode", ResultElement.getText());
            result.put("note", PurchaseOrderElement.element("Note").getText());
            return result;
        }
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ????XML??/*from   w  w  w.j  a v a 2s .  c  o m*/
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> SFOutboundList(DispatchContext dctx, Map<String, Object> context) {
    String message = verificationOutboundListParameters(context);
    String localOrderTypeId = (String) context.get("localOrderTypeId");//??
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Delegator delegator = dctx.getDelegator();
    if (!message.equals("success")) {
        return ServiceUtil.returnError(message);
    }
    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "SALE_ORDER_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");

    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element SaleOrderRequest = Body.addElement("SaleOrderRequest");
    Element CompanyCode = SaleOrderRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element SaleOrders = SaleOrderRequest.addElement("SaleOrders");
    for (Map<String, Object> POrder : (List<Map<String, Object>>) context.get("saleOrders")) {
        Element SaleOrder = SaleOrders.addElement("SaleOrder");

        Element WarehouseCode = SaleOrder.addElement("WarehouseCode");
        WarehouseCode.setText(WAREHOUSE_CODE);//?

        Element ErpOrder = SaleOrder.addElement("ErpOrder");
        String ErpOrderStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("erpOrder"))) {
            ErpOrderStr = POrder.get("erpOrder").toString();
        }
        ErpOrder.setText(ErpOrderStr);//???

        Element ErpOrderType = SaleOrder.addElement("ErpOrderType");
        String ErpOrderTypeStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("ErpOrderType"))) {
            ErpOrderTypeStr = POrder.get("erpOrderType").toString();
        }
        ErpOrderType.setText(ErpOrderTypeStr);//?

        Element SFOrderType = SaleOrder.addElement("SFOrderType");
        String SFOrderTypeStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("SFOrderType"))) {
            SFOrderTypeStr = OUT_WAREHOUSE_TYPE.get(POrder.get("SFOrderType").toString());
        }
        SFOrderType.setText(SFOrderTypeStr);//?

        Element OrderTotalAmount = SaleOrder.addElement("OrderTotalAmount");
        String OrderTotalAmountStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("orderTotalAmount"))) {
            OrderTotalAmountStr = POrder.get("orderTotalAmount").toString();
        }
        OrderTotalAmount.setText(OrderTotalAmountStr);

        /*
        Map<String, Object> orderCarrier = new HashMap<String, Object>();
         orderCarrier.put("carrier", "CP");//?
         orderCarrier.put("carrierProduct", "1");
         orderCarrier.put("paymentOfCharge", "");
         orderCarrier.put("monthlyAccount", MONTHLY_ACCOUNT);
         **/

        Element orderCarrier = SaleOrder.addElement("OrderCarrier");
        orderCarrier.addElement("Carrier").addText("?");
        orderCarrier.addElement("CarrierProduct").addText("");
        orderCarrier.addElement("PaymentOfCharge").addText("");

        Map<String, Object> orderReceiverInfo = (Map<String, Object>) POrder.get("orderReceiverInfo");
        Element OrderReceiverInfo = SaleOrder.addElement("OrderReceiverInfo");

        Element ReceiverCompany = OrderReceiverInfo.addElement("ReceiverCompany");
        String ReceiverCompanyStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverCompany"))) {
            ReceiverCompanyStr = orderReceiverInfo.get("receiverCompany").toString();
        }
        ReceiverCompany.setText(ReceiverCompanyStr);
        Element ReceiverName = OrderReceiverInfo.addElement("ReceiverName");
        String ReceiverNameStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverName"))) {
            ReceiverNameStr = orderReceiverInfo.get("receiverName").toString();
        }
        ReceiverName.setText(ReceiverNameStr);
        Element ReceiverZipCode = OrderReceiverInfo.addElement("ReceiverZipCode");
        String ReceiverZipCodeStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverZipCode"))) {
            ReceiverZipCodeStr = orderReceiverInfo.get("receiverZipCode").toString();
        }
        ReceiverZipCode.setText(ReceiverZipCodeStr);
        Element ReceiverMobile = OrderReceiverInfo.addElement("ReceiverMobile");
        String ReceiverMobileStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverMobile"))) {
            ReceiverMobileStr = orderReceiverInfo.get("receiverMobile").toString();
        }
        ReceiverMobile.setText(ReceiverMobileStr);
        Element ReceiverPhone = OrderReceiverInfo.addElement("ReceiverPhone");
        String ReceiverPhoneStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverPhone"))) {
            ReceiverPhoneStr = orderReceiverInfo.get("receiverPhone").toString();
        }
        ReceiverPhone.setText(ReceiverPhoneStr);
        Element ReceiverCountry = OrderReceiverInfo.addElement("ReceiverCountry");
        String ReceiverCountryStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverCountry"))) {
            ReceiverCountryStr = orderReceiverInfo.get("receiverCountry").toString();
        }
        ReceiverCountry.setText(ReceiverCountryStr);

        Element ReceiverProvince = OrderReceiverInfo.addElement("ReceiverProvince");
        String ReceiverProvinceStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverProvince"))) {
            //??????hardcode
            ReceiverProvinceStr = getProvinceNameHardcode(orderReceiverInfo.get("receiverProvince").toString());
        }
        ReceiverProvince.setText(ReceiverProvinceStr);

        Element ReceiverCity = OrderReceiverInfo.addElement("ReceiverCity");
        String ReceiverCityStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverCity"))) {
            ReceiverCityStr = orderReceiverInfo.get("receiverCity").toString();
        }
        ReceiverCity.setText(ReceiverCityStr);

        Element ReceiverArea = OrderReceiverInfo.addElement("ReceiverArea");
        String ReceiverAreaStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverArea"))) {
            ReceiverAreaStr = orderReceiverInfo.get("receiverArea").toString();
        }
        ReceiverArea.setText(ReceiverAreaStr);

        Element ReceiverAddress = OrderReceiverInfo.addElement("ReceiverAddress");
        String ReceiverAddressStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverAddress"))) {
            ReceiverAddressStr = orderReceiverInfo.get("receiverAddress").toString();
        }
        ReceiverAddress.setText(ReceiverAddressStr);
        Element Items = SaleOrder.addElement("OrderItems");
        List<Map<String, Object>> orderItems = (List<Map<String, Object>>) POrder.get("orderItems");
        for (Map<String, Object> orderItem : orderItems) {
            Element Item = Items.addElement("OrderItem");
            Element ErpOrderLineNum = Item.addElement("ErpOrderLineNum");
            String ErpOrderLineNumStr = "";
            if (UtilValidate.isNotEmpty(orderItem.get("erpOrderLineNum"))) {
                ErpOrderLineNumStr = orderItem.get("erpOrderLineNum").toString();
            }
            ErpOrderLineNum.setText(ErpOrderLineNumStr);
            Element SkuNo = Item.addElement("SkuNo");//??
            String SkuNoStr = "";
            if (UtilValidate.isNotEmpty(orderItem.get("skuNo"))) {
                SkuNoStr = orderItem.get("skuNo").toString();
            }
            SkuNo.setText(SkuNoStr);
            Element ItemQuantity = Item.addElement("ItemQuantity");//??
            String ItemQuantityStr = "";
            if (UtilValidate.isNotEmpty(orderItem.get("itemQuantity"))) {
                ItemQuantityStr = orderItem.get("itemQuantity").toString();
            }
            ItemQuantity.setText(ItemQuantityStr);
        }
    }
    String XMLStr = doc.getRootElement().asXML();
    List<Map<String, Object>> resultList = FastList.newInstance();
    try {
        String resultStr = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "SALE_ORDER_SERVICE", XMLStr, resultStr);
        Document resultDocument = (Document) DocumentHelper.parseText(resultStr);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultStr);
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element PurchaseOrderResponseElement = BodyElement.element("SaleOrderResponse");
            Element PurchaseOrdersElement = PurchaseOrderResponseElement.element("SaleOrders");
            List<Element> PurchaseOrderElement = PurchaseOrdersElement.elements("SaleOrder");
            for (Element itemElement : PurchaseOrderElement) {
                Map<String, Object> resultMap = FastMap.newInstance();
                Element ResultElement = itemElement.element("Result");
                Element ShipmentIdElement = itemElement.element("ShipmentId");
                Element NoteElement = itemElement.element("Note");

                resultMap.put("erpOrder", itemElement.element("ErpOrder").getText());
                resultMap.put("resultCode", ResultElement.getText());
                if (UtilValidate.isNotEmpty(ShipmentIdElement)) {
                    resultMap.put("shipmentId", ShipmentIdElement.getText());
                }

                if (UtilValidate.isNotEmpty(NoteElement)) {
                    resultMap.put("note", NoteElement.getText());
                }
                resultList.add(resultMap);

            }
            result.put("shunfengResult", resultList);
            return result;
        }
    } catch (RemoteException e) {
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ?//www .  j a v  a2  s.  c  om
 * @param request
 * @param response
 * @return
 */
public static Map<String, Object> QuerySFProductInventory(DispatchContext dctx, Map<String, Object> context) {
    Delegator delegator = dctx.getDelegator();
    Map<String, Object> result = ServiceUtil.returnSuccess();
    List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
    Map<String, Object> resultMap = new HashMap<String, Object>();

    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "RT_INVENTORY_QUERY_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element RTInventoryQueryRequest = Body.addElement("RTInventoryQueryRequest");
    Element CompanyCode = RTInventoryQueryRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?

    Element WarehouseCode = RTInventoryQueryRequest.addElement("WarehouseCode");
    WarehouseCode.setText(WAREHOUSE_CODE);//?
    if (UtilValidate.isNotEmpty(context.get("inventoryStatus"))) {
        Element InventoryStatus = RTInventoryQueryRequest.addElement("InventoryStatus");
        InventoryStatus.setText((String) context.get("inventoryStatus"));
    }
    Element RTInventorys = RTInventoryQueryRequest.addElement("RTInventorys");
    Element RTInventory = RTInventorys.addElement("RTInventory");
    if (UtilValidate.isNotEmpty(context.get("productId"))) {
        Element SkuNo = RTInventory.addElement("SkuNo");
        SkuNo.setText((String) context.get("productId"));
    }

    //      Element PageIndex = RTInventoryQueryRequest.addElement("PageIndex");
    //      if (UtilValidate.isNotEmpty(context.get("inventoryStatus"))) {
    //         PageIndex.setText((String) context.get("pageIndex"));
    //      } else {
    //         PageIndex.setText("1");
    //      }
    String XMLStr = doc.getRootElement().asXML();
    String resultStr;

    try {
        resultStr = sendSFRequest(XMLStr);
        Document resultDocument = (Document) DocumentHelper.parseText(resultStr);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultStr);
        } else {
            //            Element BodyElement = ResponseElement.element("Body");
            //            Element WmsInventoryBalancePageQueryResponse = BodyElement.element("WmsInventoryBalancePageQueryResponse");
            //            Element Result = WmsInventoryBalancePageQueryResponse.element("Result");
            //            Element TotalSize = WmsInventoryBalancePageQueryResponse.element("TotalSize");
            //            Element TotalPage = WmsInventoryBalancePageQueryResponse.element("TotalPage");
            //            Element PageIndexElement = WmsInventoryBalancePageQueryResponse.element("PageIndex");
            //            resultMap.put("totalSize", TotalSize.getText());
            //            resultMap.put("totalPage", TotalPage.getText());
            //            resultMap.put("pageIndex", PageIndexElement.getText());
            //            if (Result.getText().equals("1")) {
            //               Element List = WmsInventoryBalancePageQueryResponse.element("List");
            //               if (UtilValidate.isNotEmpty(List)) {
            //                  @SuppressWarnings("unchecked")
            //                  List<Element> items = List.elements("Item");
            //                  for (Element item : items) {
            //                     Element SkuNo = item.element("SkuNo");
            //                     Element OnHandQty = item.element("OnHandQty");
            //                     Element InventoryStatus = item.element("InventoryStatus");
            //                     Map<String, String> itemMap = new HashMap<String, String>();
            //                     itemMap.put("productId", SkuNo.getText());
            //                     itemMap.put("quantityOnHandTotal", OnHandQty.getText());
            //                     itemMap.put("inventoryStatus", InventoryStatus.getText());
            //                     resultList.add((itemMap));
            //                  }         
            //               }   
            //            }   
            resultMap.put("resultList", resultList);
            result.put("resultMap", resultMap);
        }

        return result;

    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ????XML??/*w  ww.  j a v  a 2 s. c  o m*/
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> SFGodownEntry(DispatchContext dctx, Map<String, Object> context) {
    try {
        String message = verificationGodownEntryParameters(context);
        Map<String, Object> result = ServiceUtil.returnSuccess();
        Delegator delegator = dctx.getDelegator();
        if (!message.equals("success")) {
            return ServiceUtil.returnError(message);
        }
        Document doc = (Document) DocumentHelper.createDocument();
        //Request
        Element request = doc.addElement("Request");
        request.addAttribute("service", "PURCHASE_ORDER_SERVICE");
        request.addAttribute("lang", "zh-CN");
        //Head
        Element head = request.addElement("Head");
        Element AccessCode = head.addElement("AccessCode");
        AccessCode.setText(ACCESS_CODE);//?
        Element Checkword = head.addElement("Checkword");
        Checkword.setText(CHECK_WORD);//??
        //Body
        Element Body = request.addElement("Body");

        Element PurchaseOrderRequest = Body.addElement("PurchaseOrderRequest");
        Element CompanyCode = PurchaseOrderRequest.addElement("CompanyCode");
        CompanyCode.setText(COMPANY_CODE);//?
        Element PurchaseOrders = PurchaseOrderRequest.addElement("PurchaseOrders");

        for (Map<String, Object> POrder : (List<Map<String, Object>>) context.get("purchaseOrders")) {
            List<Map<String, Object>> productItems = (List<Map<String, Object>>) POrder.get("items");

            Element PurchaseOrder = PurchaseOrders.addElement("PurchaseOrder");
            Element WarehouseCode = PurchaseOrder.addElement("WarehouseCode");
            WarehouseCode.setText(WAREHOUSE_CODE);//?

            Element ErpOrder = PurchaseOrder.addElement("ErpOrder");
            String ErpOrderStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("erpOrder"))) {
                ErpOrderStr = POrder.get("erpOrder").toString();
            }
            ErpOrder.setText(ErpOrderStr);//???

            Element ErpOrderType = PurchaseOrder.addElement("ErpOrderType");
            String ErpOrderTypeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("erpOrderType"))) {
                ErpOrderTypeStr = POrder.get("erpOrderType").toString();
            }
            ErpOrderType.setText(ErpOrderTypeStr);//?

            Element SFOrderType = PurchaseOrder.addElement("SFOrderType");
            String SFOrderTypeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("SFOrderType"))) {
                SFOrderTypeStr = IN_WAREHOUSE_TYPE.get(POrder.get("SFOrderType")).toString();
            }
            SFOrderType.setText(SFOrderTypeStr);//?

            Element OrderDate = PurchaseOrder.addElement("OrderDate");
            String OrderDateStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("orderDate"))) {
                OrderDateStr = POrder.get("orderDate").toString();
            }
            OrderDate.setText(OrderDateStr);//?

            Element Buyer = PurchaseOrder.addElement("Buyer");
            String buyStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("buyer"))) {
                buyStr = POrder.get("buyer").toString();
            }
            Buyer.setText(buyStr);//

            Element BuyerPhone = PurchaseOrder.addElement("BuyerPhone");
            String BuyerPhoneStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("buyerPhone"))) {
                BuyerPhoneStr = POrder.get("buyerPhone").toString();
            }
            BuyerPhone.setText(BuyerPhoneStr);//??

            Element ScheduledReceiptDate = PurchaseOrder.addElement("ScheduledReceiptDate");
            String ScheduledReceiptDateStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("scheduledReceiptDate"))) {
                ScheduledReceiptDateStr = POrder.get("scheduledReceiptDate").toString();
            }
            ScheduledReceiptDate.setText(ScheduledReceiptDateStr);//

            Element VendorCode = PurchaseOrder.addElement("VendorCode");
            String VendorCodeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("vendorCode"))) {
                VendorCodeStr = POrder.get("vendorCode").toString();
            }
            VendorCode.setText(VendorCodeStr);//?   

            Element TransferWarehouseCode = PurchaseOrder.addElement("TransferWarehouseCode");
            String TransferWarehouseCodeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("transferWarehouseCode"))) {
                TransferWarehouseCodeStr = POrder.get("transferWarehouseCode").toString();
            }
            TransferWarehouseCode.setText(TransferWarehouseCodeStr);//?

            Element OriginalOrderNo = PurchaseOrder.addElement("OriginalOrderNo");
            String OriginalOrderNoStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("originalOrderNo"))) {
                OriginalOrderNoStr = POrder.get("originalOrderNo").toString();
            }
            OriginalOrderNo.setText(OriginalOrderNoStr);//??

            Element Note = PurchaseOrder.addElement("Note");
            String NoteStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("note"))) {
                NoteStr = POrder.get("note").toString();
            }
            Note.setText(NoteStr);//?

            Element ReceiptMode = PurchaseOrder.addElement("ReceiptMode");
            String ReceiptModeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("receiptMode"))) {
                ReceiptModeStr = POrder.get("receiptMode").toString();
            }
            ReceiptMode.setText(ReceiptModeStr);//??

            Element LicensePlateNumber = PurchaseOrder.addElement("LicensePlateNumber");
            String LicensePlateNumberStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("licensePlateNumber"))) {
                LicensePlateNumberStr = POrder.get("licensePlateNumber").toString();
            }
            LicensePlateNumber.setText(LicensePlateNumberStr);//?

            Element Driver = PurchaseOrder.addElement("Driver");
            String DriverStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("driver"))) {
                DriverStr = POrder.get("driver").toString();
            }
            Driver.setText(DriverStr);//?

            Element TradePlatform = PurchaseOrder.addElement("TradePlatform");
            String TradePlatformStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("tradePlatform"))) {
                TradePlatformStr = POrder.get("tradePlatform").toString();
            }
            TradePlatform.setText(TradePlatformStr);//?

            Element TradeOrder = PurchaseOrder.addElement("TradeOrder");
            String TradeOrderStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("tradeOrder"))) {
                TradeOrderStr = POrder.get("tradeOrder").toString();
            }
            TradeOrder.setText(TradeOrderStr);//??

            Element DriverCalls = PurchaseOrder.addElement("DriverCalls");
            String DriverCallsStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("driverCalls"))) {
                DriverCallsStr = POrder.get("driverCalls").toString();
            }
            DriverCalls.setText(DriverCallsStr);//??
            for (int i = 1; i < 9; i++) {
                Element lot = PurchaseOrder.addElement("UserDef" + i);
                lot.setText("");
            }
            Element items = PurchaseOrder.addElement("Items");
            for (Map<String, Object> productItem : productItems) {
                Element item = items.addElement("Item");
                Element ErpOrderLineNum = item.addElement("ErpOrderLineNum");
                String ErpOrderLineNumStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("erpOrderLineNum"))) {
                    ErpOrderLineNumStr = productItem.get("erpOrderLineNum").toString();
                }
                ErpOrderLineNum.setText(ErpOrderLineNumStr);
                Element SkuNo = item.addElement("SkuNo");//??
                String SkuNoStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("skuNo"))) {
                    SkuNoStr = productItem.get("skuNo").toString();
                }
                SkuNo.setText(SkuNoStr);

                Element Qty = item.addElement("Qty");//?
                String QtyStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("qty"))) {
                    QtyStr = productItem.get("qty").toString();
                }
                Qty.setText(QtyStr);

                Element QtyUm = item.addElement("QtyUm");//???
                String QtyUmStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("qtyUm"))) {
                    QtyUmStr = productItem.get("qtyUm").toString();
                }
                QtyUm.setText(QtyUmStr);

                Element Lot = item.addElement("Lot");//?
                String lotStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("lot"))) {
                    lotStr = productItem.get("lot").toString();
                }
                Lot.setText(lotStr);

                Element itemNote = item.addElement("Note");//
                String itemNoteStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("note"))) {
                    itemNoteStr = productItem.get("note").toString();
                }
                itemNote.setText(itemNoteStr);

                Element Price = item.addElement("Price");//?
                String PriceStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("price"))) {
                    //PriceStr = productItem.get("price").toString();
                    PriceStr = "0.00";
                }
                Price.setText(PriceStr);

                Element InventoryStatus = item.addElement("InventoryStatus");
                String InventoryStatusStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("inventoryStatus"))) {
                    InventoryStatusStr = productItem.get("inventoryStatus").toString();
                }
                InventoryStatus.setText(InventoryStatusStr);
                for (int i = 1; i < 7; i++) {
                    Element lot = item.addElement("LotAttr" + i);
                    lot.setText("");
                }
                for (int i = 1; i < 9; i++) {
                    Element lot = item.addElement("UserDef" + i);
                    lot.setText("");
                }
            }
        }
        String XMLStr = doc.getRootElement().asXML();
        String resultStr = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "PURCHASE_ORDER_SERVICE", XMLStr, resultStr);
        Document resultDocument = (Document) DocumentHelper.parseText(resultStr);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");

        if (HeadElement.getText().equals("ERR")) {
            Element ErrorElement = ResponseElement.element("Error");
            String code = ErrorElement.attributeValue("code");
            String errorMessage = ErrorElement.getText();
            return ServiceUtil.returnError("ERROR : errorCode={" + code + "} message={" + errorMessage + "}");
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element PurchaseOrderResponseElement = BodyElement.element("PurchaseOrderResponse");
            Element PurchaseOrdersElement = PurchaseOrderResponseElement.element("PurchaseOrders");
            Element PurchaseOrderElement = PurchaseOrdersElement.element("PurchaseOrder");
            Element ResultElement = PurchaseOrderElement.element("Result");
            Element ReceiptIdElement = PurchaseOrderElement.element("ReceiptId");
            Element NoteElement = PurchaseOrderElement.element("Note");
            result.put("resultCode", ResultElement.getText());
            if (UtilValidate.isNotEmpty(ReceiptIdElement)) {
                result.put("receiptId", ReceiptIdElement.getText());
            }

            if (UtilValidate.isNotEmpty(NoteElement)) {
                result.put("note", NoteElement.getText());
            }
            return result;
        }
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ?//from   w w  w .  j  a v a  2s.  c  om
 * @author sven
 * @param request
 * @param response
 * @return
 */
public static String SFGodownEntryPush(HttpServletRequest request, HttpServletResponse response) {
    String logistics_interface = (String) request.getParameter("logistics_interface");
    Debug.log("logistics_interface : SFGodownEntryPush:?" + logistics_interface);
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    List<Map<String, Object>> shipmentList = FastList.newInstance();

    Document responseDoc = (Document) DocumentHelper.createDocument();
    Element responseElement = responseDoc.addElement("Response");
    responseElement.addAttribute("service", "PURCHASE_ORDER_INBOUND_SERVICE");
    responseElement.addAttribute("lang", "zh-CN");
    responseElement.addElement("Head").addText("OK");
    Element PurchaseOrderInboundResponse = responseElement.addElement("Body")
            .addElement("PurchaseOrderInboundResponse");
    try {
        GenericValue userLogin = delegator.findOne("UserLogin", true, UtilMisc.toMap("userLoginId", "system"));
        Document doc = (Document) DocumentHelper.parseText(logistics_interface);
        Element ResponseElement = doc.getRootElement();
        Element BodyElement = ResponseElement.element("Body");
        Element PurchaseOrderInboundRequest = BodyElement.element("PurchaseOrderInboundRequest");
        List<Element> PurchaseOrderList = PurchaseOrderInboundRequest.elements("PurchaseOrders");
        for (Element PurchaseOrder : PurchaseOrderList) {
            Element ErpOrder = PurchaseOrder.element("PurchaseOrder").element("ErpOrder");//???
            Element ReceiptId = PurchaseOrder.element("PurchaseOrder").element("ReceiptId");//??
            Element Status = PurchaseOrder.element("PurchaseOrder").element("Status");//?
            List<Element> items = PurchaseOrder.element("PurchaseOrder").element("Items").elements("Item");

            // ReceiptId ???
            GenericValue sfOrderAssoc = EntityUtil.getFirst(
                    delegator.findByAnd("SFOrderAssoc", UtilMisc.toMap("SFCallBackId", ReceiptId.getText())));
            if (UtilValidate.isEmpty(sfOrderAssoc)) {
                //?
                ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError",
                        "receiptId " + ReceiptId.getText() + " not found", null);
                //return "error";
                continue;
            }
            if ("SHIPMENT_IN".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                //ofbizshipment?
                for (Element item : items) {
                    Map<String, Object> shipmentMap = UtilMisc.toMap("productId",
                            item.element("SkuNo").getText(), "quantity",
                            new BigDecimal(item.element("PlanQty").getText()), "actualQuantity",
                            new BigDecimal(item.element("ActualQty").getText()));
                    shipmentList.add(shipmentMap);
                }
                //  ??
                dispatcher.runSync("shunfengShipmentReceive", UtilMisc.toMap("shipmentItems", shipmentList,
                        "shipmentId", sfOrderAssoc.getString("shipmentId"), "userLogin", userLogin));
            } else if ("ORDER_IN".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                //?
                String returnId = sfOrderAssoc.getString("returnId");
                List<Map<String, Object>> reutnItems = FastList.newInstance();
                for (Element item : items) {
                    Map<String, Object> temp = UtilMisc.toMap("productId", item.element("SkuNo").getText(),
                            "quantity", new BigDecimal(item.element("PlanQty").getText()), "actualQuantity",
                            new BigDecimal(item.element("ActualQty").getText()));
                    reutnItems.add(temp);
                }
                Map<String, Object> returnMap = dispatcher.runSync("OMSReturnReceive",
                        UtilMisc.toMap("returnId", returnId, "itemList", reutnItems, "userLogin", userLogin));
                if (ServiceUtil.isError(returnMap)) {
                    ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError",
                            ServiceUtil.getErrorMessage(returnMap), null);
                }
            }
        }
    } catch (DocumentException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    } catch (GenericEntityException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    } catch (GenericServiceException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    }
    setResponseMsg(PurchaseOrderInboundResponse, "1", "");
    responseToShunfeng(request, response, responseDoc.getRootElement().asXML());

    return "success";
}