lifecycle management changes

feature/appm-store/pbac
Chathura Ekanayake 7 years ago
parent 3f279918eb
commit 9f76f51ee0

@ -18,6 +18,9 @@
package org.wso2.carbon.device.application.mgt.api.services; package org.wso2.carbon.device.application.mgt.api.services;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension; import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info; import io.swagger.annotations.Info;
@ -25,13 +28,19 @@ import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag; import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.Platform;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
@SwaggerDefinition( @SwaggerDefinition(
info = @Info( info = @Info(
@ -40,7 +49,7 @@ import javax.ws.rs.core.Response;
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = "name", value = "LifecycleManagementService"), @ExtensionProperty(name = "name", value = "LifecycleManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/lifecycle"), @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/lifecycles"),
}) })
} }
), ),
@ -54,23 +63,115 @@ import javax.ws.rs.core.Response;
name = "Get Lifecycle Details", name = "Get Lifecycle Details",
description = "Get lifecycle details", description = "Get lifecycle details",
key = "perm:lifecycle:get", key = "perm:lifecycle:get",
permissions = {"/device-mgt/lifecycle/get"} permissions = {"/device-mgt/lifecycles/get"}
), ),
@Scope( @Scope(
name = "Add a lifecycle state", name = "Add a lifecycle state",
description = "Add a lifecycle state", description = "Add a lifecycle state",
key = "perm:lifecycle:add", key = "perm:lifecycle:add",
permissions = {"/device-mgt/lifecycle/add"} permissions = {"/device-mgt/lifecycles/add"}
), ),
@Scope(
name = "Delete a lifecycle state",
description = "Delete a lifecycle state",
key = "perm:lifecycle:delete",
permissions = {"/device-mgt/lifecycles/delete"}
)
} }
) )
@Path("/lifecycle") @Path("/lifecycles")
@Api(value = "Lifecycle Management", description = "This API carries all lifecycle management related operations.") @Api(value = "Lifecycle Management", description = "This API carries all lifecycle management related operations.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface LifecycleManagementAPI { public interface LifecycleManagementAPI {
String SCOPE = "scope";
@GET @GET
@Path("/states") @Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get lifecycle states",
notes = "Get all lifecycle states",
tags = "Lifecycle Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:lifecycle:get")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved lifecycle states.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the lifecycle list.",
response = ErrorResponse.class)
})
Response getLifecycleStates(); Response getLifecycleStates();
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add a lifecycle state",
notes = "This will add a new lifecycle state",
tags = "Lifecycle Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:lifecycle:add")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully add a lifecycle state.",
response = Application.class),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred adding a lifecycle state.",
response = ErrorResponse.class)
})
Response addLifecycleState(LifecycleState state);
@Path("/{identifier}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Remove lifecycle state",
notes = "Remove lifecycle state",
tags = "Lifecycle Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:platform:remove")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the platform"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting the platform.",
response = ErrorResponse.class)
})
Response deleteLifecycleState(@PathParam("identifier") String identifier);
} }

@ -38,13 +38,12 @@ import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Path("/lifecycle") @Path("/lifecycles")
public class LifecycleManagementAPIImpl implements LifecycleManagementAPI { public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
private static Log log = LogFactory.getLog(LifecycleManagementAPIImpl.class); private static Log log = LogFactory.getLog(LifecycleManagementAPIImpl.class);
@GET @GET
@Path("/states")
public Response getLifecycleStates() { public Response getLifecycleStates() {
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
List<LifecycleState> lifecycleStates = new ArrayList<>(); List<LifecycleState> lifecycleStates = new ArrayList<>();
@ -59,7 +58,6 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
} }
@POST @POST
@Path("/states")
public Response addLifecycleState(LifecycleState state) { public Response addLifecycleState(LifecycleState state) {
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
try { try {
@ -73,7 +71,7 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
} }
@DELETE @DELETE
@Path("/states/{identifier}") @Path("/{identifier}")
public Response deleteLifecycleState(@PathParam("identifier") String identifier) { public Response deleteLifecycleState(@PathParam("identifier") String identifier) {
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
try { try {

@ -27,6 +27,7 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<jaxrs:serviceBeans> <jaxrs:serviceBeans>
<ref bean="applicationMgtServiceBean"/> <ref bean="applicationMgtServiceBean"/>
<ref bean="platformMgtServiceBean"/> <ref bean="platformMgtServiceBean"/>
<ref bean="lifecycleMgtServiceBean"/>
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
<ref bean="jsonProvider"/> <ref bean="jsonProvider"/>
@ -35,6 +36,7 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.ApplicationManagementAPIImpl"/> <bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.ApplicationManagementAPIImpl"/>
<bean id="platformMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.PlatformManagementAPIImpl" /> <bean id="platformMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.PlatformManagementAPIImpl" />
<bean id="lifecycleMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.LifecycleManagementAPIImpl" />
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.api.JSONMessageHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.api.JSONMessageHandler"/>
</beans> </beans>

@ -44,6 +44,19 @@ public class ConnectionManagerUtil {
private static ThreadLocal<TxState> currentTxState = new ThreadLocal<>(); private static ThreadLocal<TxState> currentTxState = new ThreadLocal<>();
private static DataSource dataSource; private static DataSource dataSource;
public static void openDBConnection() throws DBConnectionException {
Connection conn = currentConnection.get();
if (conn != null) {
throw new IllegalTransactionStateException("Database connection has already been obtained.");
}
try {
conn = dataSource.getConnection();
} catch (SQLException e) {
throw new DBConnectionException("Failed to get a database connection.", e);
}
currentConnection.set(conn);
}
public static Connection getDBConnection() throws DBConnectionException { public static Connection getDBConnection() throws DBConnectionException {
Connection conn = currentConnection.get(); Connection conn = currentConnection.get();
if (conn == null) { if (conn == null) {

Loading…
Cancel
Save