12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package com.sagacloud.route.processors;
- import com.sagacloud.Exceptions.InvalidPostException;
- import org.apache.camel.Exchange;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- /**
- * Created by wo on 9/4/18.
- */
- public class ContractMethods {
- public static void preQueryEq(Exchange exchange) {
- exchange.getIn().setBody("{\"customInfo\":false,\"linkInfos\":false,\"criteria\":{\"type\":[\"Eq\"]}}");
- }
- public static void extractSupplierContractIds(Exchange exchange) {
- extract(exchange, "SupplierContractID", "DPSupplierID", exchange.getProperty("DPSupplierID", String.class));
- }
- public static void extractInsuranceNum(Exchange exchange) {
- extract(exchange, "InsuranceNum", "DPInsurerID", exchange.getProperty("DPInsurerID", String.class));
- }
- private static void extract(Exchange exchange, String info, String venderInfo, String venderId){
- String inStr = exchange.getIn().getBody(String.class);
- JSONObject json = new JSONObject(inStr);
- if(!json.getString("Result").equalsIgnoreCase("success")){
- return;
- }
- List<JSONObject> contents = new ArrayList<>();
- Set<String> contractIds = new HashSet<>();
- json.getJSONArray("Content").forEach(obj ->{
- JSONObject item = (JSONObject) obj;
- JSONObject infos = item.getJSONObject("infos");
- if(infos.has(venderInfo) && infos.getString(venderInfo).trim().equalsIgnoreCase(venderId) && infos.has(info)){
- if(contractIds.contains(infos.getString(info))){
- return;
- }
- JSONObject content = new JSONObject();
- content.put(info, infos.getString(info));
- if(info.equalsIgnoreCase("InsuranceNum")){
- if(infos.has("InsuranceFile")){
- content.put("InsuranceFile", infos.get("InsuranceFile"));
- }
- }
- contents.add(content);
- contractIds.add(infos.getString(info));
- }
- });
- JSONObject result = new JSONObject("{\"result\":\"success\",\"resultMsg\":\"\"}");
- result.put("content", contents);
- exchange.getOut().setBody(result);
- }
- public static void validateDPSupplierID(Exchange exchange) throws InvalidPostException {
- String inStr = exchange.getIn().getBody(String.class);
- JSONObject json = new JSONObject(inStr);
- if(!json.has("DPSupplierID")){
- throw new InvalidPostException("Need DPSupplierID");
- }
- exchange.setProperty("DPSupplierID", json.getString("DPSupplierID"));
- }
- public static void validateDPInsurerID(Exchange exchange) throws InvalidPostException {
- String inStr = exchange.getIn().getBody(String.class);
- JSONObject json = new JSONObject(inStr);
- if(!json.has("DPInsurerID")){
- throw new InvalidPostException("Need DPInsurerID");
- }
- exchange.setProperty("DPInsurerID", json.getString("DPInsurerID").trim());
- }
- }
|