田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
package com.vci.client.bof;
 
import java.util.Date;
 
import org.apache.commons.lang3.StringUtils;
 
import com.vci.corba.common.data.VCIInvocationInfo;
import com.vci.client.LogonApplication;
import com.vci.client.omd.linktype.itf.LinkTypeInterface;
import com.vci.client.omd.linktype.itf.LinkTypeInterfaceImpl;
import com.vci.common.annotaion.MethodTypeAnnotation;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.mw.ClientContextVariable;
import com.vci.mw.LaunchModeEnum;
 
public class ClientLinkObjectOperation {
 
    
    private String getUserName() {
        String username = "";
        if(ClientContextVariable.getClientLanuchMode().equals(LaunchModeEnum.WebApp)){
            VCIInvocationInfo vcii = ClientContextVariable.getInvocationInfo();
            if(vcii !=null){
                username = ClientContextVariable.getInvocationInfo().userName;
            }
        }
        if(StringUtils.isEmpty(username)){
            username = LogonApplication.getUserEntityObject().getUserName();
        }
        return username;
    }
    public ClientLinkObject createLinkObject(String loName) throws VCIError {
        return createLinkObject(loName, getUserName() );
    }
    
    /**
     * 构建空的链接对象
     * @param loName, 链接类型名称
     * @param userName, 创建者
     * @return 空的链接对象
     * @throws VCIError
     */
    public ClientLinkObject createLinkObject(String loName, String userName) throws VCIError {
        ClientLinkObject clo = new ClientLinkObject();
        clo.setOid(ObjectUtility.getNewObjectID36());
        clo.setCreator(userName);
        clo.setCreateTime(System.currentTimeMillis());
        clo.setLastModifier(userName);
        clo.setLastModifyTime(System.currentTimeMillis());
        clo.setFromOid("");
        clo.setFromRevisionOid("");
        clo.setFromNameOid("");
        clo.setFromBTMName("");
        clo.setToOid("");
        clo.setToRevisionOid("");
        clo.setToNameOid("");
        clo.setToBTMName("");
        clo.setLoName(loName);
        //属性初始值设置
        initLinkTypeAttributeValue(clo, loName);
        return clo;
    }
    
    private void initLinkTypeAttributeValue(ClientLinkObject clo, String linkTypeName) throws VCIError {
        LinkTypeInterface ltws = new LinkTypeInterfaceImpl();
        AttribItem[] items = ltws.getNonSystemAttributesByLinkTypeName(linkTypeName);
        for (AttribItem item : items) {
            clo.setAttributeValue(item.name, item.defValue);        
        }
    }
    
    /**
     * 保持link对象以及link对象关联的BO对象
     * @param cbos, 业务对象数组
     * @param clo, 链接对象
     * @return 操作成功返回true,操作失败返回false
     * @throws VCIError
     */
    public boolean saveLinkObject(ClientBusinessObject[] cbos, ClientLinkObject clo) throws VCIError {
        BusinessObject[] bos = new BusinessObject[cbos.length];
        for (int i = 0; i < cbos.length; i++) {
            cbos[i].dealBusinessObjectNullValue();
            bos[i] = cbos[i].getBusinessObject();
        }
        
        clo.dealLinkObjectNullValue();
        boolean rs = BOFactoryClient.getBOFactoryService().createBusinessObjectWithLink(bos, clo.getLinkObject());
        return rs;
    }
    
    /**
     * 更改LO对象的属性信息
     * @param clo, 链接对象
     * @return 操作成功返回true,操作失败返回false
     * @throws VCIError
     */
    public boolean updateLinkObject(ClientLinkObject clo) throws VCIError {
        clo.dealLinkObjectNullValue();
        
        boolean rs = BOFactoryClient.getBOFactoryService().updateLinkObject(clo.getLinkObject());
        return rs;
    }
    
    /**
     * 批量更改LO对象的属性信息
     * @param clos, 链接对象数组
     * @return 操作成功返回true,操作失败返回false
     * @throws VCIError
     */
    @MethodTypeAnnotation(getMethodType="batch")
    public boolean batchUpdateLinkObject(ClientLinkObject[] clos) throws VCIError {
        LinkObject[] los = new LinkObject[clos.length];
        for (int i = 0; i < clos.length; i++) {
            clos[i].dealLinkObjectNullValue();
            los[i] = clos[i].getLinkObject();
        }
        
        boolean rs = BOFactoryClient.getBOFactoryService().batchUpdateLinkObject(los);
        return rs;
    }
    
    /**
     * 删除LO对象
     * @param clo, 链接对象
     * @return 操作成功返回true,操作失败返回false
     * @throws VCIError
     */
    public boolean deleteLinkObject(ClientLinkObject clo) throws VCIError {
        clo.dealLinkObjectNullValue();
        boolean rs = BOFactoryClient.getBOFactoryService().deleteLinkObject(clo.getLinkObject());
        return rs;
    }
    
    /**
     * 批量删除LO对象
     * @param clos, 链接对象数组
     * @return 操作成功返回true,操作失败返回false
     * @throws VCIError
     */
    @MethodTypeAnnotation(getMethodType="batch")
    public boolean batchdDeleteLinkObject(ClientLinkObject[] clos) throws VCIError {
        LinkObject[] los = new LinkObject[clos.length];
        for (int i = 0; i < clos.length; i++) {
            clos[i].dealLinkObjectNullValue();
            los[i] = clos[i].getLinkObject();
        }
        
        boolean rs = BOFactoryClient.getBOFactoryService().batchDeleteLinkObject(los);
        return rs;
    }
    
    /**
     * 根据from端业务对象以及链接类型获取其to端的业务对象
     * @param cbo, from端业务对象
     * @param loName, 链接类型名称
     * @return to端业务对象数组
     * @throws VCIError
     */
    public ClientLinkObject[] readLinkObjectByFromBO(ClientBusinessObject cbo, String loName) throws VCIError {
        cbo.dealBusinessObjectNullValue();
        LinkObject[] rslinkObjects = BOFactoryClient.getBOFactoryService().readLinkObjectByFromBO(cbo.getBusinessObject(), loName);
        int len = rslinkObjects.length;
        ClientLinkObject[] clos = new ClientLinkObject[len];
        for (int i = 0; i < clos.length; i++) {
            clos[i] = new ClientLinkObject();
            clos[i].setLinkObject(rslinkObjects[i]);
         }
        return clos;
    }
    
    /**
     * 根据link oid 和 type获取对应链接对象的详细信息
     * @param oid, 业务对象oid
     * @param loName, 链接类型名称
     * @return 链接对象
     * @throws VCIError
     */
    public ClientLinkObject readLinkObjectById(String oid, String loName) throws VCIError {
        LinkObject linkObject = BOFactoryClient.getBOFactoryService().readLinkObjectById(oid, loName);
        ClientLinkObject clo = new ClientLinkObject();
        clo.setLinkObject(linkObject);
        return clo;
    }
}