mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fix issues in services
This commit is contained in:
parent
3596de1b28
commit
023ce0f9ec
@ -19,12 +19,22 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.application.mgt.common;
|
package io.entgra.device.mgt.core.application.mgt.common;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class SubscriptionMetadata {
|
public class SubscriptionMetadata {
|
||||||
public static final class DeviceSubscriptionStatus {
|
public static final class DeviceSubscriptionStatus {
|
||||||
public static final String NEW = "NEW";
|
public static final String NEW = "NEW";
|
||||||
public static final String PENDING = "PENDING";
|
public static final String PENDING = "PENDING";
|
||||||
public static final String COMPLETED = "COMPLETED";
|
public static final String COMPLETED = "COMPLETED";
|
||||||
public static final String FAILED = "FAILED";
|
public static final String ERROR = "ERROR";
|
||||||
|
public static final String INVALID = "INVALID";
|
||||||
|
public static final String UNAUTHORIZED = "UNAUTHORIZED";
|
||||||
|
public static final String IN_PROGRESS = "IN_PROGRESS";
|
||||||
|
public static final String REPEAT = "REPEAT";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class SubscriptionTypes {
|
public static final class SubscriptionTypes {
|
||||||
@ -33,4 +43,26 @@ public class SubscriptionMetadata {
|
|||||||
public static final String GROUP = "group";
|
public static final String GROUP = "group";
|
||||||
public static final String USER = "user";
|
public static final String USER = "user";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class DBSubscriptionStatus {
|
||||||
|
public static final List<String> COMPLETED_STATUS_LIST =
|
||||||
|
Collections.singletonList(DeviceSubscriptionStatus.COMPLETED);
|
||||||
|
public static final List<String> ERROR_STATUS_LIST =
|
||||||
|
Arrays.asList(DeviceSubscriptionStatus.ERROR, DeviceSubscriptionStatus.INVALID, DeviceSubscriptionStatus.UNAUTHORIZED);
|
||||||
|
public static final List<String> PENDING_STATUS_LIST =
|
||||||
|
Arrays.asList(DeviceSubscriptionStatus.PENDING, DeviceSubscriptionStatus.IN_PROGRESS, DeviceSubscriptionStatus.REPEAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, List<String>> deviceSubscriptionStatusToDBSubscriptionStatusMap;
|
||||||
|
static {
|
||||||
|
Map<String, List<String>> statusMap = new HashMap<>();
|
||||||
|
statusMap.put(DeviceSubscriptionStatus.COMPLETED, DBSubscriptionStatus.COMPLETED_STATUS_LIST);
|
||||||
|
statusMap.put(DeviceSubscriptionStatus.PENDING, DBSubscriptionStatus.PENDING_STATUS_LIST);
|
||||||
|
statusMap.put(DeviceSubscriptionStatus.IN_PROGRESS, DBSubscriptionStatus.PENDING_STATUS_LIST);
|
||||||
|
statusMap.put(DeviceSubscriptionStatus.REPEAT, DBSubscriptionStatus.PENDING_STATUS_LIST);
|
||||||
|
statusMap.put(DeviceSubscriptionStatus.ERROR, DBSubscriptionStatus.ERROR_STATUS_LIST);
|
||||||
|
statusMap.put(DeviceSubscriptionStatus.INVALID, DBSubscriptionStatus.ERROR_STATUS_LIST);
|
||||||
|
statusMap.put(DeviceSubscriptionStatus.UNAUTHORIZED, DBSubscriptionStatus.ERROR_STATUS_LIST);
|
||||||
|
deviceSubscriptionStatusToDBSubscriptionStatusMap = Collections.unmodifiableMap(statusMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,9 +20,21 @@
|
|||||||
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
public class SubscriptionStatisticDTO {
|
public class SubscriptionStatisticDTO {
|
||||||
private int completedDeviceCount;
|
private int completedDeviceCount = 0;
|
||||||
private int pendingDevicesCount;
|
private int pendingDevicesCount = 0;
|
||||||
private int failedDevicesCount;
|
private int failedDevicesCount = 0;
|
||||||
|
|
||||||
|
public void addToComplete(int count) {
|
||||||
|
completedDeviceCount += count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToPending(int count) {
|
||||||
|
pendingDevicesCount += count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToFailed(int count) {
|
||||||
|
failedDevicesCount += count ;
|
||||||
|
}
|
||||||
|
|
||||||
public int getCompletedDeviceCount() {
|
public int getCompletedDeviceCount() {
|
||||||
return completedDeviceCount;
|
return completedDeviceCount;
|
||||||
|
|||||||
@ -400,10 +400,10 @@ public interface SubscriptionDAO {
|
|||||||
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
|
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
|
||||||
*/
|
*/
|
||||||
List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
|
List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
|
||||||
List<Integer> deviceIds, String actionStatus, String actionType,
|
List<Integer> deviceIds, List<String> actionStatus, String actionType,
|
||||||
String actionTriggeredBy, int limit, int offset) throws ApplicationManagementDAOException;
|
String actionTriggeredBy, int limit, int offset) throws ApplicationManagementDAOException;
|
||||||
int getDeviceSubscriptionCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
int getDeviceSubscriptionCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
||||||
List<Integer> deviceIds, String actionStatus, String actionType,
|
List<Integer> deviceIds, List<String> actionStatus, String actionType,
|
||||||
String actionTriggeredBy) throws ApplicationManagementDAOException;
|
String actionTriggeredBy) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -420,11 +420,11 @@ public interface SubscriptionDAO {
|
|||||||
* @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
|
* @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
|
||||||
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
|
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
|
||||||
*/
|
*/
|
||||||
List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId, String actionStatus, String actionType,
|
List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId, List<String> actionStatus, String actionType,
|
||||||
String actionTriggeredBy, int offset, int limit) throws ApplicationManagementDAOException;
|
String actionTriggeredBy, int offset, int limit) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
int getAllSubscriptionsCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
int getAllSubscriptionsCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
||||||
String actionStatus, String actionType, String actionTriggeredBy)
|
List<String> actionStatus, String actionType, String actionTriggeredBy)
|
||||||
throws ApplicationManagementDAOException;
|
throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -46,6 +46,7 @@ import java.sql.Timestamp;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -1914,14 +1915,20 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// passed the required list for the action status
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
|
public List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
|
||||||
List<Integer> deviceIds, String actionStatus, String actionType,
|
List<Integer> deviceIds, List<String> actionStatus, String actionType,
|
||||||
String actionTriggeredBy, int limit, int offset) throws ApplicationManagementDAOException {
|
String actionTriggeredBy, int limit, int offset) throws 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
|
||||||
+ " and device ids " + deviceIds + " from the database");
|
+ " and device ids " + deviceIds + " from the database");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = this.getDBConnection();
|
Connection conn = this.getDBConnection();
|
||||||
String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
|
String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
|
||||||
@ -1940,7 +1947,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
sql.append(" AND DS.STATUS = ? ");
|
sql.append(" AND DS.STATUS IN (").
|
||||||
|
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
||||||
}
|
}
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
||||||
@ -1961,16 +1969,20 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
ps.setInt(paramIdx++, appReleaseId);
|
ps.setInt(paramIdx++, appReleaseId);
|
||||||
ps.setBoolean(paramIdx++, unsubscribe);
|
ps.setBoolean(paramIdx++, unsubscribe);
|
||||||
ps.setInt(paramIdx++, tenantId);
|
ps.setInt(paramIdx++, tenantId);
|
||||||
for (int i = 0; i < deviceIds.size(); i++) {
|
for (Integer deviceId : deviceIds) {
|
||||||
ps.setInt(paramIdx++, deviceIds.get(i));
|
ps.setInt(paramIdx++, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionStatus);
|
for (String status : actionStatus) {
|
||||||
|
ps.setString(paramIdx++, status);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionType);
|
ps.setString(paramIdx++, actionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
||||||
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
||||||
}
|
}
|
||||||
@ -2018,9 +2030,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDeviceSubscriptionCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
public int getDeviceSubscriptionCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
||||||
List<Integer> deviceIds, String actionStatus, String actionType,
|
List<Integer> deviceIds, List<String> actionStatus, String actionType,
|
||||||
String actionTriggeredBy) throws ApplicationManagementDAOException {
|
String actionTriggeredBy) throws ApplicationManagementDAOException {
|
||||||
int deviceCount = 0;
|
int deviceCount = 0;
|
||||||
|
|
||||||
|
if (deviceIds == null || deviceIds.isEmpty()) return deviceCount;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = this.getDBConnection();
|
Connection conn = this.getDBConnection();
|
||||||
StringBuilder sql = new StringBuilder("SELECT COUNT(DISTINCT DS.DM_DEVICE_ID) AS COUNT "
|
StringBuilder sql = new StringBuilder("SELECT COUNT(DISTINCT DS.DM_DEVICE_ID) AS COUNT "
|
||||||
@ -2029,8 +2044,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
sql.append(" AND DS.STATUS = ? ");
|
sql.append(" AND DS.STATUS IN (").
|
||||||
|
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
||||||
}
|
}
|
||||||
@ -2043,16 +2060,20 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
ps.setInt(paramIdx++, appReleaseId);
|
ps.setInt(paramIdx++, appReleaseId);
|
||||||
ps.setBoolean(paramIdx++, unsubscribe);
|
ps.setBoolean(paramIdx++, unsubscribe);
|
||||||
ps.setInt(paramIdx++, tenantId);
|
ps.setInt(paramIdx++, tenantId);
|
||||||
for (int i = 0; i < deviceIds.size(); i++) {
|
for (Integer deviceId : deviceIds) {
|
||||||
ps.setInt(paramIdx++, deviceIds.get(i));
|
ps.setInt(paramIdx++, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionStatus);
|
for (String status : actionStatus) {
|
||||||
|
ps.setString(paramIdx++, status);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionType);
|
ps.setString(paramIdx++, actionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
||||||
ps.setString(paramIdx, "%" + actionTriggeredBy + "%");
|
ps.setString(paramIdx, "%" + actionTriggeredBy + "%");
|
||||||
}
|
}
|
||||||
@ -2175,7 +2196,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId,
|
public List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId,
|
||||||
String actionStatus, String actionType, String actionTriggeredBy,
|
List<String> actionStatus, String actionType, String actionTriggeredBy,
|
||||||
int offset, int limit) throws ApplicationManagementDAOException {
|
int offset, int limit) throws 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
|
||||||
@ -2198,8 +2219,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? ");
|
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? ");
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
sql.append(" AND DS.STATUS = ? ");
|
sql.append(" AND DS.STATUS IN (").
|
||||||
|
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
||||||
}
|
}
|
||||||
@ -2222,11 +2245,15 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
ps.setInt(paramIdx++, tenantId);
|
ps.setInt(paramIdx++, tenantId);
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionStatus);
|
for (String status : actionStatus) {
|
||||||
|
ps.setString(paramIdx++, status);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionType);
|
ps.setString(paramIdx++, actionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
||||||
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
||||||
}
|
}
|
||||||
@ -2274,7 +2301,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAllSubscriptionsCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
public int getAllSubscriptionsCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
||||||
String actionStatus, String actionType, String actionTriggeredBy)
|
List<String> actionStatus, String actionType, String actionTriggeredBy)
|
||||||
throws ApplicationManagementDAOException {
|
throws ApplicationManagementDAOException {
|
||||||
int deviceCount = 0;
|
int deviceCount = 0;
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -2288,7 +2315,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? ");
|
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? ");
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
sql.append(" AND DS.STATUS = ? ");
|
sql.append(" AND DS.STATUS IN (").
|
||||||
|
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
||||||
}
|
}
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
||||||
@ -2306,8 +2334,11 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
ps.setInt(paramIdx++, tenantId);
|
ps.setInt(paramIdx++, tenantId);
|
||||||
|
|
||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
if (actionStatus != null && !actionStatus.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionStatus);
|
for (String status : actionStatus) {
|
||||||
|
ps.setString(paramIdx++, status);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType != null && !actionType.isEmpty()) {
|
if (actionType != null && !actionType.isEmpty()) {
|
||||||
ps.setString(paramIdx++, actionType);
|
ps.setString(paramIdx++, actionType);
|
||||||
}
|
}
|
||||||
@ -2730,42 +2761,56 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: fixed the status
|
||||||
@Override
|
@Override
|
||||||
public SubscriptionStatisticDTO getSubscriptionStatistic(List<Integer> deviceIds, String subscriptionType,
|
public SubscriptionStatisticDTO getSubscriptionStatistic(List<Integer> deviceIds, String subscriptionType,
|
||||||
boolean isUnsubscribed, int tenantId)
|
boolean isUnsubscribed, int tenantId)
|
||||||
throws ApplicationManagementDAOException {
|
throws ApplicationManagementDAOException {
|
||||||
SubscriptionStatisticDTO subscriptionStatisticDTO = new SubscriptionStatisticDTO();
|
SubscriptionStatisticDTO subscriptionStatisticDTO = new SubscriptionStatisticDTO();
|
||||||
String deviceIdsString = deviceIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
if (deviceIds == null || deviceIds.isEmpty()) return subscriptionStatisticDTO;
|
||||||
|
|
||||||
boolean doesAllEntriesRequired = true;
|
boolean doesAllEntriesRequired = true;
|
||||||
try {
|
try {
|
||||||
Connection connection = getDBConnection();
|
Connection connection = getDBConnection();
|
||||||
String sql = "SELECT COUNT(DISTINCT ID) AS COUNT, " +
|
String sql = "SELECT COUNT(DISTINCT ID) AS COUNT, " +
|
||||||
"STATUS FROM AP_DEVICE_SUBSCRIPTION WHERE " +
|
"STATUS FROM AP_DEVICE_SUBSCRIPTION WHERE " +
|
||||||
"TENANT_ID = ? AND UNSUBSCRIBED = ? AND DM_DEVICE_ID IN ("+ deviceIdsString + ")";
|
"TENANT_ID = ? AND UNSUBSCRIBED = ? AND DM_DEVICE_ID IN ("+
|
||||||
|
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")";
|
||||||
|
|
||||||
if (!Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.DEVICE)) {
|
if (!Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.DEVICE)) {
|
||||||
sql = sql + " AND ACTION_TRIGGERED_FROM = ?";
|
sql += " AND ACTION_TRIGGERED_FROM = ?";
|
||||||
doesAllEntriesRequired = false;
|
doesAllEntriesRequired = false;
|
||||||
}
|
}
|
||||||
sql = sql + " GROUP BY (STATUS)";
|
|
||||||
|
sql += " GROUP BY (STATUS)";
|
||||||
|
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
int idx = 1;
|
int idx = 1;
|
||||||
|
|
||||||
preparedStatement.setInt(idx++, tenantId);
|
preparedStatement.setInt(idx++, tenantId);
|
||||||
preparedStatement.setBoolean(idx++, isUnsubscribed);
|
preparedStatement.setBoolean(idx++, isUnsubscribed);
|
||||||
|
for (Integer deviceId : deviceIds) {
|
||||||
|
preparedStatement.setInt(idx++, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
if (!doesAllEntriesRequired) {
|
if (!doesAllEntriesRequired) {
|
||||||
preparedStatement.setString(idx, subscriptionType);
|
preparedStatement.setString(idx, subscriptionType);
|
||||||
}
|
}
|
||||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
|
// add the error and in progress
|
||||||
int count = resultSet.getInt("COUNT");
|
int count = resultSet.getInt("COUNT");
|
||||||
String status = resultSet.getString("STATUS");
|
String status = resultSet.getString("STATUS");
|
||||||
if (Objects.equals(status, "COMPLETED")) {
|
|
||||||
subscriptionStatisticDTO.setCompletedDeviceCount(count);
|
if (SubscriptionMetadata.DBSubscriptionStatus.COMPLETED_STATUS_LIST.contains(status)) {
|
||||||
} else if (Objects.equals(status, "PENDING")) {
|
subscriptionStatisticDTO.addToComplete(count);
|
||||||
subscriptionStatisticDTO.setPendingDevicesCount(count);
|
}
|
||||||
} else {
|
|
||||||
subscriptionStatisticDTO.setFailedDevicesCount(count);
|
if (SubscriptionMetadata.DBSubscriptionStatus.PENDING_STATUS_LIST.contains(status)) {
|
||||||
|
subscriptionStatisticDTO.addToPending(count);
|
||||||
|
}
|
||||||
|
if (SubscriptionMetadata.DBSubscriptionStatus.ERROR_STATUS_LIST.contains(status)) {
|
||||||
|
subscriptionStatisticDTO.addToFailed(count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
|
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionData;
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionData;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
|
||||||
@ -115,4 +116,8 @@ public class SubscriptionManagementHelperUtil {
|
|||||||
}
|
}
|
||||||
return ((float) numerator / (float) denominator) * 100;
|
return ((float) numerator / (float) denominator) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getDBSubscriptionStatus(String deviceSubscriptionStatus) {
|
||||||
|
return SubscriptionMetadata.deviceSubscriptionStatusToDBSubscriptionStatusMap.get(deviceSubscriptionStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,7 @@ public class DeviceBasedSubscriptionManagementHelperServiceImpl implements Subsc
|
|||||||
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
||||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
||||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
||||||
|
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
||||||
|
|
||||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
||||||
@ -96,11 +97,11 @@ public class DeviceBasedSubscriptionManagementHelperServiceImpl implements Subsc
|
|||||||
deviceCount = deviceManagementProviderService.getDeviceCountNotInGivenIdList(deviceIdsOfSubscription);
|
deviceCount = deviceManagementProviderService.getDeviceCountNotInGivenIdList(deviceIdsOfSubscription);
|
||||||
} else {
|
} else {
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
||||||
getId(), isUnsubscribe, tenantId, subscriptionInfo.getDeviceSubscriptionStatus(), null,
|
getId(), isUnsubscribe, tenantId, dbSubscriptionStatus, null,
|
||||||
deviceSubscriptionFilterCriteria.getTriggeredBy(), offset, limit);
|
deviceSubscriptionFilterCriteria.getTriggeredBy(), offset, limit);
|
||||||
|
|
||||||
deviceCount = subscriptionDAO.getAllSubscriptionsCount(applicationReleaseDTO.
|
deviceCount = subscriptionDAO.getAllSubscriptionsCount(applicationReleaseDTO.
|
||||||
getId(), isUnsubscribe, tenantId, subscriptionInfo.getDeviceSubscriptionStatus(), null,
|
getId(), isUnsubscribe, tenantId, dbSubscriptionStatus, null,
|
||||||
deviceSubscriptionFilterCriteria.getTriggeredBy());
|
deviceSubscriptionFilterCriteria.getTriggeredBy());
|
||||||
}
|
}
|
||||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
||||||
|
|||||||
@ -97,6 +97,7 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
|
|||||||
|
|
||||||
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
|
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
|
||||||
GroupDetailsDTO groupDetailsDTO;
|
GroupDetailsDTO groupDetailsDTO;
|
||||||
|
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
||||||
|
|
||||||
List<Integer> allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
|
List<Integer> allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
|
||||||
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
|
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
|
||||||
@ -105,7 +106,7 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
|
|||||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, allDeviceIdsOwnByGroup, null,
|
isUnsubscribe, tenantId, allDeviceIdsOwnByGroup, null,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||||
|
|
||||||
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
||||||
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||||
@ -126,12 +127,12 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
|
|||||||
List<Integer> paginatedDeviceIdsOwnByGroup = groupDetailsDTO.getDeviceIds();
|
List<Integer> paginatedDeviceIdsOwnByGroup = groupDetailsDTO.getDeviceIds();
|
||||||
|
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, paginatedDeviceIdsOwnByGroup, subscriptionInfo.getDeviceSubscriptionStatus(),
|
isUnsubscribe, tenantId, paginatedDeviceIdsOwnByGroup, dbSubscriptionStatus,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||||
|
|
||||||
deviceCount = subscriptionDAO.getDeviceSubscriptionCount(applicationReleaseDTO.getId(),
|
deviceCount = subscriptionDAO.getDeviceSubscriptionCount(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, allDeviceIdsOwnByGroup, subscriptionInfo.getDeviceSubscriptionStatus(),
|
isUnsubscribe, tenantId, allDeviceIdsOwnByGroup, dbSubscriptionStatus,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy());
|
null, deviceSubscriptionFilterCriteria.getTriggeredBy());
|
||||||
}
|
}
|
||||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
||||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe);
|
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe);
|
||||||
|
|||||||
@ -89,11 +89,12 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri
|
|||||||
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
||||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
||||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
||||||
|
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
||||||
|
|
||||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, deviceIdsOwnByRole, null,
|
isUnsubscribe, tenantId, deviceIdsOwnByRole, null,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||||
|
|
||||||
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
||||||
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||||
@ -108,11 +109,11 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri
|
|||||||
deviceCount = deviceIdsOwnByRole.size();
|
deviceCount = deviceIdsOwnByRole.size();
|
||||||
} else {
|
} else {
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, deviceIdsOwnByRole, subscriptionInfo.getDeviceSubscriptionStatus(),
|
isUnsubscribe, tenantId, deviceIdsOwnByRole, dbSubscriptionStatus,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), limit, offset);
|
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), limit, offset);
|
||||||
|
|
||||||
deviceCount = subscriptionDAO.getDeviceSubscriptionCount(applicationReleaseDTO.getId(),
|
deviceCount = subscriptionDAO.getDeviceSubscriptionCount(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, deviceIdsOwnByRole, subscriptionInfo.getDeviceSubscriptionStatus(),
|
isUnsubscribe, tenantId, deviceIdsOwnByRole, dbSubscriptionStatus,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy());
|
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy());
|
||||||
}
|
}
|
||||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.
|
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.
|
||||||
|
|||||||
@ -86,11 +86,12 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri
|
|||||||
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
||||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
||||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
||||||
|
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
||||||
|
|
||||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, deviceIdsOwnByUser, null,
|
isUnsubscribe, tenantId, deviceIdsOwnByUser, null,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||||
|
|
||||||
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
||||||
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||||
@ -105,12 +106,12 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri
|
|||||||
deviceCount = deviceIdsOwnByUser.size();
|
deviceCount = deviceIdsOwnByUser.size();
|
||||||
} else {
|
} else {
|
||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, deviceIdsOwnByUser, subscriptionInfo.getDeviceSubscriptionStatus(),
|
isUnsubscribe, tenantId, deviceIdsOwnByUser, dbSubscriptionStatus,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), limit, offset);
|
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), limit, offset);
|
||||||
|
|
||||||
deviceCount = subscriptionDAO.getDeviceSubscriptionCount(applicationReleaseDTO.getId(),
|
deviceCount = subscriptionDAO.getDeviceSubscriptionCount(applicationReleaseDTO.getId(),
|
||||||
isUnsubscribe, tenantId, deviceIdsOwnByUser, subscriptionInfo.getDeviceSubscriptionStatus(),
|
isUnsubscribe, tenantId, deviceIdsOwnByUser, dbSubscriptionStatus,
|
||||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy());
|
null, deviceSubscriptionFilterCriteria.getTriggeredBy());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
||||||
|
|||||||
@ -3304,15 +3304,28 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
public List<Integer> getDevicesNotInGivenIdList(PaginationRequest request, List<Integer> deviceIds, int tenantId)
|
public List<Integer> getDevicesNotInGivenIdList(PaginationRequest request, List<Integer> deviceIds, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
List<Integer> filteredDeviceIds = new ArrayList<>();
|
List<Integer> filteredDeviceIds = new ArrayList<>();
|
||||||
String deviceIdStringList = deviceIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
||||||
try {
|
try {
|
||||||
Connection connection = getConnection();
|
Connection connection = getConnection();
|
||||||
String sql = "SELECT ID AS DEVICE_ID FROM DM_DEVICE WHERE ID NOT IN " +
|
String sql = "SELECT ID AS DEVICE_ID FROM DM_DEVICE WHERE TENANT_ID = ?";
|
||||||
"(" + deviceIdStringList + ") AND TENANT_ID = ? LIMIT ? OFFSET ?";
|
|
||||||
|
if (deviceIds != null && !deviceIds.isEmpty()) {
|
||||||
|
sql += " AND ID NOT IN ( " + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
sql += " LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
preparedStatement.setInt(1, tenantId);
|
int paraIdx = 1;
|
||||||
preparedStatement.setInt(2, request.getRowCount());
|
preparedStatement.setInt(paraIdx++, tenantId);
|
||||||
preparedStatement.setInt(3, request.getStartIndex());
|
|
||||||
|
if (deviceIds != null && !deviceIds.isEmpty()) {
|
||||||
|
for (Integer deviceId : deviceIds) {
|
||||||
|
preparedStatement.setInt(paraIdx++, deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement.setInt(paraIdx++, request.getRowCount());
|
||||||
|
preparedStatement.setInt(paraIdx, request.getStartIndex());
|
||||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
filteredDeviceIds.add(resultSet.getInt("DEVICE_ID"));
|
filteredDeviceIds.add(resultSet.getInt("DEVICE_ID"));
|
||||||
@ -3331,15 +3344,22 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
public List<Integer> getDevicesInGivenIdList(PaginationRequest request, List<Integer> deviceIds, int tenantId)
|
public List<Integer> getDevicesInGivenIdList(PaginationRequest request, List<Integer> deviceIds, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
List<Integer> filteredDeviceIds = new ArrayList<>();
|
List<Integer> filteredDeviceIds = new ArrayList<>();
|
||||||
String deviceIdStringList = deviceIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
if (deviceIds == null || deviceIds.isEmpty()) return filteredDeviceIds;
|
||||||
|
|
||||||
|
String deviceIdStringList = deviceIds.stream().map(id -> "?").collect(Collectors.joining(","));
|
||||||
try {
|
try {
|
||||||
Connection connection = getConnection();
|
Connection connection = getConnection();
|
||||||
String sql = "SELECT ID AS DEVICE_ID FROM DM_DEVICE WHERE ID IN " +
|
String sql = "SELECT ID AS DEVICE_ID FROM DM_DEVICE WHERE ID IN " +
|
||||||
"(" + deviceIdStringList + ") AND TENANT_ID = ? LIMIT ? OFFSET ?";
|
"(" + deviceIdStringList + ") AND TENANT_ID = ? LIMIT ? OFFSET ?";
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
preparedStatement.setInt(1, tenantId);
|
int paraIdx = 1;
|
||||||
preparedStatement.setInt(2, request.getRowCount());
|
for (Integer deviceId : deviceIds) {
|
||||||
preparedStatement.setInt(3, request.getStartIndex());
|
preparedStatement.setInt(paraIdx++, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement.setInt(paraIdx++, tenantId);
|
||||||
|
preparedStatement.setInt(paraIdx++, request.getRowCount());
|
||||||
|
preparedStatement.setInt(paraIdx, request.getStartIndex());
|
||||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
filteredDeviceIds.add(resultSet.getInt("DEVICE_ID"));
|
filteredDeviceIds.add(resultSet.getInt("DEVICE_ID"));
|
||||||
@ -3358,13 +3378,24 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
public int getDeviceCountNotInGivenIdList(List<Integer> deviceIds, int tenantId)
|
public int getDeviceCountNotInGivenIdList(List<Integer> deviceIds, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
int deviceCount = 0;
|
int deviceCount = 0;
|
||||||
String deviceIdStringList = deviceIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
||||||
try {
|
try {
|
||||||
Connection connection = getConnection();
|
Connection connection = getConnection();
|
||||||
String sql = "SELECT COUNT(ID) AS COUNT FROM DM_DEVICE WHERE ID NOT IN " +
|
String sql = "SELECT COUNT(ID) AS COUNT FROM DM_DEVICE WHERE TENANT_ID = ?";
|
||||||
"(" + deviceIdStringList + ") AND TENANT_ID = ?";
|
|
||||||
|
if (deviceIds != null && !deviceIds.isEmpty()) {
|
||||||
|
sql += " AND ID NOT IN ( " + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
preparedStatement.setInt(1, tenantId);
|
int paraIdx = 1;
|
||||||
|
preparedStatement.setInt(paraIdx++, tenantId);
|
||||||
|
|
||||||
|
if (deviceIds != null && !deviceIds.isEmpty()) {
|
||||||
|
for (Integer deviceId : deviceIds) {
|
||||||
|
preparedStatement.setInt(paraIdx++, deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
deviceCount = resultSet.getInt("COUNT");
|
deviceCount = resultSet.getInt("COUNT");
|
||||||
@ -3383,7 +3414,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
public List<Device> getDevicesByDeviceIds(PaginationRequest paginationRequest, List<Integer> deviceIds, int tenantId)
|
public List<Device> getDevicesByDeviceIds(PaginationRequest paginationRequest, List<Integer> deviceIds, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
String deviceIdStringList = deviceIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
if (deviceIds == null || deviceIds.isEmpty()) return devices;
|
||||||
|
|
||||||
|
String deviceIdStringList = deviceIds.stream().map(id -> "?").collect(Collectors.joining(","));
|
||||||
boolean isOwnerProvided = false;
|
boolean isOwnerProvided = false;
|
||||||
boolean isDeviceStatusProvided = false;
|
boolean isDeviceStatusProvided = false;
|
||||||
boolean isDeviceNameProvided = false;
|
boolean isDeviceNameProvided = false;
|
||||||
@ -3409,11 +3442,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
isDeviceNameProvided = true;
|
isDeviceNameProvided = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parameterIdx = 1;
|
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
|
int parameterIdx = 1;
|
||||||
preparedStatement.setInt(parameterIdx++, tenantId);
|
preparedStatement.setInt(parameterIdx++, tenantId);
|
||||||
|
|
||||||
|
for (Integer deviceId : deviceIds) {
|
||||||
|
preparedStatement.setInt(parameterIdx++, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
if (isOwnerProvided)
|
if (isOwnerProvided)
|
||||||
preparedStatement.setString(parameterIdx++, paginationRequest.getOwner());
|
preparedStatement.setString(parameterIdx++, paginationRequest.getOwner());
|
||||||
if (isDeviceStatusProvided)
|
if (isDeviceStatusProvided)
|
||||||
|
|||||||
@ -5596,7 +5596,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
@Override
|
@Override
|
||||||
public List<Integer> getDevicesNotInGivenIdList(List<Integer> deviceIds, PaginationRequest paginationRequest)
|
public List<Integer> getDevicesNotInGivenIdList(List<Integer> deviceIds, PaginationRequest paginationRequest)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
if (paginationRequest == null) {
|
if (paginationRequest == null) {
|
||||||
String msg = "Received null for pagination request";
|
String msg = "Received null for pagination request";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user