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
package com.vci.server.omd.attribpool.delegate;
 
import java.util.List;
import java.util.ArrayList;
 
import com.vci.common.exception.VciExceptionTool;
import com.vci.common.log.ServerWithLog4j;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.server.base.exception.ExceptionLocalHandler;
import com.vci.server.cache.OMCacheProvider;
import com.vci.server.omd.attribpool.cache.APServerCacheUtil;
import com.vci.server.omd.attribpool.service.AttrPoolService;
 
public class AttributeDelegate implements IAPServerDelegate{
 
    private static AttributeDelegate instance;
    
    public static AttributeDelegate getInstance() {
        if (instance == null) {
            instance = new AttributeDelegate();
        }
        
        return instance;
    }
 
    protected VCIError getLocalVciError(String key, Throwable e) {
        VCIError error = new VCIError(key, new String[]{VciExceptionTool.getExceptionStr(e), VciExceptionTool.getExceptionDetail(e)});
        VCIError rsError = ExceptionLocalHandler.getInstance().getLocalString(error, "PLMAP");
        return rsError;
    }
    
    /**
     * 查询属性
     */
    @Override
    public boolean addAttribItem(AttribItem attribItem) throws VCIError{
        try{
            boolean success = AttrPoolService.getInstance().addAttribItem(attribItem);
            if (success)
                APServerCacheUtil.setAttribute(attribItem);
            return success;
        }catch(Throwable e){
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw getLocalVciError("P0010PLMAP-00001", e);
        }
    }
 
    /**
     * 修改属性
     */
    @Override
    public boolean modifyAbItem(AttribItem attribItem) throws VCIError{
        try{
            boolean success = AttrPoolService.getInstance().modifyAbItem(attribItem);
            if (success)
                APServerCacheUtil.setAttribute(attribItem);
            return success;
        }catch(Throwable e){
            ServerWithLog4j.logger.error(e);
            throw getLocalVciError("P0010PLMAP-00004", e);
        }
    }
 
    /**
     * 批量删除属性: abItems
     */
    @Override
    public boolean deleteAbItems(AttribItem[] abItems) throws VCIError{
        try{
            boolean success = AttrPoolService.getInstance().deleteAbItems(abItems);
            if (success) {
                for (AttribItem ai : abItems) {
                    APServerCacheUtil.delAttribute(ai.name);
                }
            }
            return success;
        }catch(Throwable e){
            ServerWithLog4j.logger.error(e);
            throw getLocalVciError("P0010PLMAP-00005", e);
        }
    }
    
    @Override
    public boolean deleteAbItem(AttribItem att) throws VCIError {
        try{
            boolean success = AttrPoolService.getInstance().deleteAbItem(att);
            if (success)
                APServerCacheUtil.delAttribute(att.name);
            return success;
        }catch(Throwable e){
            ServerWithLog4j.logger.error(e);
            throw getLocalVciError("P0010BTM-00003", e);
        }
    }
    
    @Override
    public AttribItem[] getAttribItems(String filter, int start, int rows) throws VCIError {
        List<AttribItem> attrList = new ArrayList<AttribItem>();
        AttribItem[] cAttributes = OMCacheProvider.getAttributes();
        if(filter != null && !filter.equals("")){
            for (AttribItem attr : cAttributes) {
                if (attr.name.indexOf(filter) >= 0) {
                    attrList.add(attr);
                }
            }
            cAttributes = attrList.toArray(new AttribItem[attrList.size()]);
        }
        
        return cAttributes;
    }
 
    @Override
    public boolean checkRowIsExists(String name) throws VCIError {
        //return APServerCacheUtil.getInstance().checkRowIsExists(name);
        return OMCacheProvider.existAttribute(name);
    }
 
    @Override
    public AttribItem[] getAttribItemsByNames(String[] attNames)
            throws VCIError {
        //return APServerCacheUtil.getInstance().getAttribItemsByNames(attNames);
        return OMCacheProvider.getAttributes(attNames);
    }
 
    @Override
    public AttribItem getAttribItemByName(String abName) throws VCIError {
        //return APServerCacheUtil.getInstance().getAttribItemByName(abName);
        return OMCacheProvider.getAttribute(abName);
    }
 
    @Override
    public String getAttribItemDataType(String abName) throws VCIError {
        //return APServerCacheUtil.getInstance().getAttribItemDataType(abName);
        AttribItem attr = OMCacheProvider.getAttribute(abName);
        if (attr == null)
            return "VTString";
        return attr.vtDataType;
    }
 
    @Override
    public String getAPData() throws VCIError {
        return "";
    }
 
    @Override
    public String[] getAPNamesByEMName(String emName) throws VCIError {
        List<String> attrNameList = new ArrayList<String>();
        
        AttribItem[] items = OMCacheProvider.getAttributes();
        for (AttribItem attr : items) {
            if (attr.other.indexOf(emName) >= 0) {
                attrNameList.add(attr.name); 
            }
        }
        
        return attrNameList.toArray(new String[attrNameList.size()]);
        //return APServerCacheUtil.getAPNamesByEMName(emName);
    }
 
    @Override
    public AttribItem[] getAttribItemsOutNames(String[] abNameArray, String text)
            throws VCIError {
        List<String> abNameList = new ArrayList<String>();
        for (String ab : abNameArray) {
            abNameList.add(ab);
        }
        AttribItem[] items = OMCacheProvider.getAttributes();
        
        List<AttribItem> attrList = new ArrayList<AttribItem>();
        for (AttribItem attr : items) {
            if (attr.name.indexOf(text) >= 0 && !abNameList.contains(attr.name)) {
                attrList.add(attr);
            }
        }
        
        return attrList.toArray(new AttribItem[attrList.size()]);
        //return APServerCacheUtil.getAttribItemsOutNames(abNameArray, text);
    }
    
    public boolean xml2DB(String userName) throws VCIError {
        return AttrPoolService.getInstance().xml2DB(userName);
    }
 
}