public Device getDevice(String iotDeviceId) throws DigitalDisplayDeviceMgtPluginException { Connection conn = null; PreparedStatement stmt = null; Device device = null; ResultSet resultSet = null; try { conn = DigitalDisplayDAO.getConnection(); String selectDBQuery = "SELECT DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME" + " FROM DIGITAL_DISPLAY_DEVICE WHERE DIGITAL_DISPLAY_DEVICE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, iotDeviceId); resultSet = stmt.executeQuery(); if (resultSet.next()) { device = new Device(); device.setName(resultSet.getString(DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_NAME)); if (log.isDebugEnabled()) { log.debug( "Digital Display device " + iotDeviceId + " data has been fetched from " + "Digital Display database."); } } } catch (SQLException e) { String msg = "Error occurred while fetching Digital Display device : '" + iotDeviceId + "'"; log.error(msg, e); throw new DigitalDisplayDeviceMgtPluginException(msg, e); } finally { DigitalDisplayUtils.cleanupResources(stmt, resultSet); DigitalDisplayDAO.closeConnection(); } return device; }
private boolean register(String deviceId, String name) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { return false; } Device device = new Device(); device.setDeviceIdentifier(deviceId); EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); enrolmentInfo.setDateOfEnrolment(new Date().getTime()); enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); device.setName(name); device.setType(VirtualFireAlarmConstants.DEVICE_TYPE); enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); device.setEnrolmentInfo(enrolmentInfo); return APIUtil.getDeviceManagementService().enrollDevice(device); } catch (DeviceManagementException e) { log.error(e.getMessage(), e); return false; } }
public List<Device> getAllDevices() throws DigitalDisplayDeviceMgtPluginException { Connection conn = null; PreparedStatement stmt = null; ResultSet resultSet = null; Device iotDevice; List<Device> iotDevices = new ArrayList<Device>(); try { conn = DigitalDisplayDAO.getConnection(); String selectDBQuery = "SELECT DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME FROM DIGITAL_DISPLAY_DEVICE"; stmt = conn.prepareStatement(selectDBQuery); resultSet = stmt.executeQuery(); while (resultSet.next()) { iotDevice = new Device(); iotDevice.setDeviceIdentifier( resultSet.getString(DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_ID)); iotDevice.setName(resultSet.getString(DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_NAME)); iotDevices.add(iotDevice); } if (log.isDebugEnabled()) { log.debug("All Digital Display device details have fetched from Digital Display database."); } return iotDevices; } catch (SQLException e) { String msg = "Error occurred while fetching all Digital Display device data'"; log.error(msg, e); throw new DigitalDisplayDeviceMgtPluginException(msg, e); } finally { DigitalDisplayUtils.cleanupResources(stmt, resultSet); DigitalDisplayDAO.closeConnection(); } }