Search in sources :

Example 11 with DeviceManagementException

use of org.wso2.carbon.device.mgt.common.DeviceManagementException in project product-iots by wso2.

the class ZipUtil method getSketchArchive.

/**
 * Get agent sketch.
 *
 * @param archivesPath       Path of the zip file to create.
 * @param templateSketchPath Path of the sketch.
 * @param contextParams      Map of parameters to be included in the zip file.
 * @param zipFileName        Name of the zip file.
 * @return Created zip archive.
 * @throws DeviceManagementException
 * @throws IOException
 */
public static ZipArchive getSketchArchive(String archivesPath, String templateSketchPath, Map contextParams, String zipFileName) throws DeviceManagementException, IOException {
    String sketchPath = CarbonUtils.getCarbonHome() + File.separator + templateSketchPath;
    // clear directory
    FileUtils.deleteDirectory(new File(archivesPath));
    // clear zip
    FileUtils.deleteDirectory(new File(archivesPath + ".zip"));
    if (!new File(archivesPath).mkdirs()) {
        // new dir
        String message = "Could not create directory at path: " + archivesPath;
        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);
        }
        // ommit copying the props file
        templateFiles.add("sketch.properties");
        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);
    }
}
Also used : DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) File(java.io.File)

Example 12 with DeviceManagementException

use of org.wso2.carbon.device.mgt.common.DeviceManagementException 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;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException)

Example 13 with DeviceManagementException

use of org.wso2.carbon.device.mgt.common.DeviceManagementException in project product-iots by wso2.

the class DeviceTypeManager method disenrollDevice.

@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
    boolean status;
    try {
        if (log.isDebugEnabled()) {
            log.debug("Dis-enrolling sampledevice device : " + deviceId);
        }
        DeviceTypeDAO.beginTransaction();
        status = deviceTypeDAO.getDeviceTypeDAO().deleteDevice(deviceId.getId());
        DeviceTypeDAO.commitTransaction();
    } catch (DeviceMgtPluginException e) {
        try {
            DeviceTypeDAO.rollbackTransaction();
        } catch (DeviceMgtPluginException iotDAOEx) {
            String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
            log.warn(msg, iotDAOEx);
        }
        String msg = "Error while removing the sampledevice device : " + deviceId.getId();
        log.error(msg, e);
        throw new DeviceManagementException(msg, e);
    }
    return status;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException)

Example 14 with DeviceManagementException

use of org.wso2.carbon.device.mgt.common.DeviceManagementException 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 15 with DeviceManagementException

use of org.wso2.carbon.device.mgt.common.DeviceManagementException 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

DeviceManagementException (org.wso2.carbon.device.mgt.common.DeviceManagementException)14 ConnectedCupDeviceMgtPluginException (org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException)4 DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)4 IOException (java.io.IOException)3 Date (java.util.Date)2 Path (javax.ws.rs.Path)2 Device (org.wso2.carbon.device.mgt.common.Device)2 DeviceIdentifier (org.wso2.carbon.device.mgt.common.DeviceIdentifier)2 EnrolmentInfo (org.wso2.carbon.device.mgt.common.EnrolmentInfo)2 ZipArchive (org.wso2.iot.sampledevice.api.util.ZipArchive)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 APIManagementProviderService (org.wso2.carbon.apimgt.application.extension.APIManagementProviderService)1