package foundation.icall;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
import foundation.dao.DataPackage;
|
import foundation.dao.DataSource;
|
import foundation.dao.bizlogic.IActionProvider;
|
import foundation.data.mapping.Mappings;
|
import foundation.data.mapping.MappingsRuntime;
|
import foundation.icall.callout.CallMethod;
|
import foundation.icall.callout.Fields;
|
import foundation.icall.callout.IRemoteSource;
|
import foundation.icall.callout.MethodType;
|
import foundation.icall.callout.RemoteDBCallProvider;
|
import foundation.icall.callout.RemoteServerCallProvider;
|
import foundation.icall.callout.RemoteSourceBucket;
|
import foundation.io.template.ResponseTemplate;
|
import foundation.io.template.Template;
|
import foundation.util.MapList;
|
import foundation.util.Util;
|
import foundation.workflow.ActionMeta;
|
import foundation.workflow.WorkStep;
|
|
|
public class ICall {
|
|
protected static Logger logger;
|
private static RemoteSourceBucket sourceBucket;
|
|
private ICallMeta meta;
|
private IRemoteSource remoteSource;
|
private ICallDirection direction;
|
|
static {
|
logger = LogManager.getLogger(ICall.class);
|
}
|
|
public ICall(ICallMeta meta) {
|
this.meta = meta;
|
this.direction = ICallDirection.Unknown;
|
|
init();
|
}
|
|
|
public static ICall getInstance(String name) {
|
ICallBucket bucket = ICallBucket.getInstance();
|
return bucket.getOne(name);
|
}
|
|
private void init() {
|
//1. remote source
|
String sourceName = meta.getSourceName();
|
sourceBucket = RemoteSourceBucket.getInstance();
|
remoteSource = sourceBucket.getOne(sourceName);
|
direction = remoteSource.getDirection();
|
}
|
|
public void sendRemoteServerCall(WorkStep step, OutboundResult result) throws Exception {
|
String actionName = meta.getActionName();
|
|
//1. 如果没有配置特定的执行逻辑,使用默认(实现类)执行
|
if (Util.isEmpty(actionName)) {
|
RemoteServerCallProvider provider = new RemoteServerCallProvider(result, this);
|
provider.exec(step, null);
|
return;
|
}
|
|
//2. 如果配置了特定的执行逻辑,用指定的实现类执行
|
ActionMeta actionMeta = ActionMeta.getInstance(actionName);
|
IActionProvider provider = actionMeta.createProvider();
|
|
String method = actionMeta.getMethodName();
|
provider.exec(step, method);
|
}
|
|
public void sendRemoteDBCall(WorkStep step, OutboundResult result) throws Exception {
|
String actionName = meta.getActionName();
|
|
//1. 如果没有配置特定的执行逻辑,用默认的逻辑(实现类)执行
|
if (Util.isEmpty(actionName)) {
|
RemoteDBCallProvider provider = new RemoteDBCallProvider(result);
|
provider.exec(step, null);
|
return;
|
}
|
|
//2. 如果配置了特定的执行逻辑,用指定的实现类执行
|
ActionMeta actionMeta = ActionMeta.getInstance(actionName);
|
|
if (actionMeta == null) {
|
logger.error("{}不存在", actionName);
|
throw new Exception("sendRemoteDBCall 执行错误");
|
}
|
|
IActionProvider provider = actionMeta.createProvider();
|
String method = actionMeta.getMethodName();
|
provider.exec(step, method);
|
}
|
|
@SuppressWarnings("unchecked")
|
public <T extends IRemoteSource> T remoteSource() {
|
return (T)remoteSource;
|
}
|
|
public String getId() {
|
return meta.getId();
|
}
|
|
public ICallMeta getMeta() {
|
return meta;
|
}
|
|
public String getURL() {
|
return meta.getURL();
|
}
|
|
public String getRemoteFilter() {
|
return meta.getRemoteFilter();
|
}
|
|
public String getDataName() {
|
return meta.getDataName();
|
}
|
|
public String getName() {
|
return meta.getName();
|
}
|
|
public ICallDirection getType() {
|
return direction;
|
}
|
|
public Mappings getMappings() {
|
return null;
|
}
|
|
public MappingsRuntime getMappingsRuntime(DataPackage dataPackage) {
|
return null;
|
}
|
|
public CallMethod getCallMethod() {
|
return null;
|
}
|
|
public IRemoteSource getRemoteSource() {
|
return remoteSource;
|
}
|
|
public String getSourceName() {
|
return meta.getSourceName();
|
}
|
|
public boolean isPermitEmptyStamp() {
|
return meta.isPermitEmptyStamp();
|
}
|
|
public String getHistoryTableName() {
|
return meta.getHistoryTableName();
|
}
|
|
public Fields getIdFields() {
|
return meta.getIdFields();
|
}
|
|
public String getStampField() {
|
return meta.getStampField();
|
}
|
|
public String getOrderByField() {
|
return meta.getOrderByField();
|
}
|
|
public String getIOTaskName() {
|
return meta.getIOTaskName();
|
}
|
|
public boolean isPageActive() {
|
return meta.isPageActive();
|
}
|
|
public String getRoute() {
|
return meta.getRoute();
|
}
|
|
public String getMonitorId() {
|
return meta.getMonitorId();
|
}
|
|
public String getTitle() {
|
return meta.getTitle();
|
}
|
|
public ContentType getContentType() {
|
return meta.getContentType();
|
}
|
|
public MapList<String, Template> getRequestTemplateList() {
|
return meta.getRequestTemplateList();
|
}
|
|
public ResponseTemplate getResponseTemplate() {
|
return meta.getResponseTemplate();
|
}
|
|
|
public DataSource[] getRequestDataSources() {
|
return meta.getRequestDataSources();
|
}
|
|
|
public MethodType getMethodType() {
|
return meta.getMethodType();
|
}
|
}
|