Code modified

(cherry picked from commit 605168e770)
4.x.x
MalshaPiumini 4 years ago committed by Pahansith
parent f3d1ad4f0d
commit 82ebe79f2d

@ -133,8 +133,7 @@ public interface SubscriptionManager {
* @return deviceDetails - device details for given application release. * @return deviceDetails - device details for given application release.
* @throws {@link ApplicationManagementException} Exception of the application management * @throws {@link ApplicationManagementException} Exception of the application management
*/ */
PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID, PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID) throws ApplicationManagementException;
List<String> status) throws ApplicationManagementException;
/*** /***
* This method used to get category details. * This method used to get category details.
@ -153,7 +152,6 @@ 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 request paginated request object. * @param request paginated request object.
* @param status status of the devices.
* @param actionStatus status of the operation. * @param actionStatus status of the operation.
* @param appUUID application release UUID * @param appUUID application release UUID
* @return {@link PaginationResult} * @return {@link PaginationResult}
@ -161,6 +159,6 @@ public interface SubscriptionManager {
* 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, List<String> status,String actionStatus) PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus)
throws ApplicationManagementException; throws ApplicationManagementException;
} }

@ -1219,7 +1219,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID, List<String> status) public PaginationResult getAppInstalledDevices(PaginationRequest request, String appUUID)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil DeviceManagementProviderService deviceManagementProviderService = HelperUtil
@ -1259,7 +1259,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
//pass the device id list to device manager service method //pass the device id list to device manager service method
try { try {
PaginationResult deviceDetails = deviceManagementProviderService.getAppSubscribedDevices PaginationResult deviceDetails = deviceManagementProviderService.getAppSubscribedDevices
(request, deviceIdList, status); (request, deviceIdList);
if (deviceDetails == null) { if (deviceDetails == null) {
String msg = "Couldn't found an subscribed devices details for device ids: " + deviceIdList; String msg = "Couldn't found an subscribed devices details for device ids: " + deviceIdList;
@ -1338,7 +1338,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, List<String> status,String actionStatus) public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus)
throws ApplicationManagementException { throws ApplicationManagementException {
int limitValue = request.getRowCount(); int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex(); int offsetValue = request.getStartIndex();
@ -1375,8 +1375,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
.collect(Collectors.toList()); .collect(Collectors.toList());
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
.getAppSubscribedDevices(request, deviceIdList, status); (request, deviceIdList);
List<DeviceSubscriptionData> deviceSubscriptionDataList = new ArrayList<>(); List<DeviceSubscriptionData> deviceSubscriptionDataList = new ArrayList<>();
if (!paginationResult.getData().isEmpty()) { if (!paginationResult.getData().isEmpty()) {

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

@ -75,41 +75,62 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
if (user != null && !user.isEmpty()) { if (user != null && !user.isEmpty()) {
request.setOwner(user); request.setOwner(user);
} }
// if (status != null && !status.isEmpty()) { if (status != null && !status.isEmpty()) {
// boolean isStatusEmpty = true; boolean isStatusEmpty = true;
// for (String statusString : status){ for (String statusString : status) {
// if (StringUtils.isNotBlank(statusString)){ if (StringUtils.isNotBlank(statusString)) {
// isStatusEmpty = false; isStatusEmpty = false;
// break; break;
// } }
// } }
// if (!isStatusEmpty) { if (!isStatusEmpty) {
// for (String status_ : status) { for (String status_ : status) {
// switch (status_) { switch (status_) {
// case "ACTIVE": case "ACTIVE":
// case "INACTIVE": case "INACTIVE":
// case "UNCLAIMED": case "UNCLAIMED":
// case "UNREACHABLE": case "UNREACHABLE":
// case "SUSPENDED": case "SUSPENDED":
// case "DISENROLLMENT_REQUESTED": case "DISENROLLMENT_REQUESTED":
// case "REMOVED": case "REMOVED":
// case "BLOCKED": case "BLOCKED":
// case "CREATED": case "CREATED":
// break; break;
// default: default:
// String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types are " + String msg = "Invalid enrollment status type: " + status_ + ". \nValid status types " +
// "ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " + "are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
// "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED"; "DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED";
// log.error(msg); log.error(msg);
// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
// } }
// } }
// request.setStatusList(status); request.setStatusList(status);
// } }
// } }
if (actionStatus != null && !actionStatus.isEmpty()) {
if (StringUtils.isNotBlank(actionStatus)) {
switch (actionStatus) {
case "PENDING":
case "ERROR":
case "IN_PROGRESS":
case "NOTNOW":
case "COMPLETED":
case "REPEATED":
break;
default:
String msg = "Invalid enrollment action status type: " + actionStatus + ". " +
"\nValid action status types are PENDING | ERROR | IN_PROGRESS | NOTNOW | " +
"COMPLETED | REPEATED";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
}
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscriptionData = subscriptionManager PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails
.getAppSubscriptionDetails(request, uuid, status, actionStatus); (request, uuid, 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";

@ -654,12 +654,11 @@ public interface DeviceDAO {
* @param deviceIds device ids of the subscribed devices. * @param deviceIds device ids of the subscribed devices.
* @param tenantId Id of the current tenant. * @param tenantId Id of the current tenant.
* @param request paginated request object. * @param request paginated request object.
* @param status status of the devices.
* @return devices - subscribed device details list * @return devices - subscribed device details list
* @throws DeviceManagementDAOException if connections establishment fails. * @throws DeviceManagementDAOException if connections establishment fails.
*/ */
List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId, List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId)
List<String> status) throws DeviceManagementDAOException; throws DeviceManagementDAOException;
/** /**
* @param deviceIds device ids of the subscribed devices. * @param deviceIds device ids of the subscribed devices.

@ -877,12 +877,12 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
@Override @Override
public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId, public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId)
List<String> status)
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
Connection conn; Connection conn;
int limitValue = request.getRowCount(); int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex(); int offsetValue = request.getStartIndex();
List<String> status = request.getStatusList();
String name = request.getDeviceName(); String name = request.getDeviceName();
String user = request.getOwner(); String user = request.getOwner();
String ownership = request.getOwnership(); String ownership = request.getOwnership();

@ -847,12 +847,12 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
@Override @Override
public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId, public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId)
List<String> status)
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
Connection conn; Connection conn;
int limitValue = request.getRowCount(); int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex(); int offsetValue = request.getStartIndex();
List<String> status = request.getStatusList();
String name = request.getDeviceName(); String name = request.getDeviceName();
String user = request.getOwner(); String user = request.getOwner();
String ownership = request.getOwnership(); String ownership = request.getOwnership();

@ -827,12 +827,12 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
@Override @Override
public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId, public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId)
List<String> status)
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
Connection conn; Connection conn;
int limitValue = request.getRowCount(); int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex(); int offsetValue = request.getStartIndex();
List<String> status = request.getStatusList();
String name = request.getDeviceName(); String name = request.getDeviceName();
String user = request.getOwner(); String user = request.getOwner();
String ownership = request.getOwnership(); String ownership = request.getOwnership();

@ -693,12 +693,12 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
@Override @Override
public List<Device> getSubscribedDevices(PaginationRequest request, public List<Device> getSubscribedDevices(PaginationRequest request, List<Integer> deviceIds, int tenantId)
List<Integer> deviceIds, int tenantId, List<String> status)
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
Connection conn; Connection conn;
int limitValue = request.getRowCount(); int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex(); int offsetValue = request.getStartIndex();
List<String> status = request.getStatusList();
String name = request.getDeviceName(); String name = request.getDeviceName();
String user = request.getOwner(); String user = request.getOwner();
String ownership = request.getOwnership(); String ownership = request.getOwnership();

@ -910,7 +910,7 @@ public interface DeviceManagementProviderService {
* @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.
*/ */
PaginationResult getAppSubscribedDevices(PaginationRequest request, List<Integer> devicesIds, List<String> status) PaginationResult getAppSubscribedDevices(PaginationRequest request, List<Integer> devicesIds)
throws DeviceManagementException; throws DeviceManagementException;
/** /**

@ -4156,8 +4156,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public PaginationResult getAppSubscribedDevices(PaginationRequest request, List<Integer> devicesIds, public PaginationResult getAppSubscribedDevices(PaginationRequest request, List<Integer> devicesIds) throws DeviceManagementException {
List<String> status) throws DeviceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting all devices details for device ids: " + devicesIds); log.debug("Getting all devices details for device ids: " + devicesIds);
@ -4166,14 +4165,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
List<Device> subscribedDeviceDetails; List<Device> subscribedDeviceDetails;
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
subscribedDeviceDetails = deviceDAO.getSubscribedDevices(request, devicesIds, tenantId, status); subscribedDeviceDetails = deviceDAO.getSubscribedDevices(request, devicesIds, tenantId);
if (subscribedDeviceDetails.isEmpty()) { if (subscribedDeviceDetails.isEmpty()) {
paginationResult.setData(new ArrayList<>()); paginationResult.setData(new ArrayList<>());
paginationResult.setRecordsFiltered(0); paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0); paginationResult.setRecordsTotal(0);
return paginationResult; return paginationResult;
} }
int count = deviceDAO.getSubscribedDeviceCount(devicesIds, tenantId, status); int count = deviceDAO.getSubscribedDeviceCount(devicesIds, tenantId, request.getStatusList());
paginationResult.setRecordsFiltered(count); paginationResult.setRecordsFiltered(count);
paginationResult.setRecordsTotal(count); paginationResult.setRecordsTotal(count);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {

Loading…
Cancel
Save