Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.seer.datacruncher.utils.generic.StreamsUtils.java

License:Open Source License

/**
 * Publishes loading stream (SchemaType == 4) to database.
 * /* ww  w .  ja  v  a2 s  .c om*/
 * @param datastreamDTO
 */
public static void loadingStreamToDB(DatastreamDTO datastreamDTO, SchemaEntity loadingStream) {
    Map<String, List<SchemaFieldEntity>> map = new HashMap<String, List<SchemaFieldEntity>>();
    for (SchemaFieldEntity field : schemasDao.retrieveAllLeaves(datastreamDTO.getIdSchema())) {
        if (field.getLinkToDb() != null && !field.getLinkToDb().isEmpty()) {
            String tableName = field.getLinkToDb().split("[.]")[0];
            List<SchemaFieldEntity> list = map.get(tableName);
            if (list == null) {
                list = new ArrayList<SchemaFieldEntity>();
                map.put(tableName, list);
            }
            list.add(field);
        }
    }
    log.info("___loadingStreamToDB map.size() = " + map.size());
    if (map.size() > 0) {
        Connection connection = ConnectionPoolsSet.getConnection(loadingStream.getIdDatabase());
        for (Map.Entry<String, List<SchemaFieldEntity>> entry : map.entrySet()) {
            List<SchemaFieldEntity> list = entry.getValue();
            String[] arrSqlFields = new String[list.size()];
            String[] arrSqlValues = new String[list.size()];
            List<Element> xmlTextNodes = null;
            try {
                xmlTextNodes = parseStreamXml(datastreamDTO.getOutput());
            } catch (DocumentException e) {
                log.error("LoadingStreamToDB :: Document parse exception", e);
            }
            int i = 0;
            for (Element el : xmlTextNodes) {
                String fieldPath = formatPathForXmlNode(el.getPath());
                String fieldValue = el.getText();
                for (SchemaFieldEntity schemaField : list) {
                    if (fieldPath.equals(
                            getFieldPathPrefix(datastreamDTO.getIdStreamType()) + schemaField.getPath("/"))
                            && schemaField.getLinkToDb() != null && !schemaField.getLinkToDb().isEmpty()) {
                        String[] pathParts = schemaField.getLinkToDb().split("[.]");
                        arrSqlFields[i] = pathParts[pathParts.length - 1];
                        arrSqlValues[i] = schemaField.getIdFieldType() == FieldType.alphanumeric
                                ? "'" + fieldValue + "'"
                                : fieldValue;
                        i++;
                    }
                }
            }
            String sql = MessageFormat.format("INSERT INTO {0} ({1}) VALUES ({2})", entry.getKey(),
                    CommonUtils.stringAsCommaSeparated(arrSqlFields),
                    CommonUtils.stringAsCommaSeparated(arrSqlValues));
            try {
                connection.setAutoCommit(false);
                Statement stmt = null;
                try {
                    stmt = connection.createStatement();
                    log.info("___loadingStreamToDB sql = " + sql);
                    stmt.executeUpdate(sql);
                    log.info("___loadingStreamToDB exec update success");
                } finally {
                    stmt.close();
                }
            } catch (SQLException e) {
                try {
                    connection.rollback();
                } catch (SQLException e1) {
                    //skip
                }
                log.error("LoadingStreamToDB :: sql statement execution exception", e);
            }
        }
        try {
            if (connection != null) {
                log.info("___loadingStreamToDB before commit");
                connection.commit();
                log.info("___loadingStreamToDB commit success");
            }
        } catch (SQLException e) {
            log.error("LoadingStreamToDB :: connection close exception", e);
        }

    }
}

From source file:com.seer.datacruncher.validation.MacroRulesValidation.java

License:Open Source License

/**
 * Apply validation macro rules./*  w ww .  j a  v a  2  s.c  o  m*/
 * @param datastreamDTO
 * @return ResultStepValidation
 */
protected ResultStepValidation doValidation(DatastreamDTO datastreamDTO) {
    long schemaId = datastreamDTO.getIdSchema();
    List<MacroEntity> list = new ArrayList<MacroEntity>();
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = domFactory.newDocumentBuilder();
        Document doc = builder
                .parse(new ByteArrayInputStream(schemasXSDDao.find(schemaId).getSchemaXSD().getBytes()));
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr = xpath.compile("//annotation/appinfo/text()");
        Object result = expr.evaluate(doc, XPathConstants.NODESET);
        NodeList nodes = (NodeList) result;
        for (int i = 0; i < nodes.getLength(); i++) {
            String val = nodes.item(i).getNodeValue();
            if (val.startsWith("@RuleCheck")) {
                String[] arr = val.split(";\n");
                for (String s : arr) {
                    list.add(macrosDao.getMacroEntityByName(s.trim().substring(11)));
                }
                break;
            }
        }
    } catch (ParserConfigurationException e) {
        log.error("ParserConfigurationException", e);
    } catch (SAXException e) {
        log.error("SAXException", e);
    } catch (IOException e) {
        log.error("IOException", e);
    } catch (XPathExpressionException e) {
        log.error("XPathExpressionException", e);
    }
    ResultStepValidation resultStepValidation = new ResultStepValidation();
    resultStepValidation.setValid(true);
    resultStepValidation.setMessageResult(I18n.getMessage("success.validationOK"));
    List<Element> xmlTextNodes = null;
    try {
        xmlTextNodes = StreamsUtils.parseStreamXml(datastreamDTO.getOutput());
    } catch (DocumentException e) {
        log.error("Stream parse exception", e);
    }
    JexlEngine jexl = JexlEngineFactory.getInstance();
    boolean isSuccess = true;
    Pattern pattern = Pattern.compile(MACRO_SQL_VALIDATOR_PATTERN, Pattern.CASE_INSENSITIVE);
    for (MacroEntity ent : list) {
        if (!isSuccess)
            continue;
        String rule = ent.getRule();
        List<Map<String, String>> varsList = parseVars(ent.getVars());
        combineVariableLists(varsList, schemaId);
        Matcher matcher = pattern.matcher(rule);
        while (matcher.find()) {
            String varName = matcher.group(4);
            String sqlRes = "false";
            for (Map<String, String> m : varsList) {
                if (m.get("uniqueName").equals(varName)) {
                    for (Element el : xmlTextNodes) {
                        int t = datastreamDTO.getIdStreamType();
                        String fieldPath = (t == StreamType.XML || t == StreamType.XMLEXI ? "" : "ROOT/")
                                + m.get("nodePath");
                        if (fieldPath.equals(StreamsUtils.formatPathForXmlNode(el.getPath()))) {
                            String prepSql = matcher.group().replaceAll(matcher.group(4),
                                    "\"" + el.getText() + "\"");
                            String signum = matcher.group(3);
                            if (signum.equals("<")) {
                                prepSql = prepSql.replaceAll(signum, ">=");
                            } else if (signum.equals(">")) {
                                prepSql = prepSql.replaceAll(signum, "<=");
                            } else if (signum.equals("!=")) {
                                prepSql = prepSql.replaceAll(signum, "=");
                            }
                            Query q = entityManager.createNativeQuery(prepSql);
                            @SuppressWarnings("rawtypes")
                            List resList = q.getResultList();
                            if ((signum.equals("=") && resList.size() > 0)
                                    || (signum.equals("!=") && resList.size() == 0)
                                    || (signum.equals(">") && resList.size() == 0)
                                    || (signum.equals("<") && resList.size() == 0)) {
                                sqlRes = "true";
                            }
                            break;
                        }
                    }
                }
            }
            rule = rule.replaceAll(matcher.group(), sqlRes);
        }
        Expression e = jexl.createExpression(rule);
        JexlContext context = new MapContext();
        for (Map<String, String> m : varsList) {
            for (Element el : xmlTextNodes) {
                int t = datastreamDTO.getIdStreamType();
                String fieldPath = (t == StreamType.XML || t == StreamType.XMLEXI ? "" : "ROOT/")
                        + m.get("nodePath");
                if (fieldPath.equals(StreamsUtils.formatPathForXmlNode(el.getPath()))) {
                    context.set(m.get("uniqueName"),
                            JEXLFieldFactory.getField(m.get("fieldType"), el.getText()).getValue());
                    break;
                }
            }
        }
        Object res = e.evaluate(context);
        if (res != null) {
            isSuccess = false;
            resultStepValidation.setValid(false);
            if (ent.getErrorType() == StreamStatus.Warning.getCode()) {
                resultStepValidation.setWarning(true);
            }
            resultStepValidation
                    .setMessageResult(I18n.getMessage("error.validationMacro") + ": " + res.toString());
        }
    }
    return resultStepValidation;
}

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

/**
 * ??()/*from w ww .j av a  2 s.  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  ww  .j  ava2  s.c  om*/
 * ?
 * @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  .ja  v  a2s.  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??// ww  w .  jav  a  2  s.c  om
 * @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

/**
 * ?/*from w  w  w. j a v  a2  s. com*/
 * @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??//www  . j  av  a  2  s .  c  om
 * @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   www  . ja va 2 s. c o  m*/
 * @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";
}

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

/**
 * ?/*from w  ww  . j  a va2s. c o  m*/
 * @author sven
 * @param request
 * @param response
 * @return
 */
public static String SFInventoryPush(HttpServletRequest request, HttpServletResponse response) {
    String logistics_interface = (String) request.getParameter("logistics_interface");
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");

    Document responseDoc = (Document) DocumentHelper.createDocument();
    Element responseElement = responseDoc.addElement("Response");
    responseElement.addAttribute("service", "INVENTORY_BALANCE_SERVICE");
    responseElement.addAttribute("lang", "zh-CN");
    responseElement.addElement("Head").addText("OK");
    Element InventoryBalanceResponse = responseElement.addElement("Body")
            .addElement("InventoryBalanceResponse");

    try {
        Document doc = (Document) DocumentHelper.parseText(logistics_interface);
        Element ResponseElement = doc.getRootElement();
        Element BodyElement = ResponseElement.element("Body");
        Element InventoryBalanceRequest = BodyElement.element("InventoryBalanceRequest");
        Element InventoryBalances = InventoryBalanceRequest.element("InventoryBalances");
        Element Status = InventoryBalanceRequest.element("Status");
        // ?1?
        if (UtilValidate.isEmpty(InventoryBalances) || "1".equals(Status.getText())) {
            setResponseMsg(InventoryBalanceResponse, "1", "");
            responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
            return "success";
        }
        List<Element> inventoryBalanceList = InventoryBalances.elements("InventoryBalance");
        for (Element inventoryBalance : inventoryBalanceList) {
            Element SkuNo = inventoryBalance.element("SkuNo");
            Element Qty = inventoryBalance.element("Qty");
            Element InventoryStatus = inventoryBalance.element("InventoryStatus");

            GenericValue invTemp = delegator.makeValue("ShunfengInventoryTemp");
            invTemp.put("baseId", delegator.getNextSeqId("ShunfengInventoryTemp"));
            invTemp.put("productId", SkuNo.getText());
            invTemp.put("availableToPromiseTotal", new BigDecimal(Qty.getText()));
            invTemp.put("quantityOnHandTotal", new BigDecimal(Qty.getText()));
            invTemp.put("inventoryStatus", InventoryStatus.getText());
            invTemp.put("pushDateTime", UtilDateTime.nowTimestamp());
            invTemp.create();
        }
        setResponseMsg(InventoryBalanceResponse, "1", "");
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
    } catch (DocumentException e) {
        setResponseMsg(InventoryBalanceResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    } catch (GenericEntityException e) {
        setResponseMsg(InventoryBalanceResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    }
    return "success";
}