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 static Device convertToDevice(MobileDevice mobileDevice) { Device device = null; if (mobileDevice != null) { device = new Device(); List<Device.Property> propertyList = new ArrayList<Device.Property>(); propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); propertyList.add(getProperty(MOBILE_DEVICE_OS_BUILD_DATE, mobileDevice.getOsBuildDate())); propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); if (mobileDevice.getLatitude() != null) { propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); } if (mobileDevice.getLongitude() != null) { propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); } propertyList.add(getProperty(MOBILE_DEVICE_SERIAL, mobileDevice.getSerial())); if (mobileDevice.getDeviceProperties() != null) { for (Map.Entry<String, String> deviceProperty : mobileDevice.getDeviceProperties().entrySet()) { propertyList.add(getProperty(deviceProperty.getKey(), deviceProperty.getValue())); } } device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; }
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(); } }