Browse Source

REPORT-6544 使用Lucene,重新实现RecentSearchManager

master
XiaXiang 7 years ago
parent
commit
a5b772f159
  1. 7
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 8
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java
  3. 8
      designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java
  4. 77
      designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java
  5. 97
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  6. 303
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java
  7. 6
      designer/src/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java
  8. 317
      designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/1.java
  9. 10
      designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java
  10. 9
      designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java
  11. 178
      designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java
  12. 28
      designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java
  13. 193
      designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java
  14. 18
      designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java

7
designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java

@ -70,9 +70,10 @@ public class AlphaFineConstants {
public static final String PLUGIN_SEARCH_URL = SiteCenter.getInstance().acquireUrlByKind("plugin.searchAPI");
public static final String PLUGIN_URL = SiteCenter.getInstance().acquireUrlByKind("af.plugin");
public static final String PLUGIN_URL = SiteCenter.getInstance().acquireUrlByKind("af.pluginInfo");
public static final String REUSE_URL = SiteCenter.getInstance().acquireUrlByKind("af.reuseInfo");
public static final String REUSE_URL = SiteCenter.getInstance().acquireUrlByKind("af.reuse");
public static final String DOCUMENT_DOC_URL = SiteCenter.getInstance().acquireUrlByKind("af.doc_view");
@ -87,4 +88,6 @@ public class AlphaFineConstants {
public static final String SEARCH_API = SiteCenter.getInstance().acquireUrlByKind("af.cloud_search");
}

8
designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java

@ -7,8 +7,8 @@ import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.NoResultModel;
import com.fr.design.mainframe.alphafine.component.AlphaFineDialog;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.RecommendSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager;
import com.fr.general.Inter;
import com.fr.general.ProcessCanceledException;
import com.fr.stable.StringUtils;
@ -89,8 +89,8 @@ public class AlphaFineHelper {
}
public static List<AlphaCellModel> getFilterResult() {
List<AlphaCellModel> recentList = RecentSearchManager.getRecentSearchManger().getRecentModelList();
List<AlphaCellModel> recommendList = RecommendSearchManager.getRecommendSearchManager().getRecommendModelList();
List<AlphaCellModel> recentList = RecentSearchManager.getInstance().getRecentModelList();
List<AlphaCellModel> recommendList = RecommendSearchManager.getInstance().getRecommendModelList();
SearchResult filterResult = new SearchResult();
filterResult.addAll(recentList);
filterResult.addAll(recommendList);

8
designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java

@ -2,10 +2,10 @@ package com.fr.design.mainframe.alphafine.cell;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.search.manager.ActionSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.DocumentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.FileSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.PluginSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.ActionSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.DocumentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.FileSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.PluginSearchManager;
import com.fr.json.JSONObject;
/**

77
designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java

@ -1,53 +1,48 @@
package com.fr.design.mainframe.alphafine.cell.model;
import com.fr.base.FRContext;
import com.fr.design.extra.WebViewDlgHelper;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.env.RemoteEnv;
import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import com.fr.stable.StringUtils;
/**
* Created by XiaXiang on 2017/4/20.
*/
public class PluginModel extends AlphaCellModel {
private static final String PLUGIN_INFORMATION_URL = "http://shop.finereport.com/ShopServer?pg=plugin&pid=";
private static final String REUSE_INFORMATION_URL = "http://shop.finereport.com/reuses/";
private String pluginUrl;
private String imageUrl;
private String version;
private String jartime;
private String link;
private String informationUrl;
private int pluginId;
private String pluginId;
private int id;
private int price;
public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId, int serchCount) {
this(name, content, imageUrl, version, jartime, link, type, price, pluginId);
public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, String pluginId, CellType type, int price, int id, int serchCount) {
this(name, content, imageUrl, version, jartime, link, pluginId, type, price, id);
setSearchCount(serchCount);
}
public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId) {
public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, String pluginId, CellType type, int price, int id) {
super(name, content);
this.link = link;
setType(type);
this.pluginId = pluginId;
if (getType() == CellType.PLUGIN) {
this.pluginUrl = AlphaFineConstants.PLUGIN_URL + pluginId;
this.informationUrl = PLUGIN_INFORMATION_URL + this.pluginId;
} else {
this.pluginUrl = AlphaFineConstants.REUSE_URL + pluginId;
this.informationUrl = REUSE_INFORMATION_URL + this.pluginId;
}
this.id = id;
this.imageUrl = imageUrl;
this.jartime = jartime;
this.version = version;
this.price = price;
this.pluginId = pluginId;
if (getType() == CellType.PLUGIN) {
this.informationUrl = AlphaFineConstants.PLUGIN_URL + id;
} else {
this.informationUrl = AlphaFineConstants.REUSE_URL + id;
}
}
public String getImageUrl() {
@ -58,14 +53,6 @@ public class PluginModel extends AlphaCellModel {
this.imageUrl = imageUrl;
}
public String getPluginUrl() {
return pluginUrl;
}
public void setPluginUrl(String pluginUrl) {
this.pluginUrl = pluginUrl;
}
public String getVersion() {
return version;
}
@ -103,7 +90,7 @@ public class PluginModel extends AlphaCellModel {
JSONObject object = JSONObject.create();
try {
JSONObject modelObject = JSONObject.create();
modelObject.put("name", getName()).put("description", getContent()).put("pic", getImageUrl()).put("version", getVersion()).put("jartime", getJartime()).put("type", getType().getTypeValue()).put("price", getPrice()).put("id", getPluginId()).put("link", getLink()).put("searchCount", getSearchCount());
modelObject.put("name", getName()).put("description", getContent()).put("pic", getImageUrl()).put("version", getVersion()).put("jartime", getJartime()).put("id", getId()).put("pluginid", getPluginId()).put("type", getType().getTypeValue()).put("price", getPrice()).put("link", getLink()).put("searchCount", getSearchCount());
object.put("result", modelObject).put("cellType", getType().getTypeValue());
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
@ -119,16 +106,12 @@ public class PluginModel extends AlphaCellModel {
@Override
public void doAction() {
try {
Desktop.getDesktop().browse(new URI(getPluginUrl()));
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (URISyntaxException e) {
FRLogger.getLogger().error(e.getMessage());
if (StringUtils.isBlank(this.pluginId) || FRContext.getCurrentEnv() instanceof RemoteEnv) {
return;
}
WebViewDlgHelper.showPluginInStore(getName(), "[" + ModelToJson().optString("result") + "]");
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -139,21 +122,21 @@ public class PluginModel extends AlphaCellModel {
}
PluginModel that = (PluginModel) o;
return pluginUrl != null ? pluginUrl.equals(that.pluginUrl) : that.pluginUrl == null;
return pluginId != null ? pluginId.equals(that.pluginId) : that.pluginId == null;
}
@Override
public int hashCode() {
return pluginUrl != null ? pluginUrl.hashCode() : 0;
return pluginId != null ? pluginId.hashCode() : 0;
}
public int getPluginId() {
return pluginId;
public int getId() {
return id;
}
public void setPluginId(int pluginId) {
this.pluginId = pluginId;
public void setId(int id) {
this.id = id;
}
public String getInformationUrl() {
@ -163,4 +146,12 @@ public class PluginModel extends AlphaCellModel {
public void setInformationUrl(String informationUrl) {
this.informationUrl = informationUrl;
}
public String getPluginId() {
return pluginId;
}
public void setPluginId(String pluginId) {
this.pluginId = pluginId;
}
}

97
designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -23,12 +23,12 @@ import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane;
import com.fr.design.mainframe.alphafine.preview.FilePreviewPane;
import com.fr.design.mainframe.alphafine.preview.NoResultPane;
import com.fr.design.mainframe.alphafine.preview.PluginPreviewPane;
import com.fr.design.mainframe.alphafine.search.manager.ActionSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.DocumentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.FileSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.PluginSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.RecommendSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.ActionSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.DocumentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.FileSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.PluginSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager;
import com.fr.form.main.Form;
import com.fr.form.main.FormIO;
import com.fr.general.ComparatorUtils;
@ -390,7 +390,6 @@ public class AlphaFineDialog extends UIDialog {
*/
private void rebuildList(String searchText) {
resetContainer();
if (searchText.startsWith(ADVANCED_SEARCH_MARK)) {
if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) {
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
@ -445,47 +444,35 @@ public class AlphaFineDialog extends UIDialog {
}
private void buildDocumentList(final String searchText) {
SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText);
for (AlphaCellModel object : documentModelList) {
searchListModel.addElement(object);
}
addSearchResult(DocumentSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildFileList(final String searchText) {
SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText);
for (AlphaCellModel object : fileModelList) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
addSearchResult(FileSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildActionList(final String searchText) {
SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText);
for (AlphaCellModel object : actionModelList) {
searchListModel.addElement(object);
}
addSearchResult(ActionSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildPluginList(final String searchText) {
SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText);
for (AlphaCellModel object : pluginModelList) {
searchListModel.addElement(object);
}
addSearchResult(PluginSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildRecommendList(final String searchText) {
SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText);
for (AlphaCellModel object : recommendModelList) {
searchListModel.addElement(object);
}
addSearchResult(RecommendSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildRecentList(final String searchText) {
SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText);
for (AlphaCellModel object : recentModelList) {
addSearchResult(RecentSearchManager.getInstance().getLessSearchResult(searchText));
}
private synchronized void addSearchResult(SearchResult searchResult) {
for (AlphaCellModel object : searchResult) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
}
/**
@ -636,6 +623,7 @@ public class AlphaFineDialog extends UIDialog {
private void dealWithMoreOrLessResult(int index, MoreModel selectedValue) {
if (ComparatorUtils.equals(Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), selectedValue.getContent())) {
selectedValue.setContent(Inter.getLocText("FR-Designer_AlphaFine_ShowLess"));
rebuildShowMoreList(index, selectedValue);
} else {
selectedValue.setContent(Inter.getLocText("FR-Designer_AlphaFine_ShowAll"));
@ -676,7 +664,9 @@ public class AlphaFineDialog extends UIDialog {
searchResultList.setSelectedIndex(searchResultList.getSelectedIndex() + 1);
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
searchResultList.setSelectedIndex(searchResultList.getSelectedIndex() - 1);
} else escAlphaFineDialog(e);
} else {
escAlphaFineDialog(e);
}
}
});
@ -758,9 +748,8 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel
*/
private void saveLocalHistory(AlphaCellModel cellModel) {
RecentSearchManager recentSearchManager = RecentSearchManager.getRecentSearchManger();
recentSearchManager.addRecentModel(storeText, cellModel);
recentSearchManager.saveXMLFile();
RecentSearchManager searchManager = RecentSearchManager.getInstance();
searchManager.addModel(storeText, cellModel, cellModel.getSearchCount() + 1);
sendDataToServer(storeText, cellModel);
}
@ -806,14 +795,34 @@ public class AlphaFineDialog extends UIDialog {
* @param index
* @param selectedValue
*/
private void rebuildShowMoreList(int index, MoreModel selectedValue) {
SearchResult moreResult = getMoreResult(selectedValue);
private void rebuildShowMoreList(final int index, final MoreModel selectedValue) {
if ((selectedValue).getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowLess"))) {
for (int i = 0; i < moreResult.size(); i++) {
this.searchListModel.add(index + AlphaFineConstants.SHOW_SIZE + 1 + i, moreResult.get(i));
splitLabel.setIcon(new ImageIcon(getClass().getResource(AlphaFineConstants.IMAGE_URL + "bigloading.gif")));
if (this.searchWorker != null && !this.searchWorker.isDone()) {
this.searchWorker.cancel(true);
this.searchWorker = null;
}
this.searchWorker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
SearchResult moreResults = getMoreResult(selectedValue);
for (int i = 0; i < moreResults.size(); i++) {
searchListModel.add(index + AlphaFineConstants.SHOW_SIZE + 1 + i, moreResults.get(i));
}
return null;
}
@Override
protected void done() {
if (!isCancelled()) {
splitLabel.setIcon(null);
}
}
};
this.searchWorker.execute();
} else {
for (int i = 0; i < moreResult.size(); i++) {
for (int i = 0; i < getMoreResult(selectedValue).size(); i++) {
this.searchListModel.remove(index + AlphaFineConstants.SHOW_SIZE + 1);
}
@ -824,16 +833,16 @@ public class AlphaFineDialog extends UIDialog {
SearchResult moreResult;
switch (selectedValue.getContentType()) {
case PLUGIN:
moreResult = PluginSearchManager.getPluginSearchManager().getMoreSearchResult();
moreResult = PluginSearchManager.getInstance().getMoreSearchResult(searchTextField.getText());
break;
case DOCUMENT:
moreResult = DocumentSearchManager.getDocumentSearchManager().getMoreSearchResult();
moreResult = DocumentSearchManager.getInstance().getMoreSearchResult(searchTextField.getText());
break;
case FILE:
moreResult = FileSearchManager.getFileSearchManager().getMoreSearchResult();
moreResult = FileSearchManager.getInstance().getMoreSearchResult(searchTextField.getText());
break;
case ACTION:
moreResult = ActionSearchManager.getActionSearchManager().getMoreSearchResult();
moreResult = ActionSearchManager.getInstance().getMoreSearchResult(searchTextField.getText());
break;
default:
moreResult = new SearchResult();

303
designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java

@ -1,303 +0,0 @@
package com.fr.design.mainframe.alphafine.search.manager;
import com.fr.base.FRContext;
import com.fr.base.Utils;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
import com.fr.design.mainframe.alphafine.cell.model.ActionModel;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.toolbar.UpdateActionManager;
import com.fr.file.XMLFileManager;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLableReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Created by XiaXiang on 2017/5/15.
*/
public class RecentSearchManager extends XMLFileManager implements AlphaFineSearchProcessor {
private static final String XML_TAG = "AlphaFineRecent";
private static final int MAX_SIZE = 3;
private static RecentSearchManager recentSearchManager = null;
private static File recentFile = null;
private SearchResult modelList;
private SearchResult recentModelList;
private Map<String, SearchResult> recentKVModelMap = new HashMap<>();
public synchronized static RecentSearchManager getRecentSearchManger() {
if (recentSearchManager == null) {
recentSearchManager = new RecentSearchManager();
try {
XMLTools.readFileXML(recentSearchManager, recentSearchManager.getRecentEnvFile());
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
return recentSearchManager;
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
reader.readXMLObject(new XMLReadable() {
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if (nodeName.equals("RecentModelList")) {
String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY);
final SearchResult list = new SearchResult();
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
readCellModel(reader, list);
}
}
);
recentKVModelMap.put(key, list);
}
}
}
});
}
}
private void readCellModel(XMLableReader reader, List<AlphaCellModel> list) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if (nodeName.equals("model")) {
String modelValue = reader.getAttrAsString("cellModel", StringUtils.EMPTY);
addModelToList(list, modelValue);
}
}
}
private void addModelToList(List<AlphaCellModel> list, String modelValue) {
try {
AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(modelValue));
if (model != null) {
list.add(model);
}
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_TAG);
if (!recentKVModelMap.isEmpty()) {
for (String key : recentKVModelMap.keySet()) {
writer.startTAG("RecentModelList");
writer.attr("searchKey", key);
for (AlphaCellModel model : recentKVModelMap.get(key)) {
try {
String modelValue = model.ModelToJson().toString();
writer.startTAG("model");
writer.attr("cellModel", modelValue);
writer.end();
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
writer.end();
}
}
writer.end();
}
@Override
public String fileName() {
return "AlphaFine_Recent.xml";
}
/**
* 获取xml
*
* @return
*/
private File getRecentFile() {
if (recentFile == null) {
recentFile = new File(ProductConstants.getEnvHome() + File.separator + fileName());
}
return recentFile;
}
private File getRecentEnvFile() {
File envFile = getRecentFile();
if (!envFile.exists()) {
createRecentFile(envFile);
}
return envFile;
}
/**
* 创建XML
*
* @param envFile
*/
private void createRecentFile(File envFile) {
try {
FileWriter fileWriter = new FileWriter(envFile);
StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphaFineRecent></AlphaFineRecent>");
Utils.copyCharTo(stringReader, fileWriter);
stringReader.close();
fileWriter.close();
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
/**
* 保存XML到设计器安装目录
*/
public void saveXMLFile() {
File xmlFile = this.getRecentEnvFile();
if (xmlFile == null) {
return;
}
if (!xmlFile.getParentFile().exists()) {//建立目录.
StableUtils.mkdirs(xmlFile.getParentFile());
}
String tempName = xmlFile.getName() + ProjectConstants.TEMP_SUFFIX;
File tempFile = new File(xmlFile.getParentFile(), tempName);
writeTempFile(tempFile);
IOUtils.renameTo(tempFile, xmlFile);
}
private void writeTempFile(File tempFile) {
try {
OutputStream fout = new FileOutputStream(tempFile);
XMLTools.writeOutputStreamXML(this, fout);
fout.flush();
fout.close();
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
}
public List<AlphaCellModel> getRecentModelList() {
return recentModelList;
}
/**
* 根据搜索字段获取对应的model列表
*
* @param searchText
* @return
*/
private synchronized SearchResult getRecentModelList(String searchText) {
recentModelList = new SearchResult();
for (String key : recentKVModelMap.keySet()) {
AlphaFineHelper.checkCancel();
if (ComparatorUtils.equals(key, searchText)) {
recentModelList = recentKVModelMap.get(searchText);
SearchResult resultModelList = recentModelList;
Iterator<AlphaCellModel> modelIterator = resultModelList.iterator();
SearchResult searchResult = new SearchResult();
while (modelIterator.hasNext()) {
AlphaCellModel model = modelIterator.next();
if (model.getType() == CellType.ACTION && !UpdateActionManager.getUpdateActionManager().isEnable(((ActionModel) model).getAction())) {
continue;
} else {
searchResult.add(model);
}
}
Collections.sort(searchResult);
int size = searchResult.size();
if (size > MAX_SIZE) {
SearchResult result = new SearchResult();
result.addAll(searchResult.subList(0, MAX_SIZE));
return result;
}
return searchResult;
}
}
return recentModelList;
}
/**
* 将搜索结果加入到当前MAP中
*
* @param searchKey
* @param cellModel
*/
public void addRecentModel(String searchKey, AlphaCellModel cellModel) {
if (recentKVModelMap.keySet().contains(searchKey)) {
List<AlphaCellModel> cellModels = recentKVModelMap.get(searchKey);
int index = cellModels.indexOf(cellModel);
if (index >= 0) {
cellModels.get(index).addSearchCount();
} else {
cellModels.add(cellModel);
}
//trimToSize(cellModels);
} else {
SearchResult list = new SearchResult();
list.add(cellModel);
recentKVModelMap.put(searchKey, list);
}
}
private synchronized void trimToSize(List<AlphaCellModel> cellModels) {
if (cellModels.size() > AlphaFineConstants.MAX_FILE_SIZE) {
cellModels.remove(0);
}
}
@Override
public synchronized SearchResult getLessSearchResult(String searchText) {
this.modelList = new SearchResult();
recentModelList = getRecentModelList(searchText);
if (recentModelList != null && recentModelList.size() > 0) {
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest")));
}
modelList.addAll(recentModelList);
return modelList;
}
@Override
public SearchResult getMoreSearchResult() {
return new SearchResult();
}
}

6
designer/src/com/fr/design/mainframe/alphafine/search/manager/AlphaFineSearchProcessor.java → designer/src/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java

@ -1,11 +1,11 @@
package com.fr.design.mainframe.alphafine.search.manager;
package com.fr.design.mainframe.alphafine.search.manager.fun;
import com.fr.design.mainframe.alphafine.model.SearchResult;
/**
* Created by XiaXiang on 2017/3/27.
*/
public interface AlphaFineSearchProcessor {
public interface AlphaFineSearchProvider {
/**
* 获取默认显示条数
*
@ -19,5 +19,5 @@ public interface AlphaFineSearchProcessor {
*
* @return
*/
SearchResult getMoreSearchResult();
SearchResult getMoreSearchResult(String searchText);
}

317
designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/1.java

@ -0,0 +1,317 @@
//package com.fr.design.mainframe.alphafine.search.manager.impl;
//
//import com.fr.base.FRContext;
//import com.fr.base.Utils;
//import com.fr.design.actions.UpdateAction;
//import com.fr.design.mainframe.alphafine.AlphaFineConstants;
//import com.fr.design.mainframe.alphafine.AlphaFineHelper;
//import com.fr.design.mainframe.alphafine.CellType;
//import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
//import com.fr.design.mainframe.alphafine.cell.model.ActionModel;
//import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
//import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
//import com.fr.design.mainframe.alphafine.model.SearchResult;
//import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
//import com.fr.design.mainframe.toolbar.UpdateActionManager;
//import com.fr.file.XMLFileManager;
//import com.fr.general.ComparatorUtils;
//import com.fr.general.FRLogger;
//import com.fr.general.IOUtils;
//import com.fr.general.Inter;
//import com.fr.json.JSONException;
//import com.fr.json.JSONObject;
//import com.fr.stable.ProductConstants;
//import com.fr.stable.StableUtils;
//import com.fr.stable.StringUtils;
//import com.fr.stable.project.ProjectConstants;
//import com.fr.stable.xml.XMLPrintWriter;
//import com.fr.stable.xml.XMLReadable;
//import com.fr.stable.xml.XMLTools;
//import com.fr.stable.xml.XMLableReader;
//
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.io.OutputStream;
//import java.io.StringReader;
//import java.util.Collections;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
///**
// * Created by XiaXiang on 2017/5/15.
// */
//public class RecentSearchManager extends XMLFileManager implements AlphaFineSearchProvider {
//
// private static final String XML_TAG = "AFSearch_Recent";
// private static final int MAX_SIZE = 3;
// private static RecentSearchManager recentSearchManager = null;
// private static File recentFile = null;
// private SearchResult modelList;
// private SearchResult recentModelList;
// private Map<String, SearchResult> recentKVModelMap = new HashMap<>();
//
// public synchronized static RecentSearchManager getInstance() {
// if (recentSearchManager == null) {
// recentSearchManager = new RecentSearchManager();
// try {
// XMLTools.readFileXML(recentSearchManager, recentSearchManager.getRecentEnvFile());
// } catch (Exception e) {
// FRContext.getLogger().error(e.getMessage(), e);
// }
// }
// return recentSearchManager;
//
// }
//
// @Override
// public void readXML(XMLableReader reader) {
// if (reader.isAttr()) {
// reader.readXMLObject(new XMLReadable() {
// public void readXML(XMLableReader reader) {
// if (reader.isChildNode()) {
// String nodeName = reader.getTagName();
// if (nodeName.equals("RecentModelList")) {
// String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY);
// final SearchResult list = new SearchResult();
// reader.readXMLObject(new XMLReadable() {
// @Override
// public void readXML(XMLableReader reader) {
// readCellModel(reader, list);
// }
// }
// );
// recentKVModelMap.put(key, list);
// }
// }
// }
// });
// }
//
// }
//
// private void readCellModel(XMLableReader reader, List<AlphaCellModel> list) {
// if (reader.isChildNode()) {
// String nodeName = reader.getTagName();
// if (nodeName.equals("model")) {
// String modelValue = reader.getAttrAsString("cellModel", StringUtils.EMPTY);
// addModelToList(list, modelValue);
// }
// }
// }
//
//
// private void addModelToList(List<AlphaCellModel> list, String modelValue) {
// try {
// AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(modelValue));
// if (model != null) {
// list.add(model);
// }
// } catch (JSONException e) {
// FRLogger.getLogger().error(e.getMessage());
// }
// }
//
//
// @Override
// public void writeXML(XMLPrintWriter writer) {
// writer.startTAG(XML_TAG);
// if (!recentKVModelMap.isEmpty()) {
// for (String key : recentKVModelMap.keySet()) {
// writer.startTAG("RecentModelList");
// writer.attr("searchKey", key);
// for (AlphaCellModel model : recentKVModelMap.get(key)) {
// try {
// String modelValue = model.ModelToJson().toString();
// writer.startTAG("model");
// writer.attr("cellModel", modelValue);
// writer.end();
// } catch (JSONException e) {
// FRLogger.getLogger().error(e.getMessage());
// }
// }
// writer.end();
// }
// }
// writer.end();
//
// }
//
// @Override
// public String fileName() {
// return "AFSearch_Recent.xml";
// }
//
//
// /**
// * 获取xml
// *
// * @return
// */
// private File getRecentFile() {
// if (recentFile == null) {
// recentFile = new File(ProductConstants.getEnvHome() + File.separator + fileName());
// }
// return recentFile;
// }
//
// private File getOldFile() {
// return new File(ProductConstants.getEnvHome() + File.separator + "AlphaFine_Recent.xml");
// }
//
// private File getRecentEnvFile() {
// File envFile = getRecentFile();
// File oldFile = getOldFile();
// if (oldFile.exists()) {
// StableUtils.deleteFile(oldFile);
// }
// if (!envFile.exists()) {
// createRecentFile(envFile);
// }
// return envFile;
// }
//
// /**
// * 创建XML
// *
// * @param envFile
// */
// private void createRecentFile(File envFile) {
// try {
// FileWriter fileWriter = new FileWriter(envFile);
// StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AFSearch_Recent></AFSearch_Recent>");
// Utils.copyCharTo(stringReader, fileWriter);
// stringReader.close();
// fileWriter.close();
// } catch (IOException e) {
// FRContext.getLogger().error(e.getMessage(), e);
// }
// }
//
// /**
// * 保存XML到设计器安装目录
// */
// public void saveXMLFile() {
// File xmlFile = this.getRecentEnvFile();
// if (xmlFile == null) {
// return;
// }
// if (!xmlFile.getParentFile().exists()) {//建立目录.
// StableUtils.mkdirs(xmlFile.getParentFile());
// }
//
// String tempName = xmlFile.getName() + ProjectConstants.TEMP_SUFFIX;
// File tempFile = new File(xmlFile.getParentFile(), tempName);
//
// writeTempFile(tempFile);
// IOUtils.renameTo(tempFile, xmlFile);
// }
//
// private void writeTempFile(File tempFile) {
// try {
// OutputStream fout = new FileOutputStream(tempFile);
// XMLTools.writeOutputStreamXML(this, fout);
// fout.flush();
// fout.close();
// } catch (Exception e) {
// FRContext.getLogger().error(e.getMessage());
// }
// }
//
//
// public List<AlphaCellModel> getRecentModelList() {
// return recentModelList;
// }
//
// /**
// * 根据搜索字段获取对应的model列表
// *
// * @param searchText
// * @return
// */
// private synchronized SearchResult getRecentModelList(String searchText) {
// recentModelList = new SearchResult();
// for (String key : recentKVModelMap.keySet()) {
// AlphaFineHelper.checkCancel();
// if (ComparatorUtils.equals(key, searchText)) {
// recentModelList = recentKVModelMap.get(searchText);
// SearchResult resultModelList = recentModelList;
// Iterator<AlphaCellModel> modelIterator = resultModelList.iterator();
// SearchResult searchResult = new SearchResult();
// while (modelIterator.hasNext()) {
// AlphaCellModel model = modelIterator.next();
// if (model.getType() == CellType.ACTION) {
// UpdateAction action = UpdateActionManager.getUpdateActionManager().getActionByName(model.getName());
// if (action != null) {
// ((ActionModel) model).setAction(action);
// searchResult.add(model);
// }
// } else {
// searchResult.add(model);
// }
//
// }
// Collections.sort(searchResult);
// int size = searchResult.size();
// if (size > MAX_SIZE) {
// SearchResult result = new SearchResult();
// result.addAll(searchResult.subList(0, MAX_SIZE));
// return result;
// }
// return searchResult;
// }
// }
// return recentModelList;
// }
//
// /**
// * 将搜索结果加入到当前MAP中
// *
// * @param searchKey
// * @param cellModel
// */
// public void addRecentModel(String searchKey, AlphaCellModel cellModel) {
// if (recentKVModelMap.keySet().contains(searchKey)) {
// List<AlphaCellModel> cellModels = recentKVModelMap.get(searchKey);
// int index = cellModels.indexOf(cellModel);
// if (index >= 0) {
// cellModels.get(index).addSearchCount();
// } else {
// cellModels.add(cellModel);
// }
// //trimToSize(cellModels);
// } else {
// SearchResult list = new SearchResult();
// list.add(cellModel);
// recentKVModelMap.put(searchKey, list);
// }
// }
//
//
// private synchronized void trimToSize(List<AlphaCellModel> cellModels) {
// if (cellModels.size() > AlphaFineConstants.MAX_FILE_SIZE) {
// cellModels.remove(0);
// }
// }
//
//
// @Override
// public synchronized SearchResult getLessSearchResult(String searchText) {
// this.modelList = new SearchResult();
// recentModelList = getRecentModelList(searchText);
// if (recentModelList != null && recentModelList.size() > 0) {
// modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest")));
// }
// modelList.addAll(recentModelList);
// return modelList;
// }
//
// @Override
// public SearchResult getMoreSearchResult(String searchText) {
// return new SearchResult();
// }
//
//}

10
designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java → designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java

@ -1,4 +1,4 @@
package com.fr.design.mainframe.alphafine.search.manager;
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
@ -8,6 +8,7 @@ import com.fr.design.mainframe.alphafine.cell.model.ActionModel;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
import com.fr.design.mainframe.toolbar.UpdateActionManager;
import com.fr.design.mainframe.toolbar.UpdateActionModel;
import com.fr.general.ComparatorUtils;
@ -20,13 +21,13 @@ import java.util.List;
/**
* Created by XiaXiang on 2017/3/27.
*/
public class ActionSearchManager implements AlphaFineSearchProcessor {
public class ActionSearchManager implements AlphaFineSearchProvider {
private static ActionSearchManager actionSearchManager = null;
private SearchResult filterModelList;
private SearchResult lessModelList;
private SearchResult moreModelList;
public synchronized static ActionSearchManager getActionSearchManager() {
public synchronized static ActionSearchManager getInstance() {
if (actionSearchManager == null) {
actionSearchManager = new ActionSearchManager();
}
@ -63,6 +64,7 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainAction()) {
List<UpdateActionModel> updateActions = UpdateActionManager.getUpdateActionManager().getUpdateActions();
for (UpdateActionModel updateActionModel : updateActions) {
AlphaFineHelper.checkCancel();
if (StringUtils.isNotBlank(updateActionModel.getSearchKey())) {
if (updateActionModel.getSearchKey().contains(searchText) && updateActionModel.getAction().isEnabled()) {
filterModelList.add(new ActionModel(updateActionModel.getActionName(), updateActionModel.getParentName(), updateActionModel.getAction()));
@ -91,7 +93,7 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
}
@Override
public SearchResult getMoreSearchResult() {
public SearchResult getMoreSearchResult(String searchText) {
return moreModelList;
}
}

9
designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java → designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java

@ -1,4 +1,4 @@
package com.fr.design.mainframe.alphafine.search.manager;
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
@ -7,6 +7,7 @@ import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.model.DocumentModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.http.HttpClient;
@ -18,12 +19,12 @@ import com.fr.stable.StringUtils;
/**
* Created by XiaXiang on 2017/3/27.
*/
public class DocumentSearchManager implements AlphaFineSearchProcessor {
public class DocumentSearchManager implements AlphaFineSearchProvider {
private static DocumentSearchManager documentSearchManager = null;
private SearchResult lessModelList;
private SearchResult moreModelList;
public synchronized static DocumentSearchManager getDocumentSearchManager() {
public synchronized static DocumentSearchManager getInstance() {
if (documentSearchManager == null) {
documentSearchManager = new DocumentSearchManager();
@ -106,7 +107,7 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
}
@Override
public SearchResult getMoreSearchResult() {
public SearchResult getMoreSearchResult(String searchText) {
return moreModelList;
}

178
designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java → designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java

@ -1,4 +1,4 @@
package com.fr.design.mainframe.alphafine.search.manager;
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.base.Env;
import com.fr.base.FRContext;
@ -6,24 +6,21 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.FileModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
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.FRLogger;
import com.fr.general.Inter;
import com.fr.json.JSONObject;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@ -31,7 +28,7 @@ import java.util.List;
/**
* Created by XiaXiang on 2017/3/27.
*/
public class FileSearchManager implements AlphaFineSearchProcessor {
public class FileSearchManager implements AlphaFineSearchProvider {
private static final int MARK_LENGTH = 6;
private static final String DS_NAME = "dsname=\"";
private static final String FRM_PREFIX = "k:frm ";
@ -40,12 +37,15 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
private SearchResult filterModelList;
private SearchResult lessModelList;
private SearchResult moreModelList;
private String searchText;
private List<FileNode> fileNodes = null;
//停止搜索
private boolean stopSearch = false;
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
private boolean isContainCpt = true;
private boolean isContainFrm = true;
public synchronized static FileSearchManager getFileSearchManager() {
public synchronized static FileSearchManager getInstance() {
init();
return fileSearchManager;
}
@ -73,51 +73,71 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
this.filterModelList = new SearchResult();
this.lessModelList = new SearchResult();
this.moreModelList = new SearchResult();
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());
}
if (StringUtils.isBlank(searchText) || ComparatorUtils.equals(searchText, DS_NAME)) {
this.searchText = dealWithSearchText(searchText);
if (StringUtils.isBlank(this.searchText) || ComparatorUtils.equals(this.searchText, DS_NAME)) {
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_Templates")));
return lessModelList;
}
Env env = FRContext.getCurrentEnv();
fileNodes = new ArrayList<>();
fileNodes = listTpl(env, ProjectConstants.REPORTLETS_NAME, true);
AlphaFineHelper.checkCancel();
isContainCpt = true;
isContainFrm = true;
for (FileNode node : fileNodes) {
boolean isAlreadyContain = false;
String fileEnvPath = node.getEnvPath();
String filePath = StableUtils.pathJoin(env.getPath(), fileEnvPath);
isAlreadyContain = searchFile(searchText, node, isAlreadyContain);
searchFileContent(searchText, node, isAlreadyContain, filePath);
doSearch(this.searchText, true, env);
if (stopSearch) {
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));
stopSearch = false;
return this.lessModelList;
}
if (filterModelList.isEmpty()) {
return new SearchResult();
}
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), false, CellType.FILE));
lessModelList.addAll(filterModelList);
return lessModelList;
}
@Override
public SearchResult getMoreSearchResult(String searchText) {
if (moreModelList != null && !moreModelList.isEmpty()) {
return moreModelList;
}
SearchResult result = new SearchResult();
for (AlphaCellModel object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object)) {
result.add(object);
this.filterModelList = new SearchResult();
this.moreModelList = new SearchResult();
Env env = FRContext.getCurrentEnv();
AlphaFineHelper.checkCancel();
isContainCpt = true;
isContainFrm = true;
doSearch(this.searchText, false, env);
moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size()));
return moreModelList;
}
private void doSearch(String searchText, boolean needMore, Env env) {
for (FileNode node : fileNodes) {
boolean isAlreadyContain = false;
isAlreadyContain = searchFile(searchText, node, isAlreadyContain, needMore);
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent() && node.getLock() == null) {
searchFileContent(env, searchText, node, isAlreadyContain, needMore);
}
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && stopSearch) {
return;
}
}
if (result.isEmpty()) {
return lessModelList;
} else if (result.size() < AlphaFineConstants.SHOW_SIZE + 1) {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates")));
lessModelList.addAll(result);
} else {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE));
lessModelList.addAll(result.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(result.subList(AlphaFineConstants.SHOW_SIZE, result.size()));
}
}
return this.lessModelList;
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;
}
/**
@ -126,35 +146,36 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
* @param searchText
* @param node
* @param isAlreadyContain
* @param filePath
*/
private void searchFileContent(String searchText, FileNode node, boolean isAlreadyContain, String filePath) {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent()) {
try {
InputStreamReader isr = new InputStreamReader(new FileInputStream(new File(filePath)), "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;
}
private void searchFileContent(Env env, String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) {
try {
InputStream inputStream = env.readBean(node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1), ProjectConstants.REPORTLETS_NAME);
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) {
FileModel model = new FileModel(node.getName(), node.getEnvPath());
this.filterModelList.add(model);
}
if (isFoundInContent && !isAlreadyContain) {
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 (FileNotFoundException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
}
isr.close();
reader.close();
} catch (Exception e) {
FRLogger.getLogger().error("file read error: " + e.getMessage());
}
}
@ -166,22 +187,23 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
* @param isAlreadyContain
* @return
*/
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain) {
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) {
if (node.getName().toLowerCase().contains(searchText)) {
FileModel model = new FileModel(node.getName(), node.getEnvPath());
this.filterModelList.add(model);
if (!AlphaFineHelper.getFilterResult().contains(model)) {
AlphaFineHelper.checkCancel();
filterModelList.add(model);
}
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) {
stopSearch = true;
}
isAlreadyContain = true;
}
}
return isAlreadyContain;
}
@Override
public SearchResult getMoreSearchResult() {
return moreModelList;
}
/**
* 获取工作目录下所有符合要求的模板
*
@ -252,4 +274,20 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
public void setContainFrm(boolean containFrm) {
isContainFrm = containFrm;
}
public SearchResult getMoreModelList() {
return moreModelList;
}
public void setMoreModelList(SearchResult moreModelList) {
this.moreModelList = moreModelList;
}
public String getSearchText() {
return searchText;
}
public void setSearchText(String searchText) {
this.searchText = searchText;
}
}

28
designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java → designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java

@ -1,4 +1,4 @@
package com.fr.design.mainframe.alphafine.search.manager;
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
@ -7,6 +7,7 @@ import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.cell.model.PluginModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
@ -14,6 +15,8 @@ import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.plugin.basic.version.Version;
import com.fr.plugin.basic.version.VersionIntervalFactory;
import com.fr.stable.StringUtils;
import java.io.UnsupportedEncodingException;
@ -22,13 +25,13 @@ import java.net.URLEncoder;
/**
* Created by XiaXiang on 2017/3/27.
*/
public class PluginSearchManager implements AlphaFineSearchProcessor {
public class PluginSearchManager implements AlphaFineSearchProvider {
private static PluginSearchManager pluginSearchManager = null;
private SearchResult lessModelList;
private SearchResult moreModelList;
public synchronized static PluginSearchManager getPluginSearchManager() {
public synchronized static PluginSearchManager getInstance() {
if (pluginSearchManager == null) {
pluginSearchManager = new PluginSearchManager();
}
@ -36,16 +39,25 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
}
private static boolean isCompatibleCurrentEnv(String envVersion){
return VersionIntervalFactory.create(envVersion).contain(Version.currentEnvVersion());
}
private static PluginModel getPluginModel(JSONObject object, boolean isFromCloud) {
String name = object.optString("name");
String content = object.optString("description");
int pluginId = object.optInt("id");
String pluginId = object.optString("pluginid");
String envVersion = object.optString("envversion");
if (!isCompatibleCurrentEnv(envVersion)) {
return null;
}
int id = object.optInt("id");
int searchCount = object.optInt("searchCount");
String imageUrl = null;
try {
imageUrl = isFromCloud ? AlphaFineConstants.PLUGIN_IMAGE_URL + URLEncoder.encode(object.optString("pic").toString().substring(AlphaFineConstants.PLUGIN_IMAGE_URL.length()), "utf8") : object.optString("pic");
} catch (UnsupportedEncodingException e) {
FRLogger.getLogger().error(e.getMessage());
FRLogger.getLogger().error("plugin icon error: " + e.getMessage());
}
String version = null;
String jartime = null;
@ -59,7 +71,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
type = CellType.REUSE;
}
int price = object.optInt("price");
return new PluginModel(name, content, imageUrl, version, jartime, link, type, price, pluginId, searchCount);
return new PluginModel(name, content, imageUrl, version, jartime, link, pluginId, type, price, id, searchCount);
}
/**
@ -105,7 +117,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel();
PluginModel cellModel = getPluginModel(jsonArray.optJSONObject(i), false);
if (!AlphaFineHelper.getFilterResult().contains(cellModel)) {
if (cellModel != null && !AlphaFineHelper.getFilterResult().contains(cellModel)) {
searchResult.add(cellModel);
}
}
@ -137,7 +149,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
}
@Override
public SearchResult getMoreSearchResult() {
public SearchResult getMoreSearchResult(String searchText) {
return this.moreModelList;
}
}

193
designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java

@ -0,0 +1,193 @@
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
import com.fr.general.Inter;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FRLoggerFactory;
import com.fr.stable.ProductConstants;
import com.fr.third.org.apache.lucene.analysis.Analyzer;
import com.fr.third.org.apache.lucene.analysis.standard.StandardAnalyzer;
import com.fr.third.org.apache.lucene.document.Document;
import com.fr.third.org.apache.lucene.document.Field;
import com.fr.third.org.apache.lucene.document.IntField;
import com.fr.third.org.apache.lucene.document.StringField;
import com.fr.third.org.apache.lucene.index.DirectoryReader;
import com.fr.third.org.apache.lucene.index.IndexReader;
import com.fr.third.org.apache.lucene.index.IndexWriter;
import com.fr.third.org.apache.lucene.index.IndexWriterConfig;
import com.fr.third.org.apache.lucene.index.Term;
import com.fr.third.org.apache.lucene.search.IndexSearcher;
import com.fr.third.org.apache.lucene.search.Query;
import com.fr.third.org.apache.lucene.search.ScoreDoc;
import com.fr.third.org.apache.lucene.search.Sort;
import com.fr.third.org.apache.lucene.search.SortField;
import com.fr.third.org.apache.lucene.search.TermQuery;
import com.fr.third.org.apache.lucene.search.TopFieldDocs;
import com.fr.third.org.apache.lucene.store.Directory;
import com.fr.third.org.apache.lucene.store.FSDirectory;
import com.fr.third.org.apache.lucene.util.Version;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* Created by XiaXiang on 2018/1/22.
*/
public class RecentSearchManager implements AlphaFineSearchProvider {
private static final int MAX_SIZE = 3;
private static RecentSearchManager recentSearchManager = null;
IndexReader indexReader = null;
IndexSearcher indexSearcher = null;
//索引存储路径
private String path = ProductConstants.getEnvHome() + File.separator + "searchIndex";
//分词器,暂时先用这个
private Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
// 存储目录
private Directory directory = null;
private IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
private IndexWriter indexWriter = null;
private SearchResult recentModelList;
private SearchResult modelList;
public synchronized static RecentSearchManager getInstance() {
if (recentSearchManager == null) {
return new RecentSearchManager();
}
return recentSearchManager;
}
@Override
public SearchResult getLessSearchResult(String searchText) {
this.modelList = new SearchResult();
recentModelList = getRecentModelList(searchText);
if (recentModelList != null && recentModelList.size() > 0) {
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest")));
}
modelList.addAll(recentModelList);
return modelList;
}
@Override
public SearchResult getMoreSearchResult(String searchText) {
return new SearchResult();
}
public synchronized SearchResult getRecentModelList(String searchText) {
return searchBySort(searchText);
}
public List<AlphaCellModel> getRecentModelList() {
return recentModelList;
}
/**
* 初始化indexWriter
*/
private void initWriter() {
if (indexWriter == null) {
try {
directory = FSDirectory.open(new File(path));
} catch (IOException e) {
FRLoggerFactory.getLogger().error("cannot open directory " + path);
}
try {
indexWriter = new IndexWriter(directory, config);
} catch (IOException e) {
FRLoggerFactory.getLogger().error("not privilege to write to" + path);
}
}
}
/**
* 初始化indexReader
*/
private void initReader() {
if (indexReader == null) {
try {
directory = FSDirectory.open(new File(path));
indexReader = DirectoryReader.open(directory);
} catch (IOException e) {
FRLoggerFactory.getLogger().error("not privilege to read " + path);
}
indexSearcher = new IndexSearcher(indexReader);
}
}
/**
* 添加模型
* @param searchKey
* @param cellModel
* @param searchCount
*/
public void addModel(String searchKey, AlphaCellModel cellModel, int searchCount) {
try {
initWriter();
Document doc = new Document();
doc.add(new StringField("searchKey", searchKey, Field.Store.YES));
doc.add(new StringField("cellModel", cellModel.ModelToJson().toString(), Field.Store.YES));
doc.add(new IntField("searchCount", searchCount, Field.Store.YES));
writeDoc(doc);
} catch (JSONException e) {
FRLoggerFactory.getLogger().error("add document error: " + e.getMessage());
}
}
/**
* 写文档建立索引
* @param doc
*/
private void writeDoc(Document doc) {
try {
indexWriter.addDocument(doc);
indexWriter.commit();
indexWriter.close();
} catch (IOException e) {
FRLoggerFactory.getLogger().error("write document error: " + e.getMessage());
}
}
/**
* 按序搜索
* @param key
* @return
*/
private synchronized SearchResult searchBySort(String key) {
recentModelList = new SearchResult();
try {
initReader();
IndexSearcher searcher = new IndexSearcher(indexReader);
//构建排序字段
SortField[] sortField = new SortField[1];
sortField[0] = new SortField("searchCount", SortField.Type.INT, true);
Sort sortKey = new Sort(sortField);
String searchField = "searchKey";
Term term = new Term(searchField, key);
Query query = new TermQuery(term);
TopFieldDocs docs = searcher.search(query, MAX_SIZE, sortKey);
ScoreDoc[] scores = docs.scoreDocs;
this.recentModelList = new SearchResult();
//遍历结果
for (ScoreDoc scoreDoc : scores) {
Document document = searcher.doc(scoreDoc.doc);
System.out.println(document.get("cellModel") + "\n" + document.get("searchCount") + "\n");
AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(document.get("cellModel")));
this.recentModelList.add(model);
}
} catch (Exception e) {
FRLoggerFactory.getLogger().error("local search error: " + e.getMessage());
return recentModelList;
}
return recentModelList;
}
}

18
designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java → designer/src/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java

@ -1,7 +1,6 @@
package com.fr.design.mainframe.alphafine.search.manager;
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.SiteCenterToken;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType;
@ -10,6 +9,7 @@ import com.fr.design.mainframe.alphafine.cell.model.ActionModel;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.http.HttpClient;
@ -25,12 +25,12 @@ import java.util.List;
/**
* Created by XiaXiang on 2017/3/31.
*/
public class RecommendSearchManager implements AlphaFineSearchProcessor {
public class RecommendSearchManager implements AlphaFineSearchProvider {
private static RecommendSearchManager recommendSearchManager = null;
private SearchResult modelList;
private SearchResult recommendModelList;
public synchronized static RecommendSearchManager getRecommendSearchManager() {
public synchronized static RecommendSearchManager getInstance() {
if (recommendSearchManager == null) {
recommendSearchManager = new RecommendSearchManager();
}
@ -44,14 +44,12 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
this.recommendModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) {
String result;
String url = AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText);
url = String.format("%s?token=%s", url, SiteCenterToken.generateToken());
HttpClient httpClient = new HttpClient(url);
HttpClient httpClient = new HttpClient(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText));
httpClient.asGet();
if (!httpClient.isServerAlive()) {
return getNoConnectList();
}
httpClient.setTimeout(5000);
httpClient.setTimeout(3000);
result = httpClient.getResponseText();
AlphaFineHelper.checkCancel();
try {
@ -93,7 +91,7 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
* @return
*/
private boolean alreadyContain(AlphaCellModel cellModel) {
return RecentSearchManager.getRecentSearchManger().getRecentModelList().contains(cellModel) || this.recommendModelList.contains(cellModel);
return RecentSearchManager.getInstance().getRecentModelList().contains(cellModel) || this.recommendModelList.contains(cellModel);
}
private SearchResult getNoConnectList() {
@ -104,7 +102,7 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
}
@Override
public SearchResult getMoreSearchResult() {
public SearchResult getMoreSearchResult(String searchText) {
return new SearchResult();
}
Loading…
Cancel
Save