package com.vci.client.omd.provider;
|
|
import java.io.BufferedReader;
|
import java.io.BufferedWriter;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileNotFoundException;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.io.InputStreamReader;
|
import java.io.OutputStreamWriter;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
|
import org.dom4j.Document;
|
import org.dom4j.DocumentException;
|
import org.dom4j.Element;
|
import org.dom4j.io.SAXReader;
|
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.btm.BTMServicePrx;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.omd.lcm.LifeCycle;
|
import com.vci.corba.omd.vrm.VersionRule;
|
import com.vci.client.common.ClientLog4j;
|
import com.vci.client.common.providers.ServiceProvider;
|
import com.vci.corba.common.VCIError;
|
import com.vci.omd.constants.OmdConstants;
|
|
|
/**
|
* 对外部提供业务类型的属性列表
|
* 获取属性的数据类型, 属性: 系统属性, 属性池属性
|
*
|
*/
|
public class BtmProvider {
|
private static BTMServicePrx btmService = null;
|
|
|
private BtmProvider(){
|
}
|
|
private static class InstanceHolder{
|
public static BtmProvider btmProvider = new BtmProvider();
|
}
|
public static BtmProvider getInstance(){
|
return InstanceHolder.btmProvider;
|
}
|
|
public static BTMServicePrx getService(){
|
try {
|
if (btmService == null) {
|
btmService = ServiceProvider.getOMDService().getBTMService();
|
}
|
|
if (btmService == null)
|
{
|
ClientLog4j.logger.error("BtmProvider.getService, 获取【btmService】失败");
|
}
|
|
return btmService;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return btmService;
|
}
|
|
public String[] getSysAttributes() {
|
try {
|
return getService().getSysAttributes();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return null;
|
}
|
|
public AttribItem[] getSysAttribItems() {
|
try {
|
return getService().getSysAttribItems();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return null;
|
}
|
|
|
/**
|
* 获取业务类型的属性列表
|
* @param btmName
|
* @return
|
*/
|
public AttribItem[] getBtAbItems(String btmName){
|
AttribItem[] abItems;
|
String[] abNames = null;
|
|
try {
|
abNames = getService().getBtmApNameArray(btmName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
|
abItems = ApProvider.getAttribItemsByNames(abNames);
|
|
return abItems;
|
}
|
|
/**
|
* 获取全部业务类型
|
* @return
|
*/
|
public BtmItem[] getAllBtmItems(){
|
BtmItem[] btmItems = null;
|
try {
|
btmItems = getService().getAllBtmItem("");
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return btmItems;
|
}
|
|
/**
|
* 获取业务类型的子类型
|
* @param btmName
|
* @return
|
*/
|
public BtmItem[] getChildrenBtmItems(String btmName){
|
BtmItem[] btmItems = null;
|
try {
|
btmItems = getService().getChildrenBtms(btmName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return btmItems;
|
}
|
|
/**
|
* 获取指定的业务类型
|
* @param btmName
|
* @return
|
*/
|
public static BtmItem getBtmItemByName(String btmName){
|
BtmItem btmItem = null;
|
try {
|
btmItem = getService().getBtmItemByName(btmName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return btmItem;
|
}
|
/**
|
*
|
* 获取业务类型的全部属性(包括系统属性)数组
|
* @return
|
*/
|
public static List<String> getAllAbNames(String btmName){
|
List<String> abList = new ArrayList<String>();
|
|
for (String attr : getService().getSysAttributes())
|
abList.add(attr);
|
|
String[] abNames = null;
|
try {
|
abNames = getService().getBtmApNameArray(btmName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
|
for(int i = 0; i < abNames.length; i++){
|
abList.add(abNames[i]);
|
}
|
|
return abList;
|
}
|
|
/**
|
* 获取业务类型的属性(不包括系统属性)数组
|
* @param btmName
|
* @return
|
*/
|
public static String[] getAbNames(String btmName){
|
String[] abNames = null;
|
|
try {
|
abNames = getService().getBtmApNameArray(btmName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
abNames = new String[0];
|
}
|
|
return abNames;
|
}
|
|
/**
|
* 获取属性的数据类型, 属性: 系统属性, 属性池属性
|
* @param abUpperName
|
* @return"ISLastR","ISFirstR","ISLastV","ISFirstV",
|
*/
|
public static String getAbItemDataType(String abName){
|
String dataType = null;
|
String abUpperName = abName.toUpperCase();
|
//系统属性
|
if(abUpperName.equals("OID") || abUpperName.equals("REVISIONOID") || abUpperName.equals("NAMEOID") || abUpperName.equals("BTMNAME")
|
|| abUpperName.equals("CREATOR") || abUpperName.equals("LASTMODIFIER") || abUpperName.equals("REVISIONRULE")
|
|| abUpperName.equals("VERSIONRULE") || abUpperName.equals("REVISIONVALUE") || abUpperName.equals("VERSIONVALUE")
|
|| abUpperName.equals("LCTID") || abUpperName.equals("LCSTATUS")
|
|| abUpperName.equals("ID") || abUpperName.equals("NAME") || abUpperName.equals("DESCRIPTION")
|
|| abUpperName.equals("OWNER") || abUpperName.equals("CHECKINBY")
|
|| abUpperName.equals("CHECKOUTBY") || abUpperName.equals("COPYFROMVERSION")
|
|| abUpperName.equals("ISLASTR") || abUpperName.equals("ISFIRSTR")
|
|| abUpperName.equals("ISLASTV") || abUpperName.equals("ISFIRSTV")
|
|| abUpperName.equals("F_OID") || abUpperName.equals("F_REVISIONOID")
|
|| abUpperName.equals("F_NAMEOID") || abUpperName.equals("F_BTWNAME")
|
|| abUpperName.equals("T_OID") || abUpperName.equals("T_REVISIONOID")
|
|| abUpperName.equals("T_NAMEOID") || abUpperName.equals("T_BTWNAME")){
|
dataType = "VTString";
|
}else if(abUpperName.equals("REVISIONSEQ") || abUpperName.equals("VERSIONSEQ")){
|
dataType = "VTInteger";
|
}else if(abUpperName.equals("CREATETIME") || abUpperName.equals("LASTMODIFYTIME")
|
|| abUpperName.equals("TS") || abUpperName.equals("CHECKINTIME") || abUpperName.equals("CHECKOUTTIME")){
|
dataType = "VTDateTime";
|
//属性池中属性
|
}else{
|
dataType = ApProvider.getAbItemDataType(abName);
|
}
|
return dataType;
|
}
|
|
/**
|
* (对外)提供业务类型的数据文件数据
|
* @return
|
*/
|
public static String getBTMData(){
|
String content = "";
|
try {
|
content = getService().getBTMData();
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return content;
|
}
|
|
|
/**
|
* 获取业务类型的公共基类列表
|
* @param btms
|
* @return
|
*/
|
public List<String> getCommonFBtmNames(List<String> btmNames){
|
List<String> list = new ArrayList<String>();
|
Map<String, List<String>> bListMap = new HashMap<String, List<String>>();
|
for(int i = 0; i < btmNames.size(); i++){
|
String btmName = btmNames.get(i);
|
List<String> bNameList = getFBtmNameList(btmName);
|
if(bNameList != null && bNameList.size() > 0){
|
bListMap.put(btmName, bNameList);
|
}
|
}
|
Iterator<String> ite = bListMap.keySet().iterator();
|
//取第一个业务类型的父类型列表
|
String firstName = null;
|
List<String> bNameList = null;
|
while(ite.hasNext()){
|
firstName = ite.next();
|
bNameList = bListMap.get(firstName);
|
break;
|
}
|
if(bNameList == null || bNameList.size() < 1){
|
return null;
|
}
|
//取第一个业务类型的父类型列表中的父类型
|
for(int i = 0; i < bNameList.size(); i++){
|
String fName = bNameList.get(i);
|
//判断其他的业务类型父类型列表中是否全部含有 该父类型
|
//当其他的的业务类型父类型列表中全部含有该父类型时, 该父类型即为 公共父类型
|
Iterator<String> ite_ = bListMap.keySet().iterator();
|
boolean flag = true;
|
while(ite_.hasNext()){
|
String btmName = ite_.next();
|
if(btmName.equals(firstName)){
|
continue;
|
}
|
bNameList = bListMap.get(btmName);
|
if(!bNameList.contains(fName)){
|
flag = false;
|
break;
|
}
|
}
|
if(flag){
|
list.add(fName);
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 返回所有父类型名
|
* @param btmName
|
* @return
|
*/
|
public List<String> getFBtmNameList(String btmName){
|
try {
|
BtmItem btm = getService().getBtmItemByName(btmName);
|
List<String> list = new ArrayList<String>();
|
while(btm.fName != null && !btm.fName.equals("")){
|
list.add(btm.fName);
|
btm = getService().getBtmItemByName(btm.fName);
|
}
|
return list;
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
/**
|
* 获取业务类型的子类型名
|
*/
|
public String[] getChildrenNames(String btmName){
|
try {
|
return getService().getChildrenNames(btmName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
|
/**
|
* 获取属性other中type的值
|
* @param other
|
* @param type
|
* @return
|
*/
|
public static String getOtherValueByType(String other, String type){
|
String[] otherArray = other.split(";");
|
for(int i = 0; i < otherArray.length; i++){
|
String otherValue = otherArray[i];
|
if(otherValue.contains(type)){
|
return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
|
}
|
}
|
return null;
|
|
}
|
|
/**
|
* 获取属性字段的sql语句
|
* @param array
|
* @return
|
*/
|
public static String getAbSql(AttribItem abItem){
|
String sql = "";
|
if(abItem == null){
|
return sql;
|
}
|
String abName = abItem.name;
|
String vtType = abItem.vtDataType;
|
String other = abItem.other;
|
String defValue = abItem.defValue;
|
|
if(vtType.equals("VTString")){
|
int length = 50;
|
String lengthStr = getOtherValueByType(other, "length");
|
if(lengthStr != null && !lengthStr.equals("")){
|
length = Integer.valueOf(lengthStr);
|
}
|
sql += abName.toUpperCase() + " VARCHAR2(" + length + ")";
|
if(!defValue.equals("")){
|
sql += " default '" + defValue + "'";
|
}
|
sql += ",\n\t";
|
}else if(vtType.equals("VTInteger") || vtType.equals("VTLong")){
|
sql += abName.toUpperCase() + " NUMBER";
|
if(!defValue.equals("")){
|
sql += " default " + defValue;
|
}
|
sql += ",\n\t";
|
}else if(vtType.equals("VTDouble")){
|
int length = 20;
|
String lengthStr = getOtherValueByType(other, "length");
|
if(lengthStr != null && !lengthStr.equals("")){
|
length = Integer.valueOf(lengthStr);
|
}
|
|
int accuracy = 2;
|
String accuracyStr = getOtherValueByType(other, "accuracy");
|
if(accuracyStr != null && !accuracyStr.equals("")){
|
accuracy = Integer.valueOf(accuracyStr);
|
}
|
sql += abName.toUpperCase() + " NUMBER(" + length + ", " + accuracy +")";
|
if(!defValue.equals("")){
|
sql += " default " + defValue;
|
}
|
sql += ",\n\t";
|
}else if(vtType.equals("VTBoolean")){
|
sql += abName.toUpperCase() + " VARCHAR2(8)";
|
if(!defValue.equals("")){
|
sql += " default '" + defValue + "'";
|
}
|
sql += ",\n\t";
|
}else if(vtType.equals("VTImage")){
|
sql += abName.toUpperCase() + " VARCHAR2(255)";
|
sql += ",\n\t";
|
}else if(vtType.equals("VTDate")){
|
sql += abName.toUpperCase() + " DATE";
|
sql += ",\n\t";
|
}else if(vtType.equals("VTTime")){
|
sql += abName.toUpperCase() + " TIMESTAMP";
|
sql += ",\n\t";
|
}else if(vtType.equals("VTDateTime")){
|
sql += abName.toUpperCase() + " TIMESTAMP";
|
sql += ",\n\t";
|
}else if(vtType.equals("VTNote")){
|
sql += abName.toUpperCase() + " VARCHAR2(255)";
|
sql += ",\n\t";
|
}else if(vtType.equals("VTFilePath")){
|
sql += abName.toUpperCase() + " VARCHAR2(255)";
|
sql += ",\n\t";
|
}else if(vtType.equals("VTClob")){
|
sql += abName.toUpperCase() + " CLOB";
|
sql += ",\n\t";
|
}
|
|
return sql;
|
}
|
|
/**
|
* 生成创建业务类型的DDL
|
* @param btm
|
* @return
|
*/
|
// public static String getCreateBTMTableSql(BtmItem btm){
|
// String btmName = btm.name;
|
// String btmTableName = OmdTools.getBTTableName(btmName);
|
// String sql = "create Table " + btmTableName + "(" + OmdTools.getOtherFieldBtSql();
|
// String[] apNames = null;
|
// try {
|
// apNames = getService().getBtmApNameArray(btmName);
|
// } catch (VCIError e) {
|
// e.printStackTrace();
|
// }
|
// if(apNames != null && apNames.length != 0){
|
// for(int k = 0; k < apNames.length; k++){
|
// String abName = apNames[k];
|
// AttribItem abItem = null;
|
//
|
// abItem = ApProvider.getAbItemByName(abName);
|
//
|
// String abSql = getAbSql(abItem);
|
// sql += abSql;
|
// }
|
// }
|
//
|
// sql = sql.substring(0, sql.lastIndexOf(","));
|
// sql += "\n)";
|
// return sql;
|
// }
|
/**
|
* 将业务类型树导出为.sql文件
|
* add by caill 2015.12.21
|
* */
|
// public boolean expBtmDataSql(String dir, BtmItem[] allBtmItems) throws VCIError {
|
// new File(dir).mkdir();
|
// File file = new File(dir + "/platformBtm.sql");
|
// FileWriter w = null;;
|
// BufferedWriter bw = null;
|
// try {
|
// w = new FileWriter(file);
|
// bw = new BufferedWriter(w);
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
//
|
// for(int i = 0; i < allBtmItems.length; i++){
|
// String sql = getBTMTableSqlByName(allBtmItems[i]);
|
// try {
|
// bw.write(sql);
|
// bw.write("\r\n");
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
// }
|
// try {
|
// bw.flush();
|
// bw.close();
|
// return true;
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
//
|
//
|
// return false;
|
// }
|
|
/**
|
* 生成业务类型导出为.sql文件的sql语句 add by caill 2015.12.21
|
* @param btm
|
* @return
|
*/
|
// public String getBTMTableSqlByName(BtmItem allBtmItem){
|
// String btmTableName = OmdTools.getBTTableName(allBtmItem.name);
|
// String sql = "create Table " + btmTableName + "(" + OmdTools.getOtherFieldBtSql();
|
// String[] apNames = null;
|
// try {
|
// apNames = getService().getBtmApNameArray(allBtmItem.name);
|
// } catch (VCIError e) {
|
// e.printStackTrace();
|
// }
|
// if(apNames != null && apNames.length != 0){
|
// for(int k = 0; k < apNames.length; k++){
|
// String abName = apNames[k];
|
// AttribItem abItem = null;
|
//
|
// abItem = ApProvider.getAbItemByName(abName);
|
//
|
// String abSql = getAbSql(abItem);
|
// sql += abSql;
|
// }
|
// }
|
//
|
// sql = sql.substring(0, sql.lastIndexOf(","));
|
// sql += "\n);";
|
// sql += "\r\ncomment on table "+btmTableName+" is '"+allBtmItem.label +"';"; //添加表注释
|
// if(apNames != null && apNames.length != 0){
|
// for(int k = 0; k < apNames.length; k++){
|
// String abName = apNames[k];
|
// AttribItem abItem = null;
|
//
|
// abItem = ApProvider.getAbItemByName(abName);
|
//
|
// sql += "\r\ncomment on column "+btmTableName+"."+abItem.name+" is '"+ abItem.label +"';";
|
// }
|
// }
|
// return sql;
|
// }
|
|
/**
|
* 获取增加主键sql
|
* @param typeName
|
* @return
|
*/
|
// public static String getAddPKSql(String typeName){
|
// return "alter table " + OmdTools.getBTTableName(typeName) + " add constraint PKBTM_" + typeName + " primary key (OID)\n";
|
// }
|
|
/**
|
* Array-->List
|
* @param array
|
* @return
|
*/
|
public List<String> parseArrayToList(String[] array){
|
List<String> list = new ArrayList<String>();
|
for(int i = 0; i < array.length; i++){
|
list.add(array[i]);
|
}
|
return list;
|
}
|
|
/**
|
* Array-->List
|
* @param array
|
* @return
|
*/
|
public List<Integer> parseArrayToList(int[] array){
|
List<Integer> list = new ArrayList<Integer>();
|
for(int i = 0; i < array.length; i++){
|
list.add(array[i]);
|
}
|
return list;
|
}
|
|
/**
|
* Array-->String
|
* @param array
|
* @return
|
*/
|
public static String arrayTOString(String[] array){
|
String str = "";
|
if(array != null && array.length > 0){
|
for(int i = 0; i < array.length; i++){
|
str += array[i];
|
str += ",";
|
}
|
str = str.substring(0, str.lastIndexOf(","));
|
}
|
return str;
|
}
|
|
public static boolean expData(String dir, BtmItem[] bts){
|
Set<String> attNameSet = new HashSet<String>();
|
Set<String> lcNameSet = new HashSet<String>();
|
Set<String> vrNameSet = new HashSet<String>();
|
BufferedWriter bw = null;
|
FileOutputStream fos = null;
|
OutputStreamWriter osw =null;
|
try{
|
new File(dir).mkdir(); //首先新建目录 modify by zhonggy
|
File file = new File(dir + "/bt.txt");
|
//将clob字段写到单独的文件中
|
/*new File(dir + "/bt").mkdir();*/
|
//add by caill start 2015.12.23 导出时将txt文件设置为“utf-8”格式
|
fos = new FileOutputStream(file);
|
osw = new OutputStreamWriter(fos, "utf-8");
|
bw = new BufferedWriter(osw);
|
//add by caill end
|
/*w = new FileWriter(file);
|
bw = new BufferedWriter(w);*/
|
|
for(BtmItem bt : bts){
|
String[] apNames = bt.apNameArray;
|
if(apNames.length > 0){
|
attNameSet.addAll(Arrays.asList(apNames));
|
}
|
if(!bt.lifeCycle.equals("")){
|
lcNameSet.add(bt.lifeCycle);
|
}
|
for(String lcName : bt.lifeCycles){
|
lcNameSet.add(lcName);
|
}
|
|
if(!bt.revRuleName.equals("")){
|
vrNameSet.add(bt.revRuleName);
|
}
|
//若str小于缓冲区大小, 将写到缓冲区;
|
//若str大于缓冲区大小, 将刷新缓冲区(将缓冲区内容写到底层流), 然后str直接写到底层流.
|
String text = getObjectText(bt);
|
bw.write(text);
|
bw.newLine();
|
BufferedWriter clobBW = null;
|
FileOutputStream fo = null;
|
OutputStreamWriter pw =null;
|
try{
|
new File(dir + "/bt").mkdir();
|
File clobFile = new File(dir + "/bt/" + bt.oid + ".xml");
|
//add by caill start 2015.12.23 将xml内容和xml文件格式统一
|
fo = new FileOutputStream(clobFile);
|
pw = new OutputStreamWriter(fo, "utf-8");
|
clobBW = new BufferedWriter(pw);
|
clobBW.write( "<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
|
clobBW.write(getXmlText(bt));
|
clobBW.flush();
|
//add by caill end
|
/*clobW = new FileWriter(clobFile);
|
clobBW = new BufferedWriter(clobW);
|
clobBW.write( "<?xml version=\"1.0\" encoding=\"gb2312\" ?>");//gb2312
|
clobBW.write(getXmlText(bt));
|
clobBW.flush();*/
|
}catch(IOException e2){
|
e2.printStackTrace();
|
}finally{
|
try{
|
if(clobBW != null){
|
fo.close(); //add by caill 2015.12.23将fo关闭
|
pw.close(); //add by caill 2015.12.23 将pw关闭
|
clobBW.close();
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
bw.flush();
|
//导出属性
|
AttribItem[] abs = ApProvider.getAttribItemsByNames(attNameSet.toArray(new String[0]));
|
boolean apFlag = ApProvider.expData(dir, abs);
|
|
List<LifeCycle> lcs = new ArrayList<LifeCycle>();
|
for(String lcName : lcNameSet){
|
LifeCycle lifeCycle = LifeCycleProvider.getInstance().getService().getLifeCycle(lcName);
|
lcs.add(lifeCycle);
|
}
|
boolean lcFlag = LifeCycleProvider.getInstance().expData(dir, lcs.toArray(new LifeCycle[0]));
|
List<VersionRule> vrs = new ArrayList<VersionRule>();
|
for(String vrName : vrNameSet){
|
VersionRule vr = VersionRuleProvider.getInstance().getService().getVersionRule(vrName);
|
vrs.add(vr);
|
}
|
boolean vrFlag = VersionRuleProvider.getInstance().expData(dir, vrs.toArray(new VersionRule[0]));
|
|
if(true & apFlag & lcFlag & vrFlag){
|
System.out.println("**************业务类型导出成功************");
|
}else{
|
System.out.println("**************业务类型导出失败************");
|
}
|
|
return true & apFlag;
|
}catch(IOException e){
|
e.printStackTrace();
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}finally{
|
try {
|
if(bw != null){
|
fos.close(); //add by caill 2015.12.23 将fos关闭
|
osw.close(); //add by caill 2015.12.23 将osw关闭
|
bw.close();
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
return false;
|
}
|
|
/**
|
* 将对象转化成字符串
|
* {oid:qqq, name:q}
|
* @param bt
|
* @return
|
*/
|
public static String getObjectText(BtmItem bt) {
|
StringBuilder stb = new StringBuilder("{");
|
stb.append(OmdConstants.OID + ":" + bt.oid + ",");
|
stb.append(OmdConstants.NAME + ":" + bt.name + ",");
|
stb.append(OmdConstants.LABEL + ":" + bt.label + ",");
|
stb.append(OmdConstants.DESCRIPTION + ":" + bt.description + ",");
|
stb.append(OmdConstants.TS + ":" + bt.ts + ",");
|
stb.append(OmdConstants.CREATOR + ":" + bt.creator + ",");
|
stb.append(OmdConstants.CREATETIME + ":" + bt.createTime + ",");
|
stb.append(OmdConstants.MODIFIER + ":" + bt.modifier + ",");
|
stb.append(OmdConstants.MODIFYTIME + ":" + bt.modifyTime);
|
stb.append("}");
|
return stb.toString();
|
}
|
|
/**
|
* 将bt转化成xmltext
|
* @param o
|
* @return
|
*/
|
public static String getXmlText(BtmItem o){
|
String apNameArray = arrayTOString(o.apNameArray);
|
String lifeCycles = arrayTOString(o.lifeCycles);
|
StringBuilder stb = new StringBuilder("<btm>");
|
stb.append("<name>" + o.name + "</name>");
|
stb.append("<label>" + o.label + "</label>");
|
stb.append("<description>" + o.description + "</description>");
|
stb.append("<isAbstract>" + o.isAbstract + "</isAbstract>");
|
stb.append("<shape>" + o.shape + "</shape>");
|
stb.append("<implClass>" + o.implClass + "</implClass>");
|
stb.append("<fName>" + o.fName + "</fName>");
|
stb.append("<lifeCycle>" + o.lifeCycle + "</lifeCycle>");
|
stb.append("<imageName>" + o.imageName + "</imageName>");
|
stb.append("<revLevel>" + o.revLevel + "</revLevel>");
|
stb.append("<revRuleName>" + o.revRuleName + "</revRuleName>");
|
stb.append("<revInput>" + o.revInput + "</revInput>");
|
stb.append("<delimiter>" + o.delimiter + "</delimiter>");
|
stb.append("<verRuleName>" + o.verRuleName + "</verRuleName>");
|
stb.append("<apNameArray>" + apNameArray + "</apNameArray>");
|
stb.append("<lifeCycles>" + lifeCycles + "</lifeCycles>");
|
stb.append("</btm>");
|
return stb.toString();
|
}
|
|
public static List<BtmItem> getBTFromFile(String dir) {
|
File file = new File(dir + "/bt.txt");
|
List<BtmItem> list = new ArrayList<BtmItem>();
|
BufferedReader br = null;
|
FileInputStream fo = null;
|
InputStreamReader isw =null;
|
try {
|
/*r = new FileReader(file);
|
br = new BufferedReader(r);*/
|
//add by caill start 2015.12.23 导入时将txt文件内容设置为“utf-8”格式
|
fo = new FileInputStream(file);
|
isw = new InputStreamReader(fo, "utf-8");
|
br = new BufferedReader(isw);
|
//add by caill end
|
String str = null;
|
while((str = br.readLine()) != null){
|
Map<String, String> map = getMapFormText(str);
|
String oid = map.get("oid");
|
if(oid != null && !oid.equals("")){
|
File contentFile = new File(dir + "/bt/" + oid + ".xml");
|
if(!contentFile.exists()){
|
System.out.println(dir + "/bt/" + oid + ".xml不存在");
|
break;
|
}
|
BtmItem bt = new BtmItem();
|
bt.oid = oid;
|
bt.name = map.get("name");
|
bt.label = map.get("label");
|
bt.description = map.get("description");
|
bt.ts = Long.valueOf(map.get("ts"));
|
bt.creator = map.get("creator");
|
bt.createTime = Long.valueOf(map.get("createTime"));
|
bt.modifier = map.get("modifier");
|
bt.modifyTime = Long.valueOf(map.get("modifyTime"));
|
SAXReader sa = new SAXReader();
|
//add by caill 2015.12.23 导入时将saxReader对象设置为“utf-8”格式
|
sa.setEncoding("utf-8");
|
Document document = sa.read(contentFile);
|
setBTValueFormDoc(bt, document.getRootElement());
|
list.add(bt);
|
}else{
|
System.out.println(dir + "bt.txt中存在oid为空的错误记录");
|
break;
|
}
|
}
|
return list;
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
} catch (DocumentException e) {
|
e.printStackTrace();
|
} finally{
|
if(br != null){
|
try {
|
fo.close(); //add by caill 2015.12.23 将fo关闭
|
isw.close(); //add by caill 2015.12.23 将isw关闭
|
br.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|
return null;
|
}
|
/**
|
* 将文件中一条记录解析成key-value
|
* @param str
|
* @return
|
*/
|
public static Map<String, String> getMapFormText(String str) {
|
str = str.trim();
|
if(!str.startsWith("{") || !str.endsWith("}")){
|
return null;
|
}
|
Map<String, String> map = new HashMap<String, String>();
|
str = str.substring(1, str.length() - 1);
|
String[] kvs = str.split(",");
|
for(String kv : kvs){
|
String[] kv_ = kv.split(":");
|
if(kv_.length == 1){
|
map.put(kv_[0].trim(), "");
|
}else{
|
map.put(kv_[0].trim(), kv_[1].trim());
|
}
|
}
|
return map;
|
}
|
|
/**
|
* 设置EnumItem存在
|
* @param att
|
* @param element
|
*/
|
public static void setBTValueFormDoc(BtmItem bt, Element element){
|
String value = element.elementText("isAbstract");
|
bt.isAbstract = (value == null ? false : Boolean.valueOf(value));
|
value = element.elementText("fName");
|
bt.fName = (value == null ? "" : value);
|
value = element.elementText("implClass");
|
bt.implClass = (value == null ? "" : value);
|
value = element.elementText("shape");
|
bt.shape = (value == null ? "" : value);
|
value = element.elementText("lifeCycle");
|
bt.lifeCycle = (value == null ? "" : value);
|
value = element.elementText("lifeCycles");
|
if(value != null && !value.equals("")){
|
bt.lifeCycles = value.trim().split(",");
|
}else{
|
bt.lifeCycles = new String[0];
|
}
|
value = element.elementText("imageName");
|
bt.imageName = (value == null ? "" : value);
|
value = element.elementText("revLevel");
|
bt.revLevel = (value == null ? 0 : Short.valueOf(value));
|
value = element.elementText("revRuleName");
|
bt.revRuleName = (value == null ? "" : value);
|
value = element.elementText("revInput");
|
bt.revInput = (value == null ? false : Boolean.valueOf(value));
|
value = element.elementText("delimiter");
|
bt.delimiter = (value == null ? "" : value);
|
value = element.elementText("verRuleName");
|
bt.verRuleName = (value == null ? 0 : Short.valueOf(value));
|
value = element.elementText("apNameArray");
|
if(value != null && !value.equals("")){
|
bt.apNameArray = value.trim().split(",");
|
}else{
|
bt.apNameArray = new String[0];
|
}
|
}
|
|
public static boolean impData(String dir, BtmItem[] bts) {
|
try {
|
List<AttribItem> atts = ApProvider.getAttFromFile(dir);
|
boolean attFlag = ApProvider.impData(dir, atts.toArray(new AttribItem[0]));
|
if(!attFlag){
|
System.out.println("业务类型使用的属性导入失败。导入中止。");
|
return false;
|
}
|
|
List<VersionRule> vrs = VersionRuleProvider.getInstance().getVRsFromFile(dir);
|
boolean vrFlag = VersionRuleProvider.getInstance().impData(vrs.toArray(new VersionRule[0]));
|
if(!vrFlag){
|
System.out.println("业务类型使用的版本规则导入失败。导入中止。");
|
return false;
|
}
|
|
List<LifeCycle> lcs = LifeCycleProvider.getInstance().getLCFromFile(dir);
|
boolean lcFlag = LifeCycleProvider.getInstance().impData(dir, lcs.toArray(new LifeCycle[0]));
|
if(!lcFlag){
|
System.out.println("业务类型使用的生命周期导入失败。导入中止。");
|
return false;
|
}
|
|
for(BtmItem bt : bts){
|
BtmItem bt_ = getService().getBtmItemByName(bt.name);
|
//已经存在
|
if(!bt_.oid.equals("")){
|
getService().deleteBtmItem(bt_);
|
getService().addBtmItem(bt);
|
System.out.println(bt.name + "在数据库中已经存在, 覆盖。");
|
}else{
|
getService().addBtmItem(bt);
|
}
|
}
|
return true;
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return false;
|
}
|
|
/**
|
* 设置索引
|
* @param typeName
|
* @param indexAttr
|
* @return
|
*/
|
// public String getAddIndex(String typeName,String[] indexAttr){
|
// String sql = "create unique INDEX "+indexAttr[0]+" on " + OmdTools.getBTTableName(typeName) + "(" + indexAttr[1] + ")\n";
|
// return sql;
|
// }
|
/**
|
* 修改索引
|
* @param typeName
|
* @param indexAttr
|
* @return
|
*/
|
// public String getDropIndex(String typeName,String[] indexAttr){
|
// String sql = "drop INDEX "+indexAttr[0]+" \n";
|
// return sql;
|
// }
|
|
public boolean addIndex(String typeName, String[] indexAttr){
|
try {
|
return getService().addIndex(typeName, indexAttr);
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
|
return false;
|
}
|
|
public boolean dropIndex(String typeName, String[] indexAttr){
|
try {
|
return getService().dropIndex(typeName, indexAttr);
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
|
return false;
|
}
|
|
}
|