use of org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException in project product-iots by wso2.
the class DeviceTypeManager method modifyEnrollment.
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status;
try {
if (log.isDebugEnabled()) {
log.debug("Modifying the sampledevice device enrollment data");
}
DeviceTypeDAO.beginTransaction();
status = deviceTypeDAO.getDeviceTypeDAO().updateDevice(device);
DeviceTypeDAO.commitTransaction();
} catch (DeviceMgtPluginException e) {
try {
DeviceTypeDAO.rollbackTransaction();
} catch (DeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
log.warn(msg, iotDAOEx);
}
String msg = "Error while updating the enrollment of the sampledevice device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
use of org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException in project product-iots by wso2.
the class DeviceTypeUtils method setupDeviceManagementSchema.
public static void setupDeviceManagementSchema() throws DeviceMgtPluginException {
try {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME);
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
} catch (NamingException e) {
log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
} catch (Exception e) {
throw new DeviceMgtPluginException("Error occurred while initializing Iot Device " + "Management database schema", e);
}
}
use of org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException in project product-iots by wso2.
the class DeviceTypeDAOImpl method getDevice.
public Device getDevice(String deviceId) throws DeviceMgtPluginException {
Connection conn = null;
PreparedStatement stmt = null;
Device iotDevice = null;
ResultSet resultSet = null;
try {
conn = DeviceTypeDAO.getConnection();
String selectDBQuery = "SELECT sampledevice_DEVICE_ID, DEVICE_NAME" + " FROM sampledevice_DEVICE WHERE sampledevice_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
resultSet = stmt.executeQuery();
if (resultSet.next()) {
iotDevice = new Device();
iotDevice.setName(resultSet.getString(DeviceTypeConstants.DEVICE_PLUGIN_DEVICE_NAME));
if (log.isDebugEnabled()) {
log.debug("sampledevice device " + deviceId + " data has been fetched from " + "sampledevice database.");
}
}
} catch (SQLException e) {
String msg = "Error occurred while fetching sampledevice device : '" + deviceId + "'";
log.error(msg, e);
throw new DeviceMgtPluginException(msg, e);
} finally {
DeviceTypeUtils.cleanupResources(stmt, resultSet);
DeviceTypeDAO.closeConnection();
}
return iotDevice;
}
use of org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException in project product-iots by wso2.
the class ServiceComponent method activate.
protected void activate(ComponentContext ctx) {
if (log.isDebugEnabled()) {
log.debug("Activating b Management Service Component");
}
try {
DeviceTypeManagerService deviceTypeManagerService = new DeviceTypeManagerService();
BundleContext bundleContext = ctx.getBundleContext();
serviceRegistration = bundleContext.registerService(DeviceManagementService.class.getName(), deviceTypeManagerService, null);
String setupOption = System.getProperty("setup");
if (setupOption != null) {
if (log.isDebugEnabled()) {
log.debug("-Dsetup is enabled. Iot Device management repository schema " + "initialization is about to begin");
}
try {
DeviceTypeUtils.setupDeviceManagementSchema();
} catch (DeviceMgtPluginException e) {
log.error("Exception occurred while initializing device management database " + "schema", e);
}
}
if (log.isDebugEnabled()) {
log.debug("b Management Service Component has been successfully activated");
}
} catch (Throwable e) {
log.error("Error occurred while activating Current Sensor Management Service " + "Component", e);
}
}
use of org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException in project product-iots by wso2.
the class DeviceTypeManager method enrollDevice.
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
boolean status;
try {
if (log.isDebugEnabled()) {
log.debug("Enrolling a new sampledevice device : " + device.getDeviceIdentifier());
}
DeviceTypeDAO.beginTransaction();
status = deviceTypeDAO.getDeviceTypeDAO().addDevice(device);
DeviceTypeDAO.commitTransaction();
} catch (DeviceMgtPluginException e) {
try {
DeviceTypeDAO.rollbackTransaction();
} catch (DeviceMgtPluginException iotDAOEx) {
log.warn("Error occurred while roll back the device enrol transaction :" + device.toString(), iotDAOEx);
}
String msg = "Error while enrolling the sampledevice device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
Aggregations