Browse Source

REPORT-114392 FR-FBP版本本地设计适配 修复数据连接

fbp-1.0
Destiny.Lin 5 months ago
parent
commit
b3d737218c
  1. 12
      designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java
  2. 41
      designer-base/src/main/java/com/fr/design/data/DataEncryptionHelper.java
  3. 14
      designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java
  4. 16
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java
  5. 8
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java
  6. 4
      designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java
  7. 137
      designer-base/src/main/java/com/fr/design/data/datapane/preview/TableDataBeanHelper.java
  8. 49
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java

12
designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java

@ -1,12 +1,13 @@
package com.fr.design.actions.server;
import com.fr.base.TableData;
import com.fr.data.impl.Connection;
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.DataSetProcessorFactory;
import com.fr.design.DesignModelAdapter;
import com.fr.design.actions.UpdateAction;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataTreePane;
import com.fr.design.data.datapane.preview.TableDataBeanHelper;
import com.fr.design.data.tabledata.ResponseDataSourceChange;
import com.fr.design.data.tabledata.tabledatapane.TableDataManagerPane;
import com.fr.design.dialog.BasicDialog;
@ -24,7 +25,9 @@ import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.report.LockItem;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.entity.tabledata.TableDataBean;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataRepository;
import javax.swing.KeyStroke;
@ -81,11 +84,16 @@ public class GlobalTableDataAction extends UpdateAction implements ResponseDataS
// 锁定成功,执行后续操作
final DesignerFrame designerFrame = DesignerContext.getDesignerFrame();
final List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final List<ConnectionBean> connectionInfoBeans = ConnectionRepository.getInstance().getAll();
final Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : connectionInfoBeans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
final Map<String, TableData> tableDataMap = new HashMap<>();
try {
TransmissionEncryptionManager.setTransEncryptionLevel(1);
for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName() , DataSetProcessorFactory.getTableDataSet(bean.getDatasetType(), bean.getDatasetData()));
tableDataMap.put(bean.getDatasetName() , TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
}
} catch (Exception e) {
throw new RuntimeException(e);

41
designer-base/src/main/java/com/fr/design/data/DataEncryptionHelper.java

@ -0,0 +1,41 @@
package com.fr.design.data;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.stable.StringUtils;
import com.fr.workspace.server.repository.WorkplaceConstants;
/**
* 数据加解密工具类
*
* @author Destiny.Lin
* @since 11.0
* Created on 2024/8/9
*/
public class DataEncryptionHelper {
/**
* 密码加密
*/
public static String encryptPassWord(String password) {
// 如果是空密码或者默认密码,就返回默认的星号回去
if (StringUtils.isEmpty(password) || StringUtils.equals(password, DecisionServiceConstants.DEFAULT_PASSWORD)) {
return DecisionServiceConstants.DEFAULT_PASSWORD;
}
return encrypt(password);
}
/**
* 加密字符串
*/
public static String encrypt(String str) {
return TransmissionEncryptionManager.getInstance().getEncryption(WorkplaceConstants.getEncryptionMode()).encrypt(str, WorkplaceConstants.getEncryptionKey());
}
/**
* 解密字符串
*/
public static String decrypt(String str) {
return TransmissionEncryptionManager.getInstance().getEncryption(WorkplaceConstants.getDecryptionMode()).decrypt(str, WorkplaceConstants.getDecryptionKey());
}
}

14
designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java

@ -446,14 +446,14 @@ public abstract class DesignTableDataManager {
}
private static void addServerData(java.util.Map<String, TableDataWrapper> resMap) {
String[] namearray = TableDataFactory.getSortOfChineseNameOfServerData();
for (String name : namearray) {
if (globalDsCache.containsKey(name)) {
resMap.put(name, globalDsCache.get(name));
Map<String, TableData> tableDataMap = TableDataFactory.getTableDatas();
for (Entry<String, TableData> entry : tableDataMap.entrySet()) {
if (globalDsCache.containsKey(entry.getKey())) {
resMap.put(entry.getKey(), globalDsCache.get(entry.getKey()));
} else {
TableDataWrapper tdw = new ServerTableDataWrapper(TableDataConfigProviderFactory.getInstance().getTableData(name), name);
resMap.put(name, tdw);
globalDsCache.put(name, tdw);
TableDataWrapper tdw = new ServerTableDataWrapper(entry.getValue(), entry.getKey());
resMap.put(entry.getKey(), tdw);
globalDsCache.put(entry.getKey(), tdw);
}
}
}

16
designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java

@ -11,6 +11,7 @@ import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.DataSetP
import com.fr.design.data.BasicTableDataUtils;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.MapCompareUtils;
import com.fr.design.data.datapane.preview.TableDataBeanHelper;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameableCreator;
@ -227,11 +228,20 @@ public class TableDataPaneListPane extends JListControlPane implements TableData
@Override
public void populate(Map<String, TableData> tableDataMap) {
Iterator<String> nameIt = tableDataMap.keySet().iterator();
populatedTableDataSnapshot.clear();
Iterator<String> procedurenameIt = ProcedureConfig.getInstance().getProcedures().keySet().iterator();
List<NameObject> nameObjectList = new ArrayList<NameObject>();
while (nameIt.hasNext()) {
String name = nameIt.next();
TableData data = tableDataMap.get(name);
if (data != null) {
nameObjectList.add(new NameObject(name, tableDataMap.get(name)));
try {
populatedTableDataSnapshot.put(name, (TableData) tableDataMap.get(name).clone());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
while (procedurenameIt.hasNext()) {
String name = procedurenameIt.next();
@ -253,13 +263,13 @@ public class TableDataPaneListPane extends JListControlPane implements TableData
try {
switch (entryEventKind) {
case REMOVED:
deleteDatas.add(DataSetProcessorFactory.getServerDataSetBean(s, tabledata));
deleteDatas.add(TableDataBeanHelper.getServerDataSetBean(s, tabledata));
break;
case ADDED:
addDatas.add(DataSetProcessorFactory.getServerDataSetBean(s, tabledata));
addDatas.add(TableDataBeanHelper.getServerDataSetBean(s, tabledata));
break;
case UPDATED:
updateDatas.add(DataSetProcessorFactory.getServerDataSetBean(s, tabledata));
updateDatas.add(TableDataBeanHelper.getServerDataSetBean(s, tabledata));
break;
default:
break;

8
designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java

@ -138,10 +138,10 @@ public class TableDataSourceOP implements UserObjectOP<TableDataWrapper> {
Map<String, TableDataWrapper> templateDataMap;
Map<String, TableDataWrapper> serverDataMap;
Map<String, TableDataWrapper> storeProcedureMap;
templateDataMap = this.init().get(0);
serverDataMap = this.init().get(1);
storeProcedureMap = this.init().get(2);
List<Map<String, TableDataWrapper>> init = this.init();
templateDataMap = init.get(0);
serverDataMap = init.get(1);
storeProcedureMap = init.get(2);
//所有的数据集
List<ExpandMutableTreeNode> list = new ArrayList<>();

4
designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java

@ -23,6 +23,8 @@ import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.stable.StringUtils;
import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
import com.fr.workspace.server.repository.WorkplaceConstants;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
/**
* 数据连接传输工具类
*
@ -39,7 +41,7 @@ public class ConnectionInfoBeanHelper {
public static ConnectionInfoBean createConnectionInfoBean(String name, Connection connection, boolean withPassword) throws Exception {
if (connection instanceof NameDatabaseConnection) {
name = ((NameDatabaseConnection) connection).getName();
connection = ((NameDatabaseConnection) connection).createDatabase();
connection = ConnectionRepository.getInstance().getByName(name).getConnection();
}
if (JDBCConnectionProcessor.KEY.acceptConnections().contains(connection.getClass())) {
ConnectionInfoBean bean = new ConnectionInfoBean();

137
designer-base/src/main/java/com/fr/design/data/datapane/preview/TableDataBeanHelper.java

@ -0,0 +1,137 @@
package com.fr.design.data.datapane.preview;
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory;
import com.fr.base.DataSetProcessors;
import com.fr.base.Parameter;
import com.fr.base.ParameterHelper;
import com.fr.base.ParameterTypeHandler;
import com.fr.base.TableData;
import com.fr.data.impl.Connection;
import com.fr.data.impl.DBTableData;
import com.fr.data.impl.NameDatabaseConnection;
import com.fr.decision.fun.UniversalServerTableDataProvider;
import com.fr.decision.privilege.TransmissionTool;
import com.fr.decision.webservice.bean.dataset.ParameterBean;
import com.fr.decision.webservice.bean.dataset.SQLDataSetBean;
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.SQLDataSetProcessor;
import com.fr.design.data.DataEncryptionHelper;
import com.fr.general.GeneralUtils;
import com.fr.general.sql.SqlUtils;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 数据集bean工具类
*
* @author Destiny.Lin
* @since 11.0
* Created on 2024/8/9
*/
public class TableDataBeanHelper {
/**
* 根据序列化数据生成tabledata
*/
public static TableData getTableDataSet(Map<String, Connection> connectionMap, String type, String tableDataSetData) throws Exception {
if (DataSetProcessors.getProcessors().containsKey(type)) {
if (StringUtils.equals(SQLDataSetProcessor.TYPE, type)) {
return deserialize4SQL(connectionMap, null, new JSONObject(tableDataSetData));
} else {
UniversalServerTableDataProvider processor = DataSetProcessors.getProcessors().get(type);
return (TableData) processor.deserialize(null, new JSONObject(tableDataSetData));
}
}
return null;
}
/**
* 获取服务器数据集传输的bean
*/
public static ServerDataSetBean getServerDataSetBean(String name, TableData tableData) {
for (UniversalServerTableDataProvider processor : DataSetProcessors.getProcessors().values()) {
if (SQLDataSetProcessor.KEY.classForTableData() == tableData.getClass()) {
return serialize4SQL(name, tableData);
} else if (processor.classForTableData() == tableData.getClass()) {
ServerDataSetBean bean = new ServerDataSetBean();
try {
bean.setDatasetData(processor.serialize(tableData).toString());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
bean.setDatasetData(StringUtils.EMPTY);
}
bean.setDatasetName(name);
bean.setDatasetType(processor.nameForTableData());
return bean;
}
}
return new ServerDataSetBean(name);
}
private static ServerDataSetBean serialize4SQL(String name, TableData tableData) {
ServerDataSetBean bean = new ServerDataSetBean();
try {
bean.setDatasetData(serialize4SQL0((DBTableData) tableData).toString());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
bean.setDatasetData(StringUtils.EMPTY);
}
bean.setDatasetName(name);
bean.setDatasetType(SQLDataSetProcessor.KEY.nameForTableData());
return bean;
}
private static Object serialize4SQL0(DBTableData dataSet) {
SQLDataSetBean bean = new SQLDataSetBean();
if (dataSet.getDatabase() instanceof NameDatabaseConnection) {
bean.setDatabase(((NameDatabaseConnection) dataSet.getDatabase()).getName());
}
bean.setQuery(DataEncryptionHelper.encrypt(dataSet.getQuery()));
List<ParameterBean> parameterBeans = new ArrayList<>();
ParameterProvider[] parameters = dataSet.getParameters(Calculator.createCalculator());
for (ParameterProvider parameter : parameters) {
parameterBeans.add(new ParameterBean(parameter.getValue().getClass().getSimpleName(), parameter.getName(), GeneralUtils.objectToString(parameter.getValue())));
}
bean.setParameters(parameterBeans);
return JSONObject.mapFrom(bean);
}
private static TableData deserialize4SQL(Map<String, Connection> connectionMap, DBTableData oldDataSet, JSONObject object) {
DBTableData tableData = new DBTableData();
SQLDataSetBean bean = object.mapTo(SQLDataSetBean.class);
tableData.setQuery(DataEncryptionHelper.decrypt(bean.getQuery()));
Connection connection = connectionMap.get(bean.getDatabase());
if (connection != null) {
tableData.setDatabase(new NameDatabaseConnection(bean.getDatabase()));
} else {
throw new RuntimeException("not find conn by " + bean.getDatabase());
}
String sql = SqlUtils.clearSqlComments(DataEncryptionHelper.decrypt(bean.getQuery()));
Parameter[] parameters = new Parameter[bean.getParameters().size()];
for (int i = 0; i < parameters.length; i++) {
ParameterBean parameterBean = bean.getParameters().get(i);
parameters[i] = (Parameter) ParameterTypeHandler.getInstance().parseParameter(parameterBean, new Parameter(parameterBean.getName()));
}
tableData.setParameters(ParameterHelper.analyzeAndUnionSameParameters(new String[]{sql}, parameters));
if (oldDataSet != null) {
tableData.setMaxMemRowCount(oldDataSet.getMaxMemRowCount());
tableData.setPageQuerySql(oldDataSet.getPageQuerySql());
tableData.setShare(oldDataSet.isShare());
tableData.setDataQueryProcessor(oldDataSet.getDataQueryProcessor());
}
return tableData;
}
}

49
designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java

@ -4,6 +4,7 @@ import com.fanruan.config.impl.data.TableDataConfigProviderFactory;
import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import com.fr.data.impl.ClassTableData;
import com.fr.data.impl.Connection;
import com.fr.data.impl.DBTableData;
import com.fr.data.impl.DecoratedTableData;
import com.fr.data.impl.EmbeddedTableData;
@ -11,7 +12,9 @@ import com.fr.data.impl.FileTableData;
import com.fr.data.impl.MultiTDTableData;
import com.fr.data.impl.RecursionTableData;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
import com.fr.design.data.datapane.TableDataNameObjectCreator;
import com.fr.design.data.datapane.preview.TableDataBeanHelper;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
import com.fr.design.data.tabledata.tabledatapane.ClassTableDataPane;
import com.fr.design.data.tabledata.tabledatapane.DBTableDataPane;
@ -27,10 +30,13 @@ import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.authority.user.UserAuthority;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataRepository;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@ -178,10 +184,18 @@ public abstract class TableDataFactory {
public static String[] getSortOfChineseNameOfServerData() {
clearAll();
try {
Iterator<String> nameIt = TableDataRepository.getInstance().getAllNames(StringUtils.EMPTY).iterator();
while (nameIt.hasNext()) {
String name = nameIt.next();
addName(name, TableDataConfigProviderFactory.getInstance().getTableData(name));
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final List<ConnectionBean> connectionInfoBeans = ConnectionRepository.getInstance().getAll();
final Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : connectionInfoBeans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
Map<String, TableData> tableDataMap = new HashMap<>();
for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
}
for (Entry<String, TableData> entry : tableDataMap.entrySet()) {
addName(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
@ -191,6 +205,33 @@ public abstract class TableDataFactory {
return getSortedNameArray();
}
/**
* 获取服务器数据集
*/
public static Map<String, TableData> getTableDatas() {
clearAll();
Map<String, TableData> tableDataMap = new HashMap<>();
try {
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final List<ConnectionBean> connectionInfoBeans = ConnectionRepository.getInstance().getAll();
final Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : connectionInfoBeans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
}
for (Entry<String, TableData> entry : tableDataMap.entrySet()) {
addName(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return new HashMap<>();
}
return tableDataMap;
}
private static String[] getSortedNameArray() {
Iterator<Entry<String, TableDataNameObjectCreator>> entryIt = map.entrySet().iterator();
List<String> namelist = new ArrayList<String>();

Loading…
Cancel
Save