Browse Source

REPORT-10946 @Sung:离线状态下(断网)alphafine都打不开了

之前的断网情况逻辑耦合太严重了,剥离出来
final/10.0
alex.sung 6 years ago
parent
commit
77d2acb32a
  1. 20
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java
  2. 21
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  3. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java
  4. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.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. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java
  8. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java
  9. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java
  10. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java

20
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java

@ -16,11 +16,15 @@ import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager
import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.SimilarSearchManeger;
import com.fr.general.ProcessCanceledException;
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.JSONUtils;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.StatusLine;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import java.util.List;
@ -30,6 +34,7 @@ import java.util.List;
public class AlphaFineHelper {
public static final NoResultModel NO_CONNECTION_MODEL = new NoResultModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Connection_Failed"));
private static AlphaFineDialog alphaFineDialog;
private static final String URL_FOR_TEST_NETWORK = "https://www.baidu.com";
/**
* 弹出alphafine搜索面板
@ -145,4 +150,19 @@ public class AlphaFineHelper {
result.add(AlphaFineHelper.NO_CONNECTION_MODEL);
return result;
}
/**
* 判断网络是否异常
* @return
*/
public static boolean isNetworkOk(){
HttpGet getHelp = new HttpGet(URL_FOR_TEST_NETWORK);
try {
StatusLine statusLine = HttpToolbox.getHttpClient(URL_FOR_TEST_NETWORK).execute(getHelp).getStatusLine();
return statusLine.getStatusCode() == HttpStatus.SC_OK;
} catch (Exception ignore) {
// 网络异常
return false;
}
}
}

21
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -39,7 +39,6 @@ import com.fr.form.main.Form;
import com.fr.form.main.FormIO;
import com.fr.general.ComparatorUtils;
import com.fr.general.http.HttpClient;
import com.fr.general.http.HttpToolbox;
import com.fr.io.TemplateWorkBookIO;
import com.fr.io.exporter.ImageExporter;
import com.fr.json.JSONException;
@ -49,7 +48,6 @@ import com.fr.main.impl.WorkBook;
import com.fr.stable.CodeUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
@ -247,22 +245,19 @@ public class AlphaFineDialog extends UIDialog {
GridLayout gridLayout = new GridLayout(2, 3, 3, 3);
JPanel panel = new JPanel();
panel.setLayout(gridLayout);
try {
HttpGet getHelp = new HttpGet(AlphaFineConstants.ALPHA_HOT_SEARCH);
HttpToolbox.getHttpClient(AlphaFineConstants.ALPHA_HOT_SEARCH).execute(getHelp).getStatusLine();
if(AlphaFineHelper.isNetworkOk()) {
if (hotData == null) {
hotData = HotIssuesManager.getInstance().getHotIssues();
}
for (int i = 0; i < hotData.length; i++) {
panel.add(new HotIssueJpanel(hotData[i], i + 1));
}
} catch (Exception e) {
}else {
hotData = null;
for (int i = 0; i < AlphaFineConstants.HOT_ITEMS; i++) {
panel.add(new HotIssueJpanel(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Connection_Failed")}, i + 1));
}
}
hotPane.add(uiLabel, BorderLayout.NORTH);
hotPane.add(panel, BorderLayout.CENTER);
add(hotPane, BorderLayout.SOUTH);
@ -552,7 +547,7 @@ public class AlphaFineDialog extends UIDialog {
}
private void buildDocumentList(final String[] searchText) {
addSearchResult(DocumentSearchManager.getInstance().getLessSearchResult(getHotData(), searchText));
addSearchResult(DocumentSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildFileList(String searchStr, final String[] searchText) {
@ -560,24 +555,24 @@ public class AlphaFineDialog extends UIDialog {
}
private void buildActionList(final String[] searchText) {
addSearchResult(ActionSearchManager.getInstance().getLessSearchResult(getHotData(), searchText));
addSearchResult(ActionSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildPluginList(final String[] searchText) {
addSearchResult(PluginSearchManager.getInstance().getLessSearchResult(getHotData(), searchText));
addSearchResult(PluginSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildRecommendList(final String[] searchText) {
addSearchResult(RecommendSearchManager.getInstance().getLessSearchResult(getHotData(), searchText));
addSearchResult(RecommendSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildRecentList(final String[] searchText) {
addSearchResult(RecentSearchManager.getInstance().getLessSearchResult(getHotData(), searchText));
addSearchResult(RecentSearchManager.getInstance().getLessSearchResult(searchText));
}
private void buildSimilarList(final String[] searchText) {
addSearchResult(SimilarSearchManeger.getInstance().getLessSearchResult(getHotData(), searchText));
addSearchResult(SimilarSearchManeger.getInstance().getLessSearchResult(searchText));
}
private synchronized void addSearchResult(SearchResult searchResult) {

2
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java

@ -12,7 +12,7 @@ public interface AlphaFineSearchProvider {
* @param searchText
* @return
*/
SearchResult getLessSearchResult(String[][] data, String[] searchText);
SearchResult getLessSearchResult(String[] searchText);
/**
* 获取剩余条数

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

@ -57,7 +57,7 @@ public class ActionSearchManager implements AlphaFineSearchProvider {
}
@Override
public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) {
public SearchResult getLessSearchResult(String[] searchText) {
filterModelList = new SearchResult();
lessModelList = new SearchResult();
moreModelList = new SearchResult();

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

@ -51,14 +51,14 @@ public class DocumentSearchManager implements AlphaFineSearchProvider {
}
@Override
public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) {
public SearchResult getLessSearchResult(String[] searchText) {
lessModelList = new SearchResult();
moreModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainDocument()) {
if (ArrayUtils.isEmpty(searchText)) {
lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Community_Help")));
return lessModelList;
} else if (hotData == null) {
} else if (!AlphaFineHelper.isNetworkOk()) {
return AlphaFineHelper.getNoConnectList(instance);
}
SearchResult searchResult = new SearchResult();

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

@ -96,7 +96,7 @@ public class FileSearchManager implements AlphaFineSearchProvider {
}
@Override
public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) {
public SearchResult getLessSearchResult(String[] searchText) {
return null;
}

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

@ -96,7 +96,7 @@ public class PluginSearchManager implements AlphaFineSearchProvider {
}
@Override
public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) {
public SearchResult getLessSearchResult(String[] searchText) {
this.lessModelList = new SearchResult();
this.moreModelList = new SearchResult();
SearchResult searchResult = new SearchResult();
@ -104,7 +104,7 @@ public class PluginSearchManager implements AlphaFineSearchProvider {
if (ArrayUtils.isEmpty(searchText)) {
lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Plugin_Addon")));
return lessModelList;
} else if (hotData == null) {
} else if (!AlphaFineHelper.isNetworkOk()) {
return AlphaFineHelper.getNoConnectList(instance);
}
for (int j = 0; j < searchText.length; j++) {

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

@ -72,7 +72,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider {
}
@Override
public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) {
public SearchResult getLessSearchResult(String[] searchText) {
this.modelList = new SearchResult();
for (int j = 0; j < searchText.length; j++) {
recentModelList = getRecentModelList(searchText[j]);

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

@ -46,13 +46,13 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
}
@Override
public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) {
public SearchResult getLessSearchResult(String[] searchText) {
this.modelList = new SearchResult();
this.recommendModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) {
if (ArrayUtils.isEmpty(searchText)) {
return new SearchResult();
} else if(hotData == null){
} else if(!AlphaFineHelper.isNetworkOk()){
return AlphaFineHelper.getNoConnectList(instance);
}
for (int j = 0; j < searchText.length; j++) {

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

@ -37,12 +37,12 @@ public class SimilarSearchManeger implements AlphaFineSearchProvider {
}
@Override
public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) {
public SearchResult getLessSearchResult(String[] searchText) {
lessModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) {
if (ArrayUtils.isEmpty(searchText)) {
return new SearchResult();
} else if (hotData == null) {
} else if (!AlphaFineHelper.isNetworkOk()) {
return AlphaFineHelper.getNoConnectList(instance);
}
SearchResult allModelList = new SearchResult();

Loading…
Cancel
Save