|
@@ -1,5 +1,6 @@
|
|
|
package com.sagacloud.route.processors;
|
|
|
|
|
|
+import com.sagacloud.Exceptions.InvalidPostException;
|
|
|
import org.apache.camel.Exchange;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
@@ -15,14 +16,14 @@ public class ContractMethods {
|
|
|
}
|
|
|
|
|
|
public static void extractSupplierContractIds(Exchange exchange) {
|
|
|
- extract(exchange, "SupplierContractID");
|
|
|
+ extract(exchange, "SupplierContractID", "DPSupplierID", exchange.getProperty("DPSupplierID", String.class));
|
|
|
}
|
|
|
|
|
|
public static void extractInsuranceNum(Exchange exchange) {
|
|
|
- extract(exchange, "InsuranceNum");
|
|
|
+ extract(exchange, "InsuranceNum", "DPInsurerID", exchange.getProperty("DPInsurerID", String.class));
|
|
|
}
|
|
|
|
|
|
- private static void extract(Exchange exchange, String info){
|
|
|
+ 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")){
|
|
@@ -31,7 +32,8 @@ public class ContractMethods {
|
|
|
Set<String> contractIds = new HashSet<>();
|
|
|
json.getJSONArray("Content").forEach(obj ->{
|
|
|
JSONObject item = (JSONObject) obj;
|
|
|
- if(item.getJSONObject("infos").has(info)){
|
|
|
+ JSONObject infos = item.getJSONObject("infos");
|
|
|
+ if(infos.has(venderInfo) && infos.getString(venderInfo).trim().equalsIgnoreCase(venderId) && infos.has(info)){
|
|
|
contractIds.add(item.getJSONObject("infos").getString(info));
|
|
|
}
|
|
|
});
|
|
@@ -39,4 +41,22 @@ public class ContractMethods {
|
|
|
result.put("content", contractIds);
|
|
|
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());
|
|
|
+ }
|
|
|
}
|