mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added new filter in subscription details page
(cherry picked from commit dca6b53a67)
This commit is contained in:
parent
4664bb24e5
commit
fc67e8b7aa
@ -152,12 +152,13 @@ public interface SubscriptionManager {
|
|||||||
*
|
*
|
||||||
* @param request paginated request object.
|
* @param request paginated request object.
|
||||||
* @param actionStatus status of the operation.
|
* @param actionStatus status of the operation.
|
||||||
|
* @param action action related to the device.
|
||||||
* @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(PaginationRequest request, String appUUID, String actionStatus)
|
PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action)
|
||||||
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, String actionStatus) throws
|
List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId, String actionStatus, String action) 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,13 +332,15 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
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;
|
boolean isActionStatusProvided = false;
|
||||||
|
boolean isActionProvided = false;
|
||||||
|
int index = 1;
|
||||||
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, "
|
||||||
@ -356,13 +358,24 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
sql += " AND DS.STATUS= ?";
|
sql += " AND DS.STATUS= ?";
|
||||||
isActionStatusProvided = true;
|
isActionStatusProvided = true;
|
||||||
}
|
}
|
||||||
|
if (action != null && !action.isEmpty()) {
|
||||||
|
sql += " AND DS.UNSUBSCRIBED= ?";
|
||||||
|
isActionProvided = 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(index++, appReleaseId);
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(index++, tenantId);
|
||||||
if(isActionStatusProvided){
|
if (isActionStatusProvided) {
|
||||||
stmt.setString(3, actionStatus);
|
stmt.setString(index++, actionStatus);
|
||||||
|
}
|
||||||
|
if (isActionProvided) {
|
||||||
|
if (action.equals("SUBSCRIBED")) {
|
||||||
|
stmt.setString(index, "FALSE");
|
||||||
|
} else {
|
||||||
|
stmt.setString(index, "TRUE");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try (ResultSet rs = stmt.executeQuery()) {
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
|||||||
@ -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, null).isEmpty()) {
|
if (!subscriptionDAO.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null, 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, null);
|
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId, null, 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, null);
|
tenantId, null, 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, null);
|
.getDeviceSubscriptions(applicationReleaseId, tenantId, null, null);
|
||||||
if (deviceSubscriptionDTOS.isEmpty()) {
|
if (deviceSubscriptionDTOS.isEmpty()) {
|
||||||
PaginationResult paginationResult = new PaginationResult();
|
PaginationResult paginationResult = new PaginationResult();
|
||||||
paginationResult.setData(new ArrayList<>());
|
paginationResult.setData(new ArrayList<>());
|
||||||
@ -1338,8 +1338,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus)
|
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
|
||||||
throws ApplicationManagementException {
|
String action) throws ApplicationManagementException {
|
||||||
int limitValue = request.getRowCount();
|
int limitValue = request.getRowCount();
|
||||||
int offsetValue = request.getStartIndex();
|
int offsetValue = request.getStartIndex();
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
@ -1363,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, actionStatus);
|
.getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus, action);
|
||||||
if (deviceSubscriptionDTOS.isEmpty()) {
|
if (deviceSubscriptionDTOS.isEmpty()) {
|
||||||
PaginationResult paginationResult = new PaginationResult();
|
PaginationResult paginationResult = new PaginationResult();
|
||||||
paginationResult.setData(new ArrayList<>());
|
paginationResult.setData(new ArrayList<>());
|
||||||
|
|||||||
@ -124,6 +124,12 @@ public interface SubscriptionManagementAdminAPI {
|
|||||||
required = false)
|
required = false)
|
||||||
@QueryParam("user")
|
@QueryParam("user")
|
||||||
String user,
|
String user,
|
||||||
|
@ApiParam(
|
||||||
|
name = "action",
|
||||||
|
value = "The action, subscribed or unsubscribed.",
|
||||||
|
required = false)
|
||||||
|
@Size(max = 45)
|
||||||
|
@QueryParam("action") String action,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "actionStatus",
|
name = "actionStatus",
|
||||||
value = "Provide the action status details")
|
value = "Provide the action status details")
|
||||||
|
|||||||
@ -18,11 +18,9 @@
|
|||||||
|
|
||||||
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.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;
|
||||||
@ -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.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;
|
||||||
@ -60,6 +57,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
|
|||||||
public Response getAppInstalledDevices(
|
public Response getAppInstalledDevices(
|
||||||
@QueryParam("name") String name,
|
@QueryParam("name") String name,
|
||||||
@QueryParam("user") String user,
|
@QueryParam("user") String user,
|
||||||
|
@QueryParam("action") String action,
|
||||||
@QueryParam("actionStatus") String actionStatus,
|
@QueryParam("actionStatus") String actionStatus,
|
||||||
@QueryParam("status") List<String> status,
|
@QueryParam("status") List<String> status,
|
||||||
@PathParam("uuid") String uuid,
|
@PathParam("uuid") String uuid,
|
||||||
@ -76,6 +74,9 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
|
|||||||
if (user != null && !user.isEmpty()) {
|
if (user != null && !user.isEmpty()) {
|
||||||
request.setOwner(user);
|
request.setOwner(user);
|
||||||
}
|
}
|
||||||
|
if (action != null && !action.isEmpty()) {
|
||||||
|
RequestValidationUtil.validateAction(action);
|
||||||
|
}
|
||||||
if (status != null && !status.isEmpty()) {
|
if (status != null && !status.isEmpty()) {
|
||||||
boolean isStatusEmpty = true;
|
boolean isStatusEmpty = true;
|
||||||
for (String statusString : status) {
|
for (String statusString : status) {
|
||||||
@ -96,7 +97,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
|
|||||||
}
|
}
|
||||||
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
|
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
|
||||||
PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails
|
PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails
|
||||||
(request, uuid, actionStatus);
|
(request, uuid, actionStatus, action);
|
||||||
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";
|
||||||
@ -108,7 +109,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
|
|||||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException e) {
|
||||||
String msg = "Error occurred while getting app installed devices which has application release UUID of: "
|
String msg = "Error occurred while getting app installed devices which has application release UUID of: "
|
||||||
+ uuid;
|
+ uuid;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.
|
* Checks if user requested ownerships are valid.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -906,7 +906,6 @@ public interface DeviceManagementProviderService {
|
|||||||
*
|
*
|
||||||
* @param devicesIds devices ids of the subscribed devices.
|
* @param devicesIds devices ids of the subscribed devices.
|
||||||
* @param request paginated request object.
|
* @param request paginated request object.
|
||||||
* @param status status of the devices.
|
|
||||||
* @return {@link PaginationResult}
|
* @return {@link PaginationResult}
|
||||||
* @throws DeviceManagementException if any service level or DAO level error occurs.
|
* @throws DeviceManagementException if any service level or DAO level error occurs.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user