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;
|
}
|
|
}
|