forked from kevin.shehu/GGD
FINALIZED : FULLY WORKING
TODO : DATA MANIPULATION
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import Credentials.UserCredentials;
|
||||
import Files.WriteFile;
|
||||
import JSON_Unpack.ReadSensors4Partner;
|
||||
import Knowledgebase.SensorReadings;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ApiCall {
|
||||
@@ -33,11 +36,29 @@ public class ApiCall {
|
||||
}
|
||||
}
|
||||
ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner();
|
||||
String y = (readSensors4Partner.FetchSensor4Box("Germes",token));
|
||||
SensorReadings sensorReadings = new SensorReadings();
|
||||
String outputValue = (readSensors4Partner.FetchSensor4Box("Germes",token));
|
||||
System.out.println(outputValue);
|
||||
String outputValueFixed=outputValue.replace("[[","[") +outputValue.replace("[{","{")+outputValue.replace("}]","}")+ outputValue.replace("]]","]");
|
||||
System.out.println(outputValueFixed);
|
||||
JSONArray jsonArray = new JSONArray(outputValueFixed);
|
||||
System.out.println(jsonArray.length());
|
||||
for(int j=0; j<jsonArray.length(); j++) {
|
||||
JSONObject jsonobject = jsonArray.getJSONObject(j);
|
||||
String sensorTag = jsonobject.getString("sensortag");
|
||||
int value = jsonobject.getInt("value");
|
||||
System.out.println(sensorTag+":"+value);
|
||||
sensorReadings.setSensorTag(sensorTag);
|
||||
sensorReadings.setValue(value);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1 +1 @@
|
||||
70B3D57050004223,70B3D570500042D7,70B3D57050004EEF,70B3D57050006223,70B3D5705000623C
|
||||
70B3D57050004223,70B3D570500042D7,70B3D57050004EF4,70B3D57050006223,70B3D5705000623C
|
||||
|
@@ -1 +1 @@
|
||||
70B3D57050004682,70B3D570500046AB,70B3D57050004D14
|
||||
70B3D57050004682,70B3D57050004D14
|
@@ -1 +1 @@
|
||||
PlixJiy6sktkQZcj1WJVqLZCR4abCgnNaMlG2DYGZ2ga75aOA00E9jTzBmSC88tw
|
||||
CyGrh8jKqXXZCBgLzG6gnI6lMWGdzCjGW3LP9sPrH6FEu2M19UcOBF9PZaTJH963
|
@@ -36,8 +36,8 @@ public class BoxCall4Partner {
|
||||
String baseURL = userCredentials.getBaseURL();
|
||||
String homeRoot = userCredentials.getHomeRoot();
|
||||
|
||||
String outputGeneral = null;
|
||||
outputGeneral = GeneralCall4All.FetchAll(token);
|
||||
|
||||
String outputGeneral = GeneralCall4All.FetchAll(token);
|
||||
JSONArray jsonarray = new JSONArray(outputGeneral);
|
||||
|
||||
cName = readFile.ReadFromFile(homeRoot +cName +".txt");
|
||||
@@ -55,10 +55,13 @@ public class BoxCall4Partner {
|
||||
String companyOutput = httpCall.HttpGet(baseURL + "devices/" + jsonID + "/sensors" + "?access_token=" + token, token);
|
||||
listOfCompanyOutputs.add(companyOutput);
|
||||
writingIntoFile.WriteFile(homeRoot +i+" "+ cName + ".json", companyOutput);
|
||||
System.out.println(listOfCompanyOutputs);
|
||||
loopTerminator++;
|
||||
System.out.println(loopTerminator + " "+arrayOfCompany.length+" "+jsonarray.length()+" "+iterator);
|
||||
}
|
||||
|
||||
if(loopTerminator == arrayOfCompany.length ){
|
||||
System.out.println("Entered ");
|
||||
return listOfCompanyOutputs;
|
||||
}
|
||||
|
||||
|
@@ -12,9 +12,6 @@ import java.util.ArrayList;
|
||||
///url/sensors/id/read
|
||||
|
||||
public class ReadSensors4Partner {
|
||||
|
||||
|
||||
|
||||
public String FetchSensor4Box(String companyName, String token) throws Exception {
|
||||
|
||||
switch (companyName) {
|
||||
@@ -40,19 +37,22 @@ public class ReadSensors4Partner {
|
||||
|
||||
BoxCall4Partner boxCall4Partner = new BoxCall4Partner();
|
||||
String outputBox = boxCall4Partner.FetchBox(cName,token);
|
||||
String outputBoxFixed=outputBox.replace("[[","[") + outputBox.replace("]]","]"); //to make the
|
||||
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("The working array:"+jsonArray);
|
||||
ArrayList<String> list=new ArrayList<String>();
|
||||
int loopTerminator = 0;
|
||||
|
||||
char par = '"';
|
||||
for(int j=0; j<jsonArray.length(); j++){
|
||||
JSONObject jsonobject = jsonArray.getJSONObject(j);
|
||||
String jsonID = jsonobject.getString("id");
|
||||
String jsonTag = jsonobject.getString("tag");
|
||||
|
||||
String sensorOutput = httpCall.HttpGet(baseURL + "sensors/" + jsonID + "/read" + "?access_token=" + token, token);
|
||||
list.add(sensorOutput);
|
||||
String sensorTag= par+"sensortag"+par+":"+jsonTag+"}]";
|
||||
String makingList=sensorOutput.replace("}]","") ;
|
||||
list.add(makingList+","+sensorTag); // This modification of the list is done for the purpse of converting this list to a jsonarray.
|
||||
|
||||
writingIntoFile.WriteFile(homeRoot + jsonID + ".json", sensorOutput + jsonTag);
|
||||
loopTerminator++;
|
||||
if(loopTerminator == jsonArray.length()){
|
||||
|
@@ -1,4 +0,0 @@
|
||||
package JSON_Unpack;
|
||||
|
||||
public class Reading4AllSensors {
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package Knowledgebase;
|
||||
|
||||
import org.kie.api.KieServices;
|
||||
import org.kie.api.KieServices.Factory;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.rule.FactHandle;
|
||||
@@ -17,10 +18,12 @@ public class DroolsTest {
|
||||
|
||||
Product product = new Product();
|
||||
product.setType("gold");
|
||||
System.out.println(product.getDiscount());
|
||||
|
||||
FactHandle fact1;
|
||||
|
||||
fact1 = kSession.insert(product);
|
||||
System.out.println(fact1);
|
||||
kSession.fireAllRules();
|
||||
|
||||
System.out.println("The discount for the jewellery product "
|
||||
|
@@ -1,31 +0,0 @@
|
||||
package Knowledgebase;
|
||||
|
||||
public class Plants {
|
||||
private String plantType;
|
||||
private String sensorTag;
|
||||
private double outputValue;
|
||||
|
||||
public String getPlantType() {
|
||||
return plantType;
|
||||
}
|
||||
|
||||
public void setPlantType(String plantType) {
|
||||
this.plantType = plantType;
|
||||
}
|
||||
|
||||
public String getSensorTag() {
|
||||
return sensorTag;
|
||||
}
|
||||
|
||||
public void setSensorTag(String sensorTag) {
|
||||
this.sensorTag = sensorTag;
|
||||
}
|
||||
|
||||
public double getOutputValue() {
|
||||
return outputValue;
|
||||
}
|
||||
|
||||
public void setOutputValue(double outputValue) {
|
||||
this.outputValue = outputValue;
|
||||
}
|
||||
}
|
22
src/main/java/Knowledgebase/SensorReadings.java
Normal file
22
src/main/java/Knowledgebase/SensorReadings.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package Knowledgebase;
|
||||
|
||||
public class SensorReadings {
|
||||
private String sensorTag;
|
||||
private double value;
|
||||
|
||||
public String getSensorTag() {
|
||||
return sensorTag;
|
||||
}
|
||||
|
||||
public void setSensorTag(String sensorTag) {
|
||||
this.sensorTag = sensorTag;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
3
src/main/resources/maven/pom.properties
Normal file
3
src/main/resources/maven/pom.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
groupId=com.javainuse
|
||||
artifactId=drools-hello-world
|
||||
version=0.0.1-SNAPSHOT
|
@@ -10,5 +10,5 @@ rule "Offer for Gold"
|
||||
when
|
||||
productObject: Product(type=="gold")
|
||||
then
|
||||
productObject.setDiscount(25);
|
||||
productObject.setDiscount(10);
|
||||
end
|
Reference in New Issue
Block a user