forked from fanruan/design
Browse Source
* commit '5510686ed5e6c7301127590012efca2792cfb3e4': PMD修改 PMD修改 变量命名修改 变量命名修改 REPORT-5357 插件逻辑中的代码质量(关于使用Executor和线程池)master
neil
7 years ago
9 changed files with 343 additions and 162 deletions
@ -0,0 +1,42 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginConstants; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
|
||||
/** |
||||
* Created by vito on 16/5/16. |
||||
*/ |
||||
public class GetPluginCategoriesExecutor implements Executor { |
||||
private String result = "[]"; |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
String url = SiteCenter.getInstance().acquireUrlByKind("shop.plugin.category"); |
||||
if (url != null) { |
||||
HttpClient httpClient = new HttpClient(url); |
||||
result = httpClient.getResponseText(); |
||||
} else { |
||||
result = PluginConstants.CONNECTION_404; |
||||
} |
||||
|
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,75 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginConstants; |
||||
import com.fr.design.extra.PluginOperateUtils; |
||||
import com.fr.design.extra.PluginUtils; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by vito on 16/4/18. |
||||
* 获取插件分类信息 |
||||
*/ |
||||
public class GetPluginFromStoreExecutor implements Executor { |
||||
private String result = "[]"; |
||||
private String category; |
||||
private String seller; |
||||
private String fee; |
||||
|
||||
public GetPluginFromStoreExecutor(String category, String seller, String fee) { |
||||
this.category = category; |
||||
this.seller = seller; |
||||
this.fee = fee; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("shop.plugin.plist") + "?"; |
||||
boolean getRecommend = StringUtils.isEmpty(category) && StringUtils.isEmpty(seller) && StringUtils.isEmpty(fee); |
||||
if (getRecommend) { |
||||
result = PluginOperateUtils.getRecommendPlugins(); |
||||
return; |
||||
} |
||||
|
||||
if (StringUtils.isNotBlank(plistUrl)) { |
||||
StringBuilder url = new StringBuilder(); |
||||
url.append(plistUrl); |
||||
PluginOperateUtils.dealParams(url, category, seller, fee); |
||||
try { |
||||
HttpClient httpClient = new HttpClient(url.toString()); |
||||
httpClient.asGet(); |
||||
String responseText = httpClient.getResponseText(); |
||||
JSONObject resultJSONObject = new JSONObject(responseText); |
||||
JSONArray resultArr = resultJSONObject.getJSONArray("result"); |
||||
JSONArray resultJSONArray = PluginUtils.filterPluginsFromVersion(resultArr); |
||||
result = resultJSONArray.toString(); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} else { |
||||
result = PluginConstants.CONNECTION_404; |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by kerry on 2017/11/3. |
||||
*/ |
||||
public class GetPluginPrefixExecutor implements Executor { |
||||
private String result = StringUtils.EMPTY; |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
result = SiteCenter.getInstance().acquireUrlByKind("plugin.url.prefix"); |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,51 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginsReaderFromStore; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.view.PluginView; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by vito on 16/4/19. |
||||
*/ |
||||
public class ReadUpdateOnlineExecutor implements Executor { |
||||
private String result = StringUtils.EMPTY; |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
try { |
||||
List<PluginView> plugins = PluginsReaderFromStore.readPluginsForUpdate(); |
||||
JSONArray jsonArray = new JSONArray(); |
||||
for (PluginView plugin : plugins) { |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("pluginid", plugin.getID()); |
||||
jsonArray.put(jsonObject); |
||||
} |
||||
result = jsonArray.toString(); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginOperateUtils; |
||||
import com.fr.design.extra.PluginUtils; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by vito on 16/4/18. |
||||
*/ |
||||
public class SearchOnlineExecutor implements Executor { |
||||
private String result = StringUtils.EMPTY; |
||||
private String keyword; |
||||
|
||||
public SearchOnlineExecutor(String keyword) { |
||||
this.keyword = keyword; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
try { |
||||
if (StringUtils.isBlank(keyword)) { |
||||
result = PluginOperateUtils.getRecommendPlugins(); |
||||
return; |
||||
} |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("shop.plugin.store") + "&keyword=" + keyword); |
||||
httpClient.asGet(); |
||||
String responseText = httpClient.getResponseText(); |
||||
JSONObject jsonObject = new JSONObject(responseText); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("result"); |
||||
JSONArray resultJSONArray = PluginUtils.filterPluginsFromVersion(jsonArray); |
||||
result = resultJSONArray.toString(); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
Loading…
Reference in new issue