From 46f39c09186223a41577358f7bfb681cf84da4b9 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 26 Jun 2019 19:34:09 +0530 Subject: [PATCH] Add appm device subscription update feature --- .../mgt/common/services/ApplicationManager.java | 17 ++++++++++------- .../mgt/core/dao/SubscriptionDAO.java | 2 +- .../GenericSubscriptionDAOImpl.java | 4 ++-- .../mgt/core/impl/ApplicationManagerImpl.java | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index c8ef600e7d..497b361b86 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -254,13 +254,16 @@ public interface ApplicationManager { String getInstallableLifecycleState() throws ApplicationManagementException; - /** - * Get plist content to download and install the application. - * - * @param uuid Release UUID of the application. - * @return plist string - * @throws ApplicationManagementException Application management exception - */ + void updateSubsStatus (int operationId, String status) throws ApplicationManagementException; + + + /** + * Get plist content to download and install the application. + * + * @param uuid Release UUID of the application. + * @return plist string + * @throws ApplicationManagementException Application management exception + */ String getPlistArtifact(String uuid) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index e0280c3d75..f1400cc115 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -81,6 +81,6 @@ public interface SubscriptionDAO { List getSubscribedDeviceIds(List deviceIds, int tenantId) throws ApplicationManagementDAOException; - void updateDeviceSubStatus (int operationId, String status, int tenantcId) throws ApplicationManagementDAOException; + boolean updateDeviceSubStatus (int operationId, String status, int tenantcId) throws ApplicationManagementDAOException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 365c05fca9..21d88cb53c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -577,7 +577,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public void updateDeviceSubStatus (int operationId, String status, int tenantId) throws ApplicationManagementDAOException { + public boolean updateDeviceSubStatus (int operationId, String status, int tenantId) throws ApplicationManagementDAOException { Connection conn; try { conn = this.getDBConnection(); @@ -590,7 +590,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc stmt.setString(1, status); stmt.setInt(2, operationId); stmt.setInt(3, tenantId); - stmt.executeUpdate(); + return stmt.executeUpdate() != 0; } } catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to update the subscription status of the " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 2763eb616d..3de23e03b3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -2660,6 +2660,21 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + public void updateSubsStatus (int operationId, String status) throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + if (!subscriptionDAO.updateDeviceSubStatus(operationId, status, tenantId)){ + String msg = "Didn't update an any app subscription of device for operation Id: " + operationId; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } catch (ApplicationManagementDAOException e) { + String msg = "Error occured while updating app subscription status of the device."; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } + public String getPlistArtifact(String releaseUuid) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); try {