public static Document convertToDocument(File file) throws DeviceManagementException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); } catch (Exception e) { throw new DeviceManagementException( "Error occurred while parsing file, while converting " + "to a org.w3c.dom.Document : " + e.getMessage(), e); } }
public synchronized void initConfig() throws DeviceManagementException { try { File mobileDeviceMgtConfig = new File(mobileDeviceMgtConfigXMLPath); Document doc = MobileDeviceManagementUtil.convertToDocument(mobileDeviceMgtConfig); JAXBContext mobileDeviceMgmtContext = JAXBContext.newInstance(MobileDeviceManagementConfig.class); Unmarshaller unmarshaller = mobileDeviceMgmtContext.createUnmarshaller(); this.currentMobileDeviceConfig = (MobileDeviceManagementConfig) unmarshaller.unmarshal(doc); } catch (Exception e) { throw new DeviceManagementException( "Error occurred while initializing Mobile Device Management config", e); } }
@Override public List<Device> getAllDevices() throws DeviceManagementException { List<Device> devices; try { if (log.isDebugEnabled()) { log.debug("Fetching the details of all Arduino devices"); } devices = arduinoDAO.getDeviceDAO().getAllDevices(); } catch (ArduinoDeviceMgtPluginException e) { String msg = "Error while fetching all Arduino devices."; log.error(msg, e); throw new DeviceManagementException(msg, e); } return devices; }
@Override public List<Feature> getFeatures() throws DeviceManagementException { try { List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures(); List<Feature> featureList = new ArrayList<Feature>(mobileFeatures.size()); for (MobileFeature mobileFeature : mobileFeatures) { featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); } return featureList; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + "Android platform", e); } }
@Override public List<Device> getAllDevices() throws DeviceManagementException { List<Device> devices = null; try { if (log.isDebugEnabled()) { log.debug("Fetching the details of all Raspberrypi devices"); } List<Device> iotDevices = raspberrypiDAO.getDeviceDAO().getAllDevices(); } catch (RaspberrypiDeviceMgtPluginException e) { String msg = "Error while fetching all Raspberrypi devices."; log.error(msg, e); throw new DeviceManagementException(msg, e); } return devices; } }
@Override public Feature getFeature(String name) throws DeviceManagementException { try { MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); return feature; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the feature", e); } }
@Override public List<Device> getAllDevices() throws DeviceManagementException { List<Device> devices = null; try { if (log.isDebugEnabled()) { log.debug("Fetching the details of all Android devices"); } List<MobileDevice> mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices(); if (mobileDevices != null) { devices = new ArrayList<>(mobileDevices.size()); for (MobileDevice mobileDevice : mobileDevices) { devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); } } } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while fetching all Android devices", e); } return devices; }
@Override public TenantConfiguration getConfiguration() throws DeviceManagementException { Resource resource; try { String androidRegPath = MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath); if (resource != null) { JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); Unmarshaller unmarshaller = context.createUnmarshaller(); return (TenantConfiguration) unmarshaller.unmarshal( new StringReader(new String((byte[]) resource.getContent(), Charset. forName(MobilePluginConstants.CHARSET_UTF8)))); } return null; } catch (MobileDeviceMgtPluginException e) { throw new DeviceManagementException( "Error occurred while retrieving the Registry instance : " + e.getMessage(), e); } catch (JAXBException e) { throw new DeviceManagementException( "Error occurred while parsing the Android configuration : " + e.getMessage(), e); } catch (RegistryException e) { throw new DeviceManagementException( "Error occurred while retrieving the Registry resource of Android Configuration : " + e.getMessage(), e); } }
@Override public TenantConfiguration getConfiguration() throws DeviceManagementException { Resource resource; try { String windowsTenantRegistryPath = MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); resource = MobileDeviceManagementUtil.getRegistryResource(windowsTenantRegistryPath); if (resource != null) { JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); Unmarshaller unmarshaller = context.createUnmarshaller(); return (TenantConfiguration) unmarshaller.unmarshal( new StringReader(new String((byte[]) resource.getContent(), Charset. forName(MobilePluginConstants.CHARSET_UTF8)))); } return null; } catch (MobileDeviceMgtPluginException e) { throw new DeviceManagementException( "Error occurred while retrieving the Registry instance : " + e.getMessage(), e); } catch (JAXBException e) { throw new DeviceManagementException( "Error occurred while parsing the Windows configuration : " + e.getMessage(), e); } catch (RegistryException e) { throw new DeviceManagementException( "Error occurred while retrieving the Registry resource of Windows configuration : " + e.getMessage(), e); } }
public static ZipArchive getSketchArchive(String archivesPath, String templateSketchPath, Map contextParams, 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 if (!new File(archivesPath).mkdirs()) { //new dir String message = "Could not create directory at path: " + archivesPath; log.error(message); throw new DeviceManagementException(message); } zipFileName = zipFileName + ".zip"; try { Map<String, List<String>> properties = getProperties(sketchPath + File.separator + "sketch" + ".properties"); List<String> templateFiles = properties.get("templates"); for (String templateFile : templateFiles) { parseTemplate(templateSketchPath + File.separator + templateFile, archivesPath + File.separator + templateFile, contextParams); } templateFiles.add("sketch.properties"); // ommit copying the props file copyFolder(new File(sketchPath), new File(archivesPath), templateFiles); createZipArchive(archivesPath); FileUtils.deleteDirectory(new File(archivesPath)); File zip = new File(archivesPath + ".zip"); return new ZipArchive(zipFileName, zip); } catch (IOException ex) { throw new DeviceManagementException( "Error occurred when trying to read property " + "file sketch.properties", ex); } }
@Override public List<Feature> getFeatures() throws DeviceManagementException { try { WindowsDAOFactory.openConnection(); List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures(); List<Feature> featureList = new ArrayList<Feature>(mobileFeatures.size()); for (MobileFeature mobileFeature : mobileFeatures) { featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); } return featureList; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + "Windows platform", e); } finally { WindowsDAOFactory.closeConnection(); } }
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { Device device; try { if (log.isDebugEnabled()) { log.debug("Getting the details of Raspberrypi device : " + deviceId.getId()); } device = raspberrypiDAO.getDeviceDAO().getDevice(deviceId.getId()); } catch (RaspberrypiDeviceMgtPluginException e) { String msg = "Error while fetching the Raspberrypi device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return device; }
public List<Device> getAllDevices() throws DeviceManagementException { List<Device> devices = null; try { if (log.isDebugEnabled()) { log.debug("Fetching the details of all Windows devices"); } WindowsDAOFactory.openConnection(); List<MobileDevice> mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices(); if (mobileDevices != null) { devices = new ArrayList<>(mobileDevices.size()); for (MobileDevice mobileDevice : mobileDevices) { devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); } } } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while fetching all Windows devices", e); } finally { WindowsDAOFactory.closeConnection(); } return devices; }
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { Device device; try { if (log.isDebugEnabled()) { log.debug("Getting the details of Arduino device : " + deviceId.getId()); } device = arduinoDAO.getDeviceDAO().getDevice(deviceId.getId()); } catch (ArduinoDeviceMgtPluginException e) { String msg = "Error while fetching the Arduino device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return device; }
@Override public boolean addFeatures(List<Feature> features) throws DeviceManagementException { List<MobileFeature> mobileFeatures = new ArrayList<MobileFeature>(features.size()); for (Feature feature : features) { mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); } try { AndroidDAOFactory.beginTransaction(); featureDAO.addFeatures(mobileFeatures); AndroidDAOFactory.commitTransaction(); return true; } catch (MobileDeviceManagementDAOException e) { try { AndroidDAOFactory.rollbackTransaction(); } catch (MobileDeviceManagementDAOException e1) { log.warn("Error occurred while roll-backing the transaction", e); } throw new DeviceManagementException("Error occurred while adding the features", e); } }
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Raspberrypi device : " + deviceId.getId()); } Device iotDevice = raspberrypiDAO.getDeviceDAO().getDevice(deviceId.getId()); if (iotDevice != null) { isEnrolled = true; } } catch (RaspberrypiDeviceMgtPluginException e) { String msg = "Error while checking the enrollment status of Raspberrypi device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return isEnrolled; }
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Arduino device : " + deviceId.getId()); } Device iotDevice = arduinoDAO.getDeviceDAO().getDevice(deviceId.getId()); if (iotDevice != null) { isEnrolled = true; } } catch (ArduinoDeviceMgtPluginException e) { String msg = "Error while checking the enrollment status of Arduino device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return isEnrolled; }
@Override public boolean addFeatures(List<Feature> features) throws DeviceManagementException { List<MobileFeature> mobileFeatures = new ArrayList<MobileFeature>(features.size()); for (Feature feature : features) { mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); } try { WindowsDAOFactory.beginTransaction(); featureDAO.addFeatures(mobileFeatures); WindowsDAOFactory.commitTransaction(); return true; } catch (MobileDeviceManagementDAOException e) { WindowsDAOFactory.rollbackTransaction(); throw new DeviceManagementException("Error occurred while adding the features", e); } finally { WindowsDAOFactory.closeConnection(); } }
@Override public boolean removeFeature(String code) throws DeviceManagementException { boolean status; try { AndroidDAOFactory.beginTransaction(); featureDAO.deleteFeatureByCode(code); AndroidDAOFactory.commitTransaction(); status = true; } catch (MobileDeviceManagementDAOException e) { try { AndroidDAOFactory.rollbackTransaction(); } catch (MobileDeviceManagementDAOException e1) { log.warn("Error occurred while roll-backing the transaction", e); } throw new DeviceManagementException("Error occurred while removing the feature", e); } return status; }
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Android device : " + deviceId.getId()); } MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); if (mobileDevice != null) { isEnrolled = true; } } catch (MobileDeviceManagementDAOException e) { String msg = "Error while checking the enrollment status of Android device : " + deviceId.getId(); throw new DeviceManagementException(msg, e); } return isEnrolled; }