Fix code formatting

merge-requests/1/head
Sameera Wickramasekara 7 years ago
parent 3d359642bf
commit ed0b110ad6

@ -28,22 +28,20 @@ import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Produces; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.PUT;
import javax.ws.rs.DELETE;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
/** /**
* This is the API which is used to control and manage device type functionality * This is the API which is used to control and manage device type functionality.
*/ */
@SwaggerDefinition( @SwaggerDefinition(
info = @Info( info = @Info(
@ -98,7 +96,7 @@ public interface DeviceTypeService {
@Context HttpServletResponse response); @Context HttpServletResponse response);
/** /**
* Retrieve Sensor data for the given time period * Retrieve Sensor data for the given time period.
* @param deviceId unique identifier for given device type instance * @param deviceId unique identifier for given device type instance
* @param from starting time * @param from starting time
* @param to ending time * @param to ending time
@ -124,7 +122,7 @@ public interface DeviceTypeService {
Response getSensorStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from, Response getSensorStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
@QueryParam("to") long to, @QueryParam("sensorType") String sensorType); @QueryParam("to") long to, @QueryParam("sensorType") String sensorType);
/** /**
* To download device type agent source code as zip file * To download device type agent source code as zip file.
* @param deviceName name for the device type instance * @param deviceName name for the device type instance
* @param sketchType folder name where device type agent was installed into server * @param sketchType folder name where device type agent was installed into server
* @return Agent source code as zip file * @return Agent source code as zip file

@ -18,13 +18,6 @@
package org.wso2.raspberrypicodebased.api; package org.wso2.raspberrypicodebased.api;
import org.wso2.raspberrypicodebased.api.dto.DeviceJSON;
import org.wso2.raspberrypicodebased.api.dto.SensorRecord;
import org.wso2.raspberrypicodebased.api.util.APIUtil;
import org.wso2.raspberrypicodebased.api.util.ZipUtil;
import org.wso2.raspberrypicodebased.api.util.ZipArchive;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -39,23 +32,29 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.raspberrypicodebased.api.dto.DeviceJSON;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.raspberrypicodebased.api.dto.SensorRecord;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.raspberrypicodebased.api.util.APIUtil;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.raspberrypicodebased.api.util.ZipArchive;
import org.wso2.raspberrypicodebased.api.util.ZipUtil;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Produces; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -63,17 +62,16 @@ import javax.ws.rs.core.Response;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.UUID;
/** /**
* This is the API which is used to control and manage device type functionality * This is the API which is used to control and manage device type functionality.
*/ */
public class DeviceTypeServiceImpl implements DeviceTypeService { public class DeviceTypeServiceImpl implements DeviceTypeService {
@ -159,7 +157,7 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
} }
/** /**
* Retrieve Sensor data for the given time period * Retrieve Sensor data for the given time period.
* *
* @param deviceId unique identifier for given device type instance * @param deviceId unique identifier for given device type instance
* @param from starting time * @param from starting time
@ -206,7 +204,7 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
} }
/** /**
* To download device type agent source code as zip file * To download device type agent source code as zip file.
* *
* @param deviceName name for the device type instance * @param deviceName name for the device type instance
* @param sketchType folder name where device type agent was installed into server * @param sketchType folder name where device type agent was installed into server

@ -19,11 +19,12 @@
package org.wso2.raspberrypicodebased.api.dto; package org.wso2.raspberrypicodebased.api.dto;
import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
/** /**
* These information are sent by agent in each request to server * These information are sent by agent in each request to server.
*/ */
@XmlRootElement @XmlRootElement
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)

@ -38,7 +38,7 @@ public class SensorRecord {
private Map<String, Object> values; private Map<String, Object> values;
/** /**
* Unique identifier for each recode * Unique identifier for each recode.
*/ */
@XmlElement(required = false, name = "id") @XmlElement(required = false, name = "id")
private String id; private String id;

@ -19,7 +19,7 @@
package org.wso2.raspberrypicodebased.api.exception; package org.wso2.raspberrypicodebased.api.exception;
/** /**
* Device specific exception handler * Device specific exception handler.
*/ */
public class DeviceTypeException extends Exception { public class DeviceTypeException extends Exception {

@ -18,11 +18,10 @@
package org.wso2.raspberrypicodebased.api.util; package org.wso2.raspberrypicodebased.api.util;
import org.wso2.raspberrypicodebased.api.dto.SensorRecord; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
import org.wso2.carbon.analytics.api.AnalyticsDataAPI; import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse; import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry; import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
import org.wso2.carbon.analytics.dataservice.commons.SortByField; import org.wso2.carbon.analytics.dataservice.commons.SortByField;
@ -34,8 +33,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.apache.commons.logging.Log; import org.wso2.raspberrypicodebased.api.dto.SensorRecord;
import org.apache.commons.logging.LogFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

@ -18,12 +18,15 @@
package org.wso2.raspberrypicodebased.api.util; package org.wso2.raspberrypicodebased.api.util;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants; import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
import org.wso2.carbon.core.util.Utils;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
@ -43,9 +46,6 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.wso2.carbon.core.util.Utils;
import org.json.JSONObject;
import org.apache.commons.codec.binary.Base64;
/** /**
* This is used to create a zip file that includes the necessary configuration required for the agent. * This is used to create a zip file that includes the necessary configuration required for the agent.
@ -269,10 +269,10 @@ public class ZipUtil {
ZipOutputStream out = null; ZipOutputStream out = null;
try { try {
final int BUFFER = 2048; final int buffer = 2048;
FileOutputStream dest = new FileOutputStream(new File(srcFolder + ".zip")); FileOutputStream dest = new FileOutputStream(new File(srcFolder + ".zip"));
out = new ZipOutputStream(new BufferedOutputStream(dest)); out = new ZipOutputStream(new BufferedOutputStream(dest));
byte data[] = new byte[BUFFER]; byte data[] = new byte[buffer];
File subDir = new File(srcFolder); File subDir = new File(srcFolder);
String subdirList[] = subDir.list(); String subdirList[] = subDir.list();
if (subdirList == null) { if (subdirList == null) {
@ -290,24 +290,23 @@ public class ZipUtil {
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
FileInputStream fi = new FileInputStream(srcFolder + "/" + sd + "/" + files[i]); FileInputStream fi = new FileInputStream(srcFolder + "/" + sd + "/" + files[i]);
origin = new BufferedInputStream(fi, BUFFER); origin = new BufferedInputStream(fi, buffer);
ZipEntry entry = new ZipEntry(sd + "/" + files[i]); ZipEntry entry = new ZipEntry(sd + "/" + files[i]);
out.putNextEntry(entry); out.putNextEntry(entry);
int count; int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) { while ((count = origin.read(data, 0, buffer)) != -1) {
out.write(data, 0, count); out.write(data, 0, count);
out.flush(); out.flush();
} }
} }
} else //it is just a file } else { //it is just a file
{
FileInputStream fi = new FileInputStream(f); FileInputStream fi = new FileInputStream(f);
origin = new BufferedInputStream(fi, BUFFER); origin = new BufferedInputStream(fi, buffer);
ZipEntry entry = new ZipEntry(sd); ZipEntry entry = new ZipEntry(sd);
out.putNextEntry(entry); out.putNextEntry(entry);
int count; int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) { while ((count = origin.read(data, 0, buffer)) != -1) {
out.write(data, 0, count); out.write(data, 0, count);
out.flush(); out.flush();
} }

@ -19,6 +19,7 @@
package org.wso2.raspberrypicodebased.plugin.constants; package org.wso2.raspberrypicodebased.plugin.constants;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
import java.io.File; import java.io.File;
/** /**
@ -26,20 +27,20 @@ import java.io.File;
* stream definition and device specific dome constants * stream definition and device specific dome constants
*/ */
public class DeviceTypeConstants { public class DeviceTypeConstants {
public final static String DEVICE_TYPE = "raspberrypicodebased"; public static final String DEVICE_TYPE = "raspberrypicodebased";
public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME"; public static final String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME";
public final static String DEVICE_PLUGIN_DEVICE_ID = "raspberrypicodebased_DEVICE_ID"; public static final String DEVICE_PLUGIN_DEVICE_ID = "raspberrypicodebased_DEVICE_ID";
public final static String STATE_ON = "ON"; public static final String STATE_ON = "ON";
public final static String STATE_OFF = "OFF"; public static final String STATE_OFF = "OFF";
public final static String BULB_CONTEXT = "BULB"; public static final String BULB_CONTEXT = "BULB";
//sensor events summerized table name //sensor events summerized table name
public static final String SENSOR_TYPE1_EVENT_TABLE = "ORG_WSO2_IOT_DEVICES_sensor_temp"; public static final String SENSOR_TYPE1_EVENT_TABLE = "ORG_WSO2_IOT_DEVICES_sensor_temp";
public static final String SENSOR_TYPE2_EVENT_TABLE = "ORG_WSO2_IOT_DEVICES_no_sensor1"; public static final String SENSOR_TYPE2_EVENT_TABLE = "ORG_WSO2_IOT_DEVICES_no_sensor1";
public static final String DATA_SOURCE_NAME = "jdbc/raspberrypicodebasedDM_DB"; public static final String DATA_SOURCE_NAME = "jdbc/raspberrypicodebasedDM_DB";
public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super"; public static final String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super";
public final static String SENSOR_TYPE1 = "sensor_temp"; public static final String SENSOR_TYPE1 = "sensor_temp";
public final static String SENSOR_TYPE2 = "no_sensor1"; public static final String SENSOR_TYPE2 = "no_sensor1";
//mqtt tranport related constants //mqtt tranport related constants
public static final String MQTT_ADAPTER_NAME = "sensor_temp_mqtt"; public static final String MQTT_ADAPTER_NAME = "sensor_temp_mqtt";
@ -65,8 +66,8 @@ public class DeviceTypeConstants {
public static final String CLEAR_SESSION_PROPERTY_KEY = "clearSession"; public static final String CLEAR_SESSION_PROPERTY_KEY = "clearSession";
public static final String TOPIC = "topic"; public static final String TOPIC = "topic";
public final static String SENSOR_TYPE1_STREAM_DEFINITION = "org.wso2.iot.devices.sensor_temp"; public static final String SENSOR_TYPE1_STREAM_DEFINITION = "org.wso2.iot.devices.sensor_temp";
public final static String SENSOR_TYPE1_STREAM_DEFINITION_VERSION = "1.0.0"; public static final String SENSOR_TYPE1_STREAM_DEFINITION_VERSION = "1.0.0";
public static final String MQTT_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator public static final String MQTT_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator

@ -19,7 +19,7 @@
package org.wso2.raspberrypicodebased.plugin.exception; package org.wso2.raspberrypicodebased.plugin.exception;
/** /**
* Device type plugin exception handler * Device type plugin exception handler.
*/ */
public class DeviceMgtPluginException extends Exception { public class DeviceMgtPluginException extends Exception {

@ -20,9 +20,6 @@ package org.wso2.raspberrypicodebased.plugin.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.raspberrypicodebased.plugin.impl.dao.DeviceTypeDAO;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.wso2.raspberrypicodebased.plugin.impl.feature.DeviceTypeFeatureManager;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
@ -32,8 +29,10 @@ import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.wso2.raspberrypicodebased.plugin.impl.dao.DeviceTypeDAO;
import org.wso2.raspberrypicodebased.plugin.impl.feature.DeviceTypeFeatureManager;
import java.util.ArrayList;
import java.util.List; import java.util.List;

@ -18,29 +18,25 @@
package org.wso2.raspberrypicodebased.plugin.impl; package org.wso2.raspberrypicodebased.plugin.impl;
import java.util.HashMap; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import java.util.Map; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
import org.wso2.carbon.device.mgt.common.InitialOperationConfig; import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
/**
*Devicetype manager service.
*/
public class DeviceTypeManagerService implements DeviceManagementService { public class DeviceTypeManagerService implements DeviceManagementService {
private DeviceManager deviceManager; private DeviceManager deviceManager;
private OperationMonitoringTaskConfig operationMonitoringTaskConfig; private OperationMonitoringTaskConfig operationMonitoringTaskConfig;

@ -20,10 +20,9 @@ package org.wso2.raspberrypicodebased.plugin.impl.dao;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants; import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.raspberrypicodebased.plugin.impl.dao.impl.DeviceTypeDAOImpl;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException; import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.wso2.raspberrypicodebased.plugin.impl.dao.impl.DeviceTypeDAOImpl;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
@ -33,7 +32,7 @@ import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* Database handler which is specified for raspberrypicodebased type * Database handler which is specified for raspberrypicodebased type.
*/ */
public class DeviceTypeDAO { public class DeviceTypeDAO {

@ -20,22 +20,18 @@ package org.wso2.raspberrypicodebased.plugin.impl.dao.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants; import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException; import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.wso2.raspberrypicodebased.plugin.impl.dao.DeviceTypeDAO; import org.wso2.raspberrypicodebased.plugin.impl.dao.DeviceTypeDAO;
import org.wso2.raspberrypicodebased.plugin.impl.util.DeviceTypeUtils; import org.wso2.raspberrypicodebased.plugin.impl.util.DeviceTypeUtils;
import org.wso2.carbon.device.mgt.common.Device;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Implements IotDeviceDAO for raspberrypicodebased Devices. * Implements IotDeviceDAO for raspberrypicodebased Devices.
@ -85,7 +81,8 @@ public class DeviceTypeDAOImpl {
try { try {
conn = DeviceTypeDAO.getConnection(); conn = DeviceTypeDAO.getConnection();
String createDBQuery = String createDBQuery =
"INSERT INTO raspberrypicodebased_DEVICE(raspberrypicodebased_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)"; "INSERT INTO raspberrypicodebased_DEVICE(raspberrypicodebased_DEVICE_ID, DEVICE_NAME)" +
" VALUES (?, ?)";
stmt = conn.prepareStatement(createDBQuery); stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, device.getDeviceIdentifier()); stmt.setString(1, device.getDeviceIdentifier());
stmt.setString(2, device.getName()); stmt.setString(2, device.getName());

@ -15,20 +15,17 @@
*/ */
package org.wso2.raspberrypicodebased.plugin.impl.feature; package org.wso2.raspberrypicodebased.plugin.impl.feature;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.FeatureManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Device type specific feature management server * Device type specific feature management server.
*/ */
public class DeviceTypeFeatureManager implements FeatureManager { public class DeviceTypeFeatureManager implements FeatureManager {

@ -32,8 +32,8 @@ import java.io.File;
public class DeviceSchemaInitializer extends DatabaseCreator { public class DeviceSchemaInitializer extends DatabaseCreator {
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class); private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts" private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() +
+ File.separator + "cdm" + File.separator + "plugins" + File.separator; File.separator + "dbscripts" + File.separator + "cdm" + File.separator + "plugins" + File.separator;
public DeviceSchemaInitializer(DataSource dataSource) { public DeviceSchemaInitializer(DataSource dataSource) {
super(dataSource); super(dataSource);

@ -18,32 +18,21 @@
package org.wso2.raspberrypicodebased.plugin.impl.util; package org.wso2.raspberrypicodebased.plugin.impl.util;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.Utils; import org.wso2.carbon.core.util.Utils;
import org.wso2.carbon.event.output.adapter.core.MessageType; import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/** /**
* Contains utility methods used by raspberrypicodebased plugin. * Contains utility methods used by raspberrypicodebased plugin.
@ -97,18 +86,18 @@ public class DeviceTypeUtils {
} }
public static String replaceMqttProperty(String urlWithPlaceholders) { public static String replaceMqttProperty(String urlWithPlaceholders) {
String MQTT_BROKER_HOST = null; String mqttBrokerHost = null;
String MQTT_PORT = null; String mqttPort = null;
if (!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")) { if (!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")) {
MQTT_BROKER_HOST = "\\$".concat(DeviceTypeConstants.MQTT_BROKER_HOST); mqttBrokerHost = "\\$".concat(DeviceTypeConstants.MQTT_BROKER_HOST);
} }
if (!DeviceTypeConstants.MQTT_PORT.startsWith("$")) { if (!DeviceTypeConstants.MQTT_PORT.startsWith("$")) {
MQTT_PORT = "\\$".concat(DeviceTypeConstants.MQTT_PORT); mqttPort = "\\$".concat(DeviceTypeConstants.MQTT_PORT);
} }
urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders); urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders);
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_PORT, "" + urlWithPlaceholders = urlWithPlaceholders.replaceAll(mqttPort, "" +
(DeviceTypeConstants.DEFAULT_MQTT_PORT + getPortOffset())); (DeviceTypeConstants.DEFAULT_MQTT_PORT + getPortOffset()));
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_BROKER_HOST, urlWithPlaceholders = urlWithPlaceholders.replaceAll(mqttBrokerHost,
System.getProperty(DeviceTypeConstants.DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost")); System.getProperty(DeviceTypeConstants.DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost"));
return urlWithPlaceholders; return urlWithPlaceholders;
} }

@ -18,17 +18,15 @@
package org.wso2.raspberrypicodebased.plugin.internal; package org.wso2.raspberrypicodebased.plugin.internal;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.wso2.raspberrypicodebased.plugin.impl.util.DeviceTypeUtils;
import org.wso2.raspberrypicodebased.plugin.impl.DeviceTypeManagerService;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import org.wso2.raspberrypicodebased.plugin.impl.DeviceTypeManagerService;
import org.wso2.raspberrypicodebased.plugin.impl.util.DeviceTypeUtils;
/** /**
* @scr.component name="org.wso2.raspberrypicodebased.plugin.internal.ServiceComponent" * @scr.component name="org.wso2.raspberrypicodebased.plugin.internal.ServiceComponent"

@ -20,18 +20,18 @@
""" """
import argparse import argparse
import httplib import calendar
import logging import logging
import logging.handlers import logging.handlers
import signal import signal
import ssl import ssl
import sys import sys
import threading import threading
import time, calendar import time
from functools import wraps from functools import wraps
import mqttHandler
import iotUtils import iotUtils
import mqttHandler
import running_mode import running_mode

@ -23,6 +23,7 @@
import ConfigParser import ConfigParser
import os import os
import random import random
import running_mode import running_mode
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -81,7 +82,6 @@ def switchBulb(state):
if running_mode == "N": if running_mode == "N":
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False) GPIO.setwarnings(False)
GPIO.setup(BULB_PIN,GPIO.OUT) GPIO.setup(BULB_PIN,GPIO.OUT)

@ -20,8 +20,9 @@
**/ **/
""" """
import time
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import time
import iotUtils import iotUtils
from token_updater import RefreshToken from token_updater import RefreshToken

@ -21,10 +21,10 @@
""" """
import json import json
import urllib
import iotUtils
import requests import requests
import urllib
import iotUtils
applicationKey = None applicationKey = None
refreshToken = None refreshToken = None

@ -17,7 +17,7 @@
~ under the License. ~ under the License.
--> -->
<datasources-configuration xmlns:svns="http://org.wso2.securevault/configuration"> <datasources-configuration>
<providers> <providers>
<provider>org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader</provider> <provider>org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader</provider>
</providers> </providers>

Loading…
Cancel
Save