@ -1704,12 +1704,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
@Override
public List < SubscriptionsDTO > getGroupsSubscriptionDetailsByUUID ( String uuid , String subscriptionStatus , int offset ,
public List < SubscriptionsDTO > getGroupsSubscriptionDetailsByUUID (
int limit ) throws ApplicationManagementException {
String uuid , String subscriptionStatus , PaginationRequest request , int offset , int limit )
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
String groupName ;
String status ;
try {
try {
ConnectionManagerUtil . openDBConnection ( ) ;
ConnectionManagerUtil . openDBConnection ( ) ;
@ -1720,8 +1720,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log . error ( msg ) ;
log . error ( msg ) ;
throw new NotFoundException ( msg ) ;
throw new NotFoundException ( msg ) ;
}
}
ApplicationDTO applicationDTO = this . applicationDAO . getAppWithRelatedRelease ( uuid , tenantId ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
List < SubscriptionsDTO > groupDetailsWithDevices = new ArrayList < > ( ) ;
List < SubscriptionsDTO > groupDetailsWithDevices = new ArrayList < > ( ) ;
List < GroupSubscriptionDTO > groupDetails =
List < GroupSubscriptionDTO > groupDetails =
@ -1733,11 +1733,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
GroupManagementProviderService groupManagementProviderService = HelperUtil . getGroupManagementProviderService ( ) ;
GroupManagementProviderService groupManagementProviderService = HelperUtil . getGroupManagementProviderService ( ) ;
for ( GroupSubscriptionDTO groupDetail : groupDetails ) {
for ( GroupSubscriptionDTO groupDetail : groupDetails ) {
groupName = groupDetail . getGroupName ( ) ;
if ( StringUtils . isNotBlank ( request . getGroupName ( ) ) & & ! request . getGroupName ( ) . equals ( groupDetail . getGroupName ( ) ) ) {
continue ;
}
String groupName = StringUtils . isNotBlank ( request . getGroupName ( ) ) ? request . getGroupName ( ) : groupDetail . getGroupName ( ) ;
// Retrieve group details and device IDs for the group using the service layer
// Retrieve group details and device IDs for the group using the service layer
GroupDetailsDTO groupDetailWithDevices =
GroupDetailsDTO groupDetailWithDevices =
groupManagementProviderService . getGroupDetailsWithDevices ( groupName , offset , limit ) ;
groupManagementProviderService . getGroupDetailsWithDevices (
groupName , applicationDTO . getDeviceTypeId ( ) , request . getOwner ( ) ,
request . getDeviceName ( ) , request . getDeviceStatus ( ) , offset , limit ) ;
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO ( ) ;
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO ( ) ;
groupDetailDTO . setId ( groupDetailWithDevices . getGroupId ( ) ) ;
groupDetailDTO . setId ( groupDetailWithDevices . getGroupId ( ) ) ;
@ -1760,24 +1767,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List < Integer > deviceIds = groupDetailWithDevices . getDeviceIds ( ) ;
List < Integer > deviceIds = groupDetailWithDevices . getDeviceIds ( ) ;
Map < String , Integer > statusCounts = new HashMap < > ( ) ;
Map < String , Integer > statusCounts = new HashMap < > ( ) ;
statusCounts . put ( "PENDING" , 0 ) ;
statusCounts . put ( "COMPLETED" , 0 ) ;
statusCounts . put ( "COMPLETED" , 0 ) ;
statusCounts . put ( "ERROR" , 0 ) ;
statusCounts . put ( "ERROR" , 0 ) ;
statusCounts . put ( "PENDING" , 0 ) ;
statusCounts . put ( "NEW" , 0 ) ;
statusCounts . put ( "NEW" , 0 ) ;
statusCounts . put ( "SUBSCRIBED" , 0 ) ;
statusCounts . put ( "SUBSCRIBED" , 0 ) ;
// Get subscribed devices if unsubscribed devices are requested
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
if ( unsubscribe ) {
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
}
for ( Integer deviceId : deviceIds ) {
for ( Integer deviceId : deviceIds ) {
List < DeviceSubscriptionDTO > deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
// Get subscribed devices if unsubscribed devices are requested
groupDetail . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds ) ;
List < DeviceSubscriptionDTO > deviceSubscriptions ;
if ( unsubscribe ) {
deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
appReleaseId , ! unsubscribe , tenantId , deviceIds ,
request . getActionStatus ( ) , request . getActionType ( ) , request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
} else {
deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
groupDetail . getAppReleaseId ( ) , false , tenantId , deviceIds ,
request . getActionStatus ( ) , request . getActionType ( ) , request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
}
List < DeviceSubscriptionDTO > filteredDeviceSubscriptions = deviceSubscriptions . stream ( )
. filter ( subscription - > StringUtils . isBlank ( request . getTabActionStatus ( ) ) | | subscription . getStatus ( ) . equals ( request . getTabActionStatus ( ) ) )
. collect ( Collectors . toList ( ) ) ;
boolean isNewDevice = true ;
boolean isNewDevice = true ;
for ( DeviceSubscriptionDTO subscription : deviceSubscriptions ) {
for ( DeviceSubscriptionDTO subscription : filtere dD eviceSubscriptions) {
if ( subscription . getDeviceId ( ) = = deviceId ) {
if ( subscription . getDeviceId ( ) = = deviceId ) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData ( ) ;
deviceDetail . setDeviceId ( subscription . getDeviceId ( ) ) ;
deviceDetail . setDeviceId ( subscription . getDeviceId ( ) ) ;
@ -1795,7 +1807,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail . setType ( groupDetailWithDevices . getDeviceTypes ( ) . get ( deviceId ) ) ;
deviceDetail . setType ( groupDetailWithDevices . getDeviceTypes ( ) . get ( deviceId ) ) ;
deviceDetail . setDeviceIdentifier ( groupDetailWithDevices . getDeviceIdentifiers ( ) . get ( deviceId ) ) ;
deviceDetail . setDeviceIdentifier ( groupDetailWithDevices . getDeviceIdentifiers ( ) . get ( deviceId ) ) ;
status = subscription . getStatus ( ) ;
String status = subscription . getStatus ( ) ;
switch ( status ) {
switch ( status ) {
case "COMPLETED" :
case "COMPLETED" :
installedDevices . add ( deviceDetail ) ;
installedDevices . add ( deviceDetail ) ;
@ -1813,13 +1825,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
pendingDevices . add ( deviceDetail ) ;
pendingDevices . add ( deviceDetail ) ;
statusCounts . put ( "PENDING" , statusCounts . get ( "PENDING" ) + 1 ) ;
statusCounts . put ( "PENDING" , statusCounts . get ( "PENDING" ) + 1 ) ;
break ;
break ;
default :
newDevices . add ( deviceDetail ) ;
statusCounts . put ( "NEW" , statusCounts . get ( "NEW" ) + 1 ) ;
break ;
}
}
isNewDevice = false ;
isNewDevice = false ;
}
}
}
}
if ( isNewDevice ) {
if ( isNewDevice ) {
boolean isSubscribedDevice = false ;
boolean isSubscribedDevice = false ;
for ( DeviceSubscriptionDTO subscribedDevice : subscribe dD eviceSubscriptions) {
for ( DeviceSubscriptionDTO subscribedDevice : deviceSubscriptions) {
if ( subscribedDevice . getDeviceId ( ) = = deviceId ) {
if ( subscribedDevice . getDeviceId ( ) = = deviceId ) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData ( ) ;
subscribedDeviceDetail . setDeviceId ( subscribedDevice . getDeviceId ( ) ) ;
subscribedDeviceDetail . setDeviceId ( subscribedDevice . getDeviceId ( ) ) ;
@ -1861,17 +1877,38 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
}
}
CategorizedSubscriptionResult categorizedSubscriptionResult ;
List < DeviceSubscriptionData > requestedDevices = new ArrayList < > ( ) ;
if ( subscribedDevices . isEmpty ( ) ) {
if ( StringUtils . isNotBlank ( request . getTabActionStatus ( ) ) ) {
categorizedSubscriptionResult =
switch ( request . getTabActionStatus ( ) ) {
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
case "COMPLETED" :
requestedDevices = installedDevices ;
break ;
case "PENDING" :
requestedDevices = pendingDevices ;
break ;
case "ERROR" :
requestedDevices = errorDevices ;
break ;
case "NEW" :
requestedDevices = newDevices ;
break ;
case "SUBSCRIBED" :
requestedDevices = subscribedDevices ;
break ;
}
groupDetailDTO . setDevices ( new CategorizedSubscriptionResult ( requestedDevices , request . getTabActionStatus ( ) ) ) ;
} else {
} else {
categorizedSubscriptionResult =
CategorizedSubscriptionResult categorizedSubscriptionResult ;
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices , subscribedDevices ) ;
if ( subscribedDevices . isEmpty ( ) ) {
categorizedSubscriptionResult =
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
} else {
categorizedSubscriptionResult =
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices , subscribedDevices ) ;
}
groupDetailDTO . setDevices ( categorizedSubscriptionResult ) ;
}
}
groupDetailDTO . setDevices ( categorizedSubscriptionResult ) ;
groupDetailDTO . setStatusPercentages ( statusPercentages ) ;
groupDetailDTO . setStatusPercentages ( statusPercentages ) ;
groupDetailsWithDevices . add ( groupDetailDTO ) ;
groupDetailsWithDevices . add ( groupDetailDTO ) ;
}
}
@ -1894,11 +1931,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
@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 {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
String userName ;
String status ;
String status ;
try {
try {
@ -1910,8 +1947,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log . error ( msg ) ;
log . error ( msg ) ;
throw new NotFoundException ( msg ) ;
throw new NotFoundException ( msg ) ;
}
}
ApplicationDTO applicationDTO = this . applicationDAO . getAppWithRelatedRelease ( uuid , tenantId ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
List < SubscriptionsDTO > userSubscriptionsWithDevices = new ArrayList < > ( ) ;
List < SubscriptionsDTO > userSubscriptionsWithDevices = new ArrayList < > ( ) ;
List < SubscriptionsDTO > userSubscriptions =
List < SubscriptionsDTO > userSubscriptions =
@ -1923,11 +1960,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil . getDeviceManagementProviderService ( ) ;
DeviceManagementProviderService deviceManagementProviderService = HelperUtil . getDeviceManagementProviderService ( ) ;
for ( SubscriptionsDTO userSubscription : userSubscriptions ) {
for ( SubscriptionsDTO userSubscription : userSubscriptions ) {
userName = userSubscription . getName ( ) ;
if ( StringUtils . isNotBlank ( request . getUserName ( ) ) & & ! request . getUserName ( ) . equals ( userSubscription . getName ( ) ) ) {
continue ;
}
String userName = StringUtils . isNotBlank ( request . getUserName ( ) ) ? request . getUserName ( ) : userSubscription . getName ( ) ;
// Retrieve owner details and device IDs for the user using the service layer
// Retrieve owner details and device IDs for the user using the service layer
OwnerWithDeviceDTO ownerDetailsWithDevices =
OwnerWithDeviceDTO ownerDetailsWithDevices =
deviceManagementProviderService . getOwnersWithDeviceIds ( userName ) ;
deviceManagementProviderService . getOwnersWithDeviceIds ( userName , applicationDTO . getDeviceTypeId ( ) ,
request . getOwner ( ) , request . getDeviceName ( ) , request . getDeviceStatus ( ) ) ;
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO ( ) ;
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO ( ) ;
userSubscriptionDTO . setName ( userSubscription . getName ( ) ) ;
userSubscriptionDTO . setName ( userSubscription . getName ( ) ) ;
@ -1958,21 +2001,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
if ( unsubscribe ) {
if ( unsubscribe ) {
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
appReleaseId , ! unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
}
}
for ( Integer deviceId : deviceIds ) {
for ( Integer deviceId : deviceIds ) {
List < DeviceSubscriptionDTO > deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
List < DeviceSubscriptionDTO > deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
userSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds ) ;
userSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDeviceByDeviceId = = null ) {
continue ;
}
boolean isNewDevice = true ;
boolean isNewDevice = true ;
for ( DeviceSubscriptionDTO subscription : deviceSubscriptions ) {
for ( DeviceSubscriptionDTO subscription : deviceSubscriptions ) {
if ( subscription . getDeviceId ( ) = = deviceId ) {
if ( subscription . getDeviceId ( ) = = deviceId ) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData ( ) ;
deviceDetail . setDeviceId ( subscription . getDeviceId ( ) ) ;
deviceDetail . setDeviceId ( subscription . getDeviceId ( ) ) ;
deviceDetail . setSubId ( subscription . getId ( ) ) ;
deviceDetail . setSubId ( subscription . getId ( ) ) ;
deviceDetail . setDeviceOwner ( ownerDetailsWithDevices . getUserName ( ) ) ;
deviceDetail . setDeviceOwner ( owner WithDeviceByDeviceId . getUserName ( ) ) ;
deviceDetail . setDeviceStatus ( owner DetailsWithDevices . getDeviceStatus ( ) ) ;
deviceDetail . setDeviceStatus ( owner WithDeviceByDeviceId . getDeviceStatus ( ) ) ;
deviceDetail . setDeviceName ( owner DetailsWithDevices . getDeviceNames ( ) ) ;
deviceDetail . setDeviceName ( owner WithDeviceByDeviceId . getDeviceNames ( ) ) ;
deviceDetail . setActionType ( subscription . getActionTriggeredFrom ( ) ) ;
deviceDetail . setActionType ( subscription . getActionTriggeredFrom ( ) ) ;
deviceDetail . setStatus ( subscription . getStatus ( ) ) ;
deviceDetail . setStatus ( subscription . getStatus ( ) ) ;
deviceDetail . setActionType ( subscription . getActionTriggeredFrom ( ) ) ;
deviceDetail . setActionType ( subscription . getActionTriggeredFrom ( ) ) ;
@ -1981,8 +2032,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail . setUnsubscribed ( subscription . isUnsubscribed ( ) ) ;
deviceDetail . setUnsubscribed ( subscription . isUnsubscribed ( ) ) ;
deviceDetail . setUnsubscribedBy ( subscription . getUnsubscribedBy ( ) ) ;
deviceDetail . setUnsubscribedBy ( subscription . getUnsubscribedBy ( ) ) ;
deviceDetail . setUnsubscribedTimestamp ( subscription . getUnsubscribedTimestamp ( ) ) ;
deviceDetail . setUnsubscribedTimestamp ( subscription . getUnsubscribedTimestamp ( ) ) ;
deviceDetail . setType ( owner DetailsWithDevices . getDeviceTypes ( ) ) ;
deviceDetail . setType ( owner WithDeviceByDeviceId . getDeviceTypes ( ) ) ;
deviceDetail . setDeviceIdentifier ( owner DetailsWithDevices . getDeviceIdentifiers ( ) ) ;
deviceDetail . setDeviceIdentifier ( owner WithDeviceByDeviceId . getDeviceIdentifiers ( ) ) ;
status = subscription . getStatus ( ) ;
status = subscription . getStatus ( ) ;
switch ( status ) {
switch ( status ) {
@ -2012,16 +2063,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if ( subscribedDevice . getDeviceId ( ) = = deviceId ) {
if ( subscribedDevice . getDeviceId ( ) = = deviceId ) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData ( ) ;
subscribedDeviceDetail . setDeviceId ( subscribedDevice . getDeviceId ( ) ) ;
subscribedDeviceDetail . setDeviceId ( subscribedDevice . getDeviceId ( ) ) ;
subscribedDeviceDetail . setDeviceName ( owner DetailsWithDevices . getDeviceNames ( ) ) ;
subscribedDeviceDetail . setDeviceName ( owner WithDeviceByDeviceId . getDeviceNames ( ) ) ;
subscribedDeviceDetail . setDeviceOwner ( owner DetailsWithDevices . getUserName ( ) ) ;
subscribedDeviceDetail . setDeviceOwner ( owner WithDeviceByDeviceId . getUserName ( ) ) ;
subscribedDeviceDetail . setDeviceStatus ( owner DetailsWithDevices . getDeviceStatus ( ) ) ;
subscribedDeviceDetail . setDeviceStatus ( owner WithDeviceByDeviceId . getDeviceStatus ( ) ) ;
subscribedDeviceDetail . setSubId ( subscribedDevice . getId ( ) ) ;
subscribedDeviceDetail . setSubId ( subscribedDevice . getId ( ) ) ;
subscribedDeviceDetail . setActionTriggeredBy ( subscribedDevice . getSubscribedBy ( ) ) ;
subscribedDeviceDetail . setActionTriggeredBy ( subscribedDevice . getSubscribedBy ( ) ) ;
subscribedDeviceDetail . setActionTriggeredTimestamp ( subscribedDevice . getSubscribedTimestamp ( ) ) ;
subscribedDeviceDetail . setActionTriggeredTimestamp ( subscribedDevice . getSubscribedTimestamp ( ) ) ;
subscribedDeviceDetail . setActionType ( subscribedDevice . getActionTriggeredFrom ( ) ) ;
subscribedDeviceDetail . setActionType ( subscribedDevice . getActionTriggeredFrom ( ) ) ;
subscribedDeviceDetail . setStatus ( subscribedDevice . getStatus ( ) ) ;
subscribedDeviceDetail . setStatus ( subscribedDevice . getStatus ( ) ) ;
subscribedDeviceDetail . setType ( owner DetailsWithDevices . getDeviceTypes ( ) ) ;
subscribedDeviceDetail . setType ( owner WithDeviceByDeviceId . getDeviceTypes ( ) ) ;
subscribedDeviceDetail . setDeviceIdentifier ( owner DetailsWithDevices . getDeviceIdentifiers ( ) ) ;
subscribedDeviceDetail . setDeviceIdentifier ( owner WithDeviceByDeviceId . getDeviceIdentifiers ( ) ) ;
subscribedDevices . add ( subscribedDeviceDetail ) ;
subscribedDevices . add ( subscribedDeviceDetail ) ;
statusCounts . put ( "SUBSCRIBED" , statusCounts . get ( "SUBSCRIBED" ) + 1 ) ;
statusCounts . put ( "SUBSCRIBED" , statusCounts . get ( "SUBSCRIBED" ) + 1 ) ;
isSubscribedDevice = true ;
isSubscribedDevice = true ;
@ -2031,11 +2082,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if ( ! isSubscribedDevice ) {
if ( ! isSubscribedDevice ) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData ( ) ;
newDeviceDetail . setDeviceId ( deviceId ) ;
newDeviceDetail . setDeviceId ( deviceId ) ;
newDeviceDetail . setDeviceOwner ( owner DetailsWithDevices . getUserName ( ) ) ;
newDeviceDetail . setDeviceOwner ( owner WithDeviceByDeviceId . getUserName ( ) ) ;
newDeviceDetail . setDeviceStatus ( owner DetailsWithDevices . getDeviceStatus ( ) ) ;
newDeviceDetail . setDeviceStatus ( owner WithDeviceByDeviceId . getDeviceStatus ( ) ) ;
newDeviceDetail . setDeviceName ( owner DetailsWithDevices . getDeviceNames ( ) ) ;
newDeviceDetail . setDeviceName ( owner WithDeviceByDeviceId . getDeviceNames ( ) ) ;
newDeviceDetail . setType ( owner DetailsWithDevices . getDeviceTypes ( ) ) ;
newDeviceDetail . setType ( owner WithDeviceByDeviceId . getDeviceTypes ( ) ) ;
newDeviceDetail . setDeviceIdentifier ( owner DetailsWithDevices . getDeviceIdentifiers ( ) ) ;
newDeviceDetail . setDeviceIdentifier ( owner WithDeviceByDeviceId . getDeviceIdentifiers ( ) ) ;
newDevices . add ( newDeviceDetail ) ;
newDevices . add ( newDeviceDetail ) ;
statusCounts . put ( "NEW" , statusCounts . get ( "NEW" ) + 1 ) ;
statusCounts . put ( "NEW" , statusCounts . get ( "NEW" ) + 1 ) ;
}
}
@ -2050,20 +2101,42 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
}
}
CategorizedSubscriptionResult categorizedSubscriptionResult ;
List < DeviceSubscriptionData > requestedDevices = new ArrayList < > ( ) ;
if ( subscribedDevices . isEmpty ( ) ) {
if ( StringUtils . isNotBlank ( request . getTabActionStatus ( ) ) ) {
categorizedSubscriptionResult =
switch ( request . getTabActionStatus ( ) ) {
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
case "COMPLETED" :
requestedDevices = installedDevices ;
break ;
case "PENDING" :
requestedDevices = pendingDevices ;
break ;
case "ERROR" :
requestedDevices = errorDevices ;
break ;
case "NEW" :
requestedDevices = newDevices ;
break ;
case "SUBSCRIBED" :
requestedDevices = subscribedDevices ;
break ;
}
userSubscriptionDTO . setDevices ( new CategorizedSubscriptionResult ( requestedDevices , request . getTabActionStatus ( ) ) ) ;
} else {
} else {
categorizedSubscriptionResult =
CategorizedSubscriptionResult categorizedSubscriptionResult ;
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices , subscribedDevices ) ;
if ( subscribedDevices . isEmpty ( ) ) {
}
categorizedSubscriptionResult =
userSubscriptionDTO . setDevices ( categorizedSubscriptionResult ) ;
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
userSubscriptionDTO . setStatusPercentages ( statusPercentages ) ;
} else {
categorizedSubscriptionResult =
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ,
subscribedDevices ) ;
}
userSubscriptionDTO . setDevices ( categorizedSubscriptionResult ) ;
userSubscriptionDTO . setStatusPercentages ( statusPercentages ) ;
}
userSubscriptionsWithDevices . add ( userSubscriptionDTO ) ;
userSubscriptionsWithDevices . add ( userSubscriptionDTO ) ;
}
}
return userSubscriptionsWithDevices ;
return userSubscriptionsWithDevices ;
} catch ( ApplicationManagementDAOException e ) {
} catch ( ApplicationManagementDAOException e ) {
String msg = "Error occurred while getting user subscriptions for the application release UUID: " + uuid ;
String msg = "Error occurred while getting user subscriptions for the application release UUID: " + uuid ;
@ -2081,7 +2154,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
@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 {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
@ -2097,8 +2171,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log . error ( msg ) ;
log . error ( msg ) ;
throw new NotFoundException ( msg ) ;
throw new NotFoundException ( msg ) ;
}
}
ApplicationDTO applicationDTO = this . applicationDAO . getAppWithRelatedRelease ( uuid , tenantId ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
List < SubscriptionsDTO > roleSubscriptionsWithDevices = new ArrayList < > ( ) ;
List < SubscriptionsDTO > roleSubscriptionsWithDevices = new ArrayList < > ( ) ;
List < SubscriptionsDTO > roleSubscriptions =
List < SubscriptionsDTO > roleSubscriptions =
@ -2110,7 +2184,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil . getDeviceManagementProviderService ( ) ;
DeviceManagementProviderService deviceManagementProviderService = HelperUtil . getDeviceManagementProviderService ( ) ;
for ( SubscriptionsDTO roleSubscription : roleSubscriptions ) {
for ( SubscriptionsDTO roleSubscription : roleSubscriptions ) {
roleName = roleSubscription . getName ( ) ;
roleName = StringUtils . isNotBlank ( request . getRoleName ( ) ) ? request . getRoleName ( ) : roleSubscription . getName ( ) ;
SubscriptionsDTO roleSubscriptionDTO = new SubscriptionsDTO ( ) ;
SubscriptionsDTO roleSubscriptionDTO = new SubscriptionsDTO ( ) ;
roleSubscriptionDTO . setName ( roleSubscription . getName ( ) ) ;
roleSubscriptionDTO . setName ( roleSubscription . getName ( ) ) ;
@ -2139,7 +2214,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for ( String user : users ) {
for ( String user : users ) {
OwnerWithDeviceDTO ownerDetailsWithDevices ;
OwnerWithDeviceDTO ownerDetailsWithDevices ;
try {
try {
ownerDetailsWithDevices = deviceManagementProviderService . getOwnersWithDeviceIds ( user ) ;
ownerDetailsWithDevices = deviceManagementProviderService . getOwnersWithDeviceIds ( user , applicationDTO . getDeviceTypeId ( ) ,
request . getOwner ( ) , request . getDeviceName ( ) , request . getDeviceStatus ( ) ) ;
} catch ( DeviceManagementDAOException e ) {
} catch ( DeviceManagementDAOException e ) {
throw new ApplicationManagementException ( "Error retrieving owner details with devices for user: " + user , e ) ;
throw new ApplicationManagementException ( "Error retrieving owner details with devices for user: " + user , e ) ;
}
}
@ -2150,13 +2226,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
List < DeviceSubscriptionDTO > subscribedDeviceSubscriptions = new ArrayList < > ( ) ;
if ( unsubscribe ) {
if ( unsubscribe ) {
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
subscribedDeviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
appReleaseId , ! unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) , request . getActionType ( ) ,
request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
}
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDeviceByDeviceId = = null ) {
continue ;
}
}
List < DeviceSubscriptionDTO > deviceSubscriptions ;
List < DeviceSubscriptionDTO > deviceSubscriptions ;
try {
try {
deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
deviceSubscriptions = subscriptionDAO . getSubscriptionDetailsByDeviceIds (
roleSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds ) ;
roleSubscription . getAppReleaseId ( ) , unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) ,
request . getActionType ( ) , request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
} catch ( ApplicationManagementDAOException e ) {
} catch ( ApplicationManagementDAOException e ) {
throw new ApplicationManagementException ( "Error retrieving device subscriptions" , e ) ;
throw new ApplicationManagementException ( "Error retrieving device subscriptions" , e ) ;
}
}
@ -2166,9 +2249,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if ( deviceSubscription . getDeviceId ( ) = = deviceId ) {
if ( deviceSubscription . getDeviceId ( ) = = deviceId ) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData ( ) ;
deviceDetail . setDeviceId ( deviceSubscription . getDeviceId ( ) ) ;
deviceDetail . setDeviceId ( deviceSubscription . getDeviceId ( ) ) ;
deviceDetail . setDeviceName ( owner DetailsWithDevices . getDeviceNames ( ) ) ;
deviceDetail . setDeviceName ( owner WithDeviceByDeviceId . getDeviceNames ( ) ) ;
deviceDetail . setDeviceOwner ( owner DetailsWithDevices . getUserName ( ) ) ;
deviceDetail . setDeviceOwner ( owner WithDeviceByDeviceId . getUserName ( ) ) ;
deviceDetail . setDeviceStatus ( owner DetailsWithDevices . getDeviceStatus ( ) ) ;
deviceDetail . setDeviceStatus ( owner WithDeviceByDeviceId . getDeviceStatus ( ) ) ;
deviceDetail . setActionType ( deviceSubscription . getActionTriggeredFrom ( ) ) ;
deviceDetail . setActionType ( deviceSubscription . getActionTriggeredFrom ( ) ) ;
deviceDetail . setStatus ( deviceSubscription . getStatus ( ) ) ;
deviceDetail . setStatus ( deviceSubscription . getStatus ( ) ) ;
deviceDetail . setActionType ( deviceSubscription . getActionTriggeredFrom ( ) ) ;
deviceDetail . setActionType ( deviceSubscription . getActionTriggeredFrom ( ) ) ;
@ -2178,8 +2261,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail . setUnsubscribed ( deviceSubscription . isUnsubscribed ( ) ) ;
deviceDetail . setUnsubscribed ( deviceSubscription . isUnsubscribed ( ) ) ;
deviceDetail . setUnsubscribedBy ( deviceSubscription . getUnsubscribedBy ( ) ) ;
deviceDetail . setUnsubscribedBy ( deviceSubscription . getUnsubscribedBy ( ) ) ;
deviceDetail . setUnsubscribedTimestamp ( deviceSubscription . getUnsubscribedTimestamp ( ) ) ;
deviceDetail . setUnsubscribedTimestamp ( deviceSubscription . getUnsubscribedTimestamp ( ) ) ;
deviceDetail . setType ( owner DetailsWithDevices . getDeviceTypes ( ) ) ;
deviceDetail . setType ( owner WithDeviceByDeviceId . getDeviceTypes ( ) ) ;
deviceDetail . setDeviceIdentifier ( owner DetailsWithDevices . getDeviceIdentifiers ( ) ) ;
deviceDetail . setDeviceIdentifier ( owner WithDeviceByDeviceId . getDeviceIdentifiers ( ) ) ;
status = deviceSubscription . getStatus ( ) ;
status = deviceSubscription . getStatus ( ) ;
switch ( status ) {
switch ( status ) {
@ -2209,16 +2292,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if ( subscribedDevice . getDeviceId ( ) = = deviceId ) {
if ( subscribedDevice . getDeviceId ( ) = = deviceId ) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData ( ) ;
subscribedDeviceDetail . setDeviceId ( subscribedDevice . getDeviceId ( ) ) ;
subscribedDeviceDetail . setDeviceId ( subscribedDevice . getDeviceId ( ) ) ;
subscribedDeviceDetail . setDeviceName ( owner DetailsWithDevices . getDeviceNames ( ) ) ;
subscribedDeviceDetail . setDeviceName ( owner WithDeviceByDeviceId . getDeviceNames ( ) ) ;
subscribedDeviceDetail . setDeviceOwner ( owner DetailsWithDevices . getUserName ( ) ) ;
subscribedDeviceDetail . setDeviceOwner ( owner WithDeviceByDeviceId . getUserName ( ) ) ;
subscribedDeviceDetail . setDeviceStatus ( owner DetailsWithDevices . getDeviceStatus ( ) ) ;
subscribedDeviceDetail . setDeviceStatus ( owner WithDeviceByDeviceId . getDeviceStatus ( ) ) ;
subscribedDeviceDetail . setSubId ( subscribedDevice . getId ( ) ) ;
subscribedDeviceDetail . setSubId ( subscribedDevice . getId ( ) ) ;
subscribedDeviceDetail . setActionTriggeredBy ( subscribedDevice . getSubscribedBy ( ) ) ;
subscribedDeviceDetail . setActionTriggeredBy ( subscribedDevice . getSubscribedBy ( ) ) ;
subscribedDeviceDetail . setActionTriggeredTimestamp ( subscribedDevice . getSubscribedTimestamp ( ) ) ;
subscribedDeviceDetail . setActionTriggeredTimestamp ( subscribedDevice . getSubscribedTimestamp ( ) ) ;
subscribedDeviceDetail . setActionType ( subscribedDevice . getActionTriggeredFrom ( ) ) ;
subscribedDeviceDetail . setActionType ( subscribedDevice . getActionTriggeredFrom ( ) ) ;
subscribedDeviceDetail . setStatus ( subscribedDevice . getStatus ( ) ) ;
subscribedDeviceDetail . setStatus ( subscribedDevice . getStatus ( ) ) ;
subscribedDeviceDetail . setType ( owner DetailsWithDevices . getDeviceTypes ( ) ) ;
subscribedDeviceDetail . setType ( owner WithDeviceByDeviceId . getDeviceTypes ( ) ) ;
subscribedDeviceDetail . setDeviceIdentifier ( owner DetailsWithDevices . getDeviceIdentifiers ( ) ) ;
subscribedDeviceDetail . setDeviceIdentifier ( owner WithDeviceByDeviceId . getDeviceIdentifiers ( ) ) ;
subscribedDevices . add ( subscribedDeviceDetail ) ;
subscribedDevices . add ( subscribedDeviceDetail ) ;
statusCounts . put ( "SUBSCRIBED" , statusCounts . get ( "SUBSCRIBED" ) + 1 ) ;
statusCounts . put ( "SUBSCRIBED" , statusCounts . get ( "SUBSCRIBED" ) + 1 ) ;
isSubscribedDevice = true ;
isSubscribedDevice = true ;
@ -2228,11 +2311,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if ( ! isSubscribedDevice ) {
if ( ! isSubscribedDevice ) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData ( ) ;
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData ( ) ;
newDeviceDetail . setDeviceId ( deviceId ) ;
newDeviceDetail . setDeviceId ( deviceId ) ;
newDeviceDetail . setDeviceName ( owner DetailsWithDevices . getDeviceNames ( ) ) ;
newDeviceDetail . setDeviceName ( owner WithDeviceByDeviceId . getDeviceNames ( ) ) ;
newDeviceDetail . setDeviceOwner ( owner DetailsWithDevices . getUserName ( ) ) ;
newDeviceDetail . setDeviceOwner ( owner WithDeviceByDeviceId . getUserName ( ) ) ;
newDeviceDetail . setDeviceStatus ( owner DetailsWithDevices . getDeviceStatus ( ) ) ;
newDeviceDetail . setDeviceStatus ( owner WithDeviceByDeviceId . getDeviceStatus ( ) ) ;
newDeviceDetail . setType ( owner DetailsWithDevices . getDeviceTypes ( ) ) ;
newDeviceDetail . setType ( owner WithDeviceByDeviceId . getDeviceTypes ( ) ) ;
newDeviceDetail . setDeviceIdentifier ( owner DetailsWithDevices . getDeviceIdentifiers ( ) ) ;
newDeviceDetail . setDeviceIdentifier ( owner WithDeviceByDeviceId . getDeviceIdentifiers ( ) ) ;
newDevices . add ( newDeviceDetail ) ;
newDevices . add ( newDeviceDetail ) ;
statusCounts . put ( "NEW" , statusCounts . get ( "NEW" ) + 1 ) ;
statusCounts . put ( "NEW" , statusCounts . get ( "NEW" ) + 1 ) ;
}
}
@ -2249,23 +2332,46 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
}
}
CategorizedSubscriptionResult categorizedSubscriptionResult ;
List < DeviceSubscriptionData > requestedDevices = new ArrayList < > ( ) ;
if ( subscribedDevices . isEmpty ( ) ) {
if ( StringUtils . isNotBlank ( request . getTabActionStatus ( ) ) ) {
categorizedSubscriptionResult =
switch ( request . getTabActionStatus ( ) ) {
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
case "COMPLETED" :
requestedDevices = installedDevices ;
break ;
case "PENDING" :
requestedDevices = pendingDevices ;
break ;
case "ERROR" :
requestedDevices = errorDevices ;
break ;
case "NEW" :
requestedDevices = newDevices ;
break ;
case "SUBSCRIBED" :
requestedDevices = subscribedDevices ;
break ;
}
roleSubscriptionDTO . setDevices ( new CategorizedSubscriptionResult ( requestedDevices , request . getTabActionStatus ( ) ) ) ;
} else {
} else {
categorizedSubscriptionResult =
CategorizedSubscriptionResult categorizedSubscriptionResult ;
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices , subscribedDevices ) ;
if ( subscribedDevices . isEmpty ( ) ) {
categorizedSubscriptionResult =
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
} else {
categorizedSubscriptionResult =
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ,
subscribedDevices ) ;
}
roleSubscriptionDTO . setDevices ( categorizedSubscriptionResult ) ;
roleSubscriptionDTO . setStatusPercentages ( statusPercentages ) ;
roleSubscriptionDTO . setDeviceCount ( totalDevices ) ;
}
}
roleSubscriptionDTO . setDevices ( categorizedSubscriptionResult ) ;
roleSubscriptionDTO . setStatusPercentages ( statusPercentages ) ;
roleSubscriptionDTO . setDeviceCount ( totalDevices ) ;
roleSubscriptionsWithDevices . add ( roleSubscriptionDTO ) ;
roleSubscriptionsWithDevices . add ( roleSubscriptionDTO ) ;
}
}
return roleSubscriptionsWithDevices ;
return roleSubscriptionsWithDevices ;
} catch ( ApplicationManagementDAOException e ) {
} catch ( ApplicationManagementDAOException | DeviceManagementDAOException e ) {
String msg = "Error occurred in retrieving role subscriptions with devices" ;
String msg = "Error occurred in retrieving role subscriptions with devices" ;
log . error ( msg , e ) ;
log . error ( msg , e ) ;
throw new ApplicationManagementException ( msg , e ) ;
throw new ApplicationManagementException ( msg , e ) ;
@ -2292,7 +2398,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
@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 limit ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
@ -2307,6 +2413,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log . error ( msg ) ;
log . error ( msg ) ;
throw new NotFoundException ( msg ) ;
throw new NotFoundException ( msg ) ;
}
}
ApplicationDTO applicationDTO = this . applicationDAO . getAppWithRelatedRelease ( uuid , tenantId ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
DeviceManagementProviderService deviceManagementProviderService = HelperUtil . getDeviceManagementProviderService ( ) ;
DeviceManagementProviderService deviceManagementProviderService = HelperUtil . getDeviceManagementProviderService ( ) ;
@ -2321,7 +2428,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
List < DeviceDetailsDTO > allDevices =
List < DeviceDetailsDTO > allDevices =
deviceManagementProviderService . getDevicesByTenantId ( tenantId ) ;
deviceManagementProviderService . getDevicesByTenantId ( tenantId , applicationDTO . getDeviceTypeId ( ) ,
request . getOwner ( ) , request . getDeviceStatus ( ) ) ;
List < Integer > deviceIds = allDevices . stream ( )
List < Integer > deviceIds = allDevices . stream ( )
. map ( DeviceDetailsDTO : : getDeviceId )
. map ( DeviceDetailsDTO : : getDeviceId )
@ -2346,9 +2454,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
. collect ( Collectors . toMap ( DeviceDetailsDTO : : getDeviceId , Function . identity ( ) ) ) ;
. collect ( Collectors . toMap ( DeviceDetailsDTO : : getDeviceId , Function . identity ( ) ) ) ;
List < DeviceSubscriptionDTO > allSubscriptionsForUnSubscribed =
List < DeviceSubscriptionDTO > allSubscriptionsForUnSubscribed =
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , ! unsubscribe , tenantId , deviceIds ) ;
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , ! unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) ,
request . getActionType ( ) , request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
List < DeviceSubscriptionDTO > allSubscriptionsForSubscribed =
List < DeviceSubscriptionDTO > allSubscriptionsForSubscribed =
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , unsubscribe , tenantId , deviceIds ) ;
subscriptionDAO . getSubscriptionDetailsByDeviceIds ( appReleaseId , unsubscribe , tenantId , deviceIds , request . getActionStatus ( ) ,
request . getActionType ( ) , request . getActionTriggeredBy ( ) , request . getTabActionStatus ( ) ) ;
Map < Integer , DeviceSubscriptionDTO > allSubscriptionForUnSubscribedMap = allSubscriptionsForUnSubscribed . stream ( )
Map < Integer , DeviceSubscriptionDTO > allSubscriptionForUnSubscribedMap = allSubscriptionsForUnSubscribed . stream ( )
. collect ( Collectors . toMap ( DeviceSubscriptionDTO : : getDeviceId , Function . identity ( ) ) ) ;
. collect ( Collectors . toMap ( DeviceSubscriptionDTO : : getDeviceId , Function . identity ( ) ) ) ;
Map < Integer , DeviceSubscriptionDTO > allSubscriptionForSubscribedMap = allSubscriptionsForSubscribed . stream ( )
Map < Integer , DeviceSubscriptionDTO > allSubscriptionForSubscribedMap = allSubscriptionsForSubscribed . stream ( )
@ -2357,7 +2467,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for ( DeviceDetailsDTO device : allDevices ) {
for ( DeviceDetailsDTO device : allDevices ) {
Integer deviceId = device . getDeviceId ( ) ;
Integer deviceId = device . getDeviceId ( ) ;
OwnerWithDeviceDTO ownerWithDevice =
OwnerWithDeviceDTO ownerWithDevice =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId ) ;
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDevice = = null ) {
if ( ownerWithDevice = = null ) {
continue ;
continue ;
}
}
@ -2450,14 +2561,35 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
}
}
CategorizedSubscriptionResult categorizedSubscriptionResult ;
List < DeviceSubscriptionData > requestedDevices = new ArrayList < > ( ) ;
if ( subscribedDevices . isEmpty ( ) ) {
if ( StringUtils . isNotBlank ( request . getTabActionStatus ( ) ) ) {
categorizedSubscriptionResult =
switch ( request . getTabActionStatus ( ) ) {
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
case "COMPLETED" :
requestedDevices = installedDevices ;
break ;
case "PENDING" :
requestedDevices = pendingDevices ;
break ;
case "ERROR" :
requestedDevices = errorDevices ;
break ;
case "NEW" :
requestedDevices = newDevices ;
break ;
case "SUBSCRIBED" :
requestedDevices = subscribedDevices ;
break ;
}
} else {
} else {
categorizedSubscriptionResult =
requestedDevices . addAll ( installedDevices ) ;
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices , subscribedDevices ) ;
requestedDevices . addAll ( pendingDevices ) ;
requestedDevices . addAll ( errorDevices ) ;
requestedDevices . addAll ( newDevices ) ;
requestedDevices . addAll ( subscribedDevices ) ;
}
}
CategorizedSubscriptionResult categorizedSubscriptionResult =
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices , subscribedDevices ) ;
DeviceSubscriptionResponseDTO deviceSubscriptionResponse =
DeviceSubscriptionResponseDTO deviceSubscriptionResponse =
new DeviceSubscriptionResponseDTO ( totalDevices , statusPercentages , categorizedSubscriptionResult ) ;
new DeviceSubscriptionResponseDTO ( totalDevices , statusPercentages , categorizedSubscriptionResult ) ;
@ -2479,8 +2611,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
@Override
public DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID ( String uuid , String subscriptionStatus , int offset , int limit )
public DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID ( String uuid , String subscriptionStatus , PaginationRequest request ,
throws ApplicationManagementException {
int offset , int limit ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
boolean unsubscribe = subscriptionStatus . equals ( "unsubscribed" ) ;
@ -2493,10 +2625,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log . error ( msg ) ;
log . error ( msg ) ;
throw new NotFoundException ( msg ) ;
throw new NotFoundException ( msg ) ;
}
}
ApplicationDTO applicationDTO = this . applicationDAO . getAppWithRelatedRelease ( uuid , tenantId ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
int appReleaseId = applicationReleaseDTO . getId ( ) ;
List < DeviceSubscriptionDTO > allSubscriptions =
List < DeviceSubscriptionDTO > allSubscriptions =
subscriptionDAO . getAllSubscriptionsDetails ( appReleaseId , unsubscribe , tenantId , offset , limit ) ;
subscriptionDAO . getAllSubscriptionsDetails ( appReleaseId , unsubscribe , tenantId , request . getActionStatus ( ) ,
request . getActionType ( ) , request . getActionTriggeredBy ( ) , offset , limit ) ;
// empty response for no subscriptions
// empty response for no subscriptions
if ( allSubscriptions . isEmpty ( ) ) {
if ( allSubscriptions . isEmpty ( ) ) {
@ -2522,12 +2656,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusCounts . put ( "NEW" , 0 ) ;
statusCounts . put ( "NEW" , 0 ) ;
List < DeviceDetailsDTO > allDevices =
List < DeviceDetailsDTO > allDevices =
deviceManagementProviderService . getDevicesByTenantId ( tenantId ) ;
deviceManagementProviderService . getDevicesByTenantId ( tenantId , applicationDTO . getDeviceTypeId ( ) , request . getOwner ( ) ,
request . getDeviceStatus ( ) ) ;
for ( DeviceDetailsDTO device : allDevices ) {
for ( DeviceDetailsDTO device : allDevices ) {
Integer deviceId = device . getDeviceId ( ) ;
Integer deviceId = device . getDeviceId ( ) ;
OwnerWithDeviceDTO ownerWithDevice =
OwnerWithDeviceDTO ownerWithDevice =
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId ) ;
deviceManagementProviderService . getOwnerWithDeviceByDeviceId ( deviceId , request . getOwner ( ) , request . getDeviceName ( ) ,
request . getDeviceStatus ( ) ) ;
if ( ownerWithDevice = = null ) {
if ( ownerWithDevice = = null ) {
continue ;
continue ;
}
}
@ -2590,6 +2726,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
statusPercentages . put ( entry . getKey ( ) , Double . valueOf ( formattedPercentage ) ) ;
}
}
List < DeviceSubscriptionData > requestedDevices = new ArrayList < > ( ) ;
if ( StringUtils . isNotBlank ( request . getTabActionStatus ( ) ) ) {
switch ( request . getTabActionStatus ( ) ) {
case "COMPLETED" :
requestedDevices = installedDevices ;
break ;
case "PENDING" :
requestedDevices = pendingDevices ;
break ;
case "ERROR" :
requestedDevices = errorDevices ;
break ;
case "NEW" :
requestedDevices = newDevices ;
break ;
}
} else {
requestedDevices . addAll ( installedDevices ) ;
requestedDevices . addAll ( pendingDevices ) ;
requestedDevices . addAll ( errorDevices ) ;
requestedDevices . addAll ( newDevices ) ;
}
CategorizedSubscriptionResult categorizedSubscriptionResult =
CategorizedSubscriptionResult categorizedSubscriptionResult =
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
new CategorizedSubscriptionResult ( installedDevices , pendingDevices , errorDevices , newDevices ) ;
DeviceSubscriptionResponseDTO result =
DeviceSubscriptionResponseDTO result =