forked from community/device-mgt-core
parent
6605c1372b
commit
071e45129d
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.api.services;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Info;
|
||||
import io.swagger.annotations.SwaggerDefinition;
|
||||
import io.swagger.annotations.Tag;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "Lifecycle Management Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "LifecycleManagementService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/lifecycle"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "lifecycle_management", description = "Lifecycle Management related APIs")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Get Lifecycle Details",
|
||||
description = "Get lifecycle details",
|
||||
key = "perm:lifecycle:get",
|
||||
permissions = {"/device-mgt/lifecycle/get"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Add a lifecycle state",
|
||||
description = "Add a lifecycle state",
|
||||
key = "perm:lifecycle:add",
|
||||
permissions = {"/device-mgt/lifecycle/add"}
|
||||
),
|
||||
}
|
||||
)
|
||||
@Path("/lifecycle")
|
||||
@Api(value = "Lifecycle Management", description = "This API carries all lifecycle management related operations.")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface LifecycleManagementAPI {
|
||||
|
||||
@GET
|
||||
@Path("/states")
|
||||
Response getLifecycleStates();
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
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.APIUtil;
|
||||
import org.wso2.carbon.device.application.mgt.api.services.LifecycleManagementAPI;
|
||||
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
|
||||
import org.wso2.carbon.device.application.mgt.common.User;
|
||||
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.services.ApplicationManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/lifecycle")
|
||||
public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
|
||||
|
||||
private static Log log = LogFactory.getLog(LifecycleManagementAPIImpl.class);
|
||||
|
||||
@GET
|
||||
@Path("/states")
|
||||
public Response getLifecycleStates() {
|
||||
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
|
||||
List<LifecycleState> lifecycleStates = new ArrayList<>();
|
||||
try {
|
||||
lifecycleStates = lifecycleStateManager.getLifecycleStates();
|
||||
} catch (LifecycleManagementException e) {
|
||||
String msg = "Error occurred while retrieving lifecycle states.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(lifecycleStates).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/states")
|
||||
public Response addLifecycleState(LifecycleState state) {
|
||||
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
|
||||
try {
|
||||
lifecycleStateManager.addLifecycleState(state);
|
||||
} catch (LifecycleManagementException e) {
|
||||
String msg = "Error occurred while adding lifecycle state.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity("Lifecycle state added successfully.").build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/states/{identifier}")
|
||||
public Response deleteLifecycleState(@PathParam("identifier") String identifier) {
|
||||
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
|
||||
try {
|
||||
lifecycleStateManager.deleteLifecycleState(identifier);
|
||||
} catch (LifecycleManagementException e) {
|
||||
String msg = "Error occurred while deleting lifecycle state.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity("Lifecycle state deleted successfully.").build();
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception caused during the lifecycle management.
|
||||
*/
|
||||
public class LifecycleManagementException extends ApplicationManagementException {
|
||||
|
||||
public LifecycleManagementException(String message, Throwable ex) {
|
||||
super(message, ex);
|
||||
}
|
||||
|
||||
public LifecycleManagementException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.exception;
|
||||
|
||||
public class DAOException extends Exception {
|
||||
|
||||
public DAOException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue