Browse Source

REPORT-9407

【10.0一轮回归】远程设计时alphafine搜索的问题
research/10.0
XiaXiang 6 years ago
parent
commit
4a0bb32a04
  1. 179
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java

179
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java

@ -1,6 +1,7 @@
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.base.FRContext;
import com.fr.base.extension.FileExtension;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
@ -11,21 +12,11 @@ import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
* Created by XiaXiang on 2017/3/27.
@ -40,7 +31,7 @@ public class FileSearchManager implements AlphaFineSearchProvider {
private SearchResult lessModelList;
private SearchResult moreModelList;
private String searchText;
private List<FileNode> fileNodes = null;
private FileNode[] fileNodes = null;
//停止搜索
private boolean stopSearch = false;
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
@ -58,9 +49,6 @@ public class FileSearchManager implements AlphaFineSearchProvider {
return instance;
}
public synchronized static void init() {
}
/**
* 根据文件路径获取文件模型
@ -81,176 +69,69 @@ public class FileSearchManager implements AlphaFineSearchProvider {
this.moreModelList = new SearchResult();
this.searchText = dealWithSearchText(searchText);
if (StringUtils.isBlank(this.searchText) || ComparatorUtils.equals(this.searchText, DS_NAME)) {
lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates")));
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_Templates")));
return lessModelList;
}
fileNodes = new ArrayList<>();
fileNodes = listTpl(ProjectConstants.REPORTLETS_NAME, true);
AlphaFineHelper.checkCancel();
fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, new FileExtension[]{FileExtension.CPT, FileExtension.FRM}, true);
isContainCpt = true;
isContainFrm = true;
doSearch(this.searchText, true);
if (stopSearch) {
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE));
lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE));
stopSearch = false;
return this.lessModelList;
}
doSearch(this.searchText);
if (filterModelList.isEmpty()) {
return new SearchResult();
}
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), false, CellType.FILE));
} else if (filterModelList.size() < AlphaFineConstants.SHOW_SIZE + 1) {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates")));
lessModelList.addAll(filterModelList);
} else {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE));
lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size()));
}
return lessModelList;
}
@Override
public SearchResult getMoreSearchResult(String searchText) {
if (moreModelList != null && !moreModelList.isEmpty()) {
return moreModelList;
}
this.filterModelList = new SearchResult();
this.moreModelList = new SearchResult();
AlphaFineHelper.checkCancel();
isContainCpt = true;
isContainFrm = true;
doSearch(this.searchText, false);
moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size()));
return moreModelList;
}
private void doSearch(String searchText, boolean needMore) {
private void doSearch(String searchText) {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) {
for (FileNode node : fileNodes) {
boolean isAlreadyContain = false;
isAlreadyContain = searchFile(searchText, node, isAlreadyContain, needMore);
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent() && node.getLock() == null) {
searchFileContent(searchText, node, isAlreadyContain, needMore);
}
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && stopSearch) {
return;
}
}
}
private String dealWithSearchText(String searchText) {
if (searchText.startsWith(FRM_PREFIX)) {
isContainCpt = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length());
} else if (searchText.startsWith(CPT_PREFIX)) {
isContainFrm = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length());
}
return searchText;
}
/**
* 搜索文件内容
*
* @param searchText
* @param node
* @param isAlreadyContain
*/
private void searchFileContent(String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) {
try {
InputStream inputStream = new ByteArrayInputStream(WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1))));
InputStreamReader isr = new InputStreamReader(inputStream, "UTF-8");
BufferedReader reader = new BufferedReader(isr);
String line;
int columnNumber;
boolean isFoundInContent = false;
while ((line = reader.readLine()) != null) {
columnNumber = line.toLowerCase().indexOf(searchText);
if (columnNumber != -1) {
isFoundInContent = true;
break;
}
}
if (isFoundInContent && !isAlreadyContain) {
if (node.getName().toLowerCase().contains(searchText)) {
FileModel model = new FileModel(node.getName(), node.getEnvPath());
if (!AlphaFineHelper.getFilterResult().contains(model)) {
AlphaFineHelper.checkCancel();
filterModelList.add(model);
}
if (this.filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) {
stopSearch = true;
}
}
isr.close();
reader.close();
} catch (Exception e) {
FineLoggerFactory.getLogger().error("file read error: " + e.getMessage());
}
}
/**
* 搜索模板
*
* @param searchText
* @param node
* @param isAlreadyContain
* @return
*/
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) {
if (node.getName().toLowerCase().contains(searchText)) {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent()) {
FileNode[] fileNodes = FRContext.getFileNodes().filterFiles(searchText, ProjectConstants.REPORTLETS_NAME, new FileExtension[]{FileExtension.CPT, FileExtension.FRM}, true);
for (FileNode node : fileNodes) {
FileModel model = new FileModel(node.getName(), node.getEnvPath());
if (!AlphaFineHelper.getFilterResult().contains(model)) {
if (!AlphaFineHelper.getFilterResult().contains(model) && !filterModelList.contains(model)) {
AlphaFineHelper.checkCancel();
filterModelList.add(model);
}
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) {
stopSearch = true;
}
isAlreadyContain = true;
}
}
return isAlreadyContain;
}
/**
* 获取工作目录下所有符合要求的模板
*
* @param rootFilePath
* @param recurse
* @return
*/
private List<FileNode> listTpl(String rootFilePath, boolean recurse) {
List<FileNode> fileNodeList = new ArrayList<FileNode>();
try {
listAll(rootFilePath, fileNodeList, recurse);
} catch (Exception e) {
FRContext.getLogger().error("file search error: " + e.getMessage(), e);
private String dealWithSearchText(String searchText) {
if (searchText.startsWith(FRM_PREFIX)) {
isContainCpt = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length());
} else if (searchText.startsWith(CPT_PREFIX)) {
isContainFrm = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length());
}
return fileNodeList;
return searchText;
}
/**
* 获取当前工作目录下所有模板
*
* @param rootFilePath
* @param nodeList
* @param recurse
* @throws Exception
*/
private void listAll(String rootFilePath, List<FileNode> nodeList, boolean recurse) throws Exception {
FileNode[] fns = FRContext.getFileNodes().list(rootFilePath);
for (int i = 0; i < fns.length; i++) {
FileNode fileNode = fns[i];
if (fileNode.isDirectory()) {
if (recurse) {
listAll(rootFilePath + File.separator + fns[i].getName(), nodeList, true);
} else {
nodeList.add(fns[i]);
}
} else if (isContainCpt && fileNode.isFileType("cpt")) {
nodeList.add(fileNode);
} else if (isContainFrm && fileNode.isFileType("frm")) {
nodeList.add(fileNode);
}
}
}
/**
* 是否包含cpt

Loading…
Cancel
Save