Merge pull request 'Fix same device data loading for subscriptions' (#450) from prathabanKavin/device-mgt-core:devicelinkrejectfix into master

Reviewed-on: community/device-mgt-core#450
geofence-revoke-fix
Pahansith Gunathilake 5 months ago
commit 020c397769

@ -1965,15 +1965,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
userSubscription.getAppReleaseId(), unsubscribe, tenantId, deviceIds);
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId);
if (ownerWithDeviceByDeviceId == null) {
continue;
}
boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId());
deviceDetail.setSubId(subscription.getId());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setStatus(subscription.getStatus());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
@ -1982,8 +1987,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setUnsubscribed(subscription.isUnsubscribed());
deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy());
deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp());
deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = subscription.getStatus();
switch (status) {
@ -2013,16 +2018,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscribedDevice.getDeviceId() == deviceId) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
subscribedDeviceDetail.setSubId(subscribedDevice.getId());
subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy());
subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp());
subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom());
subscribedDeviceDetail.setStatus(subscribedDevice.getStatus());
subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
subscribedDevices.add(subscribedDeviceDetail);
statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1);
isSubscribedDevice = true;
@ -2032,11 +2037,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!isSubscribedDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
@ -2153,7 +2158,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
appReleaseId, !unsubscribe, tenantId, deviceIds);
}
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId);
if (ownerWithDeviceByDeviceId == null) {
continue;
}
List<DeviceSubscriptionDTO> deviceSubscriptions;
try {
deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
@ -2167,9 +2176,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (deviceSubscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(deviceSubscription.getDeviceId());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
deviceDetail.setStatus(deviceSubscription.getStatus());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
@ -2179,8 +2188,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setUnsubscribed(deviceSubscription.isUnsubscribed());
deviceDetail.setUnsubscribedBy(deviceSubscription.getUnsubscribedBy());
deviceDetail.setUnsubscribedTimestamp(deviceSubscription.getUnsubscribedTimestamp());
deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = deviceSubscription.getStatus();
switch (status) {
@ -2210,16 +2219,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscribedDevice.getDeviceId() == deviceId) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
subscribedDeviceDetail.setSubId(subscribedDevice.getId());
subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy());
subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp());
subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom());
subscribedDeviceDetail.setStatus(subscribedDevice.getStatus());
subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
subscribedDevices.add(subscribedDeviceDetail);
statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1);
isSubscribedDevice = true;
@ -2229,11 +2238,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!isSubscribedDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
@ -2266,7 +2275,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
return roleSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) {
} catch (ApplicationManagementDAOException | DeviceManagementDAOException e) {
String msg = "Error occurred in retrieving role subscriptions with devices";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);

@ -597,9 +597,11 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
while (rs.next()) {
if (ownerDetails.getUserName() == null) {
ownerDetails.setUserName(rs.getString("OWNER"));
ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS"));
ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME"));
}
ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS"));
ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME"));
ownerDetails.setDeviceTypes("DEVICE_TYPE");
ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION");
deviceIds.add(rs.getInt("DEVICE_ID"));
deviceCount++;
}
@ -610,10 +612,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
ownerDetails.setDeviceIds(deviceIds);
ownerDetails.setDeviceTypes("DEVICE_TYPE");
ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION");
ownerDetails.setDeviceCount(deviceCount);
return ownerDetails;
}

Loading…
Cancel
Save