Feature to manage subscription type base subscriptions and Installation Percentage Calculation based on groups, users and roles

pull/410/head
Nipuni Kavindya 6 months ago committed by prathabanKavin
parent 2da954275a
commit e3da56f793

@ -1,3 +1,21 @@
/*
* 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; package io.entgra.device.mgt.core.application.mgt.common;
import java.util.List; import java.util.List;
@ -6,13 +24,27 @@ public class CategorizedSubscriptionResult {
private List<DeviceSubscriptionData> installedDevices; private List<DeviceSubscriptionData> installedDevices;
private List<DeviceSubscriptionData> pendingDevices; private List<DeviceSubscriptionData> pendingDevices;
private List<DeviceSubscriptionData> errorDevices; private List<DeviceSubscriptionData> errorDevices;
private List<DeviceSubscriptionData> newDevices;
// without newDevices
public CategorizedSubscriptionResult(List<DeviceSubscriptionData> installedDevices, public CategorizedSubscriptionResult(List<DeviceSubscriptionData> installedDevices,
List<DeviceSubscriptionData> pendingDevices, List<DeviceSubscriptionData> pendingDevices,
List<DeviceSubscriptionData> errorDevices) { List<DeviceSubscriptionData> errorDevices) {
this.installedDevices = installedDevices; this.installedDevices = installedDevices;
this.pendingDevices = pendingDevices; this.pendingDevices = pendingDevices;
this.errorDevices = errorDevices; this.errorDevices = errorDevices;
this.newDevices = null;
}
// with newDevices
public CategorizedSubscriptionResult(List<DeviceSubscriptionData> installedDevices,
List<DeviceSubscriptionData> pendingDevices,
List<DeviceSubscriptionData> errorDevices,
List<DeviceSubscriptionData> newDevices) {
this.installedDevices = installedDevices;
this.pendingDevices = pendingDevices;
this.errorDevices = errorDevices;
this.newDevices = newDevices;
} }
public List<DeviceSubscriptionData> getInstalledDevices() { public List<DeviceSubscriptionData> getInstalledDevices() {
@ -38,4 +70,12 @@ public class CategorizedSubscriptionResult {
public void setErrorDevices(List<DeviceSubscriptionData> errorDevices) { public void setErrorDevices(List<DeviceSubscriptionData> errorDevices) {
this.errorDevices = errorDevices; this.errorDevices = errorDevices;
} }
public List<DeviceSubscriptionData> getNewDevices() {
return newDevices;
}
public void setNewDevices(List<DeviceSubscriptionData> newDevices) {
this.newDevices = newDevices;
}
} }

@ -26,12 +26,14 @@ public class DeviceSubscriptionData {
private int subId; private int subId;
private String action; private String action;
private long actionTriggeredTimestamp; private Timestamp actionTriggeredTimestamp;
private String actionTriggeredFrom;
private String actionTriggeredBy; private String actionTriggeredBy;
private String actionType; private String actionType;
private String status; private String status;
private Device device; private Device device;
private String currentInstalledVersion; private String currentInstalledVersion;
private int deviceId;
public String getAction() { public String getAction() {
return action; return action;
@ -41,14 +43,6 @@ public class DeviceSubscriptionData {
this.action = action; this.action = action;
} }
public long getActionTriggeredTimestamp() {
return actionTriggeredTimestamp;
}
public void setActionTriggeredTimestamp(long actionTriggeredTimestamp) {
this.actionTriggeredTimestamp = actionTriggeredTimestamp;
}
public String getActionTriggeredBy() { public String getActionTriggeredBy() {
return actionTriggeredBy; return actionTriggeredBy;
} }
@ -92,4 +86,28 @@ public class DeviceSubscriptionData {
public void setSubId(int subId) { public void setSubId(int subId) {
this.subId = subId; this.subId = subId;
} }
public int getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
this.deviceId = deviceId;
}
public String getActionTriggeredFrom() {
return actionTriggeredFrom;
}
public void setActionTriggeredFrom(String actionTriggeredFrom) {
this.actionTriggeredFrom = actionTriggeredFrom;
}
public Timestamp getActionTriggeredTimestamp() {
return actionTriggeredTimestamp;
}
public void setActionTriggeredTimestamp(Timestamp actionTriggeredTimestamp) {
this.actionTriggeredTimestamp = actionTriggeredTimestamp;
}
} }

@ -0,0 +1,115 @@
/*
* 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 java.sql.Timestamp;
public class DeviceOperationDTO {
private int deviceId;
private String uuid;
private String status;
private int operationId;
private String actionTriggeredFrom;
private Timestamp actionTriggeredAt;
private int appReleaseId;
private String operationCode;
private Object operationDetails;
private Object operationProperties;
public int getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
this.deviceId = deviceId;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getOperationId() {
return operationId;
}
public void setOperationId(int operationId) {
this.operationId = operationId;
}
public String getActionTriggeredFrom() {
return actionTriggeredFrom;
}
public void setActionTriggeredFrom(String actionTriggeredFrom) {
this.actionTriggeredFrom = actionTriggeredFrom;
}
public Timestamp getActionTriggeredAt() {
return actionTriggeredAt;
}
public void setActionTriggeredAt(Timestamp actionTriggeredAt) {
this.actionTriggeredAt = actionTriggeredAt;
}
public int getAppReleaseId() {
return appReleaseId;
}
public void setAppReleaseId(int appReleaseId) {
this.appReleaseId = appReleaseId;
}
public String getOperationCode() {
return operationCode;
}
public void setOperationCode(String operationCode) {
this.operationCode = operationCode;
}
public Object getOperationDetails() {
return operationDetails;
}
public void setOperationDetails(Object operationDetails) {
this.operationDetails = operationDetails;
}
public Object getOperationProperties() {
return operationProperties;
}
public void setOperationProperties(Object operationProperties) {
this.operationProperties = operationProperties;
}
}

@ -22,6 +22,7 @@ import java.sql.Timestamp;
public class GroupSubscriptionDTO { public class GroupSubscriptionDTO {
private int id; private int id;
private String groupName;
private String subscribedBy; private String subscribedBy;
private Timestamp subscribedTimestamp; private Timestamp subscribedTimestamp;
private boolean isUnsubscribed; private boolean isUnsubscribed;
@ -29,6 +30,7 @@ public class GroupSubscriptionDTO {
private Timestamp unsubscribedTimestamp; private Timestamp unsubscribedTimestamp;
private String subscribedFrom; private String subscribedFrom;
private int groupdId; private int groupdId;
private int appReleaseId;
public int getId() { return id; } public int getId() { return id; }
@ -61,4 +63,20 @@ public class GroupSubscriptionDTO {
public int getGroupdId() { return groupdId; } public int getGroupdId() { return groupdId; }
public void setGroupdId(int groupdId) { this.groupdId = groupdId; } public void setGroupdId(int groupdId) { this.groupdId = groupdId; }
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public int getAppReleaseId() {
return appReleaseId;
}
public void setAppReleaseId(int appReleaseId) {
this.appReleaseId = appReleaseId;
}
} }

@ -0,0 +1,136 @@
/*
* 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 GroupSubscriptionDetailDTO {
private int groupId;
private String groupName;
private String groupOwner;
private String subscribedBy;
private Timestamp subscribedTimestamp;
private boolean isUnsubscribed;
private String unsubscribedBy;
private Timestamp unsubscribedTimestamp;
private int appReleaseId;
private int deviceCount;
private CategorizedSubscriptionResult devices;
private Map<String, Double> statusPercentages;
// Getters and Setters
public int getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getGroupOwner() {
return groupOwner;
}
public void setGroupOwner(String groupOwner) {
this.groupOwner = groupOwner;
}
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 isUnsubscribed;
}
public void setUnsubscribed(boolean unsubscribed) {
isUnsubscribed = 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 CategorizedSubscriptionResult getDevices() {
return devices;
}
public void setDevices(CategorizedSubscriptionResult devices) {
this.devices = devices;
}
public Map<String, Double> getStatusPercentages() {
return statusPercentages;
}
public void setStatusPercentages(Map<String, Double> statusPercentages) {
this.statusPercentages = statusPercentages;
}
}

@ -18,51 +18,115 @@
package io.entgra.device.mgt.core.application.mgt.common.dto; 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.sql.Timestamp;
import java.util.Map;
public class RoleSubscriptionDTO { public class RoleSubscriptionDTO {
private int id;
private String subscribedBy; private String subscribedBy;
private Timestamp subscribedTimestamp; private Timestamp subscribedTimestamp;
private boolean isUnsubscribed; private boolean isUnsubscribed;
private boolean unsubscribed;
private String unsubscribedBy; private String unsubscribedBy;
private Timestamp unsubscribedTimestamp; private Timestamp unsubscribedTimestamp;
private String subscribedFrom; private String subscribedFrom;
private String roleName; private String roleName;
private int appReleaseId;
private int deviceCount;
private Map<String, Double> statusPercentages;
private CategorizedSubscriptionResult devices;
public int getId() { return id; } public String getSubscribedBy() {
return subscribedBy;
public void setId(int id) { this.id = id; } }
public String getSubscribedBy() { return subscribedBy; }
public void setSubscribedBy(String subscribedBy) { this.subscribedBy = subscribedBy; } public void setSubscribedBy(String subscribedBy) {
this.subscribedBy = subscribedBy;
}
public Timestamp getSubscribedTimestamp() { return subscribedTimestamp; } public Timestamp getSubscribedTimestamp() {
return subscribedTimestamp;
}
public void setSubscribedTimestamp(Timestamp subscribedTimestamp) { public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
this.subscribedTimestamp = subscribedTimestamp; this.subscribedTimestamp = subscribedTimestamp;
} }
public boolean isUnsubscribed() { return isUnsubscribed; } public boolean getUnsubscribed() {
return unsubscribed;
}
public void setUnsubscribed(boolean unsubscribed) { isUnsubscribed = unsubscribed; } public void setUnsubscribed(boolean unsubscribed) {
this.unsubscribed = unsubscribed;
}
public String getUnsubscribedBy() { return unsubscribedBy; } public boolean isUnsubscribed() {
return isUnsubscribed;
}
public void setUnsubscribedBy(String unsubscribedBy) { this.unsubscribedBy = unsubscribedBy; } public String getUnsubscribedBy() {
return unsubscribedBy;
}
public void setUnsubscribedBy(String unsubscribedBy) {
this.unsubscribedBy = unsubscribedBy;
}
public Timestamp getUnsubscribedTimestamp() { return unsubscribedTimestamp; } public Timestamp getUnsubscribedTimestamp() {
return unsubscribedTimestamp;
}
public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) { public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
this.unsubscribedTimestamp = unsubscribedTimestamp; this.unsubscribedTimestamp = unsubscribedTimestamp;
} }
public String getSubscribedFrom() { return subscribedFrom; } public String getSubscribedFrom() {
return subscribedFrom;
}
public void setSubscribedFrom(String subscribedFrom) {
this.subscribedFrom = subscribedFrom;
}
public String getRoleName() {
return roleName;
}
public void setSubscribedFrom(String subscribedFrom) { this.subscribedFrom = subscribedFrom; } public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getRoleName() { return roleName; } 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 void setRoleName(String roleName) { this.roleName = roleName; }
} }

@ -0,0 +1,52 @@
package io.entgra.device.mgt.core.application.mgt.common.dto;
import java.util.List;
public class SubscriptionResponseDTO {
private String UUID;
private List<GroupSubscriptionDetailDTO> GroupsSubscriptions;
private List<UserSubscriptionDTO> UserSubscriptions;
private List<RoleSubscriptionDTO> RolesSubscriptions;
private List<DeviceOperationDTO> DevicesOperations;
public String getUUID() {
return UUID;
}
public void setUUID(String UUID) {
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;
}
public void setDevicesOperations(List<DeviceOperationDTO> devicesOperations) {
DevicesOperations = devicesOperations;
}
}

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * 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, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -18,15 +18,107 @@
package io.entgra.device.mgt.core.application.mgt.common.dto; 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.sql.Timestamp;
import java.util.Map;
public class UserSubscriptionDTO { public class UserSubscriptionDTO {
private int id;
private String userName;
private String subscribedBy; private String subscribedBy;
private Timestamp subscribedTimestamp; private Timestamp subscribedTimestamp;
private boolean isUnsubscribed; private boolean unsubscribed;
private String unsubscribedBy; private String unsubscribedBy;
private Timestamp unsubscribedTimestamp; private Timestamp unsubscribedTimestamp;
private String subscribedFrom; private int appReleaseId;
private String userName; private int deviceCount;
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;
}
} }

@ -20,10 +20,14 @@ package io.entgra.device.mgt.core.application.mgt.common.services;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse; import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult; import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus; 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.GroupSubscriptionDetailDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO; 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.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
@ -31,6 +35,7 @@ import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
@ -218,4 +223,45 @@ public interface SubscriptionManager {
* @throws {@link SubscriptionManagementException} Exception of the subscription management * @throws {@link SubscriptionManagementException} Exception of the subscription management
*/ */
Activity getOperationAppDetails(String id) throws SubscriptionManagementException; Activity getOperationAppDetails(String id) throws SubscriptionManagementException;
/**
* Retrieves the group details associated with a given app release UUID.
*
* @param uuid the UUID of the app release
* @return a list of maps containing group details and their associated devices
* @throws ApplicationManagementException if an error occurs while fetching the group details
*/
List<GroupSubscriptionDetailDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus)
throws ApplicationManagementException;
/**
* Retrieves the user details associated with a given app release UUID.
*
* @param uuid the UUID of the app release
* @return a list of maps containing user details and their associated devices
* @throws ApplicationManagementException if an error occurs while fetching the group details
*/
List<UserSubscriptionDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus)
throws ApplicationManagementException;
/**
* Retrieves the Role details associated with a given app release UUID.
*
* @param uuid the UUID of the app release
* @return a list of maps containing role details and their associated devices
* @throws ApplicationManagementException if an error occurs while fetching the group details
*/
List<RoleSubscriptionDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus)
throws ApplicationManagementException;
/**
* This method is responsible for retrieving device subscription details related to the given UUID.
*
* @param uuid the UUID of the application release.
* @return List of device subscription details.
* @throws SubscriptionManagementException if there is an error while fetching the details.
*/
List<DeviceOperationDTO> getDeviceSubscriptionsOperationsByUUID(String uuid)
throws ApplicationManagementException;
} }

@ -18,8 +18,12 @@
package io.entgra.device.mgt.core.application.mgt.core.dao; 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.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO; 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.DeviceSubscriptionDTO; 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.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException; import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
@ -312,4 +316,62 @@ public interface SubscriptionDAO {
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data * @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/ */
void deleteScheduledSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException; void deleteScheduledSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of groups related to a UUID.
*
* @param uuid the UUID of the application release.
* @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant.
* @return groupDetails - list of group details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment fails.
*/
List<GroupSubscriptionDTO> getGroupsSubscriptionDetailsByUUID(String uuid, boolean unsubscribe, int tenantId)
throws ApplicationManagementDAOException;
/**
* This method is used to get the details of user subscriptions related to a UUID.
*
* @param uuid the UUID of the application release.
* @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant.
* @return userSubscriptions - list of user subscription details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<UserSubscriptionDTO> getUserSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId)
throws ApplicationManagementDAOException;
/**
* This method is used to get the details of role subscriptions related to a UUID.
*
* @param uuid the UUID of the application release.
* @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant.
* @return roleSubscriptions - list of role subscription details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<RoleSubscriptionDTO> getRoleSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId)
throws ApplicationManagementDAOException;
/**
* This method is used to get the details of device subscriptions related to a UUID.
*
* @param uuid the UUID of the application release.
* @param tenantId id of the current tenant.
* @return deviceSubscriptions - list of device subscription details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<DeviceOperationDTO> getDeviceSubscriptionsOperationsByUUID(String uuid, int tenantId)
throws ApplicationManagementDAOException;
/**
* This method is used to get the details of device subscriptions related to a UUID.
*
* @param appReleaseId the appReleaseId of the application release.
* @param tenantId id of the current tenant.
* @return deviceSubscriptions - list of device subscription details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<DeviceSubscriptionDTO> getDeviceSubscriptionsDetails(int appReleaseId, int tenantId)
throws ApplicationManagementDAOException;
} }

@ -17,6 +17,10 @@
*/ */
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription; 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.core.dao.SubscriptionDAO; 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.dao.impl.AbstractDAOImpl;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException; import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
@ -1635,4 +1639,258 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override
public List<GroupSubscriptionDTO> getGroupsSubscriptionDetailsByUUID(String uuid, boolean unsubscribe, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get groups related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<GroupSubscriptionDTO> groupDetails = new ArrayList<>();
String sql = "SELECT GS.GROUP_NAME, GS.SUBSCRIBED_BY, GS.SUBSCRIBED_TIMESTAMP, GS.UNSUBSCRIBED, " +
"GS.UNSUBSCRIBED_BY, GS.UNSUBSCRIBED_TIMESTAMP, GS.AP_APP_RELEASE_ID " +
"FROM AP_GROUP_SUBSCRIPTION GS " +
"JOIN AP_APP_RELEASE AR ON GS.AP_APP_RELEASE_ID = AR.ID " +
"WHERE AR.UUID = ? AND GS.UNSUBSCRIBED = ? AND AR.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setBoolean(2, unsubscribe);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
GroupSubscriptionDTO groupDetail;
while (rs.next()) {
groupDetail = new GroupSubscriptionDTO();
groupDetail.setGroupName(rs.getString("GROUP_NAME"));
groupDetail.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
groupDetail.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
groupDetail.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
groupDetail.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
groupDetail.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
groupDetail.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
groupDetails.add(groupDetail);
}
}
return groupDetails;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get groups for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting groups for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<UserSubscriptionDTO> getUserSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId)
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<>();
String sql = "SELECT US.USER_NAME, US.SUBSCRIBED_BY, US.SUBSCRIBED_TIMESTAMP, US.UNSUBSCRIBED, " +
"US.UNSUBSCRIBED_BY, US.UNSUBSCRIBED_TIMESTAMP, US.AP_APP_RELEASE_ID, AR.UUID " +
"FROM AP_USER_SUBSCRIPTION US " +
"JOIN AP_APP_RELEASE AR ON US.AP_APP_RELEASE_ID = AR.ID " +
"WHERE AR.UUID = ? AND US.UNSUBSCRIBED = ? AND AR.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setBoolean(2, unsubscribe);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
UserSubscriptionDTO userSubscription;
userSubscription = new UserSubscriptionDTO();
userSubscription.setUserName(rs.getString("USER_NAME"));
userSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
userSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
userSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
userSubscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
userSubscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
userSubscription.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
userSubscriptions.add(userSubscription);
}
}
return userSubscriptions;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get user subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting user subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<RoleSubscriptionDTO> getRoleSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get role subscriptions related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<RoleSubscriptionDTO> roleSubscriptions = new ArrayList<>();
String sql = "SELECT ARS.ROLE_NAME, ARS.SUBSCRIBED_BY, ARS.SUBSCRIBED_TIMESTAMP, ARS.UNSUBSCRIBED, " +
"ARS.UNSUBSCRIBED_BY, ARS.UNSUBSCRIBED_TIMESTAMP, ARS.AP_APP_RELEASE_ID " +
"FROM AP_ROLE_SUBSCRIPTION ARS " +
"JOIN AP_APP_RELEASE AAR ON ARS.AP_APP_RELEASE_ID = AAR.ID " +
"WHERE AAR.UUID = ? AND ARS.UNSUBSCRIBED = ? AND AAR.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setBoolean(2, unsubscribe);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
RoleSubscriptionDTO roleSubscription;
while (rs.next()) {
roleSubscription = new RoleSubscriptionDTO();
roleSubscription.setRoleName(rs.getString("ROLE_NAME"));
roleSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
roleSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
roleSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
roleSubscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
roleSubscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
roleSubscription.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
roleSubscriptions.add(roleSubscription);
}
}
return roleSubscriptions;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get role subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting role subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<DeviceOperationDTO> getDeviceSubscriptionsOperationsByUUID(String uuid, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get device subscriptions related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<DeviceOperationDTO> deviceSubscriptions = new ArrayList<>();
String sql = "SELECT " +
" aar.UUID, " +
" ads.DM_DEVICE_ID, " +
" aasom.OPERATION_ID, " +
" ads.STATUS, " +
" ads.ACTION_TRIGGERED_FROM, " +
" ads.SUBSCRIBED_TIMESTAMP AS ACTION_TRIGGERED_AT, " +
" ads.AP_APP_RELEASE_ID " +
"FROM AP_APP_SUB_OP_MAPPING aasom " +
"JOIN AP_DEVICE_SUBSCRIPTION ads ON aasom.AP_DEVICE_SUBSCRIPTION_ID = ads.ID " +
"JOIN AP_APP_RELEASE aar ON ads.AP_APP_RELEASE_ID = aar.ID " +
"WHERE aar.UUID = ? AND aar.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setInt(2, tenantId);
try (ResultSet rs = ps.executeQuery()) {
DeviceOperationDTO deviceSubscription;
while (rs.next()) {
deviceSubscription = new DeviceOperationDTO();
deviceSubscription.setDeviceId(rs.getInt("DM_DEVICE_ID"));
deviceSubscription.setUuid(rs.getString("UUID"));
deviceSubscription.setStatus(rs.getString("STATUS"));
deviceSubscription.setOperationId(rs.getInt("OPERATION_ID"));
deviceSubscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
deviceSubscription.setActionTriggeredAt(rs.getTimestamp("ACTION_TRIGGERED_AT"));
deviceSubscription.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
deviceSubscriptions.add(deviceSubscription);
}
}
}
return deviceSubscriptions;
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get device subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting device subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<DeviceSubscriptionDTO> getDeviceSubscriptionsDetails(int appReleaseId, int tenantId) throws
ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ " from the database");
}
String sql = "SELECT "
+ "DS.ID AS ID, "
+ "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
+ "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
+ "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+ "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+ "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, "
+ "DS.STATUS AS STATUS,"
+ "DS.DM_DEVICE_ID AS DEVICE_ID "
+ "FROM AP_DEVICE_SUBSCRIPTION DS "
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
try (ResultSet rs = ps.executeQuery()) {
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved device subscriptions for application release id "
+ appReleaseId);
}
List<DeviceSubscriptionDTO> deviceSubscriptions = new ArrayList<>();
DeviceSubscriptionDTO subscription;
while (rs.next()) {
subscription = new DeviceSubscriptionDTO();
subscription.setId(rs.getInt("ID"));
subscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
subscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
subscription.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
subscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
subscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_AT"));
subscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
subscription.setStatus(rs.getString("STATUS"));
subscription.setDeviceId(rs.getInt("DEVICE_ID"));
deviceSubscriptions.add(subscription);
}
return deviceSubscriptions;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection for getting device subscription for "
+ "application Id: " + appReleaseId + ".";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while while running SQL to get device subscription data for application ID: " + appReleaseId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
} }

@ -24,11 +24,21 @@ import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionI
import io.entgra.device.mgt.core.application.mgt.common.ApplicationType; import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult; import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData; import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
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.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes; import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus; import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.SubAction; import io.entgra.device.mgt.core.application.mgt.common.SubAction;
import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder; import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType; import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationPolicyDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager; import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
@ -36,8 +46,12 @@ import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException; import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException; import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dto.OperationDTO;
import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext; import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl; import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl;
@ -56,11 +70,6 @@ import org.json.JSONObject;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey; import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException; import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationPolicyDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException; import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
import io.entgra.device.mgt.core.application.mgt.common.exception.LifecycleManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.LifecycleManagementException;
@ -101,6 +110,7 @@ import io.entgra.device.mgt.core.device.mgt.core.util.MDMIOSOperationUtil;
import io.entgra.device.mgt.core.device.mgt.core.util.MDMWindowsOperationUtil; import io.entgra.device.mgt.core.device.mgt.core.util.MDMWindowsOperationUtil;
import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo; import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -1564,11 +1574,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscription.isUnsubscribed()) { if (subscription.isUnsubscribed()) {
deviceSubscriptionData.setAction(Constants.UNSUBSCRIBED); deviceSubscriptionData.setAction(Constants.UNSUBSCRIBED);
deviceSubscriptionData.setActionTriggeredBy(subscription.getUnsubscribedBy()); deviceSubscriptionData.setActionTriggeredBy(subscription.getUnsubscribedBy());
deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getUnsubscribedTimestamp().getTime() / 1000); deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getUnsubscribedTimestamp());
} else { } else {
deviceSubscriptionData.setAction(Constants.SUBSCRIBED); deviceSubscriptionData.setAction(Constants.SUBSCRIBED);
deviceSubscriptionData.setActionTriggeredBy(subscription.getSubscribedBy()); deviceSubscriptionData.setActionTriggeredBy(subscription.getSubscribedBy());
deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp().getTime() / 1000); deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp());
} }
deviceSubscriptionData.setActionType(subscription.getActionTriggeredFrom()); deviceSubscriptionData.setActionType(subscription.getActionTriggeredFrom());
deviceSubscriptionData.setStatus(subscription.getStatus()); deviceSubscriptionData.setStatus(subscription.getStatus());
@ -1686,4 +1696,440 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
} }
@Override
public List<GroupSubscriptionDetailDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
String groupName;
String status;
try {
ConnectionManagerUtil.openDBConnection();
List<GroupSubscriptionDetailDTO> groupDetailsWithDevices = new ArrayList<>();
List<GroupSubscriptionDTO> groupDetails = subscriptionDAO.getGroupsSubscriptionDetailsByUUID(uuid, unsubscribe, tenantId);
if (groupDetails == null) {
throw new ApplicationManagementException("Group details not found for UUID: " + uuid);
}
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
for (GroupSubscriptionDTO groupDetail : groupDetails) {
groupName = groupDetail.getGroupName();
// Retrieve group details and device IDs for the group using the service layer
GroupDetailsDTO groupDetailWithDevices = groupManagementProviderService.getGroupDetailsWithDeviceIds(groupName);
GroupSubscriptionDetailDTO groupDetailDTO = new GroupSubscriptionDetailDTO();
groupDetailDTO.setGroupId(groupDetailWithDevices.getGroupId());
groupDetailDTO.setGroupName(groupDetail.getGroupName());
groupDetailDTO.setGroupOwner(groupDetailWithDevices.getGroupOwner());
groupDetailDTO.setSubscribedBy(groupDetail.getSubscribedBy());
groupDetailDTO.setSubscribedTimestamp(groupDetail.getSubscribedTimestamp());
groupDetailDTO.setUnsubscribed(groupDetail.isUnsubscribed());
groupDetailDTO.setUnsubscribedBy(groupDetail.getUnsubscribedBy());
groupDetailDTO.setUnsubscribedTimestamp(groupDetail.getUnsubscribedTimestamp());
groupDetailDTO.setAppReleaseId(groupDetail.getAppReleaseId());
groupDetailDTO.setDeviceCount(groupDetailWithDevices.getDeviceCount());
// Fetch device subscriptions for each device ID in the group
List<DeviceSubscriptionData> pendingDevices = new ArrayList<>();
List<DeviceSubscriptionData> installedDevices = new ArrayList<>();
List<DeviceSubscriptionData> errorDevices = new ArrayList<>();
List<DeviceSubscriptionData> newDevices = new ArrayList<>();
List<Integer> deviceIds = groupDetailWithDevices.getDeviceIds();
Map<String, Integer> statusCounts = new HashMap<>();
statusCounts.put("PENDING", 0);
statusCounts.put("COMPLETED", 0);
statusCounts.put("ERROR", 0);
statusCounts.put("NEW", 0);
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getDeviceSubscriptionsDetails(
groupDetail.getAppReleaseId(), tenantId);
boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId());
deviceDetail.setStatus(subscription.getStatus());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setSubId(subscription.getId());
deviceDetail.setActionTriggeredBy(subscription.getSubscribedBy());
deviceDetail.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp());
status = subscription.getStatus();
switch (status) {
case "COMPLETED":
installedDevices.add(deviceDetail);
statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1);
break;
case "ERROR":
case "INVALID":
case "UNAUTHORIZED":
errorDevices.add(deviceDetail);
statusCounts.put("ERROR", statusCounts.get("ERROR") + 1);
break;
case "IN_PROGRESS":
case "PENDING":
case "REPEATED":
pendingDevices.add(deviceDetail);
statusCounts.put("PENDING", statusCounts.get("PENDING") + 1);
break;
}
isNewDevice = false;
}
}
if (isNewDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
}
int totalDevices = deviceIds.size();
Map<String, Double> statusPercentages = new HashMap<>();
for (Map.Entry<String, Integer> entry : statusCounts.entrySet()) {
double percentage = ((double) entry.getValue() / totalDevices) * 100;
statusPercentages.put(entry.getKey(), percentage);
}
CategorizedSubscriptionResult categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices);
groupDetailDTO.setDevices(categorizedSubscriptionResult);
groupDetailDTO.setStatusPercentages(statusPercentages);
groupDetailsWithDevices.add(groupDetailDTO);
}
return groupDetailsWithDevices;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while fetching groups and devices for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurred while fetching groups and devices for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (GroupManagementException e) {
String msg = "Error occurred while fetching group details and device IDs: " + e.getMessage();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public List<UserSubscriptionDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
String userName;
String status;
try {
ConnectionManagerUtil.openDBConnection();
List<UserSubscriptionDTO> userSubscriptionsWithDevices = new ArrayList<>();
List<UserSubscriptionDTO> userSubscriptions = subscriptionDAO.getUserSubscriptionsByUUID(uuid, unsubscribe, tenantId);
if (userSubscriptions == null) {
throw new ApplicationManagementException("User details not found for UUID: " + uuid);
}
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (UserSubscriptionDTO userSubscription : userSubscriptions) {
userName = userSubscription.getUserName();
// 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());
userSubscriptionDTO.setSubscribedBy(userSubscription.getSubscribedBy());
userSubscriptionDTO.setSubscribedTimestamp(userSubscription.getSubscribedTimestamp());
userSubscriptionDTO.setUnsubscribed(userSubscription.getUnsubscribed());
userSubscriptionDTO.setUnsubscribedBy(userSubscription.getUnsubscribedBy());
userSubscriptionDTO.setUnsubscribedTimestamp(userSubscription.getUnsubscribedTimestamp());
userSubscriptionDTO.setAppReleaseId(userSubscription.getAppReleaseId());
userSubscriptionDTO.setDeviceCount(ownerDetailsWithDevices.getDeviceCount());
// Fetch device subscriptions for each device ID associated with the user
List<DeviceSubscriptionData> pendingDevices = new ArrayList<>();
List<DeviceSubscriptionData> installedDevices = new ArrayList<>();
List<DeviceSubscriptionData> errorDevices = new ArrayList<>();
List<DeviceSubscriptionData> newDevices = new ArrayList<>();
List<Integer> deviceIds = ownerDetailsWithDevices.getDeviceIds();
Map<String, Integer> statusCounts = new HashMap<>();
statusCounts.put("PENDING", 0);
statusCounts.put("COMPLETED", 0);
statusCounts.put("ERROR", 0);
statusCounts.put("NEW", 0);
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getDeviceSubscriptionsDetails(
userSubscription.getAppReleaseId(), tenantId);
boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setStatus(subscription.getStatus());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setActionTriggeredBy(subscription.getSubscribedBy());
deviceDetail.setSubId(subscription.getId());
deviceDetail.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp());
status = subscription.getStatus();
switch (status) {
case "COMPLETED":
installedDevices.add(deviceDetail);
statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1);
break;
case "ERROR":
case "INVALID":
case "UNAUTHORIZED":
errorDevices.add(deviceDetail);
statusCounts.put("ERROR", statusCounts.get("ERROR") + 1);
break;
case "IN_PROGRESS":
case "PENDING":
case "REPEATED":
pendingDevices.add(deviceDetail);
statusCounts.put("PENDING", statusCounts.get("PENDING") + 1);
break;
}
isNewDevice = false;
}
}
if (isNewDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
}
int totalDevices = deviceIds.size();
Map<String, Double> statusPercentages = new HashMap<>();
for (Map.Entry<String, Integer> entry : statusCounts.entrySet()) {
double percentage = ((double) entry.getValue() / totalDevices) * 100;
statusPercentages.put(entry.getKey(), percentage);
}
CategorizedSubscriptionResult categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices);
userSubscriptionDTO.setDevices(categorizedSubscriptionResult);
userSubscriptionDTO.setStatusPercentages(statusPercentages);
userSubscriptionsWithDevices.add(userSubscriptionDTO);
}
return userSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while getting user subscriptions for the application release UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurred while getting user subscriptions for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
throw new RuntimeException(e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public List<RoleSubscriptionDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
String roleName;
String status;
try {
ConnectionManagerUtil.openDBConnection();
List<RoleSubscriptionDTO> roleSubscriptionsWithDevices = new ArrayList<>();
List<RoleSubscriptionDTO> roleSubscriptions = subscriptionDAO.getRoleSubscriptionsByUUID(uuid, unsubscribe, tenantId);
if (roleSubscriptions == null) {
throw new ApplicationManagementException("Role details not found for UUID: " + uuid);
}
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (RoleSubscriptionDTO roleSubscription : roleSubscriptions) {
roleName = roleSubscription.getRoleName();
RoleSubscriptionDTO roleSubscriptionDTO = new RoleSubscriptionDTO();
roleSubscriptionDTO.setRoleName(roleSubscription.getRoleName());
roleSubscriptionDTO.setSubscribedBy(roleSubscription.getSubscribedBy());
roleSubscriptionDTO.setSubscribedTimestamp(roleSubscription.getSubscribedTimestamp());
roleSubscriptionDTO.setUnsubscribed(roleSubscription.getUnsubscribed());
roleSubscriptionDTO.setUnsubscribedBy(roleSubscription.getUnsubscribedBy());
roleSubscriptionDTO.setUnsubscribedTimestamp(roleSubscription.getUnsubscribedTimestamp());
roleSubscriptionDTO.setAppReleaseId(roleSubscription.getAppReleaseId());
List<DeviceSubscriptionData> pendingDevices = new ArrayList<>();
List<DeviceSubscriptionData> installedDevices = new ArrayList<>();
List<DeviceSubscriptionData> errorDevices = new ArrayList<>();
List<DeviceSubscriptionData> newDevices = new ArrayList<>();
Map<String, Integer> statusCounts = new HashMap<>();
statusCounts.put("PENDING", 0);
statusCounts.put("COMPLETED", 0);
statusCounts.put("ERROR", 0);
statusCounts.put("NEW", 0);
List<String> users = this.getUsersForRole(roleName);
for (String user : users) {
OwnerWithDeviceDTO ownerDetailsWithDevices;
try {
ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user);
} catch (DeviceManagementDAOException e) {
throw new ApplicationManagementException("Error retrieving owner details with devices for user: " + user, e);
}
List<Integer> deviceIds = ownerDetailsWithDevices.getDeviceIds();
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions;
try {
deviceSubscriptions = subscriptionDAO.getDeviceSubscriptionsDetails(
roleSubscription.getAppReleaseId(), tenantId);
} catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException("Error retrieving device subscriptions", e);
}
boolean isNewDevice = true;
for (DeviceSubscriptionDTO deviceSubscription : deviceSubscriptions) {
if (deviceSubscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(deviceSubscription.getDeviceId());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
deviceDetail.setStatus(deviceSubscription.getStatus());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
deviceDetail.setActionTriggeredBy(deviceSubscription.getSubscribedBy());
deviceDetail.setSubId(deviceSubscription.getId());
deviceDetail.setActionTriggeredTimestamp(deviceSubscription.getSubscribedTimestamp());
status = deviceSubscription.getStatus();
switch (status) {
case "COMPLETED":
installedDevices.add(deviceDetail);
statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1);
break;
case "ERROR":
case "INVALID":
case "UNAUTHORIZED":
errorDevices.add(deviceDetail);
statusCounts.put("ERROR", statusCounts.get("ERROR") + 1);
break;
case "IN_PROGRESS":
case "PENDING":
case "REPEATED":
pendingDevices.add(deviceDetail);
statusCounts.put("PENDING", statusCounts.get("PENDING") + 1);
break;
}
isNewDevice = false;
}
}
if (isNewDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
}
}
int totalDevices = pendingDevices.size() + installedDevices.size() + errorDevices.size() + newDevices.size();
Map<String, Double> statusPercentages = new HashMap<>();
for (Map.Entry<String, Integer> entry : statusCounts.entrySet()) {
double percentage = totalDevices == 0 ? 0.0 : ((double) entry.getValue() / totalDevices) * 100;
statusPercentages.put(entry.getKey(), percentage);
}
CategorizedSubscriptionResult categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices);
roleSubscriptionDTO.setDevices(categorizedSubscriptionResult);
roleSubscriptionDTO.setStatusPercentages(statusPercentages);
roleSubscriptionDTO.setDeviceCount(totalDevices);
roleSubscriptionsWithDevices.add(roleSubscriptionDTO);
}
return roleSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred in retrieving role subscriptions with devices";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while retrieving the database connection";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving users for role";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
// Get user list for each role
public List<String> getUsersForRole(String roleName) throws UserStoreException {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = ctx.getTenantId();
UserStoreManager userStoreManager = DataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
String[] users = userStoreManager.getUserListOfRole(roleName);
return Arrays.asList(users);
}
@Override
public List<DeviceOperationDTO> getDeviceSubscriptionsOperationsByUUID(String uuid) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (uuid == null || uuid.isEmpty()) {
throw new IllegalArgumentException("UUID cannot be null or empty.");
}
try {
ConnectionManagerUtil.openDBConnection();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
List<DeviceOperationDTO> deviceSubscriptions = subscriptionDAO.getDeviceSubscriptionsOperationsByUUID(uuid, tenantId);
for (DeviceOperationDTO deviceSubscription : deviceSubscriptions) {
Integer operationId = deviceSubscription.getOperationId();
if (operationId != null) {
OperationDTO operationDetails = deviceManagementProviderService.getOperationDetailsById(operationId);
if (operationDetails != null) {
deviceSubscription.setOperationCode(operationDetails.getOperationCode());
deviceSubscription.setOperationDetails(operationDetails.getOperationDetails());
deviceSubscription.setOperationProperties(operationDetails.getOperationProperties());
}
}
}
return deviceSubscriptions;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while retrieving device subscriptions for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while retrieving the database connection";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (OperationManagementException e) {
throw new RuntimeException(e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
} }

@ -21,9 +21,11 @@ import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo; import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo.Status; import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo.Status;
import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List; import java.util.List;
import java.util.Map;
public interface EnrollmentDAO { public interface EnrollmentDAO {
@ -94,5 +96,13 @@ public interface EnrollmentDAO {
*/ */
boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException; boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException;
/**
* Retrieves owners and the list of device IDs related to an owner.
*
* @param owner the owner whose device IDs need to be retrieved
* @param tenantId the ID of the tenant
* @return a map containing owner details, device IDs, and device count
* @throws DeviceManagementDAOException if an error occurs while fetching the data
*/
OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int tenantId) throws DeviceManagementDAOException;
} }

@ -21,9 +21,9 @@ package io.entgra.device.mgt.core.device.mgt.core.dao;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.ReportManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper;
import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -469,4 +469,14 @@ public interface GroupDAO {
List<String> groupNames) List<String> groupNames)
throws GroupManagementDAOException; throws GroupManagementDAOException;
/**
* Get group details and list of device IDs related to the group.
*
* @param groupName Group name
* @param tenantId Tenant ID
* @return A map containing group details and a list of device IDs
* @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices
*/
GroupDetailsDTO getGroupDetailsWithDeviceIds(String groupName, int tenantId) throws GroupManagementDAOException;
} }

@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOExceptio
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.EnrollmentDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.EnrollmentDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -33,9 +34,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.ArrayList;
public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
@ -557,4 +558,36 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
return enrolmentInfo; return enrolmentInfo;
} }
@Override
public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int tenantId) throws DeviceManagementDAOException {
OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO();
List<Integer> deviceIds = new ArrayList<>();
int deviceCount = 0;
String sql = "SELECT DEVICE_ID, OWNER FROM DM_ENROLMENT WHERE OWNER = ? AND TENANT_ID = ?";
try (Connection conn = this.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, owner);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
if (ownerDetails.getUserName() == null) {
ownerDetails.setUserName(rs.getString("OWNER"));
}
deviceIds.add(rs.getInt("DEVICE_ID"));
deviceCount++;
}
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving owners and device IDs for owner: " + owner, e);
}
ownerDetails.setDeviceIds(deviceIds);
ownerDetails.setDeviceCount(deviceCount);
return ownerDetails;
}
} }

@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.GroupDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOFactory;
@ -1437,4 +1438,43 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
} }
return groupUnassignedDeviceList; return groupUnassignedDeviceList;
} }
@Override
public GroupDetailsDTO getGroupDetailsWithDeviceIds(String groupName, int tenantId) throws GroupManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName);
}
GroupDetailsDTO groupDetails = new GroupDetailsDTO();
List<Integer> deviceIds = new ArrayList<>();
String sql = "SELECT g.ID AS GROUP_ID, g.GROUP_NAME, g.OWNER, dgm.DEVICE_ID "
+ "FROM DM_GROUP g "
+ "JOIN DM_DEVICE_GROUP_MAP dgm ON g.ID = dgm.GROUP_ID "
+ "WHERE g.GROUP_NAME = ? AND g.TENANT_ID = ?";
try (Connection conn = GroupManagementDAOFactory.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, groupName);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
if (groupDetails.getGroupId() == 0) {
groupDetails.setGroupId(rs.getInt("GROUP_ID"));
groupDetails.setGroupName(rs.getString("GROUP_NAME"));
groupDetails.setGroupOwner(rs.getString("OWNER"));
}
deviceIds.add(rs.getInt("DEVICE_ID"));
}
}
} catch (SQLException e) {
throw new GroupManagementDAOException("Error occurred while retrieving group details and device IDs for group: "
+ groupName, e);
}
groupDetails.setDeviceIds(deviceIds);
groupDetails.setDeviceCount(deviceIds.size());
return groupDetails;
}
} }

@ -0,0 +1,70 @@
/*
* 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.device.mgt.core.dto;
import java.util.List;
public class GroupDetailsDTO {
private int groupId;
private String groupName;
private String groupOwner;
private List<Integer> deviceIds;
private int deviceCount;
public int getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getGroupOwner() {
return groupOwner;
}
public void setGroupOwner(String groupOwner) {
this.groupOwner = groupOwner;
}
public List<Integer> getDeviceIds() {
return deviceIds;
}
public void setDeviceIds(List<Integer> deviceIds) {
this.deviceIds = deviceIds;
}
public int getDeviceCount() {
return deviceCount;
}
public void setDeviceCount(int deviceCount) {
this.deviceCount = deviceCount;
}
}

@ -0,0 +1,118 @@
/*
* Copyright (c) 2018 - 2023, 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.device.mgt.core.dto;
import org.json.JSONObject;
import java.sql.Timestamp;
public class OperationDTO {
private int deviceId;
private String uuid;
private String status;
private int operationId;
private String actionTriggeredFrom;
private Timestamp actionTriggeredAt;
private int appReleaseId;
private String operationCode;
private JSONObject operationDetails;
private JSONObject operationProperties;
// Getters and Setters
public int getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
this.deviceId = deviceId;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getOperationId() {
return operationId;
}
public void setOperationId(int operationId) {
this.operationId = operationId;
}
public String getActionTriggeredFrom() {
return actionTriggeredFrom;
}
public void setActionTriggeredFrom(String actionTriggeredFrom) {
this.actionTriggeredFrom = actionTriggeredFrom;
}
public Timestamp getActionTriggeredAt() {
return actionTriggeredAt;
}
public void setActionTriggeredAt(Timestamp actionTriggeredAt) {
this.actionTriggeredAt = actionTriggeredAt;
}
public int getAppReleaseId() {
return appReleaseId;
}
public void setAppReleaseId(int appReleaseId) {
this.appReleaseId = appReleaseId;
}
public String getOperationCode() {
return operationCode;
}
public void setOperationCode(String operationCode) {
this.operationCode = operationCode;
}
public JSONObject getOperationDetails() {
return operationDetails;
}
public void setOperationDetails(JSONObject operationDetails) {
this.operationDetails = operationDetails;
}
public JSONObject getOperationProperties() {
return operationProperties;
}
public void setOperationProperties(JSONObject operationProperties) {
this.operationProperties = operationProperties;
}
}

@ -0,0 +1,52 @@
/*
* 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.device.mgt.core.dto;
import java.util.List;
public class OwnerWithDeviceDTO {
private String userName;
private List<Integer> deviceIds;
private int deviceCount;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public List<Integer> getDeviceIds() {
return deviceIds;
}
public void setDeviceIds(List<Integer> deviceIds) {
this.deviceIds = deviceIds;
}
public int getDeviceCount() {
return deviceCount;
}
public void setDeviceCount(int deviceCount) {
this.deviceCount = deviceCount;
}
}

@ -23,6 +23,8 @@ import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.OperationResponse; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.OperationResponse;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.DeviceActivity; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.DeviceActivity;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dto.OperationDTO;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.OperationResponseMeta; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.OperationMapping; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.OperationMapping;
@ -124,4 +126,6 @@ public interface OperationDAO {
int getDeviceActivitiesCount(ActivityPaginationRequest activityPaginationRequest) int getDeviceActivitiesCount(ActivityPaginationRequest activityPaginationRequest)
throws OperationManagementDAOException; throws OperationManagementDAOException;
OperationDTO getOperationDetailsById(int operationId, int tenantId) throws OperationManagementDAOException;
} }

@ -17,32 +17,35 @@
*/ */
package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl; package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ProfileOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.DeviceActivity;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.ActivityHolder; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.ActivityHolder;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.ActivityStatus; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.ActivityStatus;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.DeviceActivity;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.OperationResponse; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.OperationResponse;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import io.entgra.device.mgt.core.device.mgt.core.dto.OperationDTO;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.OperationResponseMeta; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ProfileOperation;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.OperationMapping; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.OperationMapping;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationDAO; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationDAO;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.sql.Blob;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -2774,4 +2777,43 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
return 0; return 0;
} }
@Override
public OperationDTO getOperationDetailsById(int operationId, int tenantId) throws OperationManagementDAOException {
OperationDTO operationDetails = new OperationDTO();
String sql = "SELECT ID, OPERATION_CODE, OPERATION_DETAILS, OPERATION_PROPERTIES " +
"FROM DM_OPERATION " +
"WHERE ID = ? AND TENANT_ID = ?";
try (Connection conn = OperationManagementDAOFactory.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, operationId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
operationDetails.setOperationId(rs.getInt("ID"));
operationDetails.setOperationCode(rs.getString("OPERATION_CODE"));
Blob detailsBlob = rs.getBlob("OPERATION_DETAILS");
if (detailsBlob != null) {
JSONObject operationDetailsJson = OperationDAOUtil.convertBlobToJsonObject(detailsBlob);
operationDetails.setOperationDetails(operationDetailsJson);
}
Blob propertiesBlob = rs.getBlob("OPERATION_PROPERTIES");
if (propertiesBlob != null) {
JSONObject operationPropertiesJson = OperationDAOUtil.convertBlobToJsonObject(propertiesBlob);
operationDetails.setOperationProperties(operationPropertiesJson);
}
}
}
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while retrieving operation details for operation ID: "
+ operationId, e);
}
return operationDetails;
}
} }

@ -33,10 +33,14 @@ import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.PolicyOperation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.PolicyOperation;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ProfileOperation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ProfileOperation;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.json.JSONObject;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.sql.Blob;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -387,4 +391,43 @@ public class OperationDAOUtil {
return operation; return operation;
} }
public static JSONObject convertBlobToJsonObject(Blob blob) throws SQLException {
String jsonString;
try (InputStream inputStream = blob.getBinaryStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
int bytesRead;
byte[] buffer = new byte[4096];
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
byte[] blobBytes = outputStream.toByteArray();
// Check if the blob data is a serialized Java object
if (blobBytes.length > 2 && (blobBytes[0] & 0xFF) == 0xAC && (blobBytes[1] & 0xFF) == 0xED) {
// Deserialize the object
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(blobBytes))) {
Object obj = ois.readObject();
if (obj instanceof String) {
jsonString = (String) obj;
} else {
jsonString = new JSONObject(obj).toString();
}
} catch (ClassNotFoundException e) {
throw new SQLException("Failed to deserialize object from BLOB", e);
}
} else {
// If not serialized, treat it as plain JSON string
jsonString = new String(blobBytes, "UTF-8");
}
} catch (IOException e) {
throw new SQLException("Failed to convert BLOB to JSON string", e);
}
// Convert JSON string to JSONObject
if (jsonString == null || jsonString.isEmpty()) {
throw new SQLException("Converted JSON string is null or empty");
}
return new JSONObject(jsonString);
}
} }

@ -19,6 +19,8 @@
package io.entgra.device.mgt.core.device.mgt.core.service; package io.entgra.device.mgt.core.device.mgt.core.service;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import io.entgra.device.mgt.core.device.mgt.core.dto.OperationDTO;
import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
import org.apache.commons.collections.map.SingletonMap; import org.apache.commons.collections.map.SingletonMap;
import io.entgra.device.mgt.core.device.mgt.common.*; import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException;
@ -1073,4 +1075,22 @@ public interface DeviceManagementProviderService {
List<Device> getEnrolledDevicesSince(Date since) throws DeviceManagementException; List<Device> getEnrolledDevicesSince(Date since) throws DeviceManagementException;
List<Device> getEnrolledDevicesPriorTo(Date before) throws DeviceManagementException; List<Device> getEnrolledDevicesPriorTo(Date before) throws DeviceManagementException;
void deleteDeviceDataByTenantDomain(String tenantDomain) throws DeviceManagementException; void deleteDeviceDataByTenantDomain(String tenantDomain) throws DeviceManagementException;
/**
* Get owner details and device IDs for a given owner and tenant.
*
* @param owner the name of the owner.
* @return a map containing owner details (Owner, DeviceIds, DeviceCount).
* @throws DeviceManagementException if an error occurs while fetching owner details.
*/
OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException;
/**
* Get operation details by operation code.
*
* @param operationId the id of the operation.
* @return Map containing operation ID, operation code, operation details, and operation properties.
* @throws OperationManagementException if an error occurs while fetching the operation details.
*/
OperationDTO getOperationDetailsById(int operationId) throws OperationManagementException;
} }

@ -22,6 +22,10 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.dao.TenantDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.TenantDAO;
import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
import io.entgra.device.mgt.core.device.mgt.core.dto.OperationDTO;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceEnrolmentLogContext; import io.entgra.device.mgt.core.notification.logger.DeviceEnrolmentLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceEnrolmentLoggerImpl; import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceEnrolmentLoggerImpl;
@ -120,6 +124,7 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceStatusDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceStatusDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceTypeDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceTypeDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.EnrollmentDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.EnrollmentDAO;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceInformationManager; import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceInformationManager;
@ -173,6 +178,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private final DeviceDAO deviceDAO; private final DeviceDAO deviceDAO;
private final DeviceTypeDAO deviceTypeDAO; private final DeviceTypeDAO deviceTypeDAO;
private final EnrollmentDAO enrollmentDAO; private final EnrollmentDAO enrollmentDAO;
private final OperationDAO operationDAO;
private final ApplicationDAO applicationDAO; private final ApplicationDAO applicationDAO;
private MetadataDAO metadataDAO; private MetadataDAO metadataDAO;
private final DeviceStatusDAO deviceStatusDAO; private final DeviceStatusDAO deviceStatusDAO;
@ -185,6 +191,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
this.operationDAO = OperationManagementDAOFactory.getOperationDAO();
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO(); this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
this.deviceStatusDAO = DeviceManagementDAOFactory.getDeviceStatusDAO(); this.deviceStatusDAO = DeviceManagementDAOFactory.getDeviceStatusDAO();
this.tenantDao = DeviceManagementDAOFactory.getTenantDAO(); this.tenantDao = DeviceManagementDAOFactory.getTenantDAO();
@ -5339,4 +5346,52 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
} }
@Override
public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
OwnerWithDeviceDTO ownerWithDeviceDTO;
try {
DeviceManagementDAOFactory.openConnection();
ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDeviceIds(owner, tenantId);
} catch (DeviceManagementDAOException | SQLException e) {
String msg = "Error occurred while retrieving device IDs for owner: " + owner;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
// Add device count to the DTO
if (ownerWithDeviceDTO != null) {
List<Integer> deviceIds = ownerWithDeviceDTO.getDeviceIds();
if (deviceIds != null) {
ownerWithDeviceDTO.setDeviceCount(deviceIds.size());
} else {
ownerWithDeviceDTO.setDeviceCount(0);
}
}
return ownerWithDeviceDTO;
}
@Override
public OperationDTO getOperationDetailsById(int operationId) throws OperationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
OperationDTO operationDetails;
try {
OperationManagementDAOFactory.openConnection();
operationDetails = this.operationDAO.getOperationDetailsById(operationId, tenantId);
} catch (SQLException | OperationManagementDAOException e) {
String msg = "Error occurred while retrieving operation details for operation ID: " + operationId;
log.error(msg, e);
throw new OperationManagementException(msg, e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
return operationDetails;
}
} }

@ -30,6 +30,7 @@ import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistEx
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException;
import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
import org.wso2.carbon.user.api.AuthorizationManager; import org.wso2.carbon.user.api.AuthorizationManager;
import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.api.UserStoreManager;
@ -371,4 +372,14 @@ public interface GroupManagementProviderService {
DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException; DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException;
DeviceGroup getUserOwnGroup(int groupId, boolean requireGroupProps, int depth) throws GroupManagementException; DeviceGroup getUserOwnGroup(int groupId, boolean requireGroupProps, int depth) throws GroupManagementException;
/**
* Get group details and device IDs for a given group name.
*
* @param groupName the name of the group.
* @return a map containing group details and device IDs.
* @throws GroupManagementException if an error occurs while fetching group details.
*/
GroupDetailsDTO getGroupDetailsWithDeviceIds(String groupName) throws GroupManagementException;
} }

@ -26,13 +26,13 @@ import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistEx
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException;
import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupDAO; import io.entgra.device.mgt.core.device.mgt.core.dao.GroupDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -1629,6 +1629,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
createGroupWithChildren(nextParentGroup, childrenGroups, requireGroupProps, tenantId, depth, counter); createGroupWithChildren(nextParentGroup, childrenGroups, requireGroupProps, tenantId, depth, counter);
} }
} }
@Override @Override
public DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException { public DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException {
DeviceTypesOfGroups deviceTypesOfGroups = new DeviceTypesOfGroups(); DeviceTypesOfGroups deviceTypesOfGroups = new DeviceTypesOfGroups();
@ -1685,4 +1686,37 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
return deviceTypesOfGroups; return deviceTypesOfGroups;
} }
@Override
public GroupDetailsDTO getGroupDetailsWithDeviceIds(String groupName) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Retrieving group details and device IDs for group: " + groupName);
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupDetailsDTO groupDetailsWithDevices;
try {
GroupManagementDAOFactory.openConnection();
groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDeviceIds(groupName, tenantId);
} catch (GroupManagementDAOException | SQLException e) {
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
// Add device count
if (groupDetailsWithDevices != null) {
List<Integer> deviceIds = (List<Integer>) groupDetailsWithDevices.getDeviceIds();
if (deviceIds != null) {
groupDetailsWithDevices.setDeviceCount(deviceIds.size());
} else {
groupDetailsWithDevices.setDeviceCount(0);
}
}
return groupDetailsWithDevices;
}
} }

Loading…
Cancel
Save