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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations