From 614d504347906408a4b11ff2b9df3a5d7957944c Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Wed, 22 Aug 2018 15:38:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=86=B2=E7=AA=81=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/AlphaFineConstants.java | 4 +++ .../alphafine/cell/CellModelHelper.java | 2 +- .../cell/render/ContentCellRender.java | 6 +++-- .../manager/impl/ComplementAdviceManager.java | 8 +++--- .../manager/impl/DocumentSearchManager.java | 4 +-- .../manager/impl/FileSearchManager.java | 2 +- .../manager/impl/RecommendSearchManager.java | 25 ++++++++----------- .../manager/impl/SegmentationManager.java | 8 +++--- .../manager/impl/SimilarSearchManeger.java | 7 +++--- 9 files changed, 34 insertions(+), 32 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index d4a532815b..5f42d03e62 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.alphafine; +import com.fr.base.extension.FileExtension; import com.fr.general.CloudCenter; import java.awt.Color; import java.awt.Dimension; @@ -123,5 +124,8 @@ public class AlphaFineConstants { public static final String CHINESE_CHARACTERS = "[\\u4e00-\\u9fa5]"; + public static final String FIRST_PAGE = "-1"; + + public static final FileExtension[] FILE_EXTENSIONS= new FileExtension[]{FileExtension.CPT, FileExtension.FRM}; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java index b388f5e8ed..83ab319a6b 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java @@ -35,7 +35,7 @@ public class CellModelHelper { case ROBOT: case RECOMMEND_ROBOT: cellModel = SimilarSearchManeger.getModelFromCloud(object.optJSONObject(RESULT)); - + break; } return cellModel; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index 3444fecdf0..53fa89bd9b 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java @@ -64,7 +64,7 @@ public class ContentCellRender implements ListCellRenderer { } } else { - titleLabel.setText(dealWithModelName(model.getName(), segmentationResult)); + titleLabel.setText(highLightModelName(model.getName(), segmentationResult)); String iconUrl = CELL_PATH + model.getType().getTypeValue() + SUFFIX; if (value instanceof RobotModel && ((RobotModel) value).isHotItemModel()) { titleLabel.setIcon(null); @@ -104,7 +104,7 @@ public class ContentCellRender implements ListCellRenderer { * @param strings * @return */ - public String dealWithModelName(String modelName, String[] strings) { + public String highLightModelName(String modelName, String[] strings) { if (strings == null) { return modelName; } @@ -127,4 +127,6 @@ public class ContentCellRender implements ListCellRenderer { return modelName.substring(index, index + string.length()); } + + } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java index 20eeee6590..f59e98df63 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java @@ -9,7 +9,7 @@ import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; -import com.fr.json.JSONTokener; +import com.fr.json.JSONUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import java.io.IOException; @@ -50,9 +50,8 @@ public class ComplementAdviceManager { try { String result = HttpToolbox.get(url); AlphaFineHelper.checkCancel(); - Object json = new JSONTokener(result).nextValue(); - if (json instanceof JSONArray) { - JSONArray jsonArray = new JSONArray(result); + JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); + if(jsonArray != null){ for (int i = 0; i < jsonArray.length(); i++) { AlphaFineHelper.checkCancel(); JSONObject jsonObject = jsonArray.optJSONObject(i); @@ -64,6 +63,7 @@ public class ComplementAdviceManager { allModelList.add(robotModel); } } + } } } catch (JSONException e) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java index 7bbbc49a4a..b8ba403aa8 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java @@ -13,7 +13,7 @@ import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; -import com.fr.third.org.apache.commons.lang3.ArrayUtils; +import com.fr.stable.ArrayUtils; import java.io.IOException; @@ -61,7 +61,7 @@ public class DocumentSearchManager implements AlphaFineSearchProvider { if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainDocument()) { SearchResult searchResult = new SearchResult(); for (int j = 0; j < searchText.length; j++) { - String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText[j] + "-1"; + String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText[j] + AlphaFineConstants.FIRST_PAGE; try { String result = HttpToolbox.get(url); AlphaFineHelper.checkCancel(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java index 626445d9cf..4e50fa9354 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java @@ -73,7 +73,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { return lessModelList; } AlphaFineHelper.checkCancel(); - fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, new FileExtension[]{FileExtension.CPT, FileExtension.FRM}, true); + fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, AlphaFineConstants.FILE_EXTENSIONS, true); isContainCpt = true; isContainFrm = true; doSearch(this.searchText); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java index db05930d8b..d13050a01b 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java @@ -14,7 +14,6 @@ import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; -import com.fr.json.JSONTokener; import com.fr.log.FineLoggerFactory; import com.fr.stable.CodeUtils; import com.fr.stable.StringUtils; @@ -61,19 +60,16 @@ public class RecommendSearchManager implements AlphaFineSearchProvider { try { String result = HttpToolbox.get(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j])); AlphaFineHelper.checkCancel(); - Object json = new JSONTokener(result).nextValue(); - if (json instanceof JSONObject) { - JSONObject jsonObject = new JSONObject(result); - if (jsonObject.optString("status").equals("success")) { - JSONArray jsonArray = jsonObject.optJSONArray("result"); - if (jsonArray != null && jsonArray.length() > 0) { - for (int i = 0; i < jsonArray.length(); i++) { - AlphaFineHelper.checkCancel(); - AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i)); - if (alphaCellModel != null && !alreadyContain(alphaCellModel)) { - - this.recommendModelList.add(alphaCellModel); - } + JSONObject jsonObject = new JSONObject(result); + if (jsonObject.optString("status").equals("success")) { + JSONArray jsonArray = jsonObject.optJSONArray("result"); + if (jsonArray != null && jsonArray.length() > 0) { + for (int i = 0; i < jsonArray.length(); i++) { + AlphaFineHelper.checkCancel(); + AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i)); + if (alphaCellModel != null && !alreadyContain(alphaCellModel)) { + + this.recommendModelList.add(alphaCellModel); } } } @@ -94,6 +90,7 @@ public class RecommendSearchManager implements AlphaFineSearchProvider { } complementAdviceModelList = ComplementAdviceManager.getInstance().getAllSearchResult(searchText); moreModelList.clear(); + if (recommendModelList.size() > 0) { if (complementAdviceModelList.size() == 0) { if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE - 2) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java index b64093c917..6f98039556 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java @@ -4,6 +4,7 @@ import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.stable.StringUtils; import com.fr.third.ibm.icu.text.BreakIterator; + import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -18,7 +19,7 @@ public class SegmentationManager { public static SegmentationManager getInstance() { if (segmentationManager == null) { - synchronized (SegmentationManager.class){ + synchronized (SegmentationManager.class) { if (segmentationManager == null) { segmentationManager = new SegmentationManager(); } @@ -50,6 +51,7 @@ public class SegmentationManager { /** * 对字符串进行分词 + * * @param searchText * @return */ @@ -67,9 +69,7 @@ public class SegmentationManager { BreakIterator itor = BreakIterator.getWordInstance(); itor.setText(searchText); int start = itor.first(); - for (int end = itor.next(); - end != BreakIterator.DONE; - start = end, end = itor.next()) { + for (int end = itor.next(); end != BreakIterator.DONE; start = end, end = itor.next()) { String temp = searchText.substring(start, end); if (!StringUtils.isEmpty(temp)) { result.add(temp); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java index 7f742d4e57..ddaffb88ad 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java @@ -12,7 +12,7 @@ import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; -import com.fr.json.JSONTokener; +import com.fr.json.JSONUtils; import com.fr.log.FineLoggerFactory; import java.io.IOException; import com.fr.third.org.apache.commons.codec.digest.DigestUtils; @@ -47,9 +47,8 @@ public class SimilarSearchManeger implements AlphaFineSearchProvider { try { String result = HttpToolbox.get(url); AlphaFineHelper.checkCancel(); - Object json = new JSONTokener(result).nextValue(); - if (json instanceof JSONArray) { - JSONArray jsonArray = new JSONArray(result); + JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); + if(jsonArray != null){ if (jsonArray.length() != 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.optJSONObject(i);