Browse Source

实现下载异常处理

menglu 3 years ago
parent
commit
0e5161f1b6

+ 10 - 4
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/BaseApi.java

@@ -196,9 +196,12 @@ public class BaseApi {
 			count = Integer.MAX_VALUE;
 		}
 		List<LogOfDownload> list = RepositoryContainer.RepositoryProject.LogOfDownloadListMap.get(name);
-		for (int i = 0; i < count && i < list.size() - 1; i++) {
-			JSONObject LogOfRun = list.get(i).toJSON();
+		for (LogOfDownload LogOfDownload : list) {
+			JSONObject LogOfRun = LogOfDownload.toJSON();
 			result.add(LogOfRun);
+			if (result.size() >= count) {
+				break;
+			}
 		}
 		return result;
 	}
@@ -210,9 +213,12 @@ public class BaseApi {
 			count = Integer.MAX_VALUE;
 		}
 		List<LogOfDownload> list = RepositoryContainer.RepositoryProject.SuccessLogOfDownloadListMap.get(name);
-		for (int i = 0; i < count && i < list.size() - 1; i++) {
-			JSONObject LogOfRun = list.get(i).toJSON();
+		for (LogOfDownload LogOfDownload : list) {
+			JSONObject LogOfRun = LogOfDownload.toJSON();
 			result.add(LogOfRun);
+			if (result.size() >= count) {
+				break;
+			}
 		}
 		return result;
 	}

+ 22 - 6
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDDownloadUtil.java

@@ -135,6 +135,9 @@ public class RWDDownloadUtil {
 					+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode,
 					param.toJSONString());
 			JSONObject resultJSON = JSON.parseObject(post_result);
+			if (!resultJSON.getString("result").equals("success")) {
+				throw new Exception(param.toJSONString() + "\n" + post_result);
+			}
 			classArray = resultJSON.getJSONArray("data");
 			classArray = classArray == null ? new JSONArray() : classArray;
 			FileUtil.Save(path + Constant.getSeperator() + "classArray.json", FastJsonUtil.toFormatString(classArray), LogOfDownload.downloadList);
@@ -153,9 +156,12 @@ public class RWDDownloadUtil {
 						+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode,
 						param.toJSONString());
 				JSONObject resultJSON = JSON.parseObject(post_result);
+				if (!resultJSON.getString("result").equals("success")) {
+					throw new Exception(param.toJSONString() + "\n" + post_result);
+				}
 				infoArray = resultJSON.getJSONArray("data");
+				infoArray = infoArray == null ? new JSONArray() : infoArray;
 			}
-			infoArray = infoArray == null ? new JSONArray() : infoArray;
 			FileUtil.Save(path + Constant.getSeperator() + "info" + Constant.getSeperator() + code + ".json", FastJsonUtil.toFormatString(infoArray),
 					LogOfDownload.downloadList);
 		}
@@ -190,9 +196,12 @@ public class RWDDownloadUtil {
 						+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode,
 						param.toJSONString());
 				JSONObject resultJSON = JSON.parseObject(post_result);
+				if (!resultJSON.getString("result").equals("success")) {
+					throw new Exception(param.toJSONString() + "\n" + post_result);
+				}
 				infoArray = resultJSON.getJSONArray("data");
+				infoArray = infoArray == null ? new JSONArray() : infoArray;
 			}
-			infoArray = infoArray == null ? new JSONArray() : infoArray;
 			FileUtil.Save(path + Constant.getSeperator() + "object" + Constant.getSeperator() + code + ".json",
 					FastJsonUtil.toFormatString(infoArray), LogOfDownload.downloadList);
 		}
@@ -222,9 +231,12 @@ public class RWDDownloadUtil {
 							+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode,
 							param.toJSONString());
 					JSONObject resultJSON = JSON.parseObject(post_result);
+					if (!resultJSON.getString("result").equals("success")) {
+						throw new Exception(param.toJSONString() + "\n" + post_result);
+					}
 					infoArray = resultJSON.getJSONArray("data");
+					infoArray = infoArray == null ? new JSONArray() : infoArray;
 				}
-				infoArray = infoArray == null ? new JSONArray() : infoArray;
 				FileUtil.Save(path + Constant.getSeperator() + "relation" + Constant.getSeperator() + graphCode + Constant.getSeperator() + relCode
 						+ ".json", FastJsonUtil.toFormatString(infoArray), LogOfDownload.downloadList);
 			}
@@ -304,7 +316,6 @@ public class RWDDownloadUtil {
 					+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode,
 					param.toJSONString());
 			sceneArray = JSON.parseArray(post_result);
-			sceneArray = sceneArray == null ? new JSONArray() : sceneArray;
 			FileUtil.Save(path + Constant.getSeperator() + "sceneArray.json", FastJsonUtil.toFormatString(sceneArray), LogOfDownload.downloadList);
 		}
 		JSONArray classArray;
@@ -317,6 +328,9 @@ public class RWDDownloadUtil {
 					+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode,
 					param.toJSONString());
 			JSONObject resultJSON = JSON.parseObject(post_result);
+			if (!resultJSON.getString("result").equals("success")) {
+				throw new Exception(param.toJSONString() + "\n" + post_result);
+			}
 			classArray = resultJSON.getJSONArray("data");
 			classArray = classArray == null ? new JSONArray() : classArray;
 			FileUtil.Save(path + Constant.getSeperator() + "classArray.json", FastJsonUtil.toFormatString(classArray), LogOfDownload.downloadList);
@@ -337,9 +351,12 @@ public class RWDDownloadUtil {
 						+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode,
 						param.toJSONString());
 				JSONObject resultJSON = JSON.parseObject(post_result);
+				if (!resultJSON.getString("result").equals("success")) {
+					throw new Exception(param.toJSONString() + "\n" + post_result);
+				}
 				infoArray = resultJSON.getJSONArray("data");
+				infoArray = infoArray == null ? new JSONArray() : infoArray;
 			}
-			infoArray = infoArray == null ? new JSONArray() : infoArray;
 			File sceneDir = new File(path + Constant.getSeperator() + "object" + Constant.getSeperator() + ibmsSceneCode);
 			if (!sceneDir.exists()) {
 				sceneDir.mkdir();
@@ -626,7 +643,6 @@ public class RWDDownloadUtil {
 						throw e;
 					}
 				}
-				infoArray = infoArray == null ? new JSONArray() : infoArray;
 				FileUtil.Save(path + Constant.getSeperator() + ibmsSceneCode + Constant.getSeperator() + ibmsClassCode + ".json",
 						FastJsonUtil.toFormatString(infoArray), LogOfDownload.downloadList);
 			}