From de9beb1f5bbd5deb485a1a6b8b7a095cc3f18520 Mon Sep 17 00:00:00 2001 From: Harshan Liyanage Date: Thu, 15 Jun 2017 14:49:40 +0530 Subject: [PATCH] Code refatcored. --- ...ApplicationManagerProviderServiceImpl.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 34080c188d..bf078a7b56 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -265,16 +265,22 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem @Override public List getApplicationListForDevice( DeviceIdentifier deviceId) throws ApplicationManagementException { + Device device = null; try { - Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId, + device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId, false); - if (device == null) { - if (log.isDebugEnabled()) { - log.debug("No device is found upon the device identifier '" + deviceId.getId() + - "' and type '" + deviceId.getType() + "'. Therefore returning null"); - } - return null; + } catch (DeviceManagementException e) { + throw new ApplicationManagementException("Error occurred while fetching the device of '" + + deviceId.getType() + "' carrying the identifier'" + deviceId.getId(), e); + } + if (device == null) { + if (log.isDebugEnabled()) { + log.debug("No device is found upon the device identifier '" + deviceId.getId() + + "' and type '" + deviceId.getType() + "'. Therefore returning null"); } + return null; + } + try { DeviceManagementDAOFactory.openConnection(); return applicationDAO.getInstalledApplications(device.getId()); } catch (DeviceManagementDAOException e) { @@ -282,10 +288,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem deviceId.getType() + "' device carrying the identifier'" + deviceId.getId(), e); } catch (SQLException e) { throw new ApplicationManagementException("Error occurred while opening a connection to the data source", e); - } catch (DeviceManagementException e) { - throw new ApplicationManagementException("Error occurred while fetching the device of '" + - deviceId.getType() + "' carrying the identifier'" + deviceId.getId(), e); - } finally { + } finally { DeviceManagementDAOFactory.closeConnection(); } }