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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
package com.vci.server.bof.delegate;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.lang3.ArrayUtils;
 
import com.vci.omd.utils.ObjectTool;
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
import com.vci.server.cache.OMCacheProvider;
import com.vci.server.mw.ServerContextVariable;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.omd.data.RevisionDataInfo;
import com.vci.corba.omd.data.VersionDataInfo;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.vrm.VersionRule;
import com.vci.corba.common.VCIError;
import com.vci.corba.common.data.VCIInvocationInfo;
import com.vci.common.objects.UserEntity;
import com.vci.common.utility.ObjectUtility;
 
/**
 * 负责服务器段的初始对象构建,以及升版本、生版次对象的构建
 * @author VCI_STGK_Lincq
 *
 */
public class BOFactoryServerBODelegate extends FactoryBaseDelegate {
 
    private static BOFactoryServerBODelegate instance = null;
    public static UserEntity userEntity = null;
    
    public BOFactoryServerBODelegate() {
        userEntity = new UserEntity();
    }
    
    public static synchronized BOFactoryServerBODelegate getInstance() {
        if (instance == null) {
            instance = new BOFactoryServerBODelegate();
        }
        
        return instance;
    }
 
    public BusinessObject initBusinessObject(String btmName) throws VCIError {
        try {
            VCIInvocationInfo vii = HibernateSessionFactory.getVciSessionInfo();
            if (vii == null)
                vii = ServerContextVariable.getInvocationInfo();
            
            BtmItem boItem = getBtmDefine(btmName);
            BusinessObject bo = new BusinessObject();
            bo.oid = ObjectUtility.getNewObjectID36();
            bo.revisionid = ObjectUtility.getNewObjectID36();
            bo.nameoid = ObjectUtility.getNewObjectID36();
            bo.btName = btmName;
            bo.isLastR = true;
            bo.isFirstR = true;
            bo.isFirstV = true;
            bo.isLastV = true;
            
            bo.creator = vii.userName;
            bo.createTime = System.currentTimeMillis();
            bo.modifier = vii.userName;
            bo.modifyTime = System.currentTimeMillis();
            bo.revisionRule = boItem.revRuleName;
            bo.versionRule = String.valueOf(boItem.verRuleName);
            
            RevisionDataInfo revisonObj = getRevisionSeqVal(boItem.revLevel, boItem.revRuleName, boItem.revInput);
            VersionDataInfo versionObj = getVersionValue(boItem.verRuleName);
            bo.revisionSeq = revisonObj.revisionSeq;
            bo.revisionValue = revisonObj.revisionVal;
            bo.versionSeq = versionObj.versionSeq;
            bo.versionValue = versionObj.versionVal;
            
            
            bo.lctId = boItem.lifeCycle;
            bo.lcStatus = getLcFirstStatus(boItem.lifeCycle);
            bo.id = "";
            bo.name = "";
            bo.description = "";
            bo.owner = vii.userName;
            //bo.checkinBy = vii.userName;
            bo.fromVersion = "";
            initTypeAttributeValue(bo);
            
            BOFactoryServerDelegate.getInstance().dealBusinessObjectNullValue(bo);
            return bo;
        } catch (VCIError e) {
            throw e;
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10002", e);
        }
        
    }
    
//    public ClientBusinessObject cloneBusinessObject(ClientBusinessObject fromBo, BtmItem btmItem, AttribItem[] attrItems, boolean isNew, String userName) throws VCIError {
//        if (isNew || userName == null || userName.trim().equals("")) {
//            userName = fromBo.getCreator();
//        }
//        
//        ClientBusinessObject toBo = new ClientBusinessObject();
//        toBo.setOid(ObjectUtility.getNewObjectID36());
//        toBo.setRevisionid(ObjectUtility.getNewObjectID36());
//        toBo.setNameoid(ObjectUtility.getNewObjectID36());
//        toBo.setBtmName(fromBo.getBtmName());
//        toBo.setIsLastR(1);
//        toBo.setIsFirstR(1);
//        toBo.setIsFirstV(1);
//        toBo.setIsLastV(1);
//        
//        toBo.setCreator(userName);
//        toBo.setCreateTime(String.valueOf(System.currentTimeMillis()));
//        toBo.setLastModifier(userName);
//        toBo.setLastModifyTime(String.valueOf(System.currentTimeMillis()));
//        toBo.setRevisionRule(btmItem.revRuleName);
//        toBo.setVersionRule(String.valueOf(btmItem.verRuleName));
//        
//        if (isNew) {
//            toBo.setRevisionSeq(fromBo.getRevisionSeq());
//            toBo.setRevisionValue(fromBo.getRevisionValue());
//            toBo.setVersionSeq(fromBo.getVersionSeq());
//            toBo.setVersionValue(fromBo.getVersionValue());
//        } else {
//            RevisionDataInfo revisonObj = getRevisionSeqVal(btmItem.revLevel, btmItem.revRuleName, btmItem.revInput);
//            VersionDataInfo versionObj = getVersionValue(btmItem.verRuleName);
//            toBo.setRevisionSeq(revisonObj.revisionSeq);
//            toBo.setRevisionValue(revisonObj.revisionVal);
//            toBo.setVersionSeq(versionObj.versionSeq);
//            toBo.setVersionValue(versionObj.versionVal);
//        }
//        
//        toBo.setLctId(fromBo.getLctId());
//        if (isNew) {
//            toBo.setLcStatus(fromBo.getLcStatus());
//        } else {
//            toBo.setLcStatus(getLcFirstStatus(btmItem.lifeCycle));
//        }
//        toBo.setId(fromBo.getId());
//        toBo.setName(fromBo.getName());
//        toBo.setDescription(fromBo.getDescription());
//        toBo.setOwner(userName);
//        toBo.setCheckinBy(userName);
//        toBo.setCopyFromVersion("");
//        initRevisionTypeAttributeValue(fromBo, toBo, attrItems, isNew);
//        
//        return toBo;
//    }
//    
//    private void initRevisionTypeAttributeValue(ClientBusinessObject fromBo, ClientBusinessObject toBo, AttribItem[] items, boolean isNew) throws VCIError {
//        if(isNew){
//            AttributeValue[] vals = fromBo.getBusinessObject().newAttrValList;
//            AttributeValue[] valsCopy = new AttributeValue[vals.length];
//            for (int i = 0; i < valsCopy.length; i++) {
//                valsCopy[i] = new AttributeValue(vals[i].attrName, vals[i].attrVal);
//            }
//            toBo.getBusinessObject().newAttrValList = valsCopy;
//        } else {
//            for (AttribItem item : items) {
//                toBo.setAttributeValue(item.name, fromBo.getAttributeValue(item.name));        
//            }
//        }
//    }
    
    private BtmItem getBtmDefine(String btmName) throws VCIError {
        try {
            //BtmItem boItem = ServerServiceProvider.getOMDService().getBTMService().getBtmItemByName(btmName);
            BtmItem boItem = OMCacheProvider.getBizType(btmName);
            return boItem;
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10001", e);
        }
    }
    
    /**
     * 设置BO对象的初始属性值
     * @param bo
     * @throws VCIError 
     */
    private void initTypeAttributeValue(BusinessObject bo) throws VCIError {
        try {
            //String[] names = ServerServiceProvider.getOMDService().getBTMService().getBtmApNameArray(bo.btmName);
            //AttribItem[] items = ServerServiceProvider.getOMDService().getAttributeService().getAttribItemsByNames(names);
            AttribItem[] items = OMCacheProvider.getAttribItemsByBizType(bo.btName);
            for (AttribItem item : items) {
                ObjectTool.setBOAttributeValue(bo, item.name, item.defValue);
            }
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10007", e);
        }
    }
    
    /**
     * 获取初始的版本信息
     * @param revLevel, 版本类型
     * @param revRuleName,版本规则名称
     * @return
     * @throws Exception 
     */
    private RevisionDataInfo getRevisionSeqVal(int revLevel, String revRuleName, boolean revInput) throws Exception {
        RevisionDataInfo obj = new RevisionDataInfo();
        obj.revisionSeq = 1;
        if (revInput) {
            obj.revisionVal = "";
            return obj;
        }
        if (revLevel == 0) {
            obj.revisionVal = "-";
        } else {
            obj.revisionVal = getFirstRevision(revRuleName);
        }
        
        return obj;
    }
    
    /**
     * 获取第一个版本值
     * @param revRuleName
     * @return
     * @throws Exception 
     */
    private String getFirstRevision(String revRuleName) throws Exception {
        //VersionRule vr = ServerServiceProvider.getOMDService().getVerRuleService().getVersionRule(revRuleName);
        VersionRule vr = OMCacheProvider.getVersionRule(revRuleName);
        if(vr!=null){
            return vr.initialValue;
        }
        return "";
//        try {
//            VersionRule[] vrs = VersionRuleProvider.getInstance().getVersionRules();
//            for (VersionRule vr : vrs) {
//                if (vr.name.equals(revRuleName)) {
//                    return vr.initialValue;
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new VCIError();
//        } catch (Throwable e) {
//            e.printStackTrace();
//            throw new VCIError();
//        }
//        return "";
    }
    
    /**
     * 获取去初始版本
     * @param verRuleName
     * @return
     */
    private VersionDataInfo getVersionValue(int verRuleName) {
        VersionDataInfo obj = new VersionDataInfo();
        obj.versionSeq = 1;
        if (verRuleName == 0) {
            obj.versionVal = "1";
        } else if (verRuleName == 1){
            obj.versionVal = "a";
        } else if (verRuleName == 2) {
            obj.versionVal = "0";
        }
        
        return obj;
    }
    
 
    /**
     * 根据生命周期名称获取第一个生命周期节点
     * @param lifeCycleName
     * @return
     * @throws Exception 
     */
    private String getLcFirstStatus(String lifeCycleName) throws Exception {
        //LifeCycle lifeCycle = ServerServiceProvider.getOMDService().getLifeCycleService().getLifeCycle(lifeCycleName);
        LifeCycle lifeCycle = OMCacheProvider.getLifeCycle(lifeCycleName);
        if(lifeCycle!=null){
            return lifeCycle.startState;
        }
        return "";
        
//        try {
//            LifeCyle[] lifeCycls = LifeCycleProvider.getInstance().getLifeCyles();
//            
//            for (LifeCyle lifeCycle : lifeCycls) {
//                if (lifeCycle.name.equals(lifeCycleName)) {
//                    return lifeCycle.startState;
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new VCIError();
//        } catch (Throwable e) {
//            e.printStackTrace();
//            throw new VCIError();
//        }
//        return "";
 
    }
 
    
    /**
     * 升版业务对象,并复制From端或To端的所有link
     * @param bo,业务对象
     * @param los,关联链接对象
     * @param isRev,true代表升版本,false代表升版次
     * @param isSave,true代表保存,false代表不保存
     * @param isFromLinkCopy, true代表传入的业务对象作为link的from端进行link的复制
     * @param isToLinkCopy,true代表传入的业务对象作为link的to端进行link的复制
     * @return
     * @throws VCIError
     */
    public BusinessObject revisionBusinessObject(BusinessObject bo,
            LinkObject[] los, boolean isRev, boolean isSave, boolean isFromLinkCopy, boolean isToLinkCopy) throws VCIError {
        BusinessObject newBo = null;
        boolean isRevision = false;
        boolean isNewVersion = false;
        bo = BOFactoryServerDelegate.getInstance().getInfoBusinessObject(bo.oid, bo.btName);
        if (isRev) {
            newBo = getNewRevisionBO(bo);
            isRevision = true;
        } else {
            newBo = getNewVersionBO(bo);
            isNewVersion = true;
        }
        BOFactoryServerDelegate.getInstance().dealBusinessObjectNullValue(newBo);
        
        LinkObject[] revFromLos = null;
        if (isFromLinkCopy) {
            revFromLos = getFromLinkData(bo, newBo, true, null);
        }
        LinkObject[] revToLos = null;
        if (isToLinkCopy) {
            revToLos = getToLinkData(bo, newBo, true, null);
        }
        if (isSave) {
            BOFactoryServerDelegate bofDelegate = BOFactoryServerDelegate.getInstance();
            if (revFromLos != null) {
                bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revFromLos);
            }
            if (revToLos != null) {
                bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revToLos);
            }
            return bofDelegate.createBusinessObject(newBo, isRevision, isNewVersion);
        }
        
        return newBo;
    }
    
    /**
     * 升版业务对象,并复制From端或To端指定类型的link
     * @param bo,业务对象
     * @param linkNames,需要复制的link名称
     * @param isRev,true代表升版本,false代表升版次
     * @param isSave,true代表保存,false代表不保存
     * @param isFromLinkCopy, true代表传入的业务对象作为link的from端进行link的复制
     * @param isToLinkCopy,true代表传入的业务对象作为link的to端进行link的复制
     * @return
     * @throws VCIError
     */
    public BusinessObject revisionBusinessObject(BusinessObject bo,
            String[] linkNames, boolean isRev, boolean isSave, boolean isFromLinkCopy, boolean isToLinkCopy) throws VCIError {
        BusinessObject newBo = null;
        boolean isRevision = false;
        boolean isNewVersion = false;
        bo = BOFactoryServerDelegate.getInstance().getInfoBusinessObject(bo.oid, bo.btName);
        if (isRev) {
            newBo = getNewRevisionBO(bo);
            isRevision = true;
        } else {
            newBo = getNewVersionBO(bo);
            isNewVersion = true;
        }
        BOFactoryServerDelegate.getInstance().dealBusinessObjectNullValue(newBo);
        
        LinkObject[] revFromLos = null;
        if (isFromLinkCopy) {
            revFromLos = getFromLinkData(bo, newBo, false, linkNames);
        }
        LinkObject[] revToLos = null;
        if (isToLinkCopy) {
            revToLos = getToLinkData(bo, newBo, false, linkNames);
        }
        if (isSave) {
            BOFactoryServerDelegate bofDelegate = BOFactoryServerDelegate.getInstance();
            if (revFromLos != null) {
                bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revFromLos);
            }
            if (revToLos != null) {
                bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revToLos);
            }
            return bofDelegate.createBusinessObject(newBo, isRevision, isNewVersion);
        }
        
        return newBo;
    }
    
    private BusinessObject getNewRevisionBO(BusinessObject bo) throws VCIError {
        try {
            BtmItem boItem = getBtmDefine(bo.btName);
            if (boItem.revLevel == 0) {
                throw this.getLocalString("P0010SOF-00015", null);
            }
            BusinessObject revBO = new BusinessObject();
            revBO.oid = ObjectUtility.getNewObjectID36();
            revBO.revisionid = ObjectUtility.getNewObjectID36();
            revBO.nameoid = bo.nameoid;
            revBO.btName = bo.btName;
            revBO.isLastR = true;
            revBO.isFirstR = false;
            revBO.isFirstV = true;
            revBO.isLastV = true;
            
            revBO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
            revBO.createTime = System.currentTimeMillis();
            revBO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
            revBO.modifyTime = System.currentTimeMillis();
            revBO.revisionRule = boItem.revRuleName;
            revBO.versionRule = String.valueOf(boItem.verRuleName);
            
            BOFactoryServerDelegate bosDelegate = BOFactoryServerDelegate.getInstance();
            RevisionDataInfo revisionInfo = bosDelegate.getNextRevisionValueObject(bo.btName, bo.nameoid, boItem.revRuleName, false, "");
            revBO.revisionSeq = revisionInfo.revisionSeq;
            revBO.revisionValue = revisionInfo.revisionVal;
            
            VersionDataInfo versionObj = getVersionValue(boItem.verRuleName);
            revBO.versionSeq = versionObj.versionSeq;
            revBO.versionValue = versionObj.versionVal;
            revBO.lctId = bo.lctId;
            revBO.lcStatus = getLcFirstStatus(bo.lctId);
            revBO.id = bo.id;
            revBO.name = bo.name;
            revBO.description = bo.description;
            revBO.owner = HibernateSessionFactory.getVciSessionInfo().userName;
            //revBO.checkinBy = HibernateSessionFactory.getVciSessionInfo().userName;
            revBO.fromVersion = bo.oid;
            initRevisionTypeAttributeValue(bo, revBO);
            
            return revBO;
        } catch (VCIError e) {
            throw e;
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10003", e);
        }
    }
    
//    private String getTableName(String btmName) {
//        return OmdTools.getBTTableName(btmName);
//    }
    
    /**
     * 初始升版本BO对象属性值
     * @param fromBo
     * @param toBo
     * @throws VCIError 
     */
    private void initRevisionTypeAttributeValue(BusinessObject fromBo, BusinessObject toBo) throws VCIError {
        AttribItem[] items;
        try {
            //String[] names = ServerServiceProvider.getOMDService().getBTMService().getBtmApNameArray(toBo.btmName);
            //items = ServerServiceProvider.getOMDService().getAttributeService().getAttribItemsByNames(names);
            //items = BtmProvider.getInstance().getBtAbItems(toBo.btmName);
            items = OMCacheProvider.getAttribItemsByBizType(toBo.btName);
            for (AttribItem item : items) {
                ObjectTool.setBOAttributeValue(toBo, item.name, ObjectTool.getBOAttributeValue(fromBo, item.name));
            }
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10006", e);
        }
        
    }
    
    private BusinessObject getNewVersionBO(BusinessObject bo) throws VCIError {
        try {
            BtmItem boItem = getBtmDefine(bo.btName);
            if (boItem.revLevel != 2) {
                throw this.getLocalString("P0010SOF-00016", null);
            }
            BusinessObject revBO = new BusinessObject();
            revBO.oid = ObjectUtility.getNewObjectID36();
            revBO.revisionid = bo.revisionid;
            revBO.nameoid = bo.nameoid;
            revBO.btName = bo.btName;
            revBO.isLastR = bo.isLastR;
            revBO.isFirstR = bo.isFirstR;
            revBO.isFirstV = false;
            revBO.isLastV = true;
            
            revBO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
            revBO.createTime = System.currentTimeMillis();
            revBO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
            revBO.modifyTime = System.currentTimeMillis();
            revBO.revisionRule = boItem.revRuleName;
            revBO.versionRule = String.valueOf(boItem.verRuleName);
            
            revBO.revisionSeq = bo.revisionSeq;
            revBO.revisionValue = bo.revisionValue;
            
            BOFactoryServerDelegate bofDelegate = BOFactoryServerDelegate
                    .getInstance();
            VersionDataInfo versionObj = bofDelegate.getNextVersionValue(bo.btName, bo.revisionid, bo.nameoid, boItem.verRuleName);
            revBO.versionSeq = versionObj.versionSeq;
            revBO.versionValue = versionObj.versionVal;
            revBO.lctId = bo.lctId;
            revBO.lcStatus = bo.lcStatus;
            revBO.id = bo.id;
            revBO.name = bo.name;
            revBO.description = bo.description;
            revBO.owner = HibernateSessionFactory.getVciSessionInfo().userName;
            //revBO.checkinBy = HibernateSessionFactory.getVciSessionInfo().userName;
            revBO.fromVersion = bo.oid;
            initRevisionTypeAttributeValue(bo, revBO);
            
            return revBO;
        } catch (VCIError e) {
            throw e;
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10003", e);
        }
    }
    
    /**
     * 根据业务对象获取其作为from端对象的所有link数据,并构建新版本的关系数据
     * @param bo
     * @param revBo
     * @param isAll, 是否复制所有的link
     * @param linkNames,需要复制的link名称
     * @return
     * @throws VCIError
     */
    private LinkObject[] getFromLinkData(BusinessObject bo, BusinessObject revBo, boolean isAll, String[] linkNames) throws VCIError {
        String[] links = getLinkTypeByFromType(bo.btName);
        
        if (links == null || links.length == 0) {
            return null;
        }
        Map<String, String> linkMap = new HashMap<String, String>();
        if (!isAll) {
            if (linkNames == null || linkNames.length == 0) {
                return null;
            }
            for (int i = 0; i < linkNames.length; i ++) {
                linkMap.put(linkNames[i], "");
            }
        }
        
        List<LinkObject> linkList = new ArrayList<LinkObject>();
        LOFactoryServerDelegate linkDelegate = LOFactoryServerDelegate.getInstance();
        for (int i = 0; i < links.length; i++) {
            if (!isAll && !linkMap.containsKey(links[i])) {
                continue;
            }
            LinkObject[] los = linkDelegate.getLinkObjectByBO(bo, links[i], true);
            for (int j = 0; j < los.length; j++) {
                LinkObject revLo = revFromBOLinkObject(los[j], revBo);
                linkList.add(revLo);
            }
        }
        
        return linkList.toArray(new LinkObject[0]);
    }
    
    /**
     * 根据from端的类型名称获取链接类型的名称
     * @param fromType
     * @return
     * @throws VCIError
     */
    private String[] getLinkTypeByFromType(String fromType) throws VCIError {
        try {
            return iteratorGetSingleLinkTypeByFromType(fromType);
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10004", e);
        }
    }
    
    private String[] iteratorGetSingleLinkTypeByFromType(String fromType) throws Exception, Throwable {
        String[] links = getSingleLinkTypeByFromType(fromType);
        if (links == null || links.length == 0) {
            //BtmItem item = ServerServiceProvider.getOMDService().getBTMService().getBtmItemByName(fromType);
            BtmItem item = OMCacheProvider.getBizType(fromType);
            links = iteratorGetSingleLinkTypeByFromType(item.fName);
        }
        return links;
    }
    
    private String[] getSingleLinkTypeByFromType(String fromType) throws Exception, Throwable {
        //LinkType[] linkTypes = ServerServiceProvider.getOMDService().getLinkTypeService().getLinkTypes();
        LinkType[] linkTypes = OMCacheProvider.getLinkTypes();
        List<String> linkList = new ArrayList<String>();
 
        for (LinkType linkType : linkTypes) {
            if (ArrayUtils.contains(linkType.btmItemsFrom, fromType))
                linkList.add(linkType.name);
        }
        
        return linkList.toArray(new String[0]);
    }
    
    /**
     * 根据From端的新版本构建新的链接对象
     * @param lo
     * @param bo
     * @return
     */
    private LinkObject revFromBOLinkObject(LinkObject lo, BusinessObject bo) {
        LinkObject revLO = new LinkObject();
        revLO.oid = ObjectUtility.getNewObjectID36();;
        revLO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
        revLO.createTime = System.currentTimeMillis();
        revLO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
        revLO.modifyTime = System.currentTimeMillis();
        revLO.fromOid = bo.oid;
        revLO.fromRevOid = bo.revisionid;
        revLO.fromNameOid = bo.nameoid;
        revLO.fromBTName = bo.btName;
        revLO.ts = System.currentTimeMillis();
        
        String[] toBos =  BOFactoryServerDelegate.getInstance().getLastReleasedBOId(lo.toNameOid);
        if (toBos != null && toBos.length != 0) {
            revLO.toOid = toBos[0];
            revLO.toRevOid = toBos[1];
            revLO.toNameOid = toBos[2];
            revLO.toBTName = toBos[3];
        } else {
            revLO.toOid = lo.toOid;
            revLO.toRevOid = lo.toRevOid;
            revLO.toNameOid = lo.toNameOid;
            revLO.toBTName = lo.toBTName;
        }
        
        revLO.ts = System.currentTimeMillis();
 
        revLO.ltName = lo.ltName;
        revLO.newAttrValList = lo.hisAttrValList;
        revLO.hisAttrValList = new AttributeValue[0];
        
        return revLO;
    }
    
    /**
     * 根据业务对象获取其作为to端对象的所有link数据,并构建新版本的关系数据
     * @param bo
     * @param revBo
     * @param isAll, 是否复制所有的link
     * @param linkNames,需要复制的link名称
     * @return
     * @throws VCIError
     */
    private LinkObject[] getToLinkData(BusinessObject bo, BusinessObject revBo, boolean isAll, String[] linkNames) throws VCIError {
        String[] links = getLinkTypeByToType(bo.btName);
        if (links == null || links.length == 0) {
            return null;
        }
        
        Map<String, String> linkMap = new HashMap<String, String>();
        if (!isAll) {
            if (linkNames == null || linkNames.length == 0) {
                return null;
            }
            for (int i = 0; i < linkNames.length; i ++) {
                linkMap.put(linkNames[i], "");
            }
        }
        List<LinkObject> linkList = new ArrayList<LinkObject>();
        LOFactoryServerDelegate linkDelegate = LOFactoryServerDelegate.getInstance();
        for (int i = 0; i < links.length; i++) {
            if (!isAll && !linkMap.containsKey(links[i])) {
                continue;
            }
            LinkObject[] los = linkDelegate.getLinkObjectByBO(bo, links[i], false);
            for (int j = 0; j < los.length; j++) {
                LinkObject revLo = revToBOLinkObject(los[j], revBo);
                linkList.add(revLo);
            }
        }
        
        return linkList.toArray(new LinkObject[0]);
    }
    
    /**
     * 根据from端的类型名称获取链接类型的名称
     * @param fromType
     * @return
     * @throws VCIError
     */
    private String[] getLinkTypeByToType(String toType) throws VCIError {
        try {
            
            //LinkType[] linkTypes = ServerServiceProvider.getOMDService().getLinkTypeService().getLinkTypes();
            LinkType[] linkTypes = OMCacheProvider.getLinkTypes();
            List<String> linkList = new ArrayList<String>();
 
            for (LinkType linkType : linkTypes) {
                if (ArrayUtils.contains(linkType.btmItemsTo, toType))
                    linkList.add(linkType.name);
            }
 
            return linkList.toArray(new String[0]);
        } catch (Throwable e) {
            e.printStackTrace();
            throw this.getLocalString("P0010SOF-10005", e);
        }
    }
    
    /**
     * 根据TO端的新版本构建新的链接对象
     * @param lo
     * @param bo
     * @return
     */
    private LinkObject revToBOLinkObject(LinkObject lo, BusinessObject bo) {
        LinkObject revLO = new LinkObject();
        revLO.oid = ObjectUtility.getNewObjectID36();;
        revLO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
        revLO.createTime = System.currentTimeMillis();
        revLO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
        revLO.modifyTime = System.currentTimeMillis();
        revLO.fromOid = lo.fromOid;
        revLO.fromRevOid = lo.fromRevOid;
        revLO.fromNameOid = lo.fromNameOid;
        revLO.fromBTName = lo.fromBTName;
        revLO.toOid = bo.oid;
        revLO.toRevOid = bo.revisionid;
        revLO.toNameOid = bo.nameoid;
        revLO.toBTName = bo.btName;
        revLO.ts = System.currentTimeMillis();
 
        revLO.ltName = lo.ltName;
        revLO.newAttrValList = lo.hisAttrValList;
        revLO.hisAttrValList = new AttributeValue[0];
        
        return revLO;
    }
}