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.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<String, List<LifecycleStateVertex>> verticesObject = new HashMap<>();
Map<LifecycleStateVertex, List<LifecycleStateVertex>> 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);

@ -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;

@ -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<String, State> getLifecycleConfiguration() throws LifecycleManagementException;
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.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;

@ -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<String, State> getLifecycleConfiguration() throws LifecycleManagementException {
return lifecycleStateManager.getLifecycleConfig();
}
@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.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;

@ -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<String, State> lifecycleStatesDup = lifecycleStates;
for (State state : lifecycleStatesDup.values()) {
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);
});
}
public Map<String, State> getLifecycleConfig() throws LifecycleManagementException {
if (lifecycleStates == null){
String msg = "Lifecycle configuration in not initialized.";
log.error(msg);
throw new LifecycleManagementException(msg);
}
return lifecycleGraph;
return lifecycleStates;
}

@ -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;

@ -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;

@ -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;

Loading…
Cancel
Save