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
APPM_Imp
Pahansith Gunathilake 4 months ago
commit 020c397769

@ -1965,15 +1965,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
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);
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId);
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(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.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());
@ -1982,8 +1987,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(ownerDetailsWithDevices.getDeviceTypes()); deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = subscription.getStatus(); status = subscription.getStatus();
switch (status) { switch (status) {
@ -2013,16 +2018,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(ownerDetailsWithDevices.getDeviceNames()); subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.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(ownerDetailsWithDevices.getDeviceTypes()); subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.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;
@ -2032,11 +2037,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(ownerDetailsWithDevices.getUserName()); newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail); newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1); statusCounts.put("NEW", statusCounts.get("NEW") + 1);
} }
@ -2153,7 +2158,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
appReleaseId, !unsubscribe, tenantId, deviceIds); appReleaseId, !unsubscribe, tenantId, deviceIds);
} }
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId);
if (ownerWithDeviceByDeviceId == null) {
continue;
}
List<DeviceSubscriptionDTO> deviceSubscriptions; List<DeviceSubscriptionDTO> deviceSubscriptions;
try { try {
deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
@ -2167,9 +2176,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(ownerDetailsWithDevices.getDeviceNames()); deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.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());
@ -2179,8 +2188,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(ownerDetailsWithDevices.getDeviceTypes()); deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = deviceSubscription.getStatus(); status = deviceSubscription.getStatus();
switch (status) { switch (status) {
@ -2210,16 +2219,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(ownerDetailsWithDevices.getDeviceNames()); subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.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(ownerDetailsWithDevices.getDeviceTypes()); subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.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;
@ -2229,11 +2238,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(ownerDetailsWithDevices.getDeviceNames()); newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail); newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1); statusCounts.put("NEW", statusCounts.get("NEW") + 1);
} }
@ -2266,7 +2275,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
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);

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

Loading…
Cancel
Save