Search in sources :

Example 6 with ConnectedCupDeviceMgtPluginException

use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.

the class ConnectedCupDAO method updateDevice.

public boolean updateDevice(Device connectedCupDevice) throws ConnectedCupDeviceMgtPluginException {
    boolean status = false;
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        conn = ConnectedCupDAOUtil.getConnection();
        String updateDBQuery = "UPDATE CONNECTED_CUP_DEVICE SET  DEVICE_NAME = ? WHERE CONNECTED_CUP_DEVICE_ID = ?";
        stmt = conn.prepareStatement(updateDBQuery);
        stmt.setString(1, connectedCupDevice.getName());
        stmt.setString(2, connectedCupDevice.getDeviceIdentifier());
        int rows = stmt.executeUpdate();
        if (rows > 0) {
            status = true;
            if (log.isDebugEnabled()) {
                log.debug("Connected Cup device " + connectedCupDevice.getDeviceIdentifier() + " data has been modified.");
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while modifying the Connected Cup device '" + connectedCupDevice.getDeviceIdentifier() + "' data.";
        log.error(msg, e);
        throw new ConnectedCupDeviceMgtPluginException(msg, e);
    } finally {
        ConnectedCupUtils.cleanupResources(stmt, null);
    }
    return status;
}
Also used : ConnectedCupDeviceMgtPluginException(org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 7 with ConnectedCupDeviceMgtPluginException

use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.

the class ConnectedCupDAO method deleteDevice.

public boolean deleteDevice(String deviceId) throws ConnectedCupDeviceMgtPluginException {
    boolean status = false;
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        conn = ConnectedCupDAOUtil.getConnection();
        String deleteDBQuery = "DELETE FROM CONNECTED_CUP_DEVICE WHERE CONNECTED_CUP_DEVICE_ID = ?";
        stmt = conn.prepareStatement(deleteDBQuery);
        stmt.setString(1, deviceId);
        int rows = stmt.executeUpdate();
        if (rows > 0) {
            status = true;
            if (log.isDebugEnabled()) {
                log.debug("Connected Cup device " + deviceId + " data has deleted" + " from the Connected Cup database.");
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while deleting Connected Cup device " + deviceId;
        log.error(msg, e);
        throw new ConnectedCupDeviceMgtPluginException(msg, e);
    } finally {
        ConnectedCupUtils.cleanupResources(stmt, null);
    }
    return status;
}
Also used : ConnectedCupDeviceMgtPluginException(org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 8 with ConnectedCupDeviceMgtPluginException

use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.

the class ConnectedCupDAO method getAllDevices.

public List<Device> getAllDevices() throws ConnectedCupDeviceMgtPluginException {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet resultSet = null;
    Device connectedCupDevice;
    List<Device> iotDevices = new ArrayList<>();
    try {
        conn = ConnectedCupDAOUtil.getConnection();
        String selectDBQuery = "SELECT CONNECTED_CUP_DEVICE_ID, DEVICE_NAME" + "FROM CONNECTED_CUP_DEVICE";
        stmt = conn.prepareStatement(selectDBQuery);
        resultSet = stmt.executeQuery();
        while (resultSet.next()) {
            connectedCupDevice = new Device();
            connectedCupDevice.setDeviceIdentifier(resultSet.getString(ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_ID));
            connectedCupDevice.setName(resultSet.getString(ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_NAME));
        }
        if (log.isDebugEnabled()) {
            log.debug("All Connected Cup device details have fetched from Connected Cup database" + ".");
        }
        return iotDevices;
    } catch (SQLException e) {
        String msg = "Error occurred while fetching all Connected Cup device data'";
        log.error(msg, e);
        throw new ConnectedCupDeviceMgtPluginException(msg, e);
    } finally {
        ConnectedCupUtils.cleanupResources(stmt, resultSet);
        ConnectedCupDAOUtil.closeConnection();
    }
}
Also used : ConnectedCupDeviceMgtPluginException(org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException) SQLException(java.sql.SQLException) Device(org.wso2.carbon.device.mgt.common.Device) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 9 with ConnectedCupDeviceMgtPluginException

use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.

the class ConnectedCupManager method enrollDevice.

@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
    boolean status;
    try {
        if (log.isDebugEnabled()) {
            log.debug("Enrolling a new Connected Cup device : " + device.getDeviceIdentifier());
        }
        ConnectedCupDAOUtil.beginTransaction();
        status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().addDevice(device);
        ConnectedCupDAOUtil.commitTransaction();
    } catch (ConnectedCupDeviceMgtPluginException e) {
        try {
            ConnectedCupDAOUtil.rollbackTransaction();
        } catch (ConnectedCupDeviceMgtPluginException iotDAOEx) {
            String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
            log.warn(msg, iotDAOEx);
        }
        String msg = "Error while enrolling the Connected Cup device : " + device.getDeviceIdentifier();
        log.error(msg, e);
        throw new DeviceManagementException(msg, e);
    }
    return status;
}
Also used : ConnectedCupDeviceMgtPluginException(org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException) DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException)

Example 10 with ConnectedCupDeviceMgtPluginException

use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.

the class ConnectedCupManager method updateDeviceInfo.

@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
    boolean status;
    try {
        if (log.isDebugEnabled()) {
            log.debug("updating the details of Connected Cup device : " + deviceIdentifier);
        }
        ConnectedCupDAOUtil.beginTransaction();
        status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().updateDevice(device);
        ConnectedCupDAOUtil.commitTransaction();
    } catch (ConnectedCupDeviceMgtPluginException e) {
        try {
            ConnectedCupDAOUtil.rollbackTransaction();
        } catch (ConnectedCupDeviceMgtPluginException iotDAOEx) {
            String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
            log.warn(msg, iotDAOEx);
        }
        String msg = "Error while updating the Connected Cup device : " + deviceIdentifier;
        log.error(msg, e);
        throw new DeviceManagementException(msg, e);
    }
    return status;
}
Also used : ConnectedCupDeviceMgtPluginException(org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException) DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException)

Aggregations

ConnectedCupDeviceMgtPluginException (org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException)10 Connection (java.sql.Connection)6 SQLException (java.sql.SQLException)6 PreparedStatement (java.sql.PreparedStatement)5 DeviceManagementException (org.wso2.carbon.device.mgt.common.DeviceManagementException)4 ResultSet (java.sql.ResultSet)2 Device (org.wso2.carbon.device.mgt.common.Device)2 ArrayList (java.util.ArrayList)1