forked from kevin.shehu/GGD
ADD: New rules for the rule Engine
FIX: ApiCall.java REWORK : JSON_Unpack
This commit is contained in:
@@ -33,37 +33,42 @@ public class ReadSensors4Partner {
|
||||
WriteFile writingIntoFile = new WriteFile();
|
||||
|
||||
String baseURL = userCredentials.getBaseURL();
|
||||
String devUrl = userCredentials.getDevUrl();
|
||||
String homeRoot = UserCredentials.getHomeRoot();
|
||||
|
||||
BoxCall4Partner boxCall4Partner = new BoxCall4Partner();
|
||||
String outputBox = boxCall4Partner.FetchBox(cName,token);
|
||||
String outputBoxFixed=outputBox.replace("[[","[") + outputBox.replace("]]","]");// To convert in Jsonarray we need to remove the array list brackets
|
||||
JSONArray jsonArray = new JSONArray(outputBoxFixed);
|
||||
System.out.println("FINAL WORKING ARRAY:"+jsonArray);
|
||||
ArrayList<String> list=new ArrayList<String>();
|
||||
int loopTerminator = 0;
|
||||
char par = '"';
|
||||
|
||||
BoxCall4Partner boxCall4Partner = new BoxCall4Partner();
|
||||
ArrayList<String> outputBox = boxCall4Partner.FetchBox(cName,token);
|
||||
for (int i=0;i<outputBox.size();i++){
|
||||
JSONArray jsonArray = new JSONArray(outputBox.get(i));
|
||||
for(int j=0; j<jsonArray.length(); j++){
|
||||
|
||||
JSONObject jsonobject = jsonArray.getJSONObject(j);
|
||||
String jsonID = jsonobject.getString("id");
|
||||
String jsonTag = jsonobject.getString("tag");
|
||||
String finalTag = ","+par+"sensorTag"+par+":"+jsonTag+"}]";
|
||||
String deviceID = jsonobject.getString("deviceId");
|
||||
String finalTag = ","+par+"deviceId"+par+":"+deviceID+","+par+"sensorTag"+par+":"+jsonTag+"}]";
|
||||
|
||||
String sensorOutput = httpCall.HttpGetCall(devUrl + "sensors/" + jsonID + "/read" + "?access_token=" + token, token);
|
||||
if (sensorOutput.contains("error")){
|
||||
System.out.println(sensorOutput);
|
||||
}
|
||||
else {
|
||||
String modification = sensorOutput.replace("}]","");
|
||||
String finalSensorOutput = modification+finalTag;
|
||||
list.add(finalSensorOutput);
|
||||
|
||||
writingIntoFile.WriteFile(homeRoot + jsonID + ".json", sensorOutput + jsonTag+","+deviceID);
|
||||
}
|
||||
|
||||
String sensorOutput = httpCall.HttpGetCall(baseURL + "sensors/" + jsonID + "/read" + "?access_token=" + token, token);
|
||||
String modification = sensorOutput.replace("}]","");
|
||||
String finalSensorOutput = modification+finalTag;
|
||||
list.add(finalSensorOutput);
|
||||
|
||||
writingIntoFile.WriteFile(homeRoot + jsonID + ".json", sensorOutput + jsonTag);
|
||||
loopTerminator++;
|
||||
if(loopTerminator == jsonArray.length()){
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user