diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/LocalTableDataSource.java b/designer-base/src/main/java/com/fr/design/data/tabledata/LocalTableDataSource.java new file mode 100644 index 0000000000..bcb717e81a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/LocalTableDataSource.java @@ -0,0 +1,52 @@ +package com.fr.design.data.tabledata; + +import com.fanruan.config.impl.data.TableDataConfigProviderFactory; +import com.fr.decision.webservice.bean.entry.FileNodeBean; +import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.FileProcessor; +import com.fr.stable.StringUtils; +import com.fr.workspace.server.repository.tabledata.BaseTableDataSource; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * LocalTableDataSource + * + * @author Destiny.Lin + * @since 11.0 + * Created on 2024/5/29 + */ +public class LocalTableDataSource extends BaseTableDataSource { + @Override + public Set getAllNames(String username) { + Set authServerDataSetNames = new HashSet<>(); + for (String authServerDataSetName : TableDataConfigProviderFactory.getInstance().getTableDatas().keySet()) { + authServerDataSetNames.add(authServerDataSetName); + } + return authServerDataSetNames; + } + + @Override + public boolean lock(String str) { + // 本地默认锁定成功,让其执行后续动作 + return true; + } + + @Override + public boolean unlock(String str) { + // 本地默认解锁成功 + return true; + } + + @Override + public boolean isLock(String str) { + // 本地默认未锁定 + return false; + } + + @Override + public List getFileList(String fileType) { + return FileProcessor.KEY.getFileList(fileType, StringUtils.EMPTY); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java index 447bb82e50..3ad4c40678 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java @@ -448,7 +448,7 @@ public class FileTableDataPane extends AbstractTableDataPane { @Override public void actionPerformed(ActionEvent e) { - FILEChooserPane fileChooser = FILEChooserPane.getInstance(true, false, new ChooseFileFilter(getFileSuffix())); + FILEChooserPane fileChooser = FILEChooserPane.getFileDataChoosePane(new ChooseFileFilter(getFileSuffix())); if (fileChooser.showOpenDialog(FileTableDataPane.this) == FILEChooserPane.OK_OPTION) { final FILE file = fileChooser.getSelectedFILE(); if (file == null) {// 选择的文件不能是 null diff --git a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java index 79b8033c42..9d21751c28 100644 --- a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java +++ b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java @@ -8,7 +8,6 @@ import com.fine.theme.utils.FineUIStyle; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.util.ScaledEmptyBorder; import com.fr.base.BaseUtils; -import com.fr.base.FRContext; import com.fr.base.extension.FileExtension; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; @@ -241,6 +240,18 @@ public class FILEChooserPane extends BasicPane { return INSTANCE; } + public static FILEChooserPane getFileDataChoosePane(FILEFilter filter) { + FILEChooserPane chooserPane = new FILEChooserPane(); + chooserPane.showEnv = true; + chooserPane.showLoc = false; + chooserPane.showWebReport = false; + // 替换掉 PlaceListModel + chooserPane.setFileDataPlaceListModel(FileDataFILE.parseType(filter)); + chooserPane.removeAllFilter(); + chooserPane.addChooseFILEFilter(filter, 0); + return chooserPane; + } + /** * @param showEnv @@ -1110,6 +1121,13 @@ public class FILEChooserPane extends BasicPane { setPlaceListModel(new MultiLocalEnvPlaceListModel()); } + protected void setFileDataPlaceListModel(String type) { + if (placesList == null) { + return; + } + setPlaceListModel(new FileDataPlaceListModel(type)); + } + /* * 选中文件 */ @@ -1342,6 +1360,31 @@ public class FILEChooserPane extends BasicPane { } + private class FileDataPlaceListModel extends AbstractPlaceListModel { + private FileDataFILE envFILE; + + FileDataPlaceListModel(String type) { + envFILE = new FileDataFILE(new FileNode(StableUtils.pathJoin(ProjectConstants.ASSETS_NAME, FileDataFILE.FILE_DATASET_NAME), true), false, StableUtils.pathJoin(ProjectConstants.ASSETS_NAME, FileDataFILE.FILE_DATASET_NAME)) { + @Override + public String getName() { + return getEnvProjectName(); + } + }; + envFILE.setType(type); + } + + @Override + public FILE getElementAt(int index) { + return envFILE; + } + + @Override + public int getSize() { + return 1 + filesOfSystem.size(); + } + + } + private class MultiLocalEnvPlaceListModel extends AbstractPlaceListModel { private static final long serialVersionUID = 6300018896958532154L; diff --git a/designer-base/src/main/java/com/fr/file/FILEFactory.java b/designer-base/src/main/java/com/fr/file/FILEFactory.java index d558483784..4d5fe6548d 100644 --- a/designer-base/src/main/java/com/fr/file/FILEFactory.java +++ b/designer-base/src/main/java/com/fr/file/FILEFactory.java @@ -8,6 +8,7 @@ public class FILEFactory { public static final String MEM_PREFIX = "mem://"; public static final String FILE_PREFIX = "file://"; public static final String ENV_PREFIX = "env://"; + public static final String FILE_DATA_PREFIX = "filedata://"; public static final String WEBREPORT_PREFIX = "webreport://"; public static final String SEPARATOR = "/"; @@ -35,6 +36,8 @@ public class FILEFactory { FileNodeFILE.webRootPath); } else if (path.startsWith(FILE_PREFIX)) { return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length()))); + } else if (path.startsWith(FILE_DATA_PREFIX)) { + return new FileDataFILE(new FileNode(path.substring(FILE_DATA_PREFIX.length()), false), false, path.substring(FILE_DATA_PREFIX.length())); } else { return new FileNodeFILE(new FileNode(path, WorkContext.getWorkResource().isDirectory(path))); } @@ -53,6 +56,8 @@ public class FILEFactory { FileNodeFILE.webRootPath); } else if (path.startsWith(FILE_PREFIX)) { return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length()))); + } else if (path.startsWith(FILE_DATA_PREFIX)) { + return new FileDataFILE(new FileNode(path.substring(FILE_DATA_PREFIX.length()), true), false, path.substring(FILE_DATA_PREFIX.length())); } else { return new FileNodeFILE(new FileNode(path, WorkContext.getWorkResource().isDirectory(path))); } diff --git a/designer-base/src/main/java/com/fr/file/FileDataFILE.java b/designer-base/src/main/java/com/fr/file/FileDataFILE.java new file mode 100644 index 0000000000..434faeee03 --- /dev/null +++ b/designer-base/src/main/java/com/fr/file/FileDataFILE.java @@ -0,0 +1,169 @@ +package com.fr.file; + +import com.fr.decision.webservice.bean.entry.FileNodeBean; +import com.fr.file.filetree.FileNode; +import com.fr.file.filter.FILEFilter; +import com.fr.general.ComparatorUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.CoreConstants; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.workspace.server.repository.tabledata.TableDataRepository; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * FileDataFILE + * + * @author Destiny.Lin + * @since 11.0 + * Created on 2024/8/20 + */ +public class FileDataFILE extends FileNodeFILE{ + public static final String FILE_DATASET_NAME = "file_dataset"; + public static final String TXT = "txt"; + public static final String XML = "xml"; + public static final String EXCEL = "excel"; + private List children = new ArrayList<>(); + private boolean builded = false; + private String id = StringUtils.EMPTY; + private String type = "txt"; + + public FileDataFILE(FileNode node) { + super(node); + } + + public FileDataFILE(FileNode node, boolean builded, String id) { + super(node); + this.builded = builded; + this.id = id; + } + + private void addChild(FileDataFILE file) { + children.add(file); + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public boolean isBuilded() { + return builded; + } + + public void setBuilded(boolean builded) { + this.builded = builded; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public FILE[] listFiles() { + + if (ComparatorUtils.equals(node, null)) { + node = new FileNode(CoreConstants.SEPARATOR, true); + } + if (!node.isDirectory()) { + return new FILE[]{this}; + } + try { + FileDataFILE root = null; + if (!this.builded) { + root = buildTree(); + FileDataFILE dataFILE = root.getFileDataFILE(this.id); + this.setChildren(dataFILE.getChildren()); + this.setType(dataFILE.getType()); + this.builded = true; + } + return this.getChildren().toArray(new FILE[0]); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + return new FILE[0]; + } + } + + @Override + public String prefix() { + return FILEFactory.FILE_DATA_PREFIX; + } + + public FileDataFILE getFileDataFILE(String id) { + if (StringUtils.equals(this.id, id) || StringUtils.equals(StableUtils.pathJoin(this.id, StringUtils.EMPTY), id)) { + return this; + } + for (FileDataFILE file : getChildren()) { + return file.getFileDataFILE(id); + } + return null; + } + + private FileDataFILE buildTree() { + List beans = TableDataRepository.getInstance().getFileList(type); + Map tree = new HashMap<>(); + FileDataFILE root = null; + // id , 父 + for (FileNodeBean bean : beans) { + FileNode fileNode = new FileNode(); + fileNode.setEnvPath(bean.getPath()); + fileNode.setDirectory(bean.getIsParent()); + tree.putIfAbsent(bean.getId(), new FileDataFILE(fileNode, true, bean.getId())); + if (StringUtils.isEmpty(bean.getpId())) { + root = tree.get(bean.getId()); + } else { + tree.putIfAbsent(bean.getpId(), createParent(bean.getpId(), beans)); + FileDataFILE file = tree.get(bean.getpId()); + if (file != null) { + file.addChild(tree.get(bean.getId())); + } + } + } + return root; + } + + private FileDataFILE createParent(String s, List beans) { + for (FileNodeBean bean : beans) { + if (StringUtils.equals(bean.getId(), s)) { + FileNode fileNode = new FileNode(); + fileNode.setEnvPath(bean.getPath()); + fileNode.setDirectory(bean.getIsParent()); + return new FileDataFILE(fileNode, true, bean.getId()); + } + } + return null; + } + + + /** + * 获取类型 + */ + public static String parseType(FILEFilter filter) { + if (filter.getDescription().contains("xls")) { + return EXCEL; + } else if (filter.getDescription().contains("xml")) { + return XML; + } else { + return TXT; + } + } +} diff --git a/designer-base/src/main/java/com/fr/file/FileNodeFILE.java b/designer-base/src/main/java/com/fr/file/FileNodeFILE.java index 8d3a7068b7..72570935a9 100644 --- a/designer-base/src/main/java/com/fr/file/FileNodeFILE.java +++ b/designer-base/src/main/java/com/fr/file/FileNodeFILE.java @@ -49,10 +49,10 @@ public class FileNodeFILE implements FILE { } - private FileNode node; + protected FileNode node; //记录下FILE对应的运行环境,每次创建都设置下当前的运行环境 - private String envPath; + protected String envPath; /** * 是否有全部权限 diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java index 89588c6430..c098989c22 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java @@ -28,9 +28,11 @@ import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDYCo import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JNDIConnectionProcessor; import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.DataSetProcessorFactory; import com.fr.design.data.datapane.connect.LocalConnectionSource; +import com.fr.design.data.tabledata.LocalTableDataSource; import com.fr.file.TableDataConfigWrapper; import com.fr.workspace.server.repository.connection.ConnectionWriterShell; import com.fr.workspace.server.repository.connection.LocalConnectionShell; +import com.fr.workspace.server.repository.tabledata.LocalTableDataShell; /** @@ -57,6 +59,7 @@ public class DesignDatasourceComponent extends DatasourceComponent { ConnectionProcessorFactory.register(JDYConnectionProcessor.KEY); DataSetProcessorFactory.init(); Carina.getApplicationContext().singleton(LocalConnectionShell.class).set(new LocalConnectionSource()); + Carina.getApplicationContext().singleton(LocalTableDataShell.class).set(new LocalTableDataSource()); } /**