P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package foundation.icall;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
import foundation.action.ActionBucket;
import foundation.action.ActionContext;
import foundation.action.ActionMeta;
import foundation.action.ActionProvider;
import foundation.dao.DataPackage;
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.RemoteDBCallProvider;
import foundation.icall.callout.RemoteSourceBucket;
import foundation.icall.log.ICallLogger;
import foundation.util.Util;
 
 
public class ICall {
    
    protected static Logger logger;
    private static RemoteSourceBucket sourceBucket;
 
    private ICallMeta meta;
    private IRemoteSource remoteSource;
    private Class<?> actionClass;
    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(ActionContext context, OutboundResult result) throws Exception {
        String actionName = meta.getActionName();
        if (Util.isEmpty(actionName)) {
            logger.error("iCall send remote server call error, empty action");
            return;
        }
        
        //1. 创建  action provider 
        ActionBucket actionBucket = ActionBucket.getInstance();
        ActionMeta actionMeta = actionBucket.get(actionName);
        IActionProvider provider = actionMeta.createProvider();
        
        //2. 创建 context
        RemoteContext remoteContext = new RemoteContext(this);
        ActionContext newContext = context.newInstance();
        newContext.addContext(remoteContext);
        
        if (provider instanceof ActionProvider) {
            ActionProvider actionProvider = (ActionProvider)provider;
            actionProvider.setContext(newContext);
        }
        
        //3. 运行
        String method = actionMeta.getMethodName();
        provider.exec(newContext, method);
 
    }
 
    public void sendRemoteDBCall(ActionContext context, OutboundResult result) throws Exception {
        //1. 创建  action provider 
        String actionName = meta.getActionName();
        IActionProvider provider = null; ActionMeta actionMeta = null;
        
        if (!Util.isEmpty(actionName)) {
            ActionBucket actionBucket = ActionBucket.getInstance();
            actionMeta = actionBucket.get(actionName);
            provider = actionMeta.createProvider();
        }
        else {
            provider = new RemoteDBCallProvider();
        }
        
        //2. 创建 context
        RemoteContext remoteContext = new RemoteContext(this);
        remoteContext.setOutboundResult(result);
        ActionContext newContext = context.newInstance();
        newContext.addContext(remoteContext);
        
        if (provider instanceof ActionProvider) {
            ActionProvider actionProvider = (ActionProvider)provider;
            actionProvider.setContext(newContext);
        }
 
        //3. 运行
        if (actionMeta != null) {
            String method = actionMeta.getMethodName();
            provider.exec(newContext, method);
        }
        else {
            ((RemoteDBCallProvider)provider).doExec(newContext);
        }
 
        ICallLogger.endAction(remoteContext.getLogRecord(), remoteContext.getResponse());
    }
    
    @SuppressWarnings("unchecked")
    public <T> T getAction() throws InstantiationException, IllegalAccessException {
        
        if (actionClass == null) {
            return null;
        }
        
        Object obj = actionClass.newInstance();
        return (T)obj;
    }
 
    @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() {
        // TODO Auto-generated method stub
        return null;
    }
 
    public MappingsRuntime getMappingsRuntime(DataPackage dataPackage) {
        // TODO Auto-generated method stub
        return null;
    }
 
    public CallMethod getCallMethod() {
        // TODO Auto-generated method stub
        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();
    }
 
}