Add a new API endpoint to get app subscription details. See merge request entgra/carbon-device-mgt!340merge-requests/341/merge
commit
d1af3d7ed1
@ -0,0 +1,80 @@
|
||||
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class DeviceSubscriptionData {
|
||||
|
||||
private String action;
|
||||
private Timestamp actionTriggeredTimestamp;
|
||||
private String actionTriggeredBy;
|
||||
private String actionType;
|
||||
private String status;
|
||||
private Device device;
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Timestamp getActionTriggeredTimestamp() {
|
||||
return actionTriggeredTimestamp;
|
||||
}
|
||||
|
||||
public void setActionTriggeredTimestamp(Timestamp actionTriggeredTimestamp) {
|
||||
this.actionTriggeredTimestamp = actionTriggeredTimestamp;
|
||||
}
|
||||
|
||||
public String getActionTriggeredBy() {
|
||||
return actionTriggeredBy;
|
||||
}
|
||||
|
||||
public void setActionTriggeredBy(String actionTriggeredBy) {
|
||||
this.actionTriggeredBy = actionTriggeredBy;
|
||||
}
|
||||
|
||||
public String getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public void setActionType(String actionType) {
|
||||
this.actionType = actionType;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Device getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(Device device) {
|
||||
this.device = device;
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. 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.store.api.services.admin;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
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.Scopes;
|
||||
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API to handle subscription management related admin tasks.
|
||||
*/
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "Subscription Management Admin Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "SubscriptionManagementAdminService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/admin/subscription"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "subscription_management, device_management", description = "Subscription Management "
|
||||
+ "related Admin APIs")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "View Application Subscriptions",
|
||||
description = "View Application Subscriptions.",
|
||||
key = "perm:admin:app:subscription:view",
|
||||
permissions = {"/app-mgt/store/admin/subscription/view"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@Path("/admin/subscription")
|
||||
@Api(value = "Subscription Management Admin API")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface SubscriptionManagementAdminAPI {
|
||||
|
||||
String SCOPE = "scope";
|
||||
|
||||
@GET
|
||||
@Path("/{uuid}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Get subscription details of specific application.",
|
||||
notes = "This will get the subscription details of specific application",
|
||||
tags = "Subscription Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully retrieved subscription details.",
|
||||
response = List.class,
|
||||
responseContainer = "List"),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n No Application found which has application release of UUID.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting data",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getAppInstalledDevices(
|
||||
@ApiParam(
|
||||
name = "uuid",
|
||||
value = "uuid of the application release.",
|
||||
required = true)
|
||||
@PathParam("uuid") String uuid,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "The starting pagination index for the complete list of qualified items.",
|
||||
defaultValue = "0")
|
||||
@QueryParam("offset") int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Provide how many device details you require from the starting pagination index/offset.",
|
||||
defaultValue = "5")
|
||||
@QueryParam("limit") int limit
|
||||
);
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.store.api.services.impl.admin;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
|
||||
import org.wso2.carbon.device.application.mgt.store.api.services.admin.SubscriptionManagementAdminAPI;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Implementation of Subscription Management related APIs.
|
||||
*/
|
||||
@Produces({"application/json"})
|
||||
@Path("/admin/subscription")
|
||||
public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagementAdminAPI {
|
||||
|
||||
private static Log log = LogFactory.getLog(SubscriptionManagementAdminAPIImpl.class);
|
||||
|
||||
@GET
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
@Path("/{uuid}")
|
||||
public Response getAppInstalledDevices(
|
||||
@PathParam("uuid") String uuid,
|
||||
@DefaultValue("0")
|
||||
@QueryParam("offset") int offset,
|
||||
@DefaultValue("5")
|
||||
@QueryParam("limit") int limit) {
|
||||
|
||||
try {
|
||||
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
|
||||
PaginationResult subscriptionData = subscriptionManager
|
||||
.getAppSubscriptionDetails(offset, limit, uuid);
|
||||
return Response.status(Response.Status.OK).entity(subscriptionData).build();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "Application with application release UUID: " + uuid + " is not found";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Found invalid payload for getting application which has UUID: " + uuid
|
||||
+ ". Hence verify the payload";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while getting app installed devices which has application release UUID of: "
|
||||
+ uuid;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue