wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
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
package com.vci.client.uif.actions.client.folder;
 
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
 
import javax.swing.ButtonGroup;
 
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientBusinessObjectOperation;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.common.oq.OQTool;
import com.vci.client.oq.QTClient;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.process.QANProcessBar;
import com.vci.client.ui.process.QANProcessBarFrame;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJLabel;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.VCIJRadioButton;
import com.vci.client.uif.actions.client.AbstractBusionessOperationAction;
import com.vci.client.uif.actions.client.UIFUtils;
import com.vci.client.uif.engine.client.tree.TreeNode;
import com.vci.client.uif.engine.client.tree.TreePanel;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.client.utils.excel.ExcelCellStyleSettingCallback;
import com.vci.client.utils.excel.ExcelFileOperation;
import com.vci.client.utils.excel.WorkboolStyleSetting;
import com.vci.common.qt.object.Condition;
import com.vci.common.qt.object.QueryTemplate;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.mw.ClientContextVariable;
 
/**
 * 导航区分类数据导入按钮
 * 
 * @author xiongchao
 * 
 */
public class FolderImportAction extends AbstractBusionessOperationAction {
 
    @Override
    public String getKey() {
        return "importFolder";
    }
 
    @Override
    public boolean doPost() {
        return doImportOperation();
    }
 
    private boolean doImportOperation() {
        Object[] messages = new Object[3];
        ButtonGroup rbtnGroup = new ButtonGroup();
        VCIJRadioButton rbtnDownTemp = new VCIJRadioButton("下载导入模板");
        VCIJRadioButton rbtnImportFromTemp = new VCIJRadioButton("从模板导入");
        rbtnGroup.add(rbtnDownTemp);
        rbtnGroup.add(rbtnImportFromTemp);
        rbtnDownTemp.setSelected(true);
        messages[0] = new VCIJLabel("请选择:");
        messages[1] = rbtnDownTemp;
        messages[2] = rbtnImportFromTemp;
        Object[] options = { "确定", "取消" };
        int res = VCIJOptionPane.showOptionDialog(ClientContextVariable.getFrame(), messages, "选择操作",
                VCIJOptionPane.DEFAULT_OPTION, VCIJOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        if (res == 0) {
            if (rbtnDownTemp.isSelected()) {
                downloadImportClassifyTemplate();
            } else {
                executeImportClassify();
            }
        }
        return false;
    }
 
    private void downloadImportClassifyTemplate() {
        File file = getFile();
        if (file == null)
            return;
        String fileName = file.getAbsolutePath();
        String[][] datas = getSampleData().toArray(new String[][] {});
        try {
            Map<Short, Short> columnWidthMap = new HashMap<Short, Short>();
            columnWidthMap.put((short) 0, (short) 5000);
            columnWidthMap.put((short) 1, (short) 5000);
            columnWidthMap.put((short) 2, (short) 5000);
            columnWidthMap.put((short) 3, (short) 5000);
            columnWidthMap.put((short) 4, (short) 5000);
            new ExcelFileOperation().writeExcelFileInfo(fileName,
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderdata"), datas,
                    getSettingCallback(columnWidthMap));
        } catch (RuntimeException e) {
            VCIOptionPane.showMessage(ClientContextVariable.getFrame(),
                    UIFUtils.getI18nString("uimodel.plm.uif.action.filecanotsave"));
            return;
        }
        try {
            VCISwingUtil.showOpenOrExplorerFileMessage(ClientContextVariable.getFrame(), file);
        } catch (IOException e) {
            e.printStackTrace();
            VCIOptionPane.showMessage(ClientContextVariable.getFrame(), e.getMessage());
        }
    }
 
    private ExcelCellStyleSettingCallback getSettingCallback(final Map<Short, Short> columnWidthMap) {
        ExcelCellStyleSettingCallback setting = new ExcelCellStyleSettingCallback() {
            @Override
            public WorkboolStyleSetting doSetWorkbookStyle(final Workbook wb) {
                WorkboolStyleSetting setting = new WorkboolStyleSetting() {
                    @Override
                    public LinkedHashMap<String, CellStyle> getStyleMap() {
                        LinkedHashMap<String, CellStyle> map = new LinkedHashMap<String, CellStyle>();
                        if (columnWidthMap != null) {
                            Iterator<Short> its = columnWidthMap.keySet().iterator();
                            while (its.hasNext()) {
                                Short key = its.next();
                                Short value = columnWidthMap.get(key);
                                wb.getSheetAt(0).setColumnWidth(key.shortValue(), value.shortValue());
                            }
                        }
                        CellStyle style = wb.createCellStyle();
                        Font font = (Font) wb.createFont();
                        font.setColor(HSSFFont.COLOR_RED);
                        style.setFont(font);
                        map.put("0*1", style);
                        map.put("0*4", style);
                        return map;
                    }
                };
                return setting;
            }
        };
        return setting;
    }
 
    private final String FOLDER_BTM_NAME = "folder";
    private final String HEADER_ID = "编号";
    private final String HEADER_NAME = "名称";
    private final String HEADER_DESC = "描述";
    private final String HEADER_QUERY_CONDITION = "查询条件";
    private final String HEADER_CLASSIFY_LEVEL = "分类位置(层级)";
    private final String FIELD_ID = "id";
    private final String FIELD_NAME = "name";
    private final String FIELD_DESC = "description";
    private final String FIELD_QUERY_CONDITION = "querycondition";
    private final String FIELD_PARENTOID_FIELD = "affiliatedfolder";
 
    private class ClassifyRowDataStruct {
        private String id = "";
        private String name = "";
        private String desc = "";
        private String queryCondition = "";
        private String parentOid = "";
        private String positionLevel = "";
 
        public String getId() {
            return id;
        }
 
        public void setId(String id) {
            this.id = id;
        }
 
        public String getName() {
            return name;
        }
 
        public void setName(String name) {
            this.name = name;
        }
 
        public String getDesc() {
            return desc;
        }
 
        public void setDesc(String desc) {
            this.desc = desc;
        }
 
        public String getQueryCondition() {
            return queryCondition;
        }
 
        public void setQueryCondition(String queryCondition) {
            this.queryCondition = queryCondition;
        }
 
        public String getParentOid() {
            return parentOid;
        }
 
        public void setParentOid(String parentOid) {
            this.parentOid = parentOid;
        }
 
        public String getPositionLevel() {
            return positionLevel;
        }
 
        public void setPositionLevel(String positionLevel) {
            this.positionLevel = positionLevel;
        }
    }
 
    protected Map<String, Integer> getHeaderIndexMap(String[] headerRowData) {
        Map<String, Integer> map = new HashMap<String, Integer>();
        Integer value = 0;
        for (int i = 0; i < headerRowData.length; i++) {
            String header = headerRowData[i];
            String key = "";
            value = i;
            if (header.trim().equalsIgnoreCase(HEADER_ID)) {
                key = HEADER_ID;
            } else if (header.trim().equalsIgnoreCase(HEADER_NAME)) {
                key = HEADER_NAME;
            } else if (header.trim().equalsIgnoreCase(HEADER_DESC)) {
                key = HEADER_DESC;
            } else if (header.trim().equalsIgnoreCase(HEADER_QUERY_CONDITION)) {
                key = HEADER_QUERY_CONDITION;
            } else if (header.trim().equalsIgnoreCase(HEADER_CLASSIFY_LEVEL)) {
                key = HEADER_CLASSIFY_LEVEL;
            }
            map.put(key, value);
        }
        return map;
    }
 
    private ClassifyRowDataStruct getClassifyRowDataStruct(Map<String, Integer> map, String[] data) {
        ClassifyRowDataStruct crd = new ClassifyRowDataStruct();
        crd.setId(data[map.get(HEADER_ID)].trim());
        crd.setName(data[map.get(HEADER_NAME)].trim());
        crd.setDesc(data[map.get(HEADER_DESC)].trim());
        crd.setQueryCondition(data[map.get(HEADER_QUERY_CONDITION)].trim());
        crd.setPositionLevel(data[map.get(HEADER_CLASSIFY_LEVEL)].trim());
        return crd;
    }
 
    private ClientBusinessObject getSelectFolderCBO() {
        TreeNode treeNode = getOwnerTreePanel().getSelectTreeNode();
        IDataNode dataNode = (IDataNode) treeNode.getObj();
        return (ClientBusinessObject) dataNode.getMaterObject();
    }
 
    private List<String[]> getSampleData() {
        List<String[]> listDatas = new LinkedList<String[]>();
        listDatas.add(
                new String[] { HEADER_ID, HEADER_NAME, HEADER_DESC, HEADER_QUERY_CONDITION, HEADER_CLASSIFY_LEVEL });
        TreeNode treeNode = getOwnerTreePanel().getSelectTreeNode();
        String[] headerData = ",,,,0".split(",");
        if (treeNode.isRoot()) {
            headerData[1] = treeNode.getUserObject().toString();
        } else {
            ClientBusinessObject cbo = getSelectFolderCBO();
            headerData = new String[] { cbo.getAttributeValue("id"), cbo.getAttributeValue("name"),
                    cbo.getAttributeValue("desc"), cbo.getAttributeValue("querycondition"), "0" };
        }
        listDatas.add(headerData);
        listDatas.add("新导入分类编号01,新导入分类名称01,,,1".split(","));
        listDatas.add("新导入分类编号0101,新导入分类名称0101,,,2".split(","));
        listDatas.add("新导入分类编号010101,新导入分类名称010101,,,3".split(","));
        listDatas.add("新导入分类编号010102,新导入分类名称010102,,,3".split(","));
        listDatas.add("新导入分类编号010103,新导入分类名称010103,,,3".split(","));
 
        listDatas.add("新导入分类编号0102,新导入分类名称0102,,,2".split(","));
        listDatas.add("新导入分类编号010201,新导入分类名称010201,,,3".split(","));
        listDatas.add("新导入分类编号010202,新导入分类名称010202,,,3".split(","));
        listDatas.add("新导入分类编号010203,新导入分类名称010303,,,3".split(","));
 
        listDatas.add("新导入分类编号0103,新导入分类名称0103,,,2".split(","));
        listDatas.add("新导入分类编号010301,新导入分类名称010301,,,3".split(","));
        listDatas.add("新导入分类编号010302,新导入分类名称010302,,,3".split(","));
        listDatas.add("新导入分类编号010303,新导入分类名称010303,,,3".split(","));
 
        listDatas.add("新导入分类编号02,新导入分类名称02,,,1".split(","));
        listDatas.add("新导入分类编号0201,新导入分类名称0201,,,2".split(","));
        listDatas.add("新导入分类编号020101,新导入分类名称020101,,,3".split(","));
        listDatas.add("新导入分类编号020102,新导入分类名称020102,,,3".split(","));
        listDatas.add("新导入分类编号020103,新导入分类名称020103,,,3".split(","));
 
        listDatas.add("新导入分类编号0202,新导入分类名称0202,,,2".split(","));
        listDatas.add("新导入分类编号020201,新导入分类名称020201,,,3".split(","));
        listDatas.add("新导入分类编号020202,新导入分类名称020202,,,3".split(","));
        listDatas.add("新导入分类编号020203,新导入分类名称020203,,,3".split(","));
 
        listDatas.add("新导入分类编号0203,新导入分类名称0203,,,2".split(","));
        listDatas.add("新导入分类编号020301,新导入分类名称020301,,,3".split(","));
        listDatas.add("新导入分类编号020302,新导入分类名称020302,,,3".split(","));
        listDatas.add("新导入分类编号020303,新导入分类名称020303,,,3".split(","));
 
        listDatas.add("新导入分类编号03,新导入分类名称03,,,1".split(","));
        listDatas.add("新导入分类编号0301,新导入分类名称0301,,,2".split(","));
        listDatas.add("新导入分类编号030101,新导入分类名称030101,,,3".split(","));
        listDatas.add("新导入分类编号030102,新导入分类名称030102,,,3".split(","));
        listDatas.add("新导入分类编号030103,新导入分类名称030103,,,3".split(","));
 
        listDatas.add("新导入分类编号0302,新导入分类名称0302,,,2".split(","));
        listDatas.add("新导入分类编号030201,新导入分类名称030201,,,3".split(","));
        listDatas.add("新导入分类编号030202,新导入分类名称030202,,,3".split(","));
        listDatas.add("新导入分类编号030203,新导入分类名称030203,,,3".split(","));
 
        listDatas.add("新导入分类编号0303,新导入分类名称0303,,,2".split(","));
        listDatas.add("新导入分类编号030301,新导入分类名称030301,,,3".split(","));
        listDatas.add("新导入分类编号030302,新导入分类名称030302,,,3".split(","));
        listDatas.add("新导入分类编号030303,新导入分类名称030303,,,3".split(","));
        return listDatas;
    }
 
    private File getFile() {
        new VCISwingUtil();
        String fileURL = VCISwingUtil.getExcelFileURL(ClientContextVariable.getFrame(), true, "");
        if (fileURL == null)
            return null;
        return new File(fileURL);
    }
 
    private void executeImportClassify() {
        String filePath = VCISwingUtil.getExcelFileURL(ClientContextVariable.getFrame(), false, "*.xls", true);
        if (filePath == null)
            return;
        String[][] datas = null;
        try {
            datas = new ExcelFileOperation().readExcelFileInfo(filePath);
        } catch (VCIException e) {
            e.printStackTrace();
            String message = LocaleDisplay.getI18nString(e.getException_code(), "RMIPFramework", Locale.getDefault());
            VCIJOptionPane.showError(ClientContextVariable.getFrame(), message);
        }
        if (datas == null || datas.length == 0)
            return;
 
        final List<?>[] errors = new List<?>[1];
        final String[][] datasFinal = datas;
        final QANProcessBarFrame frame = new QANProcessBarFrame();
        final Thread thread = new Thread() {
            public void run() {
                List<String[]> res = new LinkedList<String[]>();
                try {
                    frame.setContent(UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.importing"));
                    res = executeImportClassifyDetail(datasFinal, frame, res);
                } catch (VCIError e) {
                    UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), e);
                } catch (Exception e) {
                    e.printStackTrace();
                    UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), e);
                } finally {
                    errors[0] = res;
                    frame.setProcessBarCancel(true);
                }
            }
        };
        QANProcessBar bar = new QANProcessBar(thread, frame, frame,
                UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.folderimport"), false);
        bar.setVisible(true);
 
        if (errors[0] != null && errors[0].size() > 0) {
            VCIOptionPane.showMessage(ClientContextVariable.getFrame(),
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.folderdatahaserror"));
            writeErrorMessage(errors[0].toArray(new String[][] {}));
        } else {
            getRegionPanel().getDataModel().refresh(getRegionPanel().getDataModel());
            VCIOptionPane.showMessage(ClientContextVariable.getFrame(),
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.importsuccess"));
        }
    }
 
    private void writeErrorMessage(String[][] errors) {
        String file = VCISwingUtil.getExcelFileURL(ClientContextVariable.getFrame(), true, "");
        if (file == null || "".equals(file))
            return;
        try {
            Map<Short, Short> columnWidthMap = new HashMap<Short, Short>();
            columnWidthMap.put((short) 0, (short) 25000);
            new ExcelFileOperation().writeExcelFileInfo(file,
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.errorinfosheetname"), errors,
                    getSettingCallback(columnWidthMap));
        } catch (RuntimeException e) {
            VCIOptionPane.showMessage(ClientContextVariable.getFrame(),
                    UIFUtils.getI18nString("uimodel.plm.uif.action.filecanotsave"));
            return;
        }
        try {
            VCISwingUtil.showOpenOrExplorerFileMessage(ClientContextVariable.getFrame(), new File(file));
        } catch (IOException e) {
            e.printStackTrace();
            VCIOptionPane.showMessage(ClientContextVariable.getFrame(), e.getMessage());
        }
    }
 
    protected List<String[]> executeImportClassifyDetail(final String[][] datas, QANProcessBarFrame frame,
            List<String[]> errors) throws VCIError, Exception {
        String firstLevelParentOid = getParentOid();
        Map<String, Integer> headerIndexMap = getHeaderIndexMap(datas[0]);
 
        Map<Integer, ClassifyRowDataStruct> rowToCRDSMap = new LinkedHashMap<Integer, ClassifyRowDataStruct>();
        rowToCRDSMap.put(0, new ClassifyRowDataStruct());
 
        Map<Integer, ClientBusinessObject> rowToCBOsMap = new LinkedHashMap<Integer, ClientBusinessObject>();
        rowToCBOsMap.put(0, new ClientBusinessObject());
 
        List<ClassifyRowDataStruct> dataList = new LinkedList<ClassifyRowDataStruct>();
        dataList.add(new ClassifyRowDataStruct());
 
        List<ClientBusinessObject> dataCBOList = new LinkedList<ClientBusinessObject>();
        dataCBOList.add(new ClientBusinessObject());
 
        for (int row = 1; row < datas.length; row++) {
            frame.setContent(MessageFormat.format(
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.processingrow"), getRowToString(row)));
            String[] data = datas[row];
            ClassifyRowDataStruct crd = getClassifyRowDataStruct(headerIndexMap, data);
            if (!checkIsValid(row, crd, errors)) {
                continue;
            }
 
            if (!isNumber(crd.getPositionLevel())) {
                errors.add(new String[] { MessageFormat.format(
                        UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.rowdataColumnDataFormatError"),
                        getRowToString(row), HEADER_CLASSIFY_LEVEL, crd.getPositionLevel()) });
                continue;
            }
            dataList.add(crd);
            rowToCRDSMap.put(row, crd);
            int posLevel = Integer.valueOf(crd.getPositionLevel());
            if (posLevel == 0) {
                // 当前选择的节点
 
            } else if (posLevel == 1) { //
                crd.setParentOid(firstLevelParentOid);
            } else {
                ClientBusinessObject cboParent = getParentCRDInMap(dataList, dataCBOList, row, posLevel);
                crd.setParentOid(cboParent.getOid());
            }
            // 将行数据转换为新cbo对象
            ClientBusinessObject cbo = getNewCBO(crd);
            rowToCBOsMap.put(row, cbo);
            dataCBOList.add(cbo);
 
            frame.setContent(MessageFormat.format(
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.checkrowdataexist"),
                    getRowToString(row)));
            if (row > 1 && !checkExistFromParent(row, posLevel, crd, cbo, dataList, dataCBOList, errors)) {
                continue;
            }
        }
        if (errors.size() > 0) {
            return errors;
        }
 
        frame.setContent(UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.saveing"));
 
        List<ClientBusinessObject> cbos = dataCBOList.subList(2, dataCBOList.size());
        cboOperation.batchCreateDeleteBOLO(cbos.toArray(new ClientBusinessObject[] {}), new ClientLinkObject[0],
                new ClientBusinessObject[0], new ClientLinkObject[0]);
        return errors;
    }
 
    protected boolean checkExistFromParent(int row, int posLevel, ClassifyRowDataStruct crd, ClientBusinessObject cbo,
            List<ClassifyRowDataStruct> dataList, List<ClientBusinessObject> dataCBOList, List<String[]> errors)
            throws VCIError {
        String id = crd.getId();
        boolean idExist = false;
        if (!isEmpty(id)) {
            idExist = checkExistFromDataParent("id", row, posLevel, dataList, dataCBOList);
            if (!idExist) {
                idExist = checkIdExistFromDBParent(cbo);
                if (idExist) {
                    errors.add(new String[] { MessageFormat.format(
                            UIFUtils.getI18nString(
                                    "uimodel.plm.uif.action.folderimport.rowdataexistinfilemessageformat"),
                            getRowToString(row), HEADER_ID, id) });
                }
            } else {
                errors.add(new String[] { MessageFormat.format(
                        UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.rowdataexistinfilemessageformat"),
                        getRowToString(row), HEADER_ID, id) });
            }
        }
 
        boolean nameExist = false;
        nameExist = checkExistFromDataParent("name", row, posLevel, dataList, dataCBOList);
        if (!nameExist) {
            nameExist = checkNameExistFromDBParent(cbo);
            if (nameExist) {
                errors.add(new String[] { MessageFormat.format(
                        UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.rowdataexistindbmessageformat"),
                        getRowToString(row), HEADER_NAME, id) });
            }
        } else {
            errors.add(new String[] { MessageFormat.format(
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.rowdataexistinfilemessageformat"),
                    getRowToString(row), HEADER_NAME, id) });
        }
        return (nameExist || idExist);
    }
 
    private boolean checkExistFromDataParent(String type, int row, int posLevel, List<ClassifyRowDataStruct> dataList,
            List<ClientBusinessObject> dataCBOList) {
        boolean res = false;
        Map<String, ClassifyRowDataStruct> map = new HashMap<String, ClassifyRowDataStruct>();
        for (int i = row; Integer.valueOf(dataList.get(i).getPositionLevel()) == posLevel; i--) {
            ClassifyRowDataStruct crdget = dataList.get(i);
            String value = crdget.getId();
            if ("id".equals(type)) {
                value = crdget.getId();
            } else if ("name".equals(type)) {
                value = crdget.getName();
            }
            if (map.containsKey(value)) {
                res = true;
                break;
            }
            map.put(value, crdget);
 
            if (Integer.valueOf(dataList.get(i).getPositionLevel()) == (posLevel - 1)) {
                break;
            }
        }
        return res;
    }
 
    private boolean checkNameExistFromDBParent(ClientBusinessObject cbo) throws VCIError {
        Map<String, String> conditionMap = new HashMap<String, String>();
        conditionMap.put(FIELD_NAME, cbo.getName());
        return checkExistFromParent(cbo, conditionMap);
    }
 
    private boolean checkIdExistFromDBParent(ClientBusinessObject cbo) throws VCIError {
        Map<String, String> conditionMap = new HashMap<String, String>();
        conditionMap.put(FIELD_ID, cbo.getId());
        return checkExistFromParent(cbo, conditionMap);
    }
 
    private boolean checkExistFromParent(ClientBusinessObject cbo, Map<String, String> conditionMap) throws VCIError {
        boolean res = false;
        conditionMap.put(FIELD_PARENTOID_FIELD, cbo.getAttributeValue(FIELD_PARENTOID_FIELD));
        QueryTemplate qt = getQueryTemplate(conditionMap);
        BusinessObject[] bos = QTClient.getService().findBTMObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML());
        res = bos.length > 0;
        return res;
    }
 
    private ClientBusinessObject getParentCRDInMap(List<ClassifyRowDataStruct> dataList,
            List<ClientBusinessObject> dataCBOList, int row, int posLevel) {
        ClientBusinessObject res = null;
        int comPosLevel = posLevel - 1;
        int dataPosLevel = -1;
        for (int i = row; i >= 0; i--) {
            ClassifyRowDataStruct crd = dataList.get(i);
            dataPosLevel = Integer.valueOf(crd.getPositionLevel());
            if (dataPosLevel == comPosLevel) {
                res = dataCBOList.get(i);
                break;
            }
        }
        return res;
    }
 
    private String getRowToString(int row) {
        return String.valueOf(row + 1);
    }
 
    private boolean checkIsValid(int row, ClassifyRowDataStruct crd, List<String[]> errors) {
        boolean res = true;
        if (row != 1 && isEmpty(crd.getId())) {
            res = false;
            errors.add(new String[] { MessageFormat.format(
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.rowdataColumnDataIsEmpty"),
                    getRowToString(row), HEADER_NAME, crd.getName()) });
        }
        if (isEmpty(crd.getName())) {
            res = false;
            errors.add(new String[] { MessageFormat.format(
                    UIFUtils.getI18nString("uimodel.plm.uif.action.folderimport.rowdataColumnDataIsEmpty"),
                    getRowToString(row), HEADER_ID, crd.getId()) });
        }
        return res;
    }
 
    private boolean isEmpty(String value) {
        return (value == null || "".equals(value));
    }
 
    private Pattern ptnNumber = Pattern.compile("[0-9]{1,2}");
 
    private boolean isNumber(String value) {
        return ptnNumber.matcher(value).matches();
    }
 
    protected boolean checkExistFromParent(ClientBusinessObject cbo) {
        return false;
    }
 
    protected ClientBusinessObject getNewCBO(ClassifyRowDataStruct crds) throws VCIError {
        ClientBusinessObject cbo = cboOperation.createBusinessObject(FOLDER_BTM_NAME);
        cbo.setAttributeValue(FIELD_ID, crds.getId(), true);
        cbo.setAttributeValue(FIELD_NAME, crds.getName(), true);
        cbo.setAttributeValue(FIELD_DESC, crds.getDesc(), true);
        cbo.setAttributeValue(FIELD_QUERY_CONDITION, crds.getQueryCondition());
        cbo.setAttributeValue(FIELD_PARENTOID_FIELD, crds.getParentOid());
        return cbo;
    }
 
    protected boolean isSelectedTreeNode() {
        return getSelectedTreeNode() != null;
    }
 
    private TreeNode getSelectedTreeNode() {
        TreePanel tp = getOwnerTreePanel();
        if (tp == null)
            return null;
        return tp.getSelectTreeNode();
    }
 
    protected boolean checkSelectedNodeIsRoot() {
        TreeNode node = getSelectedTreeNode();
        if (node == null)
            return false;
        return node.isRoot();
    }
 
    protected String getParentOid() {
        String parentOid = "";
        TreePanel tp = getOwnerTreePanel();
        if (tp != null) {
            Object obj = tp.getDataModel().getSelectObjects()[0];
            if (obj instanceof IDataNode) {
                IDataNode dataNode = (IDataNode) obj;
                Object masterObj = dataNode.getMaterObject();
                if (masterObj instanceof String) { // root
                    parentOid = masterObj.toString();
                } else if (masterObj instanceof ClientBusinessObject) {
                    ClientBusinessObject cbo = (ClientBusinessObject) masterObj;
                    parentOid = cbo.getOid();
                }
            }
        }
        return parentOid;
    }
 
    private QueryTemplate getQueryTemplate(Map<String, String> conditionMap) {
        QueryTemplate qt = new QueryTemplate();
        qt.setType("btm");
        qt.setBtmType(FOLDER_BTM_NAME);
        qt.setId("id");
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        Condition condition = OQTool.getCondition(conditionMap);
        qt.setCondition(condition);
        return qt;
    }
 
    private ClientBusinessObjectOperation cboOperation = new ClientBusinessObjectOperation();
 
    private TreePanel getOwnerTreePanel() {
        TreePanel tp = null;
        if (getParentComponent() instanceof TreePanel) {
            tp = (TreePanel) getParentComponent();
        }
        return tp;
    }
 
}