From 7ef9485b7d8ee5bd5a401240f4a7db44e27f2734 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 3 May 2019 21:05:46 +0530 Subject: [PATCH] Fix issues in lifecycle retrieving API --- .../services/impl/ConfigRetrieveAPIImpl.java | 17 +++----- .../device/application/mgt/common}/State.java | 2 +- .../mgt/common}/config/LifecycleState.java | 2 +- .../mgt/common/services/AppmDataHandler.java | 5 ++- .../mgt/core/config/Configuration.java | 2 +- .../mgt/core/impl/AppmDataHandlerImpl.java | 7 ++-- ...ApplicationManagementServiceComponent.java | 2 +- .../core/lifecycle/LifecycleStateManager.java | 39 ++++--------------- .../ConfigurationTest.java | 2 +- .../LifeCycleStateManagerTest.java | 4 +- .../LifecycleManagementTest.java | 2 +- 11 files changed, 29 insertions(+), 55 deletions(-) rename components/application-mgt/{org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle => org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common}/State.java (95%) rename components/application-mgt/{org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle => org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common}/config/LifecycleState.java (96%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java index b00ee9a9b9..65269f512a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ConfigRetrieveAPIImpl.java @@ -20,7 +20,6 @@ package org.wso2.carbon.device.application.mgt.api.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.api.services.ConfigRetrieveAPI; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleStateVertex; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; @@ -31,9 +30,6 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.util.HashMap; -import java.util.List; -import java.util.Map; /** * Implementation of ApplicationDTO Management related APIs. @@ -51,6 +47,11 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI { public Response getUiConfig() { AppmDataHandler dataHandler = APIUtil.getDataHandler(); UIConfiguration uiConfiguration = dataHandler.getUIConfiguration(); + if (uiConfiguration == null){ + String msg = "UI configuration is not initiated."; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } return Response.status(Response.Status.OK).entity(uiConfiguration).build(); } @@ -60,14 +61,8 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI { @Path("/lifecycle-config") public Response getLifecycleConfig() { AppmDataHandler dataHandler = APIUtil.getDataHandler(); - Map> verticesObject = new HashMap<>(); - Map> vertices = null; try { - vertices = dataHandler.getLifecycleConfiguration().getAdjVertices(); - for (LifecycleStateVertex vt : vertices.keySet()) { - verticesObject.put(vt.getLabel(), vertices.get(vt)); - } - return Response.status(Response.Status.OK).entity(verticesObject).build(); + return Response.status(Response.Status.OK).entity(dataHandler.getLifecycleConfiguration()).build(); } catch (LifecycleManagementException e) { String msg = "Error Occurred while accessing lifecycle manager."; log.error(msg); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/State.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java similarity index 95% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/State.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java index 17aefa5147..cec1555baf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/State.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/State.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.application.mgt.core.lifecycle; +package org.wso2.carbon.device.application.mgt.common; import java.util.HashSet; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java similarity index 96% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java index 7e97175470..298ec1c57a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LifecycleState.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.application.mgt.core.lifecycle.config; +package org.wso2.carbon.device.application.mgt.common.config; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java index f633c2e359..7b8a49d177 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/AppmDataHandler.java @@ -17,12 +17,13 @@ package org.wso2.carbon.device.application.mgt.common.services; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; +import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import java.io.InputStream; +import java.util.Map; public interface AppmDataHandler { /** @@ -32,7 +33,7 @@ public interface AppmDataHandler { */ UIConfiguration getUIConfiguration(); - LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException; + Map getLifecycleConfiguration() throws LifecycleManagementException; InputStream getArtifactStream(String uuid, String artifactName) 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/config/Configuration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java index 364dd81ac4..bc4b706fed 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.config; import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.List; import javax.xml.bind.annotation.XmlElement; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java index 5de4f7f134..9ea7d644f7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; +import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; @@ -38,6 +38,7 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; import java.io.InputStream; +import java.util.Map; public class AppmDataHandlerImpl implements AppmDataHandler { @@ -59,8 +60,8 @@ public class AppmDataHandlerImpl implements AppmDataHandler { } @Override - public LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException { - return lifecycleStateManager.getLifecyccleStateGraph(); + public Map getLifecycleConfiguration() throws LifecycleManagementException { + return lifecycleStateManager.getLifecycleConfig(); } @Override diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java index ecf8280eb0..15810529f9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java @@ -32,7 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.impl.AppmDataHandlerImpl; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ndatasource.core.DataSourceService; 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 a33eaedab1..078fce37e4 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 @@ -19,11 +19,10 @@ package org.wso2.carbon.device.application.mgt.core.lifecycle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleGraph; -import org.wso2.carbon.device.application.mgt.common.config.LifecycleStateVertex; +import org.wso2.carbon.device.application.mgt.common.State; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; import org.wso2.carbon.device.mgt.core.search.mgt.Constants; @@ -64,35 +63,13 @@ public class LifecycleStateManager { } } - public LifecycleGraph getLifecyccleStateGraph() throws LifecycleManagementException { - LifecycleGraph lifecycleGraph = new LifecycleGraph(); - Map lifecycleStatesDup = lifecycleStates; - - for (State state : lifecycleStatesDup.values()) { - Set proceedingStateNames = state.getProceedingStates(); - String stateName = state.getState(); - LifecycleStateVertex lifecycleStateVertex = new LifecycleStateVertex(stateName); - if (isInitialState(stateName)) { - lifecycleStateVertex.setInitialState(true); - } - if (isUpdatableState(stateName)) { - lifecycleStateVertex.setAppUpdatable(true); - } - if (isEndState(stateName)) { - lifecycleStateVertex.setEndState(true); - } - if (isInstallableState(stateName)) { - lifecycleStateVertex.setAppInstallable(true); - } - lifecycleGraph.addVertex(lifecycleStateVertex); - if (proceedingStateNames != null) { - proceedingStateNames.forEach(proceedingStateName -> { - lifecycleGraph.addVertex(proceedingStateName); - lifecycleGraph.addEdge(stateName, proceedingStateName); - }); - } + public Map getLifecycleConfig() throws LifecycleManagementException { + if (lifecycleStates == null){ + String msg = "Lifecycle configuration in not initialized."; + log.error(msg); + throw new LifecycleManagementException(msg); } - return lifecycleGraph; + return lifecycleStates; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java index cd6803a1cb..8d982de616 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ConfigurationTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.testng.annotations.Test; import org.wso2.carbon.device.application.mgt.core.config.Configuration; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java index 7dbbfe3304..95069938af 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifeCycleStateManagerTest.java @@ -1,8 +1,8 @@ package org.wso2.carbon.device.application.mgt.core; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.State; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.State; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.HashMap; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index 4d610fe62a..496b231818 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -7,7 +7,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManageme import org.wso2.carbon.device.application.mgt.core.config.Configuration; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.config.LifecycleState; import java.util.List; import java.util.Set;