Browse Source

解决冲突,并提升代码质量

research/10.0
alex.sung 6 years ago
parent
commit
614d504347
  1. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java
  3. 6
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  4. 8
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java
  5. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java
  6. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java
  7. 5
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java
  8. 6
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java
  9. 7
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java

4
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java

@ -1,5 +1,6 @@
package com.fr.design.mainframe.alphafine; package com.fr.design.mainframe.alphafine;
import com.fr.base.extension.FileExtension;
import com.fr.general.CloudCenter; import com.fr.general.CloudCenter;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@ -123,5 +124,8 @@ public class AlphaFineConstants {
public static final String CHINESE_CHARACTERS = "[\\u4e00-\\u9fa5]"; 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};
} }

2
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java

@ -35,7 +35,7 @@ public class CellModelHelper {
case ROBOT: case ROBOT:
case RECOMMEND_ROBOT: case RECOMMEND_ROBOT:
cellModel = SimilarSearchManeger.getModelFromCloud(object.optJSONObject(RESULT)); cellModel = SimilarSearchManeger.getModelFromCloud(object.optJSONObject(RESULT));
break;
} }
return cellModel; return cellModel;
} }

6
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java

@ -64,7 +64,7 @@ public class ContentCellRender implements ListCellRenderer<Object> {
} }
} else { } else {
titleLabel.setText(dealWithModelName(model.getName(), segmentationResult)); titleLabel.setText(highLightModelName(model.getName(), segmentationResult));
String iconUrl = CELL_PATH + model.getType().getTypeValue() + SUFFIX; String iconUrl = CELL_PATH + model.getType().getTypeValue() + SUFFIX;
if (value instanceof RobotModel && ((RobotModel) value).isHotItemModel()) { if (value instanceof RobotModel && ((RobotModel) value).isHotItemModel()) {
titleLabel.setIcon(null); titleLabel.setIcon(null);
@ -104,7 +104,7 @@ public class ContentCellRender implements ListCellRenderer<Object> {
* @param strings * @param strings
* @return * @return
*/ */
public String dealWithModelName(String modelName, String[] strings) { public String highLightModelName(String modelName, String[] strings) {
if (strings == null) { if (strings == null) {
return modelName; return modelName;
} }
@ -127,4 +127,6 @@ public class ContentCellRender implements ListCellRenderer<Object> {
return modelName.substring(index, index + string.length()); return modelName.substring(index, index + string.length());
} }
} }

8
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.JSONArray;
import com.fr.json.JSONException; import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.json.JSONTokener; import com.fr.json.JSONUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.io.IOException; import java.io.IOException;
@ -50,9 +50,8 @@ public class ComplementAdviceManager {
try { try {
String result = HttpToolbox.get(url); String result = HttpToolbox.get(url);
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
Object json = new JSONTokener(result).nextValue(); JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result);
if (json instanceof JSONArray) { if(jsonArray != null){
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
JSONObject jsonObject = jsonArray.optJSONObject(i); JSONObject jsonObject = jsonArray.optJSONObject(i);
@ -64,6 +63,7 @@ public class ComplementAdviceManager {
allModelList.add(robotModel); allModelList.add(robotModel);
} }
} }
} }
} }
} catch (JSONException e) { } catch (JSONException e) {

4
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.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.third.org.apache.commons.lang3.ArrayUtils; import com.fr.stable.ArrayUtils;
import java.io.IOException; import java.io.IOException;
@ -61,7 +61,7 @@ public class DocumentSearchManager implements AlphaFineSearchProvider {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainDocument()) { if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainDocument()) {
SearchResult searchResult = new SearchResult(); SearchResult searchResult = new SearchResult();
for (int j = 0; j < searchText.length; j++) { 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 { try {
String result = HttpToolbox.get(url); String result = HttpToolbox.get(url);
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();

2
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; return lessModelList;
} }
AlphaFineHelper.checkCancel(); 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; isContainCpt = true;
isContainFrm = true; isContainFrm = true;
doSearch(this.searchText); doSearch(this.searchText);

5
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.JSONArray;
import com.fr.json.JSONException; import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.json.JSONTokener;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.CodeUtils; import com.fr.stable.CodeUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -61,8 +60,6 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
try { try {
String result = HttpToolbox.get(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j])); String result = HttpToolbox.get(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j]));
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
Object json = new JSONTokener(result).nextValue();
if (json instanceof JSONObject) {
JSONObject jsonObject = new JSONObject(result); JSONObject jsonObject = new JSONObject(result);
if (jsonObject.optString("status").equals("success")) { if (jsonObject.optString("status").equals("success")) {
JSONArray jsonArray = jsonObject.optJSONArray("result"); JSONArray jsonArray = jsonObject.optJSONArray("result");
@ -77,7 +74,6 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
} }
} }
} }
}
} catch (JSONException e) { } catch (JSONException e) {
FineLoggerFactory.getLogger().error("recommend search error! :" + e.getMessage()); FineLoggerFactory.getLogger().error("recommend search error! :" + e.getMessage());
} catch (IOException e) { } catch (IOException e) {
@ -94,6 +90,7 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
} }
complementAdviceModelList = ComplementAdviceManager.getInstance().getAllSearchResult(searchText); complementAdviceModelList = ComplementAdviceManager.getInstance().getAllSearchResult(searchText);
moreModelList.clear(); moreModelList.clear();
if (recommendModelList.size() > 0) { if (recommendModelList.size() > 0) {
if (complementAdviceModelList.size() == 0) { if (complementAdviceModelList.size() == 0) {
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE - 2) { if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE - 2) {

6
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.stable.StringUtils;
import com.fr.third.ibm.icu.text.BreakIterator; import com.fr.third.ibm.icu.text.BreakIterator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -50,6 +51,7 @@ public class SegmentationManager {
/** /**
* 对字符串进行分词 * 对字符串进行分词
*
* @param searchText * @param searchText
* @return * @return
*/ */
@ -67,9 +69,7 @@ public class SegmentationManager {
BreakIterator itor = BreakIterator.getWordInstance(); BreakIterator itor = BreakIterator.getWordInstance();
itor.setText(searchText); itor.setText(searchText);
int start = itor.first(); int start = itor.first();
for (int end = itor.next(); for (int end = itor.next(); end != BreakIterator.DONE; start = end, end = itor.next()) {
end != BreakIterator.DONE;
start = end, end = itor.next()) {
String temp = searchText.substring(start, end); String temp = searchText.substring(start, end);
if (!StringUtils.isEmpty(temp)) { if (!StringUtils.isEmpty(temp)) {
result.add(temp); result.add(temp);

7
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.JSONArray;
import com.fr.json.JSONException; import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.json.JSONTokener; import com.fr.json.JSONUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import java.io.IOException; import java.io.IOException;
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
@ -47,9 +47,8 @@ public class SimilarSearchManeger implements AlphaFineSearchProvider {
try { try {
String result = HttpToolbox.get(url); String result = HttpToolbox.get(url);
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
Object json = new JSONTokener(result).nextValue(); JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result);
if (json instanceof JSONArray) { if(jsonArray != null){
JSONArray jsonArray = new JSONArray(result);
if (jsonArray.length() != 0) { if (jsonArray.length() != 0) {
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.optJSONObject(i); JSONObject jsonObject = jsonArray.optJSONObject(i);

Loading…
Cancel
Save