From 55107aaae58237ca0db5a3cce12fb983957799fe Mon Sep 17 00:00:00 2001 From: ayyoob Date: Mon, 15 Aug 2016 15:04:26 +0530 Subject: [PATCH] fixing commit issues --- .../android/sense/data/publisher/Event.java | 24 ++--- .../streams/Location/LocationDataReader.java | 2 +- .../public/js/android_sense.js | 4 - .../public/js/arduino.js | 2 - .../carbon/device/mgt/iot/util/Utils.java | 95 ++++++++----------- .../public/js/raspberrypi.js | 2 - .../public/js/virtual_firealarm.js | 2 - 7 files changed, 50 insertions(+), 81 deletions(-) diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java index ff933ecda..5b5446d70 100755 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java @@ -12,15 +12,15 @@ public class Event { private String deviceId; private String type; private int battery; - private double gps[]; //lat,long - private float accelerometer[]; //x,y,z - private float magnetic[]; //x,y,z - private float gyroscope[]; //x,y,z + private double gps[] = new double[]{0, 0}; //lat,long + private float accelerometer[] = new float[]{0, 0, 0}; //x,y,z + private float magnetic[] = new float[]{0, 0, 0};; //x,y,z + private float gyroscope[] = new float[]{0, 0, 0};; //x,y,z private float light; private float pressure; private float proximity; - private float gravity[]; - private float rotation[]; + private float gravity[] = new float[]{0, 0, 0};; + private float rotation[] = new float[]{0, 0, 0};; private String wordSessionId; private String word; private String wordStatus; @@ -45,7 +45,7 @@ public class Event { } private double[] getGps() { - return gps != null ? gps : new double[]{0, 0}; + return gps; } public void setGps(double[] gps) { @@ -54,7 +54,7 @@ public class Event { } private float[] getAccelerometer() { - return accelerometer != null ? accelerometer : new float[]{0, 0, 0}; + return accelerometer; } public void setAccelerometer(float[] accelerometer) { @@ -63,7 +63,7 @@ public class Event { } private float[] getMagnetic() { - return magnetic != null ? magnetic : new float[]{0, 0, 0}; + return magnetic; } public void setMagnetic(float[] magnetic) { @@ -72,7 +72,7 @@ public class Event { } private float[] getGyroscope() { - return gyroscope != null ? gyroscope : new float[]{0, 0, 0}; + return gyroscope; } public void setGyroscope(float[] gyroscope) { @@ -108,7 +108,7 @@ public class Event { } private float[] getGravity() { - return gravity != null ? gravity : new float[]{0, 0, 0}; + return gravity; } public void setGravity(float gravity[]) { @@ -117,7 +117,7 @@ public class Event { } private float[] getRotation() { - return rotation != null ? rotation : new float[]{0, 0, 0}; + return rotation; } public void setRotation(float rotation[]) { diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationDataReader.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationDataReader.java index 9935f2dd4..b85969aa4 100755 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationDataReader.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationDataReader.java @@ -231,7 +231,7 @@ public class LocationDataReader extends DataReader implements LocationListener { } catch (InterruptedException e) { // Restore the interrupted status Thread.currentThread().interrupt(); - Log.e(TAG, " Location Data Retrieval Failed"); + Log.e(TAG, " Location Data Retrieval Failed", e); } } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/public/js/android_sense.js b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/public/js/android_sense.js index 6987e058f..3abfc3551 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/public/js/android_sense.js +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/public/js/android_sense.js @@ -200,7 +200,6 @@ function drawGraph_android_sense(from, to) { populateGraph(); }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); populateGraph(); }); } @@ -219,7 +218,6 @@ function drawGraph_android_sense(from, to) { getData(); }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); deviceIndex++; getData(); }); @@ -265,7 +263,6 @@ function drawGraph_android_sense(from, to) { populateGraph(); }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); populateGraph(); }); } @@ -285,7 +282,6 @@ function drawGraph_android_sense(from, to) { getData(); }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); deviceIndex++; getData(); }); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/public/js/arduino.js b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/public/js/arduino.js index 4359dc60f..76d5cb040 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/public/js/arduino.js +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/public/js/arduino.js @@ -137,7 +137,6 @@ function drawGraph_arduino(from, to) { } }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); }); } @@ -155,7 +154,6 @@ function drawGraph_arduino(from, to) { getData(); }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); deviceIndex++; getData(); }); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java index 26aaf2aa7..c11176983 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java @@ -63,6 +63,7 @@ public class Utils { } } catch (SocketException e) { hostName = "localhost"; + log.warn("Failed retrieving the hostname, therefore set to localhost", e); } return hostName; } @@ -90,25 +91,14 @@ public class Utils { templateFiles.add("sketch.properties"); // ommit copying the props file copyFolder(new File(sketchPath), new File(archivesPath), templateFiles); - + createZipArchive(archivesPath); + FileUtils.deleteDirectory(new File(archivesPath)); + File zip = new File(archivesPath + ".zip"); + return new ZipArchive(zipFileName, zip); } catch (IOException ex) { throw new DeviceManagementException( "Error occurred when trying to read property " + "file sketch.properties", ex); } - - try { - createZipArchive(archivesPath); - } catch (IOException e) { - String message = "Zip file for the specific device agent not found at path: " + archivesPath; - log.error(message); - log.error(e); - throw new DeviceManagementException(message, e); - } - FileUtils.deleteDirectory(new File(archivesPath));//clear folder - - /* now get the zip file */ - File zip = new File(archivesPath + ".zip"); - return new ZipArchive(zipFileName, zip); } private static Map> getProperties(String propertyFilePath) throws IOException { @@ -139,7 +129,7 @@ public class Utils { try { input.close(); } catch (IOException e) { - e.printStackTrace(); + log.error("Failed closing connection", e); } } } @@ -147,21 +137,25 @@ public class Utils { private static void parseTemplate(String srcFile, String dstFile, Map contextParams) throws IOException { //read from file - FileInputStream inputStream = new FileInputStream(srcFile); - String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8.toString()); - Iterator iterator = contextParams.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry mapEntry = (Map.Entry) iterator.next(); - content = content.replaceAll("\\$\\{" + mapEntry.getKey() + "\\}", mapEntry.getValue().toString()); - } - if (inputStream != null) { - inputStream.close(); - } - //write to file - FileOutputStream outputStream = new FileOutputStream(dstFile); - IOUtils.write(content, outputStream, StandardCharsets.UTF_8.toString()); - if (outputStream != null) { - outputStream.close(); + FileInputStream inputStream = null; + FileOutputStream outputStream = null; + try { + inputStream = new FileInputStream(srcFile); + outputStream = new FileOutputStream(dstFile); + String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8.toString()); + Iterator iterator = contextParams.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry mapEntry = (Map.Entry) iterator.next(); + content = content.replaceAll("\\$\\{" + mapEntry.getKey() + "\\}", mapEntry.getValue().toString()); + } + IOUtils.write(content, outputStream, StandardCharsets.UTF_8.toString()); + } finally { + if (inputStream != null) { + inputStream.close(); + } + if (outputStream != null) { + outputStream.close(); + } } } @@ -213,35 +207,16 @@ public class Utils { out.write(buffer, 0, length); } } finally { - silentClose(in); - silentClose(out); + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } } } } - private static void silentClose(InputStream is) { - if (is == null) { - return; - } - try { - is.close(); - } catch (IOException e) { - // do nothing - } - - } - - private static void silentClose(OutputStream os) { - if (os == null) { - return; - } - try { - os.close(); - } catch (IOException e) { - // do nothing - } - } - private static boolean createZipArchive(String srcFolder) throws IOException { BufferedInputStream origin = null; ZipOutputStream out = null; @@ -295,8 +270,12 @@ public class Utils { } out.flush(); } finally { - silentClose(origin); - silentClose(out); + if (origin != null) { + origin.close(); + } + if (out != null) { + out.close(); + } } return true; } diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/public/js/raspberrypi.js b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/public/js/raspberrypi.js index 3b23f1179..8fe6e9276 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/public/js/raspberrypi.js +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/public/js/raspberrypi.js @@ -137,7 +137,6 @@ function drawGraph_raspberrypi(from, to) { } }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); }); } @@ -155,7 +154,6 @@ function drawGraph_raspberrypi(from, to) { getData(); }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); deviceIndex++; getData(); }); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/public/js/virtual_firealarm.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/public/js/virtual_firealarm.js index a1b385394..25cee0cf8 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/public/js/virtual_firealarm.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/public/js/virtual_firealarm.js @@ -137,7 +137,6 @@ function drawGraph_virtual_firealarm(from, to) { } }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); }); } @@ -155,7 +154,6 @@ function drawGraph_virtual_firealarm(from, to) { getData(); }; invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); deviceIndex++; getData(); });