Device search in store subscription details page

revert-70ac1926
MalshaPiumini 4 years ago
parent 74c4f1004a
commit c2940a4568

@ -152,14 +152,15 @@ public interface SubscriptionManager {
/** /**
* This method is responsible to provide application subscription data for given application release UUID. * This method is responsible to provide application subscription data for given application release UUID.
* *
* @param offsetValue offset * @param request paginated request object.
* @param limitValue limit * @param status status of the devices.
* @param actionStatus status of the operation.
* @param appUUID application release UUID * @param appUUID application release UUID
* @return {@link PaginationResult} * @return {@link PaginationResult}
* @throws ApplicationManagementException if offset or limit contains incorrect values, if it couldn't find an * @throws ApplicationManagementException if offset or limit contains incorrect values, if it couldn't find an
* application release for given UUID, if an error occurred while getting device details of subscribed device ids, * application release for given UUID, if an error occurred while getting device details of subscribed device ids,
* if an error occurred while getting subscription details of given application release UUID. * if an error occurred while getting subscription details of given application release UUID.
*/ */
PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID) PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, List<String> status,String actionStatus)
throws ApplicationManagementException; throws ApplicationManagementException;
} }

@ -81,7 +81,7 @@ public interface SubscriptionDAO {
void addGroupSubscriptions(int tenantId, String subscribedBy, List<String> groups, int releaseId, String action) void addGroupSubscriptions(int tenantId, String subscribedBy, List<String> groups, int releaseId, String action)
throws ApplicationManagementDAOException; throws ApplicationManagementDAOException;
List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId) throws List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId, int tenantId) Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId, int tenantId)

@ -332,12 +332,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId) throws public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus) throws
ApplicationManagementDAOException { ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting device subscriptions for the application release id " + appReleaseId log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ " from the database"); + " from the database");
} }
boolean isActionStatusProvided = false;
String sql = "SELECT " String sql = "SELECT "
+ "DS.ID AS ID, " + "DS.ID AS ID, "
+ "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, " + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
@ -350,11 +351,19 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "DS.DM_DEVICE_ID AS DEVICE_ID " + "DS.DM_DEVICE_ID AS DEVICE_ID "
+ "FROM AP_DEVICE_SUBSCRIPTION DS " + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?"; + "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?";
if (actionStatus != null && !actionStatus.isEmpty()) {
sql += " AND DS.STATUS= ?";
isActionStatusProvided = true;
}
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId); stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
if(isActionStatusProvided){
stmt.setString(3, actionStatus);
}
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully retrieved device subscriptions for application release id " log.debug("Successfully retrieved device subscriptions for application release id "

@ -1445,7 +1445,7 @@ ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId).isEmpty()) { if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null).isEmpty()) {
String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid()
+ " either subscribed to device/s or it had subscribed to device/s. Therefore you are not " + " either subscribed to device/s or it had subscribed to device/s. Therefore you are not "
+ "permitted to delete the application release."; + "permitted to delete the application release.";
@ -1580,7 +1580,7 @@ ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null);
if (!deviceSubscriptionDTOS.isEmpty()) { if (!deviceSubscriptionDTOS.isEmpty()) {
String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid()
+ " either subscribed to device/s or it had subscribed to device/s. Therefore you " + " either subscribed to device/s or it had subscribed to device/s. Therefore you "

@ -377,7 +377,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (applicationDTO != null) { if (applicationDTO != null) {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = this.subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = this.subscriptionDAO
.getDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), .getDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
tenantId); tenantId, null);
AtomicBoolean isAppSubscribable = new AtomicBoolean(true); AtomicBoolean isAppSubscribable = new AtomicBoolean(true);
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) { for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) {
@ -1231,7 +1231,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId); .getDeviceSubscriptions(applicationReleaseId, tenantId, null);
if (deviceSubscriptionDTOS.isEmpty()) { if (deviceSubscriptionDTOS.isEmpty()) {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(new ArrayList<>()); paginationResult.setData(new ArrayList<>());
@ -1338,9 +1338,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public PaginationResult getAppSubscriptionDetails(int offsetValue, int limitValue, String appUUID) public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, List<String> status,String actionStatus)
throws ApplicationManagementException { throws ApplicationManagementException {
PaginationRequest request = new PaginationRequest(offsetValue, limitValue); int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService(); .getDeviceManagementProviderService();
@ -1362,7 +1363,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId); .getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus);
if (deviceSubscriptionDTOS.isEmpty()) { if (deviceSubscriptionDTOS.isEmpty()) {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(new ArrayList<>()); paginationResult.setData(new ArrayList<>());
@ -1375,7 +1376,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try { try {
//pass the device id list to device manager service method //pass the device id list to device manager service method
PaginationResult paginationResult = deviceManagementProviderService PaginationResult paginationResult = deviceManagementProviderService
.getAppSubscribedDevices(request, deviceIdList, null); .getAppSubscribedDevices(request, deviceIdList, status);
List<DeviceSubscriptionData> deviceSubscriptionDataList = new ArrayList<>(); List<DeviceSubscriptionData> deviceSubscriptionDataList = new ArrayList<>();
if (!paginationResult.getData().isEmpty()) { if (!paginationResult.getData().isEmpty()) {

@ -31,6 +31,7 @@ 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.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import javax.validation.constraints.Size;
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;
@ -111,6 +112,26 @@ public interface SubscriptionManagementAdminAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getAppInstalledDevices( Response getAppInstalledDevices(
@ApiParam(
name = "name",
value = "The device name. For example, Nexus devices can have names, suhc as shamu, bullhead or angler.",
required = false)
@Size(max = 45)
String name,
@ApiParam(
name = "user",
value = "The username of the owner of the device.",
required = false)
@QueryParam("user")
String user,
@ApiParam(
name = "actionStatus",
value = "Provide the action status details")
@QueryParam("actionStatus") String actionStatus,
@ApiParam(
name = "status",
value = "Provide the device status details, such as active or inactive.")
@QueryParam("status") List<String> status,
@ApiParam( @ApiParam(
name = "uuid", name = "uuid",
value = "uuid of the application release.", value = "uuid of the application release.",

@ -295,6 +295,38 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
if (ownership != null && !ownership.isEmpty()) { if (ownership != null && !ownership.isEmpty()) {
request.setOwnership(ownership); request.setOwnership(ownership);
} }
// if (status != null && !status.isEmpty()) {
// boolean isStatusEmpty = true;
// for (String statusString : status){
// if (StringUtils.isNotBlank(statusString)){
// isStatusEmpty = false;
// break;
// }
// }
// if (!isStatusEmpty) {
// for (String status_ : status) {
// switch (status_) {
// case "ACTIVE":
// case "INACTIVE":
// case "UNCLAIMED":
// case "UNREACHABLE":
// case "SUSPENDED":
// case "DISENROLLMENT_REQUESTED":
// case "REMOVED":
// case "BLOCKED":
// case "CREATED":
// break;
// default:
// String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " +
// "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
// "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED";
// log.error(msg);
// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
// }
// }
// request.setStatusList(status);
// }
// }
PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid, status); PaginationResult subscribedDeviceDetails = subscriptionManager.getAppInstalledDevices(request, uuid, status);
DeviceList devices = new DeviceList(); DeviceList devices = new DeviceList();
devices.setList((List<Device>) subscribedDeviceDetails.getData()); devices.setList((List<Device>) subscribedDeviceDetails.getData());

@ -18,16 +18,21 @@
package org.wso2.carbon.device.application.mgt.store.api.services.impl.admin; package org.wso2.carbon.device.application.mgt.store.api.services.impl.admin;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
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.apache.http.HttpStatus;
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.services.SubscriptionManager; 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.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; 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.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.admin.SubscriptionManagementAdminAPI; import org.wso2.carbon.device.application.mgt.store.api.services.admin.SubscriptionManagementAdminAPI;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import javax.validation.constraints.Size;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue; import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -36,6 +41,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
/** /**
* Implementation of Subscription Management related APIs. * Implementation of Subscription Management related APIs.
@ -51,6 +57,10 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
@Produces("application/json") @Produces("application/json")
@Path("/{uuid}") @Path("/{uuid}")
public Response getAppInstalledDevices( public Response getAppInstalledDevices(
@QueryParam("name") String name,
@QueryParam("user") String user,
@QueryParam("actionStatus") String actionStatus,
@QueryParam("status") List<String> status,
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@DefaultValue("0") @DefaultValue("0")
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ -58,9 +68,48 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
try { try {
PaginationRequest request = new PaginationRequest(offset, limit);
if (name != null && !name.isEmpty()) {
request.setDeviceName(name);
}
if (user != null && !user.isEmpty()) {
request.setOwner(user);
}
// if (status != null && !status.isEmpty()) {
// boolean isStatusEmpty = true;
// for (String statusString : status){
// if (StringUtils.isNotBlank(statusString)){
// isStatusEmpty = false;
// break;
// }
// }
// if (!isStatusEmpty) {
// for (String status_ : status) {
// switch (status_) {
// case "ACTIVE":
// case "INACTIVE":
// case "UNCLAIMED":
// case "UNREACHABLE":
// case "SUSPENDED":
// case "DISENROLLMENT_REQUESTED":
// case "REMOVED":
// case "BLOCKED":
// case "CREATED":
// break;
// default:
// String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " +
// "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
// "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED";
// log.error(msg);
// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
// }
// }
// request.setStatusList(status);
// }
// }
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscriptionData = subscriptionManager PaginationResult subscriptionData = subscriptionManager
.getAppSubscriptionDetails(offset, limit, uuid); .getAppSubscriptionDetails(request, uuid, status, actionStatus);
return Response.status(Response.Status.OK).entity(subscriptionData).build(); return Response.status(Response.Status.OK).entity(subscriptionData).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found"; String msg = "Application with application release UUID: " + uuid + " is not found";

Loading…
Cancel
Save