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 javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
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.MediaType;
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(
info = @Info(
@ -98,7 +96,7 @@ public interface DeviceTypeService {
@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 from starting time
* @param to ending time
@ -124,7 +122,7 @@ public interface DeviceTypeService {
Response getSensorStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
@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 sketchType folder name where device type agent was installed into server
* @return Agent source code as zip file
@ -146,4 +144,4 @@ public interface DeviceTypeService {
}
)
Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType);
}
}

@ -18,13 +18,6 @@
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.logging.Log;
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.DeviceManagementException;
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.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.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.device.mgt.common.*;
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.raspberrypicodebased.api.dto.DeviceJSON;
import org.wso2.raspberrypicodebased.api.dto.SensorRecord;
import org.wso2.raspberrypicodebased.api.util.APIUtil;
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.ws.rs.Path;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@ -63,17 +62,16 @@ import javax.ws.rs.core.Response;
import java.io.IOException;
import java.nio.ByteBuffer;
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.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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 {
@ -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 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 sketchType folder name where device type agent was installed into server
@ -227,7 +225,7 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
zipFile.getZipFile().delete();
return resp;
} catch (IllegalArgumentException ex) {
return Response.status(400).entity(ex.getMessage()).build();//bad request
return Response.status(400).entity(ex.getMessage()).build(); //bad request
} catch (DeviceManagementException ex) {
log.error(ex.getMessage(), ex);
return Response.status(500).entity(ex.getMessage()).build();
@ -313,4 +311,4 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
deviceId, deviceName, accessToken, refreshToken, apiApplicationKey.toString());
return zipFile;
}
}
}

@ -19,11 +19,12 @@
package org.wso2.raspberrypicodebased.api.dto;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import javax.xml.bind.annotation.XmlElement;
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
@JsonIgnoreProperties(ignoreUnknown = true)

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

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

@ -18,11 +18,10 @@
package org.wso2.raspberrypicodebased.api.util;
import org.wso2.raspberrypicodebased.api.dto.SensorRecord;
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.SearchResultEntry;
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.core.service.DeviceManagementProviderService;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.raspberrypicodebased.api.dto.SensorRecord;
import java.util.ArrayList;
import java.util.HashMap;

@ -18,12 +18,15 @@
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.core.util.Utils;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
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.BufferedOutputStream;
import java.io.File;
@ -43,9 +46,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.zip.ZipEntry;
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.
@ -123,8 +123,8 @@ public class ZipUtil {
, String zipFileName)
throws DeviceManagementException, IOException {
String sketchPath = CarbonUtils.getCarbonHome() + File.separator + templateSketchPath;
FileUtils.deleteDirectory(new File(archivesPath));//clear directory
FileUtils.deleteDirectory(new File(archivesPath + ".zip"));//clear zip
FileUtils.deleteDirectory(new File(archivesPath)); //clear directory
FileUtils.deleteDirectory(new File(archivesPath + ".zip")); //clear zip
if (!new File(archivesPath).mkdirs()) { //new dir
String message = "Could not create directory at path: " + archivesPath;
throw new DeviceManagementException(message);
@ -269,10 +269,10 @@ public class ZipUtil {
ZipOutputStream out = null;
try {
final int BUFFER = 2048;
final int buffer = 2048;
FileOutputStream dest = new FileOutputStream(new File(srcFolder + ".zip"));
out = new ZipOutputStream(new BufferedOutputStream(dest));
byte data[] = new byte[BUFFER];
byte data[] = new byte[buffer];
File subDir = new File(srcFolder);
String subdirList[] = subDir.list();
if (subdirList == null) {
@ -290,24 +290,23 @@ public class ZipUtil {
for (int i = 0; i < files.length; 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]);
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
while ((count = origin.read(data, 0, buffer)) != -1) {
out.write(data, 0, count);
out.flush();
}
}
} else //it is just a file
{
} else { //it is just a file
FileInputStream fi = new FileInputStream(f);
origin = new BufferedInputStream(fi, BUFFER);
origin = new BufferedInputStream(fi, buffer);
ZipEntry entry = new ZipEntry(sd);
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
while ((count = origin.read(data, 0, buffer)) != -1) {
out.write(data, 0, count);
out.flush();
}

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

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

@ -20,9 +20,6 @@ package org.wso2.raspberrypicodebased.plugin.impl;
import org.apache.commons.logging.Log;
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.DeviceIdentifier;
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.license.mgt.License;
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;

@ -18,29 +18,25 @@
package org.wso2.raspberrypicodebased.plugin.impl;
import java.util.HashMap;
import java.util.Map;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
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.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.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import java.util.List;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import java.util.HashMap;
import java.util.Map;
/**
*Devicetype manager service.
*/
public class DeviceTypeManagerService implements DeviceManagementService {
private DeviceManager deviceManager;
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
@ -86,7 +82,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
properties.put("qos", "0");
properties.put("clearSession", "true");
properties.put("scopes", "");
return new PushNotificationConfig("MQTT",false, properties);
return new PushNotificationConfig("MQTT", false, properties);
}
@Override

@ -20,10 +20,9 @@ package org.wso2.raspberrypicodebased.plugin.impl.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.impl.dao.impl.DeviceTypeDAOImpl;
import javax.naming.Context;
import javax.naming.InitialContext;
@ -33,7 +32,7 @@ import java.sql.Connection;
import java.sql.SQLException;
/**
* Database handler which is specified for raspberrypicodebased type
* Database handler which is specified for raspberrypicodebased type.
*/
public class DeviceTypeDAO {
@ -129,4 +128,4 @@ public class DeviceTypeDAO {
public DeviceTypeDAOImpl getDeviceTypeDAO() {
return new DeviceTypeDAOImpl();
}
}
}

@ -20,22 +20,18 @@ package org.wso2.raspberrypicodebased.plugin.impl.dao.impl;
import org.apache.commons.logging.Log;
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.exception.DeviceMgtPluginException;
import org.wso2.raspberrypicodebased.plugin.impl.dao.DeviceTypeDAO;
import org.wso2.raspberrypicodebased.plugin.impl.util.DeviceTypeUtils;
import org.wso2.carbon.device.mgt.common.Device;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Implements IotDeviceDAO for raspberrypicodebased Devices.
@ -85,7 +81,8 @@ public class DeviceTypeDAOImpl {
try {
conn = DeviceTypeDAO.getConnection();
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.setString(1, device.getDeviceIdentifier());
stmt.setString(2, device.getName());

@ -15,20 +15,17 @@
*/
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.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import java.util.ArrayList;
import java.util.HashMap;
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 {
@ -40,7 +37,7 @@ public class DeviceTypeFeatureManager implements FeatureManager {
private static final String QUERY_PARAMS = "queryParams";
private static final String FORM_PARAMS = "formParams";
public DeviceTypeFeatureManager () {
public DeviceTypeFeatureManager() {
feature.setCode("change-status");
feature.setName("Change status of sensor: on/off");
feature.setDescription("Change status of sensor: on/off");
@ -64,35 +61,35 @@ public class DeviceTypeFeatureManager implements FeatureManager {
feature.setMetadataEntries(metadataEntries);
}
@Override
public boolean addFeature(Feature feature) throws DeviceManagementException {
return false;
}
@Override
public boolean addFeature(Feature feature) throws DeviceManagementException {
return false;
}
@Override
public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
return false;
}
@Override
public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
return false;
}
@Override
public Feature getFeature(String name) throws DeviceManagementException {
@Override
public Feature getFeature(String name) throws DeviceManagementException {
return feature;
}
}
@Override
public List<Feature> getFeatures() throws DeviceManagementException {
@Override
public List<Feature> getFeatures() throws DeviceManagementException {
List<Feature> features = new ArrayList<>();
features.add(feature);
return features;
}
}
@Override
public boolean removeFeature(String name) throws DeviceManagementException {
return false;
}
@Override
public boolean removeFeature(String name) throws DeviceManagementException {
return false;
}
@Override
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
return false;
}
@Override
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
return false;
}
}

@ -29,22 +29,22 @@ import java.io.File;
/**
* Provides methods for initializing the database script.
*/
public class DeviceSchemaInitializer extends DatabaseCreator{
public class DeviceSchemaInitializer extends DatabaseCreator {
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
+ File.separator + "cdm" + File.separator + "plugins" + File.separator;
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() +
File.separator + "dbscripts" + File.separator + "cdm" + File.separator + "plugins" + File.separator;
public DeviceSchemaInitializer(DataSource dataSource) {
super(dataSource);
}
public DeviceSchemaInitializer(DataSource dataSource) {
super(dataSource);
}
@Override
protected String getDbScriptLocation(String databaseType) {
String scriptName = databaseType + ".sql";
if (log.isDebugEnabled()) {
log.debug("Loading database script from :" + scriptName);
}
return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
}
@Override
protected String getDbScriptLocation(String databaseType) {
String scriptName = databaseType + ".sql";
if (log.isDebugEnabled()) {
log.debug("Loading database script from :" + scriptName);
}
return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
}
}

@ -18,32 +18,21 @@
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.LogFactory;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.Utils;
import org.wso2.carbon.event.output.adapter.core.MessageType;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
import org.wso2.raspberrypicodebased.plugin.constants.DeviceTypeConstants;
import org.wso2.raspberrypicodebased.plugin.exception.DeviceMgtPluginException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
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.
@ -97,18 +86,18 @@ public class DeviceTypeUtils {
}
public static String replaceMqttProperty(String urlWithPlaceholders) {
String MQTT_BROKER_HOST = null;
String MQTT_PORT = null;
if(!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")){
MQTT_BROKER_HOST = "\\$".concat(DeviceTypeConstants.MQTT_BROKER_HOST);
String mqttBrokerHost = null;
String mqttPort = null;
if (!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")) {
mqttBrokerHost = "\\$".concat(DeviceTypeConstants.MQTT_BROKER_HOST);
}
if(!DeviceTypeConstants.MQTT_PORT.startsWith("$")){
MQTT_PORT = "\\$".concat(DeviceTypeConstants.MQTT_PORT);
if (!DeviceTypeConstants.MQTT_PORT.startsWith("$")) {
mqttPort = "\\$".concat(DeviceTypeConstants.MQTT_PORT);
}
urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders);
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_PORT, "" +
urlWithPlaceholders = urlWithPlaceholders.replaceAll(mqttPort, "" +
(DeviceTypeConstants.DEFAULT_MQTT_PORT + getPortOffset()));
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_BROKER_HOST,
urlWithPlaceholders = urlWithPlaceholders.replaceAll(mqttBrokerHost,
System.getProperty(DeviceTypeConstants.DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost"));
return urlWithPlaceholders;
}

@ -18,17 +18,15 @@
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.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.core.ServerStartupObserver;
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"

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

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

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

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

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

Loading…
Cancel
Save