ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
package com.vci.server.cache;
 
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;
 
import org.apache.commons.lang3.StringUtils;
 
import com.alibaba.fastjson.JSONObject;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.etm.EnumItem;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.stm.StatePool;
import com.vci.corba.omd.vrm.VersionRule;
import com.vci.server.cache.redis.RedisUtil;
 
public final class OMCacheProvider {
    
    public static AttribItem getAttribute(String name) {
        String attrObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, name);
        if (StringUtils.isBlank(attrObj))
            return null;
        
        return JSONObject.parseObject(attrObj, AttribItem.class);
    }
    
    public static AttribItem[] getAttributes(String[] names) {
        List<AttribItem> lstAI = new ArrayList<AttribItem>();
        for (int i = 0; i < names.length; i++) {
            String jsonObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, names[i]);
            if (StringUtils.isBlank(jsonObj))
                continue;
            
            lstAI.add(JSONObject.parseObject(jsonObj, AttribItem.class));
        }
        
        lstAI.sort(new Comparator<AttribItem>() {//使用List接口的方法排序
            @Override
            public int compare(AttribItem o1, AttribItem o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });        
        
        return lstAI.toArray(new AttribItem[0]);
    }
    
    public static AttribItem[] getAttributes() {
        List<AttribItem> lstAI = new ArrayList<AttribItem>();
        
        Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.ATTRITEMS);
        String[] jsons = map.values().toArray(new String[0]);
        for (int i = 0; i < jsons.length; i++) {
            if (StringUtils.isBlank(jsons[i]))
                continue;
            
            lstAI.add(JSONObject.parseObject(jsons[i], AttribItem.class));
        }
        
        lstAI.sort(new Comparator<AttribItem>() {//使用List接口的方法排序
            @Override
            public int compare(AttribItem o1, AttribItem o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });        
        
        return lstAI.toArray(new AttribItem[0]);
    }
    
    public static boolean existAttribute(String name) {
        if (StringUtils.isBlank(name))
            return false;
        
        String jsonObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, name.toLowerCase());
        if (StringUtils.isBlank(jsonObj))
            return false;
        
        return true;
    }
    
    public static EnumItem getEnumType(String name) {
        String jsonObj = RedisUtil.getInstance().hget(CacheNames.ENUMTYPES, name.toLowerCase());
        if (StringUtils.isBlank(jsonObj))
            return null;
        
        return JSONObject.parseObject(jsonObj, EnumItem.class);
    }
    
    public static boolean existEnumType(String name) {
        if (StringUtils.isBlank(name))
            return false;
        
        String jsonObj = RedisUtil.getInstance().hget(CacheNames.ENUMTYPES, name.toLowerCase());
        if (StringUtils.isBlank(jsonObj))
            return false;
        
        return true;
    }
    
    public static EnumItem[] getEnumTypeByFilter(String filter) {
        
        Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.ENUMTYPES);
        
        boolean isFilter = !StringUtils.isBlank(filter);
        
        List<EnumItem> lstET = new ArrayList<EnumItem>();
        String[] jsons = map.values().toArray(new String[0]);
        for (String json : jsons) {
            if (StringUtils.isBlank(json))
                continue;
            
            EnumItem item = JSONObject.parseObject(json, EnumItem.class);
            if (isFilter) {
                if (item.name.contains(filter))
                    lstET.add(item);
            } else {
                lstET.add(item);
            }
        }
        
        lstET.sort(new Comparator<EnumItem>() {//使用List接口的方法排序
            @Override
            public int compare(EnumItem o1, EnumItem o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });
 
        return lstET.toArray(new EnumItem[0]);
    }
    
    public static StatePool getLifeState(String name) {
        String jsonObj = RedisUtil.getInstance().hget(CacheNames.LIFESTATES, name.toLowerCase());
        if (StringUtils.isBlank(jsonObj))
            return null;
        
        return JSONObject.parseObject(jsonObj, StatePool.class);
    }
    
    public static StatePool[] getLifeStates() {
        List<StatePool> lstState = new ArrayList<StatePool>();
        
        Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.LIFESTATES);
        String[] jsons = map.values().toArray(new String[0]);
        for (int i = 0; i < jsons.length; i++) {
            if (StringUtils.isBlank(jsons[i]))
                continue;
            
            lstState.add(JSONObject.parseObject(jsons[i], StatePool.class));
        }
        
        lstState.sort(new Comparator<StatePool>() {//使用List接口的方法排序
            @Override
            public int compare(StatePool o1, StatePool o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });        
        
        return lstState.toArray(new StatePool[0]);
    }
    
    
    public static LifeCycle getLifeCycle(String name) {
        String jsonObj = RedisUtil.getInstance().hget(CacheNames.LIFECYCLES, name.toLowerCase());
        if (StringUtils.isBlank(jsonObj))
            return null;
        
        return JSONObject.parseObject(jsonObj, LifeCycle.class);
    }
    
    public static LifeCycle[] getLifeCycles() {
        List<LifeCycle> lstLC = new ArrayList<LifeCycle>();
        
        Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.LIFECYCLES);
        String[] jsons = map.values().toArray(new String[0]);
        for (int i = 0; i < jsons.length; i++) {
            if (StringUtils.isBlank(jsons[i]))
                continue;
            
            lstLC.add(JSONObject.parseObject(jsons[i], LifeCycle.class));
        }
        
        lstLC.sort(new Comparator<LifeCycle>() {//使用List接口的方法排序
            @Override
            public int compare(LifeCycle o1, LifeCycle o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });                
        
        return lstLC.toArray(new LifeCycle[0]);
    }
    
    /**
     * 获取事件key
     * 
     * @throws Throwable
     */
    public static String[] getLCEventKeys() {
        Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.LCEVENTS);
        
        return map.keySet().toArray(new String[0]);
    }
 
    /**
     * 获取事件value
     * 
     * @throws Throwable
     */
 
    public static String getLCEventValue(String key) throws Throwable {
        return RedisUtil.getInstance().hget(CacheNames.LCEVENTS, key);
    }
    
    public static VersionRule getVersionRule(String name) {
        String jsonObj = RedisUtil.getInstance().hget(CacheNames.VERRULES, name.toLowerCase());
        if (StringUtils.isBlank(jsonObj))
            return null;
        
        return JSONObject.parseObject(jsonObj, VersionRule.class);
    }
    
    public static VersionRule[] getVersionRules() {
        List<VersionRule> lstVR = new ArrayList<VersionRule>();
        
        Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.VERRULES);
        String[] jsons = map.values().toArray(new String[0]);
        for (int i = 0; i < jsons.length; i++) {
            if (StringUtils.isBlank(jsons[i]))
                continue;
            
            lstVR.add(JSONObject.parseObject(jsons[i], VersionRule.class));
        }
        
        lstVR.sort(new Comparator<VersionRule>() {//使用List接口的方法排序
            @Override
            public int compare(VersionRule o1, VersionRule o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });                
        
        return lstVR.toArray(new VersionRule[0]);
    }
    
 
    public static BtmItem getBizType(String name) {
        String btObj = RedisUtil.getInstance().hget(CacheNames.BIZTYPES, name.toLowerCase());
        if (StringUtils.isBlank(btObj))
            return null;
        
        return JSONObject.parseObject(btObj, BtmItem.class);
    }
    
    public static BtmItem[] getBizTypes() {
        Map<String, String> allBTs = RedisUtil.getInstance().hgetAll(CacheNames.BIZTYPES);
        
        List<BtmItem> lstObj = new ArrayList<BtmItem>();
        String[] items = allBTs.values().toArray(new String[0]);
        for (int i = 0; i < items.length; i++) {
            lstObj.add(JSONObject.parseObject(items[i], BtmItem.class));
        }
        
        lstObj.sort(new Comparator<BtmItem>() {//使用List接口的方法排序
            @Override
            public int compare(BtmItem o1, BtmItem o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });                
        
        return lstObj.toArray(new BtmItem[0]);
    }
    
    public static BtmItem[] getChildrenBizTypes(String btName) {
        Map<String, String> allBTs = RedisUtil.getInstance().hgetAll(CacheNames.BIZTYPES);
        
        List<BtmItem> lstBT = new ArrayList<BtmItem>();
        String[] items = allBTs.values().toArray(new String[0]);
        for (int i = 0; i < items.length; i++) {
            BtmItem bt = JSONObject.parseObject(items[i], BtmItem.class);
            if (bt.fName.equals(btName))
                lstBT.add(bt);
        }
        
        lstBT.sort(new Comparator<BtmItem>() {//使用List接口的方法排序
            @Override
            public int compare(BtmItem o1, BtmItem o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });        
        
        return lstBT.toArray(new BtmItem[0]);
    }    
    
    public static String[] getBTAttributes(String name) {
        String btObj = RedisUtil.getInstance().hget(CacheNames.BIZTYPES, name.toLowerCase());
        if (StringUtils.isBlank(btObj))
            return new String[0];
        
        BtmItem bt = JSONObject.parseObject(btObj, BtmItem.class);
        if (bt != null)
            return bt.apNameArray;
        
        return new String[0];
    }
 
    
    public static AttribItem[] getAttribItemsByBizType(String name) {
        String btObj = RedisUtil.getInstance().hget(CacheNames.BIZTYPES, name.toLowerCase());
        if (StringUtils.isBlank(btObj))
            return new AttribItem[0];
        
        BtmItem bt = JSONObject.parseObject(btObj, BtmItem.class);
        if (bt == null)
            return new AttribItem[0];
        
        List<AttribItem> lstAI = new ArrayList<AttribItem>();
        for (int i = 0; i < bt.apNameArray.length; i++) {
            String attrObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, bt.apNameArray[i]);
            if (StringUtils.isBlank(attrObj))
                continue;
            
            lstAI.add(JSONObject.parseObject(attrObj, AttribItem.class));
        }
        
        return lstAI.toArray(new AttribItem[0]);
    }
    
 
    public static LinkType getLinkType(String name) {
        String attrObj = RedisUtil.getInstance().hget(CacheNames.LINKTYPES, name.toLowerCase());
        if (StringUtils.isBlank(attrObj))
            return null;
        
        return JSONObject.parseObject(attrObj, LinkType.class);
    }
    
    public static LinkType[] getLinkTypes() {
        Map<String, String> allLTs = RedisUtil.getInstance().hgetAll(CacheNames.LINKTYPES);
        
        List<LinkType> lstObj = new ArrayList<LinkType>();
        String[] items = allLTs.values().toArray(new String[0]);
        for (int i = 0; i < items.length; i++) {
            lstObj.add(JSONObject.parseObject(items[i], LinkType.class));
        }
        
        lstObj.sort(new Comparator<LinkType>() {//使用List接口的方法排序
            @Override
            public int compare(LinkType o1, LinkType o2) {
                return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
            }
        });            
        
        return lstObj.toArray(new LinkType[0]);
    }
    
    
    public static String[] getLTAttributes(String name) {
        String jsonObj = RedisUtil.getInstance().hget(CacheNames.LINKTYPES, name.toLowerCase());
        if (StringUtils.isBlank(jsonObj))
            return new String[0];
        
        LinkType lt = JSONObject.parseObject(jsonObj, LinkType.class);
        if (lt != null)
            return lt.attributes;
        
        return new String[0];
    }
 
    
    public static AttribItem[] getAttribItemsByLinkType(String name) {
        String btObj = RedisUtil.getInstance().hget(CacheNames.LINKTYPES, name.toLowerCase());
        if (StringUtils.isBlank(btObj))
            return new AttribItem[0];
        
        BtmItem bt = JSONObject.parseObject(btObj, BtmItem.class);
        if (bt == null)
            return new AttribItem[0];
        
        List<AttribItem> lstAI = new ArrayList<AttribItem>();
        for (int i = 0; i < bt.apNameArray.length; i++) {
            String attrObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, bt.apNameArray[i]);
            if (StringUtils.isBlank(attrObj))
                continue;
            
            lstAI.add(JSONObject.parseObject(attrObj, AttribItem.class));
        }
        
        return lstAI.toArray(new AttribItem[0]);
    }
    
}