@ -1704,7 +1704,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List < SubscriptionsDTO > getGroupsSubscriptionDetailsByUUID ( String uuid , String subscriptionStatus , int offset ,
public List < SubscriptionsDTO > getGroupsSubscriptionDetailsByUUID ( String uuid , String subscriptionStatus , PaginationRequest request , int offset ,
int limit ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
@ -1738,7 +1738,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
// Retrieve group details and device IDs for the group using the service layer
GroupDetailsDTO groupDetailWithDevices =
groupManagementProviderService . getGroupDetailsWithDevices ( groupName , applicationDTO . getDeviceTypeId ( ) ,
offset, limit ) ;
request. getOwner ( ) , request . getDeviceName ( ) , request . getDeviceStatus ( ) , offset, limit ) ;
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO ( ) ;
groupDetailDTO . setId ( groupDetailWithDevices . getGroupId ( ) ) ;
@ -1771,12 +1771,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
if ( unsubscribe ) {
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
appReleaseId , ! unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) ) ;
}
for ( Integer deviceId : deviceIds ) {
List < DeviceSubscriptionDTO > deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
groupDetail . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds ) ;
groupDetail . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) ) ;
boolean isNewDevice = true ;
for ( DeviceSubscriptionDTO subscription : deviceSubscriptions ) {
if ( subscription . getDeviceId ( ) = = deviceId ) {
@ -1895,7 +1897,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List < SubscriptionsDTO > getUserSubscriptionsByUUID ( String uuid , String subscriptionStatus , int offset , int limit )
public List < SubscriptionsDTO > getUserSubscriptionsByUUID ( String uuid , String subscriptionStatus , PaginationRequest request , int offset , int limit )
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
@ -1928,7 +1930,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
// Retrieve owner details and device IDs for the user using the service layer
OwnerWithDeviceDTO ownerDetailsWithDevices =
deviceManagementProviderService . getOwnersWithDeviceIds ( userName , applicationDTO . getDeviceTypeId ( ) ) ;
deviceManagementProviderService . getOwnersWithDeviceIds ( userName , applicationDTO . getDeviceTypeId ( ) ,
request . getOwner ( ) , request . getDeviceName ( ) , request . getDeviceStatus ( ) ) ;
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO ( ) ;
userSubscriptionDTO . setName ( userSubscription . getName ( ) ) ;
@ -1959,14 +1962,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
if ( unsubscribe ) {
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
appReleaseId , ! unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) ) ;
}
for ( Integer deviceId : deviceIds ) {
List < DeviceSubscriptionDTO > deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
userSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds ) ;
userSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) ) ;
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId ) ;
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDeviceByDeviceId = = null ) {
continue ;
}
@ -2087,7 +2093,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List < SubscriptionsDTO > getRoleSubscriptionsByUUID ( String uuid , String subscriptionStatus , int offset , int limit )
public List < SubscriptionsDTO > getRoleSubscriptionsByUUID ( String uuid , String subscriptionStatus , PaginationRequest request , int offset , int limit )
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
@ -2145,7 +2151,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for ( String user : users ) {
OwnerWithDeviceDTO ownerDetailsWithDevices ;
try {
ownerDetailsWithDevices = deviceManagementProviderService . getOwnersWithDeviceIds ( user , applicationDTO . getDeviceTypeId ( ) ) ;
ownerDetailsWithDevices = deviceManagementProviderService . getOwnersWithDeviceIds ( user , applicationDTO . getDeviceTypeId ( ) ,
request . getOwner ( ) , request . getDeviceName ( ) , request . getDeviceStatus ( ) ) ;
} catch ( DeviceManagementDAOException e ) {
throw new ApplicationManagementException ( "Error retrieving owner details with devices for user: " + user , e ) ;
}
@ -2156,17 +2163,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
if ( unsubscribe ) {
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
appReleaseId , ! unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) ) ;
}
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId ) ;
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDeviceByDeviceId = = null ) {
continue ;
}
List < DeviceSubscriptionDTO > deviceSubscriptions ;
try {
deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
roleSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds ) ;
roleSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) ,
request . getActionType ( ) , request . getActionTriggeredBy ( ) ) ;
} catch ( ApplicationManagementDAOException e ) {
throw new ApplicationManagementException ( "Error retrieving device subscriptions" , e ) ;
}
@ -2302,7 +2312,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public DeviceSubscriptionResponseDTO getDeviceSubscriptionsDetailsByUUID ( String uuid , String subscriptionStatus , int offset ,
public DeviceSubscriptionResponseDTO getDeviceSubscriptionsDetailsByUUID ( String uuid , String subscriptionStatus , PaginationRequest request , int offset ,
int limit ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
@ -2332,7 +2342,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
List < DeviceDetailsDTO > allDevices =
deviceManagementProviderService . getDevicesByTenantId ( tenantId , applicationDTO . getDeviceTypeId ( ) ) ;
deviceManagementProviderService . getDevicesByTenantId ( tenantId , applicationDTO . getDeviceTypeId ( ) ,
request . getOwner ( ) , request . getDeviceStatus ( ) ) ;
List < Integer > deviceIds = allDevices . stream ( )
. map ( DeviceDetailsDTO : : getDeviceId )
@ -2357,9 +2368,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
. collect ( Collectors . toMap ( DeviceDetailsDTO : : getDeviceId , Function . identity ( ) ) ) ;
List < DeviceSubscriptionDTO > allSubscriptionsForUnSubscribed =
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , ! unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) ,
request . getActionType ( ) , request . getActionTriggeredBy ( ) ) ;
List < DeviceSubscriptionDTO > allSubscriptionsForSubscribed =
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , unsubscribe , tenantId , deviceIds ) ;
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) ,
request . getActionType ( ) , request . getActionTriggeredBy ( ) ) ;
Map < Integer , DeviceSubscriptionDTO > allSubscriptionForUnSubscribedMap = allSubscriptionsForUnSubscribed . stream ( )
. collect ( Collectors . toMap ( DeviceSubscriptionDTO : : getDeviceId , Function . identity ( ) ) ) ;
Map < Integer , DeviceSubscriptionDTO > allSubscriptionForSubscribedMap = allSubscriptionsForSubscribed . stream ( )
@ -2368,7 +2381,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for ( DeviceDetailsDTO device : allDevices ) {
Integer deviceId = device . getDeviceId ( ) ;
OwnerWithDeviceDTO ownerWithDevice =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId ) ;
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDevice = = null ) {
continue ;
}
@ -2490,8 +2504,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID ( String uuid , String subscriptionStatus , int offset , int limit )
throws ApplicationManagementException {
public DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID ( String uuid , String subscriptionStatus , PaginationRequest request ,
int offset , int limit ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
@ -2534,12 +2548,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusCounts . put ( "NEW" , 0 ) ;
List < DeviceDetailsDTO > allDevices =
deviceManagementProviderService . getDevicesByTenantId ( tenantId , applicationDTO . getDeviceTypeId ( ) ) ;
deviceManagementProviderService . getDevicesByTenantId ( tenantId , applicationDTO . getDeviceTypeId ( ) , request . getOwner ( ) ,
request . getDeviceStatus ( ) ) ;
for ( DeviceDetailsDTO device : allDevices ) {
Integer deviceId = device . getDeviceId ( ) ;
OwnerWithDeviceDTO ownerWithDevice =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId ) ;
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDevice = = null ) {
continue ;
}