Fix issues in lifecycle retrieving API

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 1100db4d67
commit 7ef9485b7d

@ -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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.api.services.ConfigRetrieveAPI; 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.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; 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.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* Implementation of ApplicationDTO Management related APIs. * Implementation of ApplicationDTO Management related APIs.
@ -51,6 +47,11 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI {
public Response getUiConfig() { public Response getUiConfig() {
AppmDataHandler dataHandler = APIUtil.getDataHandler(); AppmDataHandler dataHandler = APIUtil.getDataHandler();
UIConfiguration uiConfiguration = dataHandler.getUIConfiguration(); 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(); return Response.status(Response.Status.OK).entity(uiConfiguration).build();
} }
@ -60,14 +61,8 @@ public class ConfigRetrieveAPIImpl implements ConfigRetrieveAPI {
@Path("/lifecycle-config") @Path("/lifecycle-config")
public Response getLifecycleConfig() { public Response getLifecycleConfig() {
AppmDataHandler dataHandler = APIUtil.getDataHandler(); AppmDataHandler dataHandler = APIUtil.getDataHandler();
Map<String, List<LifecycleStateVertex>> verticesObject = new HashMap<>();
Map<LifecycleStateVertex, List<LifecycleStateVertex>> vertices = null;
try { try {
vertices = dataHandler.getLifecycleConfiguration().getAdjVertices(); return Response.status(Response.Status.OK).entity(dataHandler.getLifecycleConfiguration()).build();
for (LifecycleStateVertex vt : vertices.keySet()) {
verticesObject.put(vt.getLabel(), vertices.get(vt));
}
return Response.status(Response.Status.OK).entity(verticesObject).build();
} catch (LifecycleManagementException e) { } catch (LifecycleManagementException e) {
String msg = "Error Occurred while accessing lifecycle manager."; String msg = "Error Occurred while accessing lifecycle manager.";
log.error(msg); log.error(msg);

@ -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.HashSet;
import java.util.List; import java.util.List;

@ -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.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;

@ -17,12 +17,13 @@
package org.wso2.carbon.device.application.mgt.common.services; 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.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
public interface AppmDataHandler { public interface AppmDataHandler {
/** /**
@ -32,7 +33,7 @@ public interface AppmDataHandler {
*/ */
UIConfiguration getUIConfiguration(); UIConfiguration getUIConfiguration();
LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException; Map<String, State> getLifecycleConfiguration() throws LifecycleManagementException;
InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException; InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException;
} }

@ -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.RatingConfiguration;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; 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 java.util.List;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;

@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; 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 org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
public class AppmDataHandlerImpl implements AppmDataHandler { public class AppmDataHandlerImpl implements AppmDataHandler {
@ -59,8 +60,8 @@ public class AppmDataHandlerImpl implements AppmDataHandler {
} }
@Override @Override
public LifecycleGraph getLifecycleConfiguration() throws LifecycleManagementException { public Map<String, State> getLifecycleConfiguration() throws LifecycleManagementException {
return lifecycleStateManager.getLifecyccleStateGraph(); return lifecycleStateManager.getLifecycleConfig();
} }
@Override @Override

@ -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.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.impl.AppmDataHandlerImpl; 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.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.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.ndatasource.core.DataSourceService;

@ -19,11 +19,10 @@ package org.wso2.carbon.device.application.mgt.core.lifecycle;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
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.LifecycleStateVertex;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; 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.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.common.permission.mgt.PermissionManagementException;
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils;
import org.wso2.carbon.device.mgt.core.search.mgt.Constants; import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
@ -64,35 +63,13 @@ public class LifecycleStateManager {
} }
} }
public LifecycleGraph getLifecyccleStateGraph() throws LifecycleManagementException { public Map<String, State> getLifecycleConfig() throws LifecycleManagementException {
LifecycleGraph lifecycleGraph = new LifecycleGraph(); if (lifecycleStates == null){
Map<String, State> lifecycleStatesDup = lifecycleStates; String msg = "Lifecycle configuration in not initialized.";
log.error(msg);
for (State state : lifecycleStatesDup.values()) { throw new LifecycleManagementException(msg);
Set<String> 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);
});
}
} }
return lifecycleGraph; return lifecycleStates;
} }

@ -21,7 +21,7 @@ import org.junit.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.device.application.mgt.core.config.Configuration; 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.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; import java.util.List;

@ -1,8 +1,8 @@
package org.wso2.carbon.device.application.mgt.core; 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.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.State; import org.wso2.carbon.device.application.mgt.common.State;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;

@ -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.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; 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.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.List;
import java.util.Set; import java.util.Set;

Loading…
Cancel
Save