Bug fix ManifoldAPI
@@ -92,20 +92,23 @@ public class ManifoldAPI {
final String command = "jobs";
final JSONObject jobs = getInfo("jobs");
final String subCommands = "job";
- final JSONObject job = (JSONObject) jobs.get(subCommands);
- if (job != null) {
+
+ final Object objGet = jobs.get(subCommands);
+ if (objGet != null) {
+ if (objGet instanceof JSONObject) {
+ final JSONObject job = (JSONObject) objGet;
delete(command, (String) job.get("id"));
waitJob((String) job.get("id"));
- }
- final JSONArray jobList = (JSONArray) jobs.get(subCommands);
- if (jobList != null) {
- for (int i = 0; i < jobList.size(); i++) {
- final JSONObject singleConnector = (JSONObject) jobList.get(i);
+ } else if (objGet instanceof JSONArray) {
+ final JSONArray jobsList = (JSONArray) objGet;
+ for (int i = 0; i < jobsList.size(); i++) {
+ final JSONObject singleConnector = (JSONObject) jobsList.get(i);
delete(command, (String) singleConnector.get("id"));
waitJob((String) singleConnector.get("id"));
}
}
}
+ }
private static void waitJob(final String id) throws Exception {
JSONObject result;
@@ -121,17 +124,21 @@ public class ManifoldAPI {
LOGGER.info("Start cleaning " + command);
final JSONObject connectors = getInfo(command);
final String subCommands = command.substring(0, command.length() - 1);
- final JSONObject connector = (JSONObject) connectors.get(subCommands);
- if (connector != null) {
+
+ final Object objGet = connectors.get(subCommands);
+ if (objGet != null) {
+ if (objGet instanceof JSONObject) {
+ final JSONObject connector = (JSONObject) objGet;
delete(command, (String) connector.get("name"));
- }
+ } else if (objGet instanceof JSONArray) {
final JSONArray connectorList = (JSONArray) connectors.get(subCommands);
- if (connectorList != null) {
for (int i = 0; i < connectorList.size(); i++) {
final JSONObject singleConnector = (JSONObject) connectorList.get(i);
delete(command, (String) singleConnector.get("name"));
}
}
+ }
+
LOGGER.info("Connectors " + command + " cleaned");
}
@@ -177,14 +184,18 @@ public class ManifoldAPI {
final Map<String, JSONObject> connectorsMap = new HashMap<>();
final JSONObject connectors = getInfo(command);
final String subCommands = command.substring(0, command.length() - 1);
- final JSONObject connector = (JSONObject) connectors.get(subCommands);
- if (connector != null) {
+
+ final Object objGet = connectors.get(subCommands);
+ if (objGet != null) {
+ if (objGet instanceof JSONObject) {
+ final JSONObject connector = (JSONObject) objGet;
createConnectorFile(command, connector, connectorsMap);
- }
+ } else if (objGet instanceof JSONArray) {
final JSONArray connectorList = (JSONArray) connectors.get(subCommands);
- if (connectorList != null) {
for (int i = 0; i < connectorList.size(); i++) {
- createConnectorFile(command, (JSONObject) connectorList.get(i), connectorsMap);
+ final JSONObject singleConnector = (JSONObject) connectorList.get(i);
+ createConnectorFile(command, singleConnector, connectorsMap);
+ }
}
}
