From 38006c8ff0dfedf36b85da35f1e9406cd0bffffe Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 7 May 2019 02:19:18 +0530 Subject: [PATCH] Fix issues in lifecycle management feature --- .../mgt/common/services/ApplicationManager.java | 1 - .../application/mgt/core/dao/common/Util.java | 1 + .../impl/application/GenericApplicationDAOImpl.java | 2 ++ .../release/GenericApplicationReleaseDAOImpl.java | 3 ++- .../mgt/core/impl/ApplicationManagerImpl.java | 1 + .../mgt/core/lifecycle/LifecycleStateManager.java | 13 ++++--------- 6 files changed, 10 insertions(+), 11 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 756b4505e74..afd081193df 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 @@ -144,7 +144,6 @@ public interface ApplicationManager { /** * To get all the releases of a particular ApplicationDTO. * - * @param applicationId ID of the ApplicationDTO. * @param releaseUuid UUID of the ApplicationDTO Release. * @param stateName Lifecycle state to change the app * @throws ApplicationManagementException ApplicationDTO Management Exception. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 2a5031f843d..da51ababdad 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -129,6 +129,7 @@ public class Util { */ public static ApplicationReleaseDTO loadAppRelease(ResultSet rs) throws SQLException { ApplicationReleaseDTO appRelease = new ApplicationReleaseDTO(); + appRelease.setId(rs.getInt("RELEASE_ID")); appRelease.setDescription(rs.getString("RELEASE_DESCRIPTION")); appRelease.setUuid(rs.getString("RELEASE_UUID")); appRelease.setReleaseType(rs.getString("RELEASE_TYPE")); 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/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 2cb7aa2711c..7e362f85e74 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -144,6 +144,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " + "AP_APP_RELEASE.UUID AS RELEASE_UUID, " @@ -502,6 +503,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " + "AP_APP_RELEASE.UUID AS RELEASE_UUID, " 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/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index d3ba1cdaa88..c3eb59159c5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -226,7 +226,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements public ApplicationReleaseDTO getReleaseByUUID( String uuid, int tenantId) throws ApplicationManagementDAOException { Connection connection; String sql = - "SELECT AR.DESCRIPTION AS RELEASE_DESCRIPTION, " + "SELECT AR.ID AS RELEASE_ID, " + + "AR.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AR.VERSION AS RELEASE_VERSION, " + "AR.UUID AS RELEASE_UUID, " + "AR.RELEASE_TYPE AS RELEASE_TYPE, " 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 c5384ddcba8..ed179449677 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 @@ -1625,6 +1625,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationReleaseDTO.setCurrentState(stateName); this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId); this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); + ConnectionManagerUtil.commitDBTransaction(); } else { String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'" + " to '" + stateName + "'"; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java index 0a5d0cb1b65..552b42640a0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java @@ -47,7 +47,7 @@ public class LifecycleStateManager { if (lifecycleState.getProceedingStates() != null) { lifecycleState.getProceedingStates().replaceAll(String::toUpperCase); } - lifecycleStates.put(lifecycleState.getName(), lifecycleState); + lifecycleStates.put(lifecycleState.getName().toUpperCase(), lifecycleState); try { PermissionUtils.putPermission(lifecycleState.getPermission()); } catch (PermissionManagementException e) { @@ -123,15 +123,10 @@ public class LifecycleStateManager { } private String getPermissionForStateChange(String nextState) { - Iterator it = lifecycleStates.entrySet().iterator(); - LifecycleState nextLifecycleState; - while (it.hasNext()) { - Map.Entry pair = (Map.Entry) it.next(); - if (pair.getKey().toString().equalsIgnoreCase(nextState)) { - nextLifecycleState = lifecycleStates.get(nextState); - return nextLifecycleState.getPermission(); + for (Map.Entry lifecycyleState : lifecycleStates.entrySet()) { + if (lifecycyleState.getKey().equalsIgnoreCase(nextState)) { + return lifecycyleState.getValue().getPermission(); } - it.remove(); } return null; }