Generalize JSON keys of application subscription APIs.

appm_improvement
Nipuni Kavindya 5 months ago committed by prathabanKavin
parent e3e0e6de3d
commit 6db42a0f4b

@ -39,6 +39,7 @@ public class DeviceSubscriptionData {
private boolean unsubscribed;
private String unsubscribedBy;
private Timestamp unsubscribedTimestamp;
private String deviceName;
public String getAction() {
return action;
@ -159,4 +160,12 @@ public class DeviceSubscriptionData {
public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
this.unsubscribedTimestamp = unsubscribedTimestamp;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
}

@ -5,9 +5,7 @@ import java.util.List;
public class SubscriptionResponseDTO {
private String UUID;
private List<GroupSubscriptionDetailDTO> GroupsSubscriptions;
private List<UserSubscriptionDTO> UserSubscriptions;
private List<RoleSubscriptionDTO> RolesSubscriptions;
private List<SubscriptionsDTO> subscriptions;
private List<DeviceOperationDTO> DevicesOperations;
public String getUUID() {
@ -18,30 +16,6 @@ public class SubscriptionResponseDTO {
this.UUID = UUID;
}
public List<GroupSubscriptionDetailDTO> getGroupsSubscriptions() {
return GroupsSubscriptions;
}
public void setGroupsSubscriptions(List<GroupSubscriptionDetailDTO> groupsSubscriptions) {
GroupsSubscriptions = groupsSubscriptions;
}
public List<UserSubscriptionDTO> getUserSubscriptions() {
return UserSubscriptions;
}
public void setUserSubscriptions(List<UserSubscriptionDTO> userSubscriptions) {
UserSubscriptions = userSubscriptions;
}
public List<RoleSubscriptionDTO> getRolesSubscriptions() {
return RolesSubscriptions;
}
public void setRolesSubscriptions(List<RoleSubscriptionDTO> rolesSubscriptions) {
RolesSubscriptions = rolesSubscriptions;
}
public List<DeviceOperationDTO> getDevicesOperations() {
return DevicesOperations;
}
@ -49,4 +23,12 @@ public class SubscriptionResponseDTO {
public void setDevicesOperations(List<DeviceOperationDTO> devicesOperations) {
DevicesOperations = devicesOperations;
}
public List<SubscriptionsDTO> getSubscriptions() {
return subscriptions;
}
public void setSubscriptions(List<SubscriptionsDTO> subscriptions) {
this.subscriptions = subscriptions;
}
}

@ -23,45 +23,45 @@ import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionR
import java.sql.Timestamp;
import java.util.Map;
public class GroupSubscriptionDetailDTO {
private int groupId;
private String groupName;
private String groupOwner;
public class SubscriptionsDTO {
private int id;
private String owner;
private String name;
private String subscribedBy;
private Timestamp subscribedTimestamp;
private boolean isUnsubscribed;
private boolean unsubscribed;
private String unsubscribedBy;
private Timestamp unsubscribedTimestamp;
private String subscribedFrom;
private int appReleaseId;
private int deviceCount;
private String deviceOwner;
private String deviceStatus;
private CategorizedSubscriptionResult devices;
private Map<String, Double> statusPercentages;
private CategorizedSubscriptionResult devices;
// Getters and Setters
public int getGroupId() {
return groupId;
public int getId() {
return id;
}
public void setGroupId(int groupId) {
this.groupId = groupId;
public void setId(int id) {
this.id = id;
}
public String getGroupName() {
return groupName;
public String getOwner() {
return owner;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
public void setOwner(String owner) {
this.owner = owner;
}
public String getGroupOwner() {
return groupOwner;
public String getName() {
return name;
}
public void setGroupOwner(String groupOwner) {
this.groupOwner = groupOwner;
public void setName(String name) {
this.name = name;
}
public String getSubscribedBy() {
@ -80,14 +80,6 @@ public class GroupSubscriptionDetailDTO {
this.subscribedTimestamp = subscribedTimestamp;
}
public boolean isUnsubscribed() {
return isUnsubscribed;
}
public void setUnsubscribed(boolean unsubscribed) {
isUnsubscribed = unsubscribed;
}
public String getUnsubscribedBy() {
return unsubscribedBy;
}
@ -104,6 +96,14 @@ public class GroupSubscriptionDetailDTO {
this.unsubscribedTimestamp = unsubscribedTimestamp;
}
public String getSubscribedFrom() {
return subscribedFrom;
}
public void setSubscribedFrom(String subscribedFrom) {
this.subscribedFrom = subscribedFrom;
}
public int getAppReleaseId() {
return appReleaseId;
}
@ -120,12 +120,20 @@ public class GroupSubscriptionDetailDTO {
this.deviceCount = deviceCount;
}
public CategorizedSubscriptionResult getDevices() {
return devices;
public String getDeviceOwner() {
return deviceOwner;
}
public void setDevices(CategorizedSubscriptionResult devices) {
this.devices = devices;
public void setDeviceOwner(String deviceOwner) {
this.deviceOwner = deviceOwner;
}
public String getDeviceStatus() {
return deviceStatus;
}
public void setDeviceStatus(String deviceStatus) {
this.deviceStatus = deviceStatus;
}
public Map<String, Double> getStatusPercentages() {
@ -136,19 +144,19 @@ public class GroupSubscriptionDetailDTO {
this.statusPercentages = statusPercentages;
}
public String getDeviceOwner() {
return deviceOwner;
public CategorizedSubscriptionResult getDevices() {
return devices;
}
public void setDeviceOwner(String deviceOwner) {
this.deviceOwner = deviceOwner;
public void setDevices(CategorizedSubscriptionResult devices) {
this.devices = devices;
}
public String getDeviceStatus() {
return deviceStatus;
public boolean getUnsubscribed() {
return unsubscribed;
}
public void setDeviceStatus(String deviceStatus) {
this.deviceStatus = deviceStatus;
public void setUnsubscribed(boolean unsubscribed) {
this.unsubscribed = unsubscribed;
}
}

@ -1,132 +0,0 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.application.mgt.common.dto;
import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
import java.sql.Timestamp;
import java.util.Map;
public class UserSubscriptionDTO {
private String userName;
private String subscribedBy;
private Timestamp subscribedTimestamp;
private boolean unsubscribed;
private String unsubscribedBy;
private Timestamp unsubscribedTimestamp;
private int appReleaseId;
private int deviceCount;
private String deviceStatus;
private Map<String, Double> statusPercentages;
private CategorizedSubscriptionResult devices;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getSubscribedBy() {
return subscribedBy;
}
public void setSubscribedBy(String subscribedBy) {
this.subscribedBy = subscribedBy;
}
public Timestamp getSubscribedTimestamp() {
return subscribedTimestamp;
}
public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
this.subscribedTimestamp = subscribedTimestamp;
}
public boolean isUnsubscribed() {
return unsubscribed;
}
public boolean getUnsubscribed() {
return unsubscribed;
}
public void setUnsubscribed(boolean unsubscribed) {
this.unsubscribed = unsubscribed;
}
public String getUnsubscribedBy() {
return unsubscribedBy;
}
public void setUnsubscribedBy(String unsubscribedBy) {
this.unsubscribedBy = unsubscribedBy;
}
public Timestamp getUnsubscribedTimestamp() {
return unsubscribedTimestamp;
}
public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
this.unsubscribedTimestamp = unsubscribedTimestamp;
}
public int getAppReleaseId() {
return appReleaseId;
}
public void setAppReleaseId(int appReleaseId) {
this.appReleaseId = appReleaseId;
}
public int getDeviceCount() {
return deviceCount;
}
public void setDeviceCount(int deviceCount) {
this.deviceCount = deviceCount;
}
public Map<String, Double> getStatusPercentages() {
return statusPercentages;
}
public void setStatusPercentages(Map<String, Double> statusPercentages) {
this.statusPercentages = statusPercentages;
}
public CategorizedSubscriptionResult getDevices() {
return devices;
}
public void setDevices(CategorizedSubscriptionResult devices) {
this.devices = devices;
}
public String getDeviceStatus() {
return deviceStatus;
}
public void setDeviceStatus(String deviceStatus) {
this.deviceStatus = deviceStatus;
}
}

@ -22,10 +22,8 @@ import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionR
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDetailDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionResponseDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
@ -232,10 +230,10 @@ public interface SubscriptionManager {
* @param subscriptionStatus the status of the subscription (subscribed or unsubscribed)
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link GroupSubscriptionDetailDTO} which contains the details of group subscriptions.
* @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the group details
*/
List<GroupSubscriptionDetailDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
List<SubscriptionsDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
throws ApplicationManagementException;
/**
@ -245,10 +243,10 @@ public interface SubscriptionManager {
* @param subscriptionStatus the status of the subscription (subscribed or unsubscribed)
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link UserSubscriptionDTO} which contains the details of user subscriptions.
* @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the user details
*/
List<UserSubscriptionDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
List<SubscriptionsDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
throws ApplicationManagementException;
/**
@ -258,10 +256,10 @@ public interface SubscriptionManager {
* @param subscriptionStatus the status of the subscription (subscribed or unsubscribed)
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link RoleSubscriptionDTO} which contains the details of role subscriptions.
* @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the role details
*/
List<RoleSubscriptionDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
List<SubscriptionsDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
throws ApplicationManagementException;
/**

@ -19,11 +19,10 @@ package io.entgra.device.mgt.core.application.mgt.core.dao;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
@ -339,10 +338,10 @@ public interface SubscriptionDAO {
* @param tenantId id of the current tenant.
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link UserSubscriptionDTO} which contains the details of user subscriptions.
* @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<UserSubscriptionDTO> getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
List<SubscriptionsDTO> getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
int offset, int limit) throws ApplicationManagementDAOException;
/**
@ -353,10 +352,10 @@ public interface SubscriptionDAO {
* @param tenantId id of the current tenant.
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link RoleSubscriptionDTO} which contains the details of role subscriptions.
* @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<RoleSubscriptionDTO> getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
List<SubscriptionsDTO> getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
throws ApplicationManagementDAOException;
/**

@ -19,8 +19,7 @@ package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription;
import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO;
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
@ -1694,14 +1693,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public List<UserSubscriptionDTO> getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
public List<SubscriptionsDTO> getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
int offset, int limit) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get user subscriptions related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<UserSubscriptionDTO> userSubscriptions = new ArrayList<>();
List<SubscriptionsDTO> userSubscriptions = new ArrayList<>();
String subscriptionStatusTime = unsubscribe ? "US.UNSUBSCRIBED_TIMESTAMP" : "US.SUBSCRIBED_TIMESTAMP";
String sql = "SELECT US.USER_NAME, US.SUBSCRIBED_BY, US.SUBSCRIBED_TIMESTAMP, US.UNSUBSCRIBED, " +
@ -1718,9 +1717,9 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
ps.setInt(5, offset);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
UserSubscriptionDTO userSubscription;
userSubscription = new UserSubscriptionDTO();
userSubscription.setUserName(rs.getString("USER_NAME"));
SubscriptionsDTO userSubscription;
userSubscription = new SubscriptionsDTO();
userSubscription.setName(rs.getString("USER_NAME"));
userSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
userSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
userSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
@ -1745,14 +1744,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public List<RoleSubscriptionDTO> getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset,
public List<SubscriptionsDTO> getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset,
int limit) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get role subscriptions related to the given AppReleaseID.");
}
try {
Connection conn = this.getDBConnection();
List<RoleSubscriptionDTO> roleSubscriptions = new ArrayList<>();
List<SubscriptionsDTO> roleSubscriptions = new ArrayList<>();
String subscriptionStatusTime = unsubscribe ? "ARS.UNSUBSCRIBED_TIMESTAMP" : "ARS.SUBSCRIBED_TIMESTAMP";
String sql = "SELECT ARS.ROLE_NAME, ARS.SUBSCRIBED_BY, ARS.SUBSCRIBED_TIMESTAMP, ARS.UNSUBSCRIBED, " +
@ -1768,10 +1767,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
ps.setInt(4, limit);
ps.setInt(5, offset);
try (ResultSet rs = ps.executeQuery()) {
RoleSubscriptionDTO roleSubscription;
SubscriptionsDTO roleSubscription;
while (rs.next()) {
roleSubscription = new RoleSubscriptionDTO();
roleSubscription.setRoleName(rs.getString("ROLE_NAME"));
roleSubscription = new SubscriptionsDTO();
roleSubscription.setName(rs.getString("ROLE_NAME"));
roleSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
roleSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
roleSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));

@ -26,9 +26,7 @@ import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionR
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDetailDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.UserSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.RoleSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionResponseDTO;
import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
@ -1706,7 +1704,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List<GroupSubscriptionDetailDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset,
public List<SubscriptionsDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset,
int limit) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
@ -1724,7 +1722,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
int appReleaseId = applicationReleaseDTO.getId();
List<GroupSubscriptionDetailDTO> groupDetailsWithDevices = new ArrayList<>();
List<SubscriptionsDTO> groupDetailsWithDevices = new ArrayList<>();
List<GroupSubscriptionDTO> groupDetails =
subscriptionDAO.getGroupsSubscriptionDetailsByAppReleaseID(appReleaseId, unsubscribe, tenantId, offset, limit);
@ -1741,10 +1739,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
GroupDetailsDTO groupDetailWithDevices =
groupManagementProviderService.getGroupDetailsWithDevices(groupName, offset, limit);
GroupSubscriptionDetailDTO groupDetailDTO = new GroupSubscriptionDetailDTO();
groupDetailDTO.setGroupId(groupDetailWithDevices.getGroupId());
groupDetailDTO.setGroupName(groupDetail.getGroupName());
groupDetailDTO.setGroupOwner(groupDetailWithDevices.getGroupOwner());
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO();
groupDetailDTO.setId(groupDetailWithDevices.getGroupId());
groupDetailDTO.setName(groupDetail.getGroupName());
groupDetailDTO.setOwner(groupDetailWithDevices.getGroupOwner());
groupDetailDTO.setSubscribedBy(groupDetail.getSubscribedBy());
groupDetailDTO.setSubscribedTimestamp(groupDetail.getSubscribedTimestamp());
groupDetailDTO.setUnsubscribed(groupDetail.isUnsubscribed());
@ -1787,6 +1785,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setDeviceOwner(groupDetailWithDevices.getDeviceOwners().get(deviceId));
deviceDetail.setDeviceStatus(groupDetailWithDevices.getDeviceStatuses().get(deviceId));
deviceDetail.setDeviceName(groupDetailWithDevices.getDeviceNames().get(deviceId));
deviceDetail.setSubId(subscription.getId());
deviceDetail.setActionTriggeredBy(subscription.getSubscribedBy());
deviceDetail.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp());
@ -1824,6 +1823,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
subscribedDeviceDetail.setDeviceOwner(groupDetailWithDevices.getDeviceOwners().get(deviceId));
subscribedDeviceDetail.setDeviceStatus(groupDetailWithDevices.getDeviceStatuses().get(deviceId));
subscribedDeviceDetail.setDeviceName(groupDetailWithDevices.getDeviceNames().get(deviceId));
subscribedDeviceDetail.setSubId(subscribedDevice.getId());
subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy());
subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp());
@ -1840,6 +1840,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceOwner(groupDetailWithDevices.getDeviceOwners().get(deviceId));
newDeviceDetail.setDeviceStatus(groupDetailWithDevices.getDeviceStatuses().get(deviceId));
newDeviceDetail.setDeviceName(groupDetailWithDevices.getDeviceNames().get(deviceId));
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
@ -1886,7 +1887,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List<UserSubscriptionDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
public List<SubscriptionsDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
@ -1904,9 +1905,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
int appReleaseId = applicationReleaseDTO.getId();
List<UserSubscriptionDTO> userSubscriptionsWithDevices = new ArrayList<>();
List<SubscriptionsDTO> userSubscriptionsWithDevices = new ArrayList<>();
List<UserSubscriptionDTO> userSubscriptions =
List<SubscriptionsDTO> userSubscriptions =
subscriptionDAO.getUserSubscriptionsByAppReleaseID(appReleaseId, unsubscribe, tenantId, offset, limit);
if (userSubscriptions == null) {
throw new ApplicationManagementException("User details not found for appReleaseId: " + appReleaseId);
@ -1914,15 +1915,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (UserSubscriptionDTO userSubscription : userSubscriptions) {
userName = userSubscription.getUserName();
for (SubscriptionsDTO userSubscription : userSubscriptions) {
userName = userSubscription.getName();
// Retrieve owner details and device IDs for the user using the service layer
OwnerWithDeviceDTO ownerDetailsWithDevices =
deviceManagementProviderService.getOwnersWithDeviceIds(userName);
UserSubscriptionDTO userSubscriptionDTO = new UserSubscriptionDTO();
userSubscriptionDTO.setUserName(userSubscription.getUserName());
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO();
userSubscriptionDTO.setName(userSubscription.getName());
userSubscriptionDTO.setSubscribedBy(userSubscription.getSubscribedBy());
userSubscriptionDTO.setSubscribedTimestamp(userSubscription.getSubscribedTimestamp());
userSubscriptionDTO.setUnsubscribed(userSubscription.getUnsubscribed());
@ -1964,6 +1965,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setSubId(subscription.getId());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setStatus(subscription.getStatus());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
@ -2001,6 +2003,7 @@ 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.setSubId(subscribedDevice.getId());
@ -2019,6 +2022,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
@ -2063,7 +2067,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List<RoleSubscriptionDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
public List<SubscriptionsDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
@ -2081,9 +2085,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
int appReleaseId = applicationReleaseDTO.getId();
List<RoleSubscriptionDTO> roleSubscriptionsWithDevices = new ArrayList<>();
List<SubscriptionsDTO> roleSubscriptionsWithDevices = new ArrayList<>();
List<RoleSubscriptionDTO> roleSubscriptions =
List<SubscriptionsDTO> roleSubscriptions =
subscriptionDAO.getRoleSubscriptionsByAppReleaseID(appReleaseId, unsubscribe, tenantId, offset, limit);
if (roleSubscriptions == null) {
throw new ApplicationManagementException("Role details not found for appReleaseId: " + appReleaseId);
@ -2091,11 +2095,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (RoleSubscriptionDTO roleSubscription : roleSubscriptions) {
roleName = roleSubscription.getRoleName();
for (SubscriptionsDTO roleSubscription : roleSubscriptions) {
roleName = roleSubscription.getName();
RoleSubscriptionDTO roleSubscriptionDTO = new RoleSubscriptionDTO();
roleSubscriptionDTO.setRoleName(roleSubscription.getRoleName());
SubscriptionsDTO roleSubscriptionDTO = new SubscriptionsDTO();
roleSubscriptionDTO.setName(roleSubscription.getName());
roleSubscriptionDTO.setSubscribedBy(roleSubscription.getSubscribedBy());
roleSubscriptionDTO.setSubscribedTimestamp(roleSubscription.getSubscribedTimestamp());
roleSubscriptionDTO.setUnsubscribed(roleSubscription.getUnsubscribed());
@ -2148,6 +2152,7 @@ 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.setActionType(deviceSubscription.getActionTriggeredFrom());
@ -2188,6 +2193,7 @@ 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.setSubId(subscribedDevice.getId());
@ -2204,6 +2210,7 @@ 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());
newDevices.add(newDeviceDetail);
@ -2339,6 +2346,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId());
deviceDetail.setSubId(subscription.getId());
deviceDetail.setDeviceName(ownerWithDevice.getDeviceNames());
deviceDetail.setDeviceOwner(ownerWithDevice.getUserName());
deviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
@ -2374,6 +2382,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!allSubscription.isUnsubscribed()) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(allSubscription.getDeviceId());
subscribedDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus());
subscribedDeviceDetail.setSubId(allSubscription.getId());
@ -2396,6 +2405,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
&& (allDevicesMap.containsKey(deviceId))) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName());
newDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus());
newDevices.add(newDeviceDetail);
@ -2496,6 +2506,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceSubscriptionDTO subscription = allSubscriptionMap.get(deviceId);
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId());
deviceDetail.setDeviceName(ownerWithDevice.getDeviceNames());
deviceDetail.setSubId(subscription.getId());
deviceDetail.setDeviceOwner(ownerWithDevice.getUserName());
deviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus());
@ -2529,6 +2540,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} else {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceName(ownerWithDevice.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerWithDevice.getUserName());
newDeviceDetail.setDeviceStatus(ownerWithDevice.getDeviceStatus());
newDevices.add(newDeviceDetail);

@ -567,9 +567,10 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
List<Integer> deviceIds = new ArrayList<>();
int deviceCount = 0;
String sql = "SELECT DEVICE_ID, OWNER, STATUS AS DEVICE_STATUS " +
"FROM DM_ENROLMENT " +
"WHERE OWNER = ? AND TENANT_ID = ?";
String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME " +
"FROM DM_ENROLMENT e " +
"JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
"WHERE e.OWNER = ? AND e.TENANT_ID = ?";
try (Connection conn = this.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -591,6 +592,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
ownerDetails.setDeviceIds(deviceIds);
ownerDetails.setDeviceStatus("DEVICE_STATUS");
ownerDetails.setDeviceNames("DEVICE_NAME");
ownerDetails.setDeviceCount(deviceCount);
return ownerDetails;
}
@ -600,9 +602,10 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
throws DeviceManagementDAOException {
OwnerWithDeviceDTO deviceOwnerWithStatus = new OwnerWithDeviceDTO();
String sql = "SELECT DEVICE_ID, OWNER, STATUS AS DEVICE_STATUS " +
"FROM DM_ENROLMENT " +
"WHERE DEVICE_ID = ? AND TENANT_ID = ?";
String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME " +
"FROM DM_ENROLMENT e " +
"JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
"WHERE e.DEVICE_ID = ? AND e.TENANT_ID = ?";
try (Connection conn = this.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -616,6 +619,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
List<Integer> deviceIds = new ArrayList<>();
deviceIds.add(rs.getInt("DEVICE_ID"));
deviceOwnerWithStatus.setDeviceIds(deviceIds);
deviceOwnerWithStatus.setDeviceNames(rs.getString("DEVICE_NAME"));
}
}
} catch (SQLException e) {

@ -1450,13 +1450,25 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
List<Integer> deviceIds = new ArrayList<>();
Map<Integer, String> deviceOwners = new HashMap<>();
Map<Integer, String> deviceStatuses = new HashMap<>();
Map<Integer, String> deviceNames = new HashMap<>(); // New map for device names
String sql =
"SELECT g.ID AS GROUP_ID, g.GROUP_NAME, g.OWNER, e.OWNER AS DEVICE_OWNER, e.STATUS AS DEVICE_STATUS, dgm.DEVICE_ID "
+ "FROM DM_GROUP g "
+ "JOIN DM_DEVICE_GROUP_MAP dgm ON g.ID = dgm.GROUP_ID "
+ "JOIN DM_ENROLMENT e ON dgm.DEVICE_ID = e.DEVICE_ID "
+ "WHERE g.GROUP_NAME = ? AND g.TENANT_ID = ? " +
"SELECT " +
" g.ID AS GROUP_ID, " +
" g.GROUP_NAME, " +
" g.OWNER AS GROUP_OWNER, " +
" e.OWNER AS DEVICE_OWNER, " +
" e.STATUS AS DEVICE_STATUS, " +
" dgm.DEVICE_ID, " +
" d.NAME AS DEVICE_NAME " +
"FROM " +
" DM_GROUP g " +
" JOIN DM_DEVICE_GROUP_MAP dgm ON g.ID = dgm.GROUP_ID " +
" JOIN DM_ENROLMENT e ON dgm.DEVICE_ID = e.DEVICE_ID " +
" JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
"WHERE " +
" g.GROUP_NAME = ? " +
" AND g.TENANT_ID = ? " +
"LIMIT ? OFFSET ?";
try (Connection conn = GroupManagementDAOFactory.getConnection();
@ -1471,12 +1483,13 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
if (groupDetails.getGroupId() == 0) {
groupDetails.setGroupId(rs.getInt("GROUP_ID"));
groupDetails.setGroupName(rs.getString("GROUP_NAME"));
groupDetails.setGroupOwner(rs.getString("OWNER"));
groupDetails.setGroupOwner(rs.getString("GROUP_OWNER"));
}
int deviceId = rs.getInt("DEVICE_ID");
deviceIds.add(deviceId);
deviceOwners.put(deviceId, rs.getString("DEVICE_OWNER"));
deviceStatuses.put(deviceId, rs.getString("DEVICE_STATUS"));
deviceNames.put(deviceId, rs.getString("DEVICE_NAME"));
}
}
} catch (SQLException e) {
@ -1488,6 +1501,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
groupDetails.setDeviceCount(deviceIds.size());
groupDetails.setDeviceOwners(deviceOwners);
groupDetails.setDeviceStatuses(deviceStatuses);
groupDetails.setDeviceNames(deviceNames);
return groupDetails;
}
}

@ -31,6 +31,7 @@ public class GroupDetailsDTO {
private String deviceStatus;
private Map<Integer, String> deviceOwners;
private Map<Integer, String> deviceStatuses;
private Map<Integer, String> deviceNames;
public int getGroupId() {
return groupId;
@ -103,4 +104,12 @@ public class GroupDetailsDTO {
public void setDeviceStatuses(Map<Integer, String> deviceStatuses) {
this.deviceStatuses = deviceStatuses;
}
public Map<Integer, String> getDeviceNames() {
return deviceNames;
}
public void setDeviceNames(Map<Integer, String> deviceNames) {
this.deviceNames = deviceNames;
}
}

@ -26,6 +26,7 @@ public class OwnerWithDeviceDTO {
private List<Integer> deviceIds;
private int deviceCount;
private String deviceStatus;
private String deviceNames;
public String getUserName() {
return userName;
@ -58,4 +59,12 @@ public class OwnerWithDeviceDTO {
public void setDeviceStatus(String deviceStatus) {
this.deviceStatus = deviceStatus;
}
public String getDeviceNames() {
return deviceNames;
}
public void setDeviceNames(String deviceNames) {
this.deviceNames = deviceNames;
}
}

Loading…
Cancel
Save