Added new filter in subscription details page

revert-70ac1926
MalshaPiumini 4 years ago
parent 645fc43136
commit dca6b53a67

@ -152,12 +152,13 @@ public interface SubscriptionManager {
*
* @param request paginated request object.
* @param actionStatus status of the operation.
* @param action action related to the device.
* @param appUUID application release UUID
* @return {@link PaginationResult}
* @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,
* if an error occurred while getting subscription details of given application release UUID.
*/
PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus)
PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action)
throws ApplicationManagementException;
}

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

@ -332,13 +332,15 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus) throws
public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus, String action) throws
ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ " from the database");
}
boolean isActionStatusProvided = false;
boolean isActionProvided = false;
int index = 1;
String sql = "SELECT "
+ "DS.ID AS ID, "
+ "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
@ -356,13 +358,24 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
sql += " AND DS.STATUS= ?";
isActionStatusProvided = true;
}
if (action != null && !action.isEmpty()) {
sql += " AND DS.UNSUBSCRIBED= ?";
isActionProvided = true;
}
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
if(isActionStatusProvided){
stmt.setString(3, actionStatus);
stmt.setInt(index++, appReleaseId);
stmt.setInt(index++, tenantId);
if (isActionStatusProvided) {
stmt.setString(index++, actionStatus);
}
if (isActionProvided) {
if (action.equals("SUBSCRIBED")) {
stmt.setString(index, "FALSE");
} else {
stmt.setString(index, "TRUE");
}
}
try (ResultSet rs = stmt.executeQuery()) {
if (log.isDebugEnabled()) {

@ -1445,7 +1445,7 @@ ApplicationManagerImpl implements ApplicationManager {
log.error(msg);
throw new ForbiddenException(msg);
}
if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null).isEmpty()) {
if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null, null).isEmpty()) {
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 "
+ "permitted to delete the application release.";
@ -1580,7 +1580,7 @@ ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.beginDBTransaction();
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null);
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null, null);
if (!deviceSubscriptionDTOS.isEmpty()) {
String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid()
+ " 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) {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = this.subscriptionDAO
.getDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
tenantId, null);
tenantId, null, null);
AtomicBoolean isAppSubscribable = new AtomicBoolean(true);
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) {
@ -1231,7 +1231,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId, null);
.getDeviceSubscriptions(applicationReleaseId, tenantId, null, null);
if (deviceSubscriptionDTOS.isEmpty()) {
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(new ArrayList<>());
@ -1338,8 +1338,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus)
throws ApplicationManagementException {
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
String action) throws ApplicationManagementException {
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1363,7 +1363,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus);
.getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus, action);
if (deviceSubscriptionDTOS.isEmpty()) {
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(new ArrayList<>());

@ -124,6 +124,12 @@ public interface SubscriptionManagementAdminAPI {
required = false)
@QueryParam("user")
String user,
@ApiParam(
name = "action",
value = "The action, subscribed or unsubscribed.",
required = false)
@Size(max = 45)
@QueryParam("action") String action,
@ApiParam(
name = "actionStatus",
value = "Provide the action status details")

@ -18,11 +18,9 @@
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.LogFactory;
import org.apache.http.HttpStatus;
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;
@ -33,7 +31,6 @@ import org.wso2.carbon.device.application.mgt.store.api.services.impl.util.Reque
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import javax.validation.constraints.Size;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
@ -60,6 +57,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
public Response getAppInstalledDevices(
@QueryParam("name") String name,
@QueryParam("user") String user,
@QueryParam("action") String action,
@QueryParam("actionStatus") String actionStatus,
@QueryParam("status") List<String> status,
@PathParam("uuid") String uuid,
@ -76,6 +74,9 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
if (user != null && !user.isEmpty()) {
request.setOwner(user);
}
if (action != null && !action.isEmpty()) {
RequestValidationUtil.validateAction(action);
}
if (status != null && !status.isEmpty()) {
boolean isStatusEmpty = true;
for (String statusString : status) {
@ -96,7 +97,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
}
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails
(request, uuid, actionStatus);
(request, uuid, actionStatus, action);
return Response.status(Response.Status.OK).entity(subscriptionData).build();
} catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found";

@ -57,6 +57,20 @@ public class RequestValidationUtil {
}
}
/**
* Checks if user requested action is valid.
*
* @param action action upon to filter devices using action
*/
public static void validateAction(String action) throws BadRequestException {
if (action.equals("SUBSCRIBED") || action.equals("UNSUBSCRIBED")) {
} else {
String msg = "Invalid action type received.Valid action types are SUBSCRIBED | UNSUBSCRIBED";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Checks if user requested ownerships are valid.
*

@ -906,7 +906,6 @@ public interface DeviceManagementProviderService {
*
* @param devicesIds devices ids of the subscribed devices.
* @param request paginated request object.
* @param status status of the devices.
* @return {@link PaginationResult}
* @throws DeviceManagementException if any service level or DAO level error occurs.
*/

Loading…
Cancel
Save