Subscription info related API restructuring #465
Merged
tcdlpds
merged 27 commits from APPM_Imp
into master
4 months ago
@ -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;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class DeviceSubscription {
|
||||
private int deviceId;
|
||||
private int subscriptionId;
|
||||
private String deviceName;
|
||||
private String deviceIdentifier;
|
||||
private String deviceStatus;
|
||||
private String deviceOwner;
|
||||
private String deviceType;
|
||||
private String ownershipType;
|
||||
private Timestamp dateOfLastUpdate;
|
||||
private SubscriptionData subscriptionData;
|
||||
|
||||
public int getSubscriptionId() {
|
||||
return subscriptionId;
|
||||
}
|
||||
|
||||
public void setSubscriptionId(int subscriptionId) {
|
||||
this.subscriptionId = subscriptionId;
|
||||
}
|
||||
|
||||
public int getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(int deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getDeviceIdentifier() {
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||
this.deviceIdentifier = deviceIdentifier;
|
||||
}
|
||||
|
||||
public String getDeviceStatus() {
|
||||
return deviceStatus;
|
||||
}
|
||||
|
||||
public void setDeviceStatus(String deviceStatus) {
|
||||
this.deviceStatus = deviceStatus;
|
||||
}
|
||||
|
||||
public String getDeviceOwner() {
|
||||
return deviceOwner;
|
||||
}
|
||||
|
||||
public void setDeviceOwner(String deviceOwner) {
|
||||
this.deviceOwner = deviceOwner;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public String getOwnershipType() {
|
||||
return ownershipType;
|
||||
}
|
||||
|
||||
public void setOwnershipType(String ownershipType) {
|
||||
this.ownershipType = ownershipType;
|
||||
}
|
||||
|
||||
public Timestamp getDateOfLastUpdate() {
|
||||
return dateOfLastUpdate;
|
||||
}
|
||||
|
||||
public void setDateOfLastUpdate(Timestamp dateOfLastUpdate) {
|
||||
this.dateOfLastUpdate = dateOfLastUpdate;
|
||||
}
|
||||
|
||||
public SubscriptionData getSubscriptionData() {
|
||||
return subscriptionData;
|
||||
}
|
||||
|
||||
public void setSubscriptionData(SubscriptionData subscriptionData) {
|
||||
this.subscriptionData = subscriptionData;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class DeviceSubscriptionFilterCriteria {
|
||||
private String name;
|
||||
private String owner;
|
||||
private String deviceStatus;
|
||||
private String filteringDeviceSubscriptionStatus; // COMPLETE, PENDING ...
|
||||
private String triggeredBy;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getDeviceStatus() {
|
||||
return deviceStatus;
|
||||
}
|
||||
|
||||
public void setDeviceStatus(String deviceStatus) {
|
||||
this.deviceStatus = deviceStatus;
|
||||
}
|
||||
|
||||
public String getFilteringDeviceSubscriptionStatus() {
|
||||
return filteringDeviceSubscriptionStatus;
|
||||
}
|
||||
|
||||
public void setFilteringDeviceSubscriptionStatus(String filteringDeviceSubscriptionStatus) {
|
||||
this.filteringDeviceSubscriptionStatus = filteringDeviceSubscriptionStatus;
|
||||
}
|
||||
|
||||
public String getTriggeredBy() {
|
||||
return triggeredBy;
|
||||
}
|
||||
|
||||
public void setTriggeredBy(String triggeredBy) {
|
||||
this.triggeredBy = triggeredBy;
|
||||
}
|
||||
}
|
@ -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.application.mgt.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class SubscriptionData {
|
||||
private String deviceSubscriptionStatus;
|
||||
private String triggeredBy;
|
||||
private String subscriptionType;
|
||||
private Timestamp triggeredAt;
|
||||
private int subscriptionId;
|
||||
|
||||
public String getDeviceSubscriptionStatus() {
|
||||
return deviceSubscriptionStatus;
|
||||
}
|
||||
|
||||
public void setDeviceSubscriptionStatus(String deviceSubscriptionStatus) {
|
||||
this.deviceSubscriptionStatus = deviceSubscriptionStatus;
|
||||
}
|
||||
|
||||
public String getTriggeredBy() {
|
||||
return triggeredBy;
|
||||
}
|
||||
|
||||
public void setTriggeredBy(String triggeredBy) {
|
||||
this.triggeredBy = triggeredBy;
|
||||
}
|
||||
|
||||
public String getSubscriptionType() {
|
||||
return subscriptionType;
|
||||
}
|
||||
|
||||
public void setSubscriptionType(String subscriptionType) {
|
||||
this.subscriptionType = subscriptionType;
|
||||
}
|
||||
|
||||
public Timestamp getTriggeredAt() {
|
||||
return triggeredAt;
|
||||
}
|
||||
|
||||
public void setTriggeredAt(Timestamp triggeredAt) {
|
||||
this.triggeredAt = triggeredAt;
|
||||
}
|
||||
|
||||
public int getSubscriptionId() {
|
||||
return subscriptionId;
|
||||
}
|
||||
|
||||
public void setSubscriptionId(int subscriptionId) {
|
||||
this.subscriptionId = subscriptionId;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class SubscriptionEntity {
|
||||
private String identity;
|
||||
private String subscribedBy;
|
||||
private Timestamp subscribedTimestamp;
|
||||
private boolean unsubscribed;
|
||||
private String unsubscribedBy;
|
||||
private Timestamp unsubscribedTimestamp;
|
||||
private int applicationReleaseId;
|
||||
|
||||
public String getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public void setIdentity(String identity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
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 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 getApplicationReleaseId() {
|
||||
return applicationReleaseId;
|
||||
}
|
||||
|
||||
public void setApplicationReleaseId(int applicationReleaseId) {
|
||||
this.applicationReleaseId = applicationReleaseId;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class SubscriptionInfo {
|
||||
private String applicationUUID;
|
||||
private String subscriptionType;
|
||||
private String deviceSubscriptionStatus;
|
||||
private String identifier;
|
||||
private String subscriptionStatus;
|
||||
private DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria;
|
||||
|
||||
public String getApplicationUUID() {
|
||||
return applicationUUID;
|
||||
}
|
||||
|
||||
public void setApplicationUUID(String applicationUUID) {
|
||||
this.applicationUUID = applicationUUID;
|
||||
}
|
||||
|
||||
public String getSubscriptionType() {
|
||||
return subscriptionType;
|
||||
}
|
||||
|
||||
public void setSubscriptionType(String subscriptionType) {
|
||||
this.subscriptionType = subscriptionType;
|
||||
}
|
||||
|
||||
public String getDeviceSubscriptionStatus() {
|
||||
return deviceSubscriptionStatus;
|
||||
}
|
||||
|
||||
public void setDeviceSubscriptionStatus(String deviceSubscriptionStatus) {
|
||||
this.deviceSubscriptionStatus = deviceSubscriptionStatus;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getSubscriptionStatus() {
|
||||
return subscriptionStatus;
|
||||
}
|
||||
|
||||
public void setSubscriptionStatus(String subscriptionStatus) {
|
||||
this.subscriptionStatus = subscriptionStatus;
|
||||
}
|
||||
|
||||
public DeviceSubscriptionFilterCriteria getDeviceSubscriptionFilterCriteria() {
|
||||
return deviceSubscriptionFilterCriteria;
|
||||
}
|
||||
|
||||
public void setDeviceSubscriptionFilterCriteria(DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria) {
|
||||
this.deviceSubscriptionFilterCriteria = deviceSubscriptionFilterCriteria;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
|||||||
/*
|
|||||||
* 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;
|
|||||||
|
|||||||
import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
|||||||
import java.util.List;
|
|||||||
import java.util.Map;
|
|||||||
|
|||||||
public class SubscriptionMetadata {
|
|||||||
public static final class DeviceSubscriptionStatus {
|
|||||||
|
|||||||
public static final String NEW = "NEW";
|
|||||||
public static final String PENDING = "PENDING";
|
|||||||
public static final String COMPLETED = "COMPLETED";
|
|||||||
public static final String ERROR = "ERROR";
|
|||||||
public static final String INVALID = "INVALID";
|
|||||||
public static final String UNAUTHORIZED = "UNAUTHORIZED";
|
|||||||
public static final String IN_PROGRESS = "IN_PROGRESS";
|
|||||||
public static final String REPEAT = "REPEAT";
|
|||||||
}
|
|||||||
|
|||||||
public static final class SubscriptionTypes {
|
|||||||
public static final String ROLE = "role";
|
|||||||
public static final String DEVICE = "device";
|
|||||||
public static final String GROUP = "group";
|
|||||||
public static final String USER = "user";
|
|||||||
}
|
|||||||
|
|||||||
public static final class DBSubscriptionStatus {
|
|||||||
public static final List<String> COMPLETED_STATUS_LIST =
|
|||||||
Collections.singletonList(DeviceSubscriptionStatus.COMPLETED);
|
|||||||
public static final List<String> ERROR_STATUS_LIST =
|
|||||||
Arrays.asList(DeviceSubscriptionStatus.ERROR, DeviceSubscriptionStatus.INVALID, DeviceSubscriptionStatus.UNAUTHORIZED);
|
|||||||
public static final List<String> PENDING_STATUS_LIST =
|
|||||||
Arrays.asList(DeviceSubscriptionStatus.PENDING, DeviceSubscriptionStatus.IN_PROGRESS, DeviceSubscriptionStatus.REPEAT);
|
|||||||
}
|
|||||||
|
|||||||
public static Map<String, List<String>> deviceSubscriptionStatusToDBSubscriptionStatusMap;
|
|||||||
static {
|
|||||||
Map<String, List<String>> statusMap = new HashMap<>();
|
|||||||
statusMap.put(DeviceSubscriptionStatus.COMPLETED, DBSubscriptionStatus.COMPLETED_STATUS_LIST);
|
|||||||
statusMap.put(DeviceSubscriptionStatus.PENDING, DBSubscriptionStatus.PENDING_STATUS_LIST);
|
|||||||
statusMap.put(DeviceSubscriptionStatus.IN_PROGRESS, DBSubscriptionStatus.PENDING_STATUS_LIST);
|
|||||||
statusMap.put(DeviceSubscriptionStatus.REPEAT, DBSubscriptionStatus.PENDING_STATUS_LIST);
|
|||||||
statusMap.put(DeviceSubscriptionStatus.ERROR, DBSubscriptionStatus.ERROR_STATUS_LIST);
|
|||||||
statusMap.put(DeviceSubscriptionStatus.INVALID, DBSubscriptionStatus.ERROR_STATUS_LIST);
|
|||||||
statusMap.put(DeviceSubscriptionStatus.UNAUTHORIZED, DBSubscriptionStatus.ERROR_STATUS_LIST);
|
|||||||
deviceSubscriptionStatusToDBSubscriptionStatusMap = Collections.unmodifiableMap(statusMap);
|
|||||||
}
|
|||||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SubscriptionResponse {
|
||||
private String applicationUUID;
|
||||
private int count;
|
||||
private List<?> data;
|
||||
|
||||
public SubscriptionResponse(String applicationUUID, int count, List<?> data) {
|
||||
this.applicationUUID = applicationUUID;
|
||||
this.count = count;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public SubscriptionResponse(String applicationUUID, List<?> data) {
|
||||
this.applicationUUID = applicationUUID;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getApplicationUUID() {
|
||||
return applicationUUID;
|
||||
}
|
||||
|
||||
public void setApplicationUUID(String applicationUUID) {
|
||||
this.applicationUUID = applicationUUID;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public List<?> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<?> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class SubscriptionStatistics {
|
||||
private float completedPercentage;
|
||||
private float failedPercentage;
|
||||
private float pendingPercentage;
|
||||
private float newDevicesPercentage;
|
||||
|
||||
public SubscriptionStatistics() {}
|
||||
public SubscriptionStatistics(float completedPercentage, float failedPercentage, float pendingPercentage,
|
||||
float newDevicesPercentage) {
|
||||
this.completedPercentage = completedPercentage;
|
||||
this.failedPercentage = failedPercentage;
|
||||
this.pendingPercentage = pendingPercentage;
|
||||
this.newDevicesPercentage = newDevicesPercentage;
|
||||
}
|
||||
|
||||
public float getCompletedPercentage() {
|
||||
return completedPercentage;
|
||||
}
|
||||
|
||||
public void setCompletedPercentage(float completedPercentage) {
|
||||
this.completedPercentage = completedPercentage;
|
||||
}
|
||||
|
||||
public float getFailedPercentage() {
|
||||
return failedPercentage;
|
||||
}
|
||||
|
||||
public void setFailedPercentage(float failedPercentage) {
|
||||
this.failedPercentage = failedPercentage;
|
||||
}
|
||||
|
||||
public float getPendingPercentage() {
|
||||
return pendingPercentage;
|
||||
}
|
||||
|
||||
public void setPendingPercentage(float pendingPercentage) {
|
||||
this.pendingPercentage = pendingPercentage;
|
||||
}
|
||||
|
||||
public float getNewDevicesPercentage() {
|
||||
return newDevicesPercentage;
|
||||
}
|
||||
|
||||
public void setNewDevicesPercentage(float newDevicesPercentage) {
|
||||
this.newDevicesPercentage = newDevicesPercentage;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class SubscriptionStatisticDTO {
|
||||
private int completedDeviceCount = 0;
|
||||
private int pendingDevicesCount = 0;
|
||||
private int failedDevicesCount = 0;
|
||||
|
||||
public void addToComplete(int count) {
|
||||
completedDeviceCount += count;
|
||||
}
|
||||
|
||||
public void addToPending(int count) {
|
||||
pendingDevicesCount += count;
|
||||
}
|
||||
|
||||
public void addToFailed(int count) {
|
||||
failedDevicesCount += count ;
|
||||
}
|
||||
|
||||
public int getCompletedDeviceCount() {
|
||||
return completedDeviceCount;
|
||||
}
|
||||
|
||||
public void setCompletedDeviceCount(int completedDeviceCount) {
|
||||
this.completedDeviceCount = completedDeviceCount;
|
||||
}
|
||||
|
||||
public int getPendingDevicesCount() {
|
||||
return pendingDevicesCount;
|
||||
}
|
||||
|
||||
public void setPendingDevicesCount(int pendingDevicesCount) {
|
||||
this.pendingDevicesCount = pendingDevicesCount;
|
||||
}
|
||||
|
||||
public int getFailedDevicesCount() {
|
||||
return failedDevicesCount;
|
||||
}
|
||||
|
||||
public void setFailedDevicesCount(int failedDevicesCount) {
|
||||
this.failedDevicesCount = failedDevicesCount;
|
||||
}
|
||||
}
|
@ -17,8 +17,11 @@
|
|||||||
*/
|
|||||||
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription;
|
|||||||
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
|||||||
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.SubscriptionEntity;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
|
|||||||
@ -43,9 +46,11 @@ import java.sql.Timestamp;
|
|||||||
import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
|||||||
import java.util.Calendar;
|
|||||||
import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
|||||||
import java.util.List;
|
|||||||
import java.util.Map;
|
|||||||
import java.util.Objects;
|
|||||||
import java.util.StringJoiner;
|
|||||||
import java.util.stream.Collectors;
|
|||||||
|
|||||||
@ -1641,20 +1646,27 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public List<GroupSubscriptionDTO> getGroupsSubscriptionDetailsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
|
|||||||
public List<SubscriptionEntity> getGroupsSubscriptionDetailsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
|
|||||||
throws ApplicationManagementDAOException {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Request received in DAO Layer to get groups related to the given AppReleaseID.");
|
|||||||
}
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
List<GroupSubscriptionDTO> groupDetails = new ArrayList<>();
|
|||||||
List<SubscriptionEntity> subscriptionEntities = new ArrayList<>();
|
|||||||
|
|||||||
String subscriptionStatusTime = unsubscribe ? "GS.UNSUBSCRIBED_TIMESTAMP" : "GS.SUBSCRIBED_TIMESTAMP";
|
|||||||
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 " +
|
|||||||
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 " +
|
|||||||
"WHERE GS.AP_APP_RELEASE_ID = ? AND GS.UNSUBSCRIBED = ? AND GS.TENANT_ID = ? " +
|
|||||||
"WHERE GS.AP_APP_RELEASE_ID = ? " +
|
|||||||
"AND GS.UNSUBSCRIBED = ? " +
|
|||||||
"AND GS.TENANT_ID = ? " +
|
|||||||
"ORDER BY " + subscriptionStatusTime + " DESC ";
|
|||||||
|
|||||||
// Append limit and offset only if limit is not -1
|
|||||||
@ -1673,21 +1685,21 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
|||||||
GroupSubscriptionDTO groupDetail;
|
|||||||
SubscriptionEntity subscriptionEntity;
|
|||||||
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);
|
|||||||
subscriptionEntity = new SubscriptionEntity();
|
|||||||
subscriptionEntity.setIdentity(rs.getString("GROUP_NAME"));
|
|||||||
subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
|
|||||||
subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
|
|||||||
subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
|
|||||||
subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
|
|||||||
subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
|
|||||||
subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
|
|||||||
|
|||||||
subscriptionEntities.add(subscriptionEntity);
|
|||||||
}
|
|||||||
}
|
|||||||
return groupDetails;
|
|||||||
return subscriptionEntities;
|
|||||||
}
|
|||||||
} catch (DBConnectionException e) {
|
|||||||
String msg = "Error occurred while obtaining the DB connection to get groups for the given UUID.";
|
|||||||
@ -1701,20 +1713,27 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public List<SubscriptionsDTO> getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
|
|||||||
public List<SubscriptionEntity> getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
|
|||||||
int offset, int limit) throws ApplicationManagementDAOException {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Request received in DAO Layer to get user subscriptions related to the given UUID.");
|
|||||||
}
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
List<SubscriptionsDTO> userSubscriptions = new ArrayList<>();
|
|||||||
List<SubscriptionEntity> subscriptionEntities = new ArrayList<>();
|
|||||||
|
|||||||
String subscriptionStatusTime = unsubscribe ? "US.UNSUBSCRIBED_TIMESTAMP" : "US.SUBSCRIBED_TIMESTAMP";
|
|||||||
String sql = "SELECT US.USER_NAME, US.SUBSCRIBED_BY, US.SUBSCRIBED_TIMESTAMP, US.UNSUBSCRIBED, " +
|
|||||||
"US.UNSUBSCRIBED_BY, US.UNSUBSCRIBED_TIMESTAMP, US.AP_APP_RELEASE_ID " +
|
|||||||
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 " +
|
|||||||
"FROM AP_USER_SUBSCRIPTION US " +
|
|||||||
"WHERE US.AP_APP_RELEASE_ID = ? AND US.UNSUBSCRIBED = ? AND US.TENANT_ID = ? " +
|
|||||||
"WHERE US.AP_APP_RELEASE_ID = ? " +
|
|||||||
"AND US.UNSUBSCRIBED = ? " +
|
|||||||
"AND US.TENANT_ID = ? " +
|
|||||||
"ORDER BY " + subscriptionStatusTime + " DESC " +
|
|||||||
"LIMIT ? OFFSET ?";
|
|||||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
|||||||
@ -1724,21 +1743,21 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
ps.setInt(4, limit);
|
|||||||
ps.setInt(5, offset);
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
|||||||
SubscriptionEntity subscriptionEntity;
|
|||||||
while (rs.next()) {
|
|||||||
SubscriptionsDTO userSubscription;
|
|||||||
userSubscription = new SubscriptionsDTO();
|
|||||||
userSubscription.setName(rs.getString("USER_NAME"));
|
|||||||
userSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
|
|||||||
userSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
|
|||||||
userSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
|
|||||||
userSubscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
|
|||||||
userSubscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
|
|||||||
userSubscription.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
|
|||||||
|
|||||||
userSubscriptions.add(userSubscription);
|
|||||||
subscriptionEntity = new SubscriptionEntity();
|
|||||||
subscriptionEntity.setIdentity(rs.getString("USER_NAME"));
|
|||||||
subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
|
|||||||
subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
|
|||||||
subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
|
|||||||
subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
|
|||||||
subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
|
|||||||
subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
|
|||||||
|
|||||||
subscriptionEntities.add(subscriptionEntity);
|
|||||||
}
|
|||||||
}
|
|||||||
return userSubscriptions;
|
|||||||
return subscriptionEntities;
|
|||||||
}
|
|||||||
} catch (DBConnectionException e) {
|
|||||||
String msg = "Error occurred while obtaining the DB connection to get user subscriptions for the given UUID.";
|
|||||||
@ -1752,20 +1771,27 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public List<SubscriptionsDTO> getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset,
|
|||||||
int limit) throws ApplicationManagementDAOException {
|
|||||||
public List<SubscriptionEntity> getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset,
|
|||||||
int limit) throws ApplicationManagementDAOException {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Request received in DAO Layer to get role subscriptions related to the given AppReleaseID.");
|
|||||||
}
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
List<SubscriptionsDTO> roleSubscriptions = new ArrayList<>();
|
|||||||
List<SubscriptionEntity> subscriptionEntities = new ArrayList<>();
|
|||||||
|
|||||||
String subscriptionStatusTime = unsubscribe ? "ARS.UNSUBSCRIBED_TIMESTAMP" : "ARS.SUBSCRIBED_TIMESTAMP";
|
|||||||
String sql = "SELECT ARS.ROLE_NAME, ARS.SUBSCRIBED_BY, ARS.SUBSCRIBED_TIMESTAMP, ARS.UNSUBSCRIBED, " +
|
|||||||
"ARS.UNSUBSCRIBED_BY, ARS.UNSUBSCRIBED_TIMESTAMP, ARS.AP_APP_RELEASE_ID " +
|
|||||||
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 " +
|
|||||||
"WHERE ARS.AP_APP_RELEASE_ID = ? AND ARS.UNSUBSCRIBED = ? AND ARS.TENANT_ID = ? " +
|
|||||||
"WHERE ARS.AP_APP_RELEASE_ID = ? " +
|
|||||||
"AND ARS.UNSUBSCRIBED = ? " +
|
|||||||
"AND ARS.TENANT_ID = ? " +
|
|||||||
"ORDER BY " + subscriptionStatusTime + " DESC " +
|
|||||||
"LIMIT ? OFFSET ?";
|
|||||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
|||||||
@ -1775,21 +1801,21 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
ps.setInt(4, limit);
|
|||||||
ps.setInt(5, offset);
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
|||||||
SubscriptionsDTO roleSubscription;
|
|||||||
SubscriptionEntity subscriptionEntity;
|
|||||||
while (rs.next()) {
|
|||||||
roleSubscription = new SubscriptionsDTO();
|
|||||||
roleSubscription.setName(rs.getString("ROLE_NAME"));
|
|||||||
roleSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
|
|||||||
roleSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
|
|||||||
roleSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
|
|||||||
roleSubscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
|
|||||||
roleSubscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
|
|||||||
roleSubscription.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
|
|||||||
|
|||||||
roleSubscriptions.add(roleSubscription);
|
|||||||
subscriptionEntity = new SubscriptionEntity();
|
|||||||
subscriptionEntity.setIdentity(rs.getString("ROLE_NAME"));
|
|||||||
subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
|
|||||||
subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
|
|||||||
subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
|
|||||||
subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
|
|||||||
subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
|
|||||||
subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
|
|||||||
|
|||||||
subscriptionEntities.add(subscriptionEntity);
|
|||||||
}
|
|||||||
}
|
|||||||
return roleSubscriptions;
|
|||||||
return subscriptionEntities;
|
|||||||
}
|
|||||||
} catch (DBConnectionException e) {
|
|||||||
String msg = "Error occurred while obtaining the DB connection to get role subscriptions for the given UUID.";
|
|||||||
@ -1918,14 +1944,20 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
// passed the required list for the action status
|
|||||||
@Override
|
|||||||
public List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
|
|||||||
List<Integer> deviceIds, String actionStatus, String actionType,
|
|||||||
String actionTriggeredBy, String tabActionStatus) throws ApplicationManagementDAOException {
|
|||||||
List<Integer> deviceIds, List<String> actionStatus, String actionType,
|
|||||||
String actionTriggeredBy, int limit, int offset) throws ApplicationManagementDAOException {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Getting device subscriptions for the application release id " + appReleaseId
|
|||||||
+ " and device ids " + deviceIds + " from the database");
|
|||||||
}
|
|||||||
|
|||||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
|||||||
return Collections.emptyList();
|
|||||||
}
|
|||||||
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
|
|||||||
@ -1940,11 +1972,15 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
+ "DS.STATUS AS STATUS, "
|
|||||||
+ "DS.DM_DEVICE_ID AS DEVICE_ID "
|
|||||||
+ "FROM AP_DEVICE_SUBSCRIPTION DS "
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? AND DS.DM_DEVICE_ID IN (" +
|
|||||||
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? "
|
|||||||
+ "AND DS.UNSUBSCRIBED = ? "
|
|||||||
+ "AND DS.TENANT_ID = ? "
|
|||||||
+ "AND DS.DM_DEVICE_ID IN ("
|
|||||||
+ deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
sql.append(" AND DS.STATUS = ? ");
|
|||||||
sql.append(" AND DS.STATUS IN (").
|
|||||||
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
|||||||
}
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
|||||||
@ -1953,27 +1989,41 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
sql.append(" AND DS.SUBSCRIBED_BY LIKE ? ");
|
|||||||
}
|
|||||||
|
|||||||
sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC");
|
|||||||
sql.append("ORDER BY ").append(subscriptionStatusTime).
|
|||||||
append(" DESC ");
|
|||||||
|
|||||||
if (offset >= 0 && limit >= 0) {
|
|||||||
sql.append("LIMIT ? OFFSET ?");
|
|||||||
}
|
|||||||
|
|||||||
try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
|
|||||||
int paramIdx = 1;
|
|||||||
ps.setInt(paramIdx++, appReleaseId);
|
|||||||
ps.setBoolean(paramIdx++, unsubscribe);
|
|||||||
ps.setInt(paramIdx++, tenantId);
|
|||||||
for (int i = 0; i < deviceIds.size(); i++) {
|
|||||||
ps.setInt(paramIdx++, deviceIds.get(i));
|
|||||||
for (Integer deviceId : deviceIds) {
|
|||||||
ps.setInt(paramIdx++, deviceId);
|
|||||||
}
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, actionStatus);
|
|||||||
for (String status : actionStatus) {
|
|||||||
ps.setString(paramIdx++, status);
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, actionType);
|
|||||||
}
|
|||||||
|
|||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
|||||||
}
|
|||||||
|
|||||||
if (offset >= 0 && limit >= 0) {
|
|||||||
ps.setInt(paramIdx++, limit);
|
|||||||
ps.setInt(paramIdx, offset);
|
|||||||
}
|
|||||||
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Successfully retrieved device subscriptions for application release id "
|
|||||||
@ -2010,9 +2060,178 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public int getDeviceSubscriptionCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
|||||||
List<Integer> deviceIds, List<String> actionStatus, String actionType,
|
|||||||
String actionTriggeredBy) throws ApplicationManagementDAOException {
|
|||||||
int deviceCount = 0;
|
|||||||
|
|||||||
if (deviceIds == null || deviceIds.isEmpty()) return deviceCount;
|
|||||||
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
StringBuilder sql = new StringBuilder("SELECT COUNT(DISTINCT DS.DM_DEVICE_ID) AS COUNT "
|
|||||||
+ "FROM AP_DEVICE_SUBSCRIPTION DS "
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? "
|
|||||||
+ "AND DS.UNSUBSCRIBED = ? "
|
|||||||
+ "AND DS.TENANT_ID = ? "
|
|||||||
+ "AND DS.DM_DEVICE_ID IN ("
|
|||||||
+ deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
sql.append(" AND DS.STATUS IN (").
|
|||||||
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
|||||||
}
|
|||||||
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
|||||||
}
|
|||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
sql.append(" AND DS.SUBSCRIBED_BY LIKE ?");
|
|||||||
}
|
|||||||
|
|||||||
try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
|
|||||||
int paramIdx = 1;
|
|||||||
ps.setInt(paramIdx++, appReleaseId);
|
|||||||
ps.setBoolean(paramIdx++, unsubscribe);
|
|||||||
ps.setInt(paramIdx++, tenantId);
|
|||||||
for (Integer deviceId : deviceIds) {
|
|||||||
ps.setInt(paramIdx++, deviceId);
|
|||||||
}
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
for (String status : actionStatus) {
|
|||||||
ps.setString(paramIdx++, status);
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, actionType);
|
|||||||
}
|
|||||||
|
|||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
ps.setString(paramIdx, "%" + actionTriggeredBy + "%");
|
|||||||
}
|
|||||||
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Successfully retrieved device subscriptions for application release id "
|
|||||||
+ appReleaseId + " and device ids " + deviceIds);
|
|||||||
}
|
|||||||
if (rs.next()) {
|
|||||||
deviceCount = rs.getInt("COUNT");
|
|||||||
}
|
|||||||
return deviceCount;
|
|||||||
}
|
|||||||
} catch (SQLException e) {
|
|||||||
String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId
|
|||||||
+ " and device ids: " + deviceIds + ".";
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementDAOException(msg, e);
|
|||||||
}
|
|||||||
} catch (DBConnectionException e) {
|
|||||||
String msg = "Error occurred while obtaining the DB connection for getting device subscriptions for "
|
|||||||
+ "application Id: " + appReleaseId + " and device ids: " + deviceIds + ".";
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementDAOException(msg, e);
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
// @Override
|
|||||||
// public List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
|
|||||||
// List<Integer> deviceIds, String actionStatus, String actionType,
|
|||||||
// String actionTriggeredBy, String tabActionStatus) throws ApplicationManagementDAOException {
|
|||||||
// if (log.isDebugEnabled()) {
|
|||||||
// log.debug("Getting device subscriptions for the application release id " + appReleaseId
|
|||||||
// + " and device ids " + deviceIds + " from the database");
|
|||||||
// }
|
|||||||
// try {
|
|||||||
// Connection conn = this.getDBConnection();
|
|||||||
// String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
|
|||||||
// StringBuilder sql = new StringBuilder("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.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? AND DS.DM_DEVICE_ID IN (" +
|
|||||||
// deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
|
|||||||
//
|
|||||||
// if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
// sql.append(" AND DS.STATUS = ? ");
|
|||||||
// }
|
|||||||
// if (actionType != null && !actionType.isEmpty()) {
|
|||||||
// sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
|||||||
// }
|
|||||||
// if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
// sql.append(" AND DS.SUBSCRIBED_BY LIKE ? ");
|
|||||||
// }
|
|||||||
//
|
|||||||
// sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC");
|
|||||||
//
|
|||||||
// try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
|
|||||||
// int paramIdx = 1;
|
|||||||
// ps.setInt(paramIdx++, appReleaseId);
|
|||||||
// ps.setBoolean(paramIdx++, unsubscribe);
|
|||||||
// ps.setInt(paramIdx++, tenantId);
|
|||||||
// for (int i = 0; i < deviceIds.size(); i++) {
|
|||||||
// ps.setInt(paramIdx++, deviceIds.get(i));
|
|||||||
// }
|
|||||||
//
|
|||||||
// if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
// ps.setString(paramIdx++, actionStatus);
|
|||||||
// }
|
|||||||
// if (actionType != null && !actionType.isEmpty()) {
|
|||||||
// ps.setString(paramIdx++, actionType);
|
|||||||
// }
|
|||||||
// if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
// ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
|||||||
// }
|
|||||||
//
|
|||||||
// try (ResultSet rs = ps.executeQuery()) {
|
|||||||
// if (log.isDebugEnabled()) {
|
|||||||
// log.debug("Successfully retrieved device subscriptions for application release id "
|
|||||||
// + appReleaseId + " and device ids " + deviceIds);
|
|||||||
// }
|
|||||||
// List<DeviceSubscriptionDTO> subscriptions = new ArrayList<>();
|
|||||||
// while (rs.next()) {
|
|||||||
// DeviceSubscriptionDTO 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"));
|
|||||||
// subscriptions.add(subscription);
|
|||||||
// }
|
|||||||
// return subscriptions;
|
|||||||
// }
|
|||||||
// } catch (SQLException e) {
|
|||||||
// String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId
|
|||||||
// + " and device ids: " + deviceIds + ".";
|
|||||||
// log.error(msg, e);
|
|||||||
// throw new ApplicationManagementDAOException(msg, e);
|
|||||||
// }
|
|||||||
// } catch (DBConnectionException e) {
|
|||||||
// String msg = "Error occurred while obtaining the DB connection for getting device subscriptions for "
|
|||||||
// + "application Id: " + appReleaseId + " and device ids: " + deviceIds + ".";
|
|||||||
// log.error(msg, e);
|
|||||||
// throw new ApplicationManagementDAOException(msg, e);
|
|||||||
// }
|
|||||||
//
|
|||||||
// }
|
|||||||
|
|||||||
@Override
|
|||||||
public List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId,
|
|||||||
String actionStatus, String actionType, String actionTriggeredBy,
|
|||||||
List<String> actionStatus, String actionType, String actionTriggeredBy,
|
|||||||
int offset, int limit) throws ApplicationManagementDAOException {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Getting device subscriptions for the application release id " + appReleaseId
|
|||||||
@ -2032,11 +2251,15 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
+ "DS.STATUS AS STATUS, "
|
|||||||
+ "DS.DM_DEVICE_ID AS DEVICE_ID "
|
|||||||
+ "FROM AP_DEVICE_SUBSCRIPTION DS "
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? ");
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? "
|
|||||||
+ "AND DS.UNSUBSCRIBED = ? "
|
|||||||
+ "AND DS.TENANT_ID = ? ");
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
sql.append(" AND DS.STATUS = ? ");
|
|||||||
sql.append(" AND DS.STATUS IN (").
|
|||||||
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
|||||||
}
|
|||||||
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
|||||||
}
|
|||||||
@ -2044,8 +2267,11 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
sql.append(" AND ").append(actionTriggeredColumn).append(" LIKE ? ");
|
|||||||
}
|
|||||||
|
|||||||
sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC ")
|
|||||||
.append("LIMIT ? OFFSET ?");
|
|||||||
sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC ");
|
|||||||
|
|||||||
if (limit >= 0 && offset >= 0) {
|
|||||||
sql.append("LIMIT ? OFFSET ?");
|
|||||||
}
|
|||||||
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
@ -2056,17 +2282,23 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
ps.setInt(paramIdx++, tenantId);
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, actionStatus);
|
|||||||
for (String status : actionStatus) {
|
|||||||
ps.setString(paramIdx++, status);
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, actionType);
|
|||||||
}
|
|||||||
|
|||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
|||||||
}
|
|||||||
|
|||||||
ps.setInt(paramIdx++, limit);
|
|||||||
ps.setInt(paramIdx++, offset);
|
|||||||
if (limit >= 0 && offset >= 0) {
|
|||||||
ps.setInt(paramIdx++, limit);
|
|||||||
ps.setInt(paramIdx, offset);
|
|||||||
}
|
|||||||
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
@ -2104,6 +2336,70 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public int getAllSubscriptionsCount(int appReleaseId, boolean unsubscribe, int tenantId,
|
|||||||
List<String> actionStatus, String actionType, String actionTriggeredBy)
|
|||||||
throws ApplicationManagementDAOException {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Getting device subscriptions for the application release id " + appReleaseId
|
|||||||
+ " from the database");
|
|||||||
}
|
|||||||
String actionTriggeredColumn = unsubscribe ? "DS.UNSUBSCRIBED_BY" : "DS.SUBSCRIBED_BY";
|
|||||||
StringBuilder sql = new StringBuilder("SELECT COUNT(DISTINCT DS.DM_DEVICE_ID) AS COUNT "
|
|||||||
+ "FROM AP_DEVICE_SUBSCRIPTION DS "
|
|||||||
+ "WHERE DS.AP_APP_RELEASE_ID = ? "
|
|||||||
+ "AND DS.UNSUBSCRIBED = ? "
|
|||||||
+ "AND DS.TENANT_ID = ? ");
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
sql.append(" AND DS.STATUS IN (").
|
|||||||
append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
|
|||||||
}
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
tcdlpds
commented 4 months ago
Review
This can be replaced with return 0; |
|||||||
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
|
|||||||
}
|
|||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
sql.append(" AND ").append(actionTriggeredColumn).append(" LIKE ?");
|
|||||||
}
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
|
|||||||
int paramIdx = 1;
|
|||||||
ps.setInt(paramIdx++, appReleaseId);
|
|||||||
ps.setBoolean(paramIdx++, unsubscribe);
|
|||||||
ps.setInt(paramIdx++, tenantId);
|
|||||||
|
|||||||
if (actionStatus != null && !actionStatus.isEmpty()) {
|
|||||||
for (String status : actionStatus) {
|
|||||||
ps.setString(paramIdx++, status);
|
|||||||
}
|
|||||||
}
|
|||||||
if (actionType != null && !actionType.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, actionType);
|
|||||||
}
|
|||||||
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
|
|||||||
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
|
|||||||
}
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Successfully retrieved device subscriptions for application release id "
|
|||||||
+ appReleaseId);
|
|||||||
}
|
|||||||
return rs.next() ? rs.getInt("COUNT") : 0;
|
|||||||
}
|
|||||||
}
|
|||||||
} 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 running SQL to get device subscription data for application ID: " + appReleaseId;
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementDAOException(msg, e);
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public int getAllSubscriptionCount(int appReleaseId, int tenantId)
|
|||||||
throws ApplicationManagementDAOException {
|
|||||||
@ -2496,13 +2792,85 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
// todo: fixed the status
|
|||||||
@Override
|
|||||||
public SubscriptionStatisticDTO getSubscriptionStatistic(List<Integer> deviceIds, String subscriptionType,
|
|||||||
boolean isUnsubscribed, int tenantId)
|
|||||||
throws ApplicationManagementDAOException {
|
|||||||
SubscriptionStatisticDTO subscriptionStatisticDTO = new SubscriptionStatisticDTO();
|
|||||||
if (deviceIds == null || deviceIds.isEmpty()) return subscriptionStatisticDTO;
|
|||||||
|
|||||||
boolean doesAllEntriesRequired = true;
|
|||||||
try {
|
|||||||
Connection connection = getDBConnection();
|
|||||||
String sql = "SELECT COUNT(DISTINCT ID) AS COUNT, " +
|
|||||||
"STATUS FROM AP_DEVICE_SUBSCRIPTION " +
|
|||||||
"WHERE TENANT_ID = ? " +
|
|||||||
"AND UNSUBSCRIBED = ?" +
|
|||||||
"AND DM_DEVICE_ID IN (" +
|
|||||||
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")";
|
|||||||
|
|||||||
if (!Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.DEVICE)) {
|
|||||||
sql += " AND ACTION_TRIGGERED_FROM = ?";
|
|||||||
doesAllEntriesRequired = false;
|
|||||||
}
|
|||||||
|
|||||||
sql += " GROUP BY (STATUS)";
|
|||||||
|
|||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
|||||||
int idx = 1;
|
|||||||
|
|||||||
preparedStatement.setInt(idx++, tenantId);
|
|||||||
preparedStatement.setBoolean(idx++, isUnsubscribed);
|
|||||||
for (Integer deviceId : deviceIds) {
|
|||||||
preparedStatement.setInt(idx++, deviceId);
|
|||||||
}
|
|||||||
|
|||||||
if (!doesAllEntriesRequired) {
|
|||||||
preparedStatement.setString(idx, subscriptionType);
|
|||||||
}
|
|||||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
|||||||
while (resultSet.next()) {
|
|||||||
// add the error and in progress
|
|||||||
int count = resultSet.getInt("COUNT");
|
|||||||
String status = resultSet.getString("STATUS");
|
|||||||
|
|||||||
if (SubscriptionMetadata.DBSubscriptionStatus.COMPLETED_STATUS_LIST.contains(status)) {
|
|||||||
subscriptionStatisticDTO.addToComplete(count);
|
|||||||
}
|
|||||||
|
|||||||
if (SubscriptionMetadata.DBSubscriptionStatus.PENDING_STATUS_LIST.contains(status)) {
|
|||||||
subscriptionStatisticDTO.addToPending(count);
|
|||||||
}
|
|||||||
if (SubscriptionMetadata.DBSubscriptionStatus.ERROR_STATUS_LIST.contains(status)) {
|
|||||||
subscriptionStatisticDTO.addToFailed(count);
|
|||||||
}
|
|||||||
}
|
|||||||
}
|
|||||||
}
|
|||||||
return subscriptionStatisticDTO;
|
|||||||
} catch (DBConnectionException e) {
|
|||||||
String msg = "Error occurred while obtaining the DB connection for getting subscription statistics";
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementDAOException(msg, e);
|
|||||||
} catch (SQLException e) {
|
|||||||
String msg = "Error occurred while running SQL for getting subscription statistics";
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementDAOException(msg, e);
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
public int countSubscriptionsByStatus(int appReleaseId, int tenantId, String actionStatus, String actionTriggeredFrom) throws ApplicationManagementDAOException {
|
|||||||
if (log.isDebugEnabled()) {
|
|||||||
log.debug("Request received in DAO Layer to count device subscriptions by status and actionTriggeredFrom for the given AppReleaseID.");
|
|||||||
}
|
|||||||
try {
|
|||||||
Connection conn = this.getDBConnection();
|
|||||||
String sql = "SELECT COUNT(*) FROM AP_DEVICE_SUBSCRIPTION WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ? AND STATUS = ? AND ACTION_TRIGGERED_FROM = ?";
|
|||||||
String sql = "SELECT COUNT(*) FROM AP_DEVICE_SUBSCRIPTION " +
|
|||||||
"WHERE AP_APP_RELEASE_ID = ? " +
|
|||||||
"AND TENANT_ID = ? " +
|
|||||||
"AND STATUS = ?" +
|
|||||||
" AND ACTION_TRIGGERED_FROM = ?";
|
|||||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
|||||||
ps.setInt(1, appReleaseId);
|
|||||||
ps.setInt(2, tenantId);
|
|||||||
@ -2525,4 +2893,5 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
}
|
|||||||
return 0;
|
|||||||
}
|
|||||||
|
|||||||
}
|
|||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
|||||||
/*
|
|||||||
* 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.core.util;
|
|||||||
|
|||||||
public class SubscriptionManagementUtil {
|
|||||||
public static final class DeviceSubscriptionStatus {
|
|||||||
tcdlpds
commented 4 months ago
Review
Can't we remove this file. |
|||||||
public static final String COMPLETED = "COMPLETED";
|
|||||||
public static final String ERROR ="ERROR";
|
|||||||
public static final String NEW = "NEW";
|
|||||||
public static final String SUBSCRIBED = "SUBSCRIBED";
|
|||||||
}
|
|||||||
}
|
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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.core.util.subscription.mgt;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionData;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.Device;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SubscriptionManagementHelperUtil {
|
||||
|
||||
/**
|
||||
* Retrieves device subscription data based on the provided filters.
|
||||
*
|
||||
* @param deviceSubscriptionDTOS List of DeviceSubscriptionDTO objects.
|
||||
* @param deviceSubscriptionFilterCriteria Filter criteria for device subscription.
|
||||
* @param isUnsubscribed Boolean indicating whether to filter unsubscribed devices.
|
||||
* @param deviceTypeId Device type ID.
|
||||
* @param limit Limit for pagination.
|
||||
* @param offset Offset for pagination.
|
||||
* @return List of DeviceSubscription objects.
|
||||
* @throws DeviceManagementException If an error occurs during device management.
|
||||
*/
|
||||
public static List<DeviceSubscription> getDeviceSubscriptionData(List<DeviceSubscriptionDTO> deviceSubscriptionDTOS,
|
||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria,
|
||||
boolean isUnsubscribed, int deviceTypeId, int limit, int offset)
|
||||
throws DeviceManagementException {
|
||||
List<Integer> deviceIds = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||
PaginationRequest paginationRequest = new PaginationRequest(offset, limit);
|
||||
paginationRequest.setDeviceName(deviceSubscriptionFilterCriteria.getName());
|
||||
paginationRequest.setDeviceStatus(deviceSubscriptionFilterCriteria.getDeviceStatus());
|
||||
paginationRequest.setOwner(deviceSubscriptionFilterCriteria.getOwner());
|
||||
paginationRequest.setDeviceTypeId(deviceTypeId);
|
||||
List<Device> devices = HelperUtil.getDeviceManagementProviderService().getDevicesByDeviceIds(paginationRequest, deviceIds);
|
||||
return populateDeviceData(deviceSubscriptionDTOS, devices, isUnsubscribed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total count of device subscriptions based on the provided filters.
|
||||
*
|
||||
* @param deviceSubscriptionDTOS List of DeviceSubscriptionDTO objects.
|
||||
* @param deviceSubscriptionFilterCriteria Filter criteria for device subscription.
|
||||
* @param deviceTypeId Device type ID.
|
||||
* @return int Total count of device subscriptions.
|
||||
* @throws DeviceManagementException If an error occurs during device management.
|
||||
*/
|
||||
public static int getTotalDeviceSubscriptionCount(List<DeviceSubscriptionDTO> deviceSubscriptionDTOS,
|
||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria, int deviceTypeId)
|
||||
throws DeviceManagementException {
|
||||
List<Integer> deviceIds = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||
PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
|
||||
paginationRequest.setDeviceName(deviceSubscriptionFilterCriteria.getName());
|
||||
paginationRequest.setDeviceStatus(deviceSubscriptionFilterCriteria.getDeviceStatus());
|
||||
paginationRequest.setOwner(deviceSubscriptionFilterCriteria.getOwner());
|
||||
paginationRequest.setDeviceTypeId(deviceTypeId);
|
||||
return HelperUtil.getDeviceManagementProviderService().getDeviceCountByDeviceIds(paginationRequest, deviceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates device subscription data based on the provided devices and subscription DTOs.
|
||||
*
|
||||
* @param deviceSubscriptionDTOS List of DeviceSubscriptionDTO objects.
|
||||
* @param devices List of Device objects.
|
||||
* @param isUnsubscribed Boolean indicating whether to filter unsubscribed devices.
|
||||
* @return List of DeviceSubscription objects.
|
||||
*/
|
||||
private static List<DeviceSubscription> populateDeviceData(List<DeviceSubscriptionDTO> deviceSubscriptionDTOS,
|
||||
List<Device> devices, boolean isUnsubscribed) {
|
||||
List<DeviceSubscription> deviceSubscriptions = new ArrayList<>();
|
||||
for (Device device : devices) {
|
||||
int idx = deviceSubscriptionDTOS.indexOf(new DeviceSubscriptionDTO(device.getId()));
|
||||
if (idx >= 0) {
|
||||
DeviceSubscriptionDTO deviceSubscriptionDTO = deviceSubscriptionDTOS.get(idx);
|
||||
DeviceSubscription deviceSubscription = new DeviceSubscription();
|
||||
deviceSubscription.setDeviceId(device.getId());
|
||||
deviceSubscription.setDeviceIdentifier(device.getDeviceIdentifier());
|
||||
deviceSubscription.setDeviceOwner(device.getEnrolmentInfo().getOwner());
|
||||
deviceSubscription.setDeviceType(device.getType());
|
||||
deviceSubscription.setDeviceName(device.getName());
|
||||
deviceSubscription.setDeviceStatus(device.getEnrolmentInfo().getStatus().name());
|
||||
deviceSubscription.setOwnershipType(device.getEnrolmentInfo().getOwnership().name());
|
||||
deviceSubscription.setDateOfLastUpdate(new Timestamp(device.getEnrolmentInfo().getDateOfLastUpdate()));
|
||||
SubscriptionData subscriptionData = getSubscriptionData(isUnsubscribed, deviceSubscriptionDTO);
|
||||
deviceSubscription.setSubscriptionData(subscriptionData);
|
||||
deviceSubscriptions.add(deviceSubscription);
|
||||
}
|
||||
}
|
||||
return deviceSubscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SubscriptionData object based on the provided subscription DTO.
|
||||
*
|
||||
* @param isUnsubscribed Boolean indicating whether to filter unsubscribed devices.
|
||||
* @param deviceSubscriptionDTO DeviceSubscriptionDTO object.
|
||||
* @return SubscriptionData object.
|
||||
*/
|
||||
private static SubscriptionData getSubscriptionData(boolean isUnsubscribed, DeviceSubscriptionDTO deviceSubscriptionDTO) {
|
||||
SubscriptionData subscriptionData = new SubscriptionData();
|
||||
subscriptionData.setTriggeredBy(isUnsubscribed ? deviceSubscriptionDTO.getUnsubscribedBy() :
|
||||
deviceSubscriptionDTO.getSubscribedBy());
|
||||
subscriptionData.setTriggeredAt(deviceSubscriptionDTO.getSubscribedTimestamp());
|
||||
subscriptionData.setDeviceSubscriptionStatus(deviceSubscriptionDTO.getStatus());
|
||||
subscriptionData.setSubscriptionType(deviceSubscriptionDTO.getActionTriggeredFrom());
|
||||
subscriptionData.setSubscriptionId(deviceSubscriptionDTO.getId());
|
||||
return subscriptionData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the device subscription status based on the provided subscription info.
|
||||
*
|
||||
* @param subscriptionInfo SubscriptionInfo object.
|
||||
* @return Device subscription status.
|
||||
*/
|
||||
public static String getDeviceSubscriptionStatus(SubscriptionInfo subscriptionInfo) {
|
||||
return getDeviceSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionFilterCriteria().
|
||||
getFilteringDeviceSubscriptionStatus(), subscriptionInfo.getDeviceSubscriptionStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the device subscription status based on the provided filter and status.
|
||||
*
|
||||
* @param deviceSubscriptionStatusFilter Filtered device subscription status.
|
||||
* @param deviceSubscriptionStatus Device subscription status.
|
||||
* @return Device subscription status.
|
||||
*/
|
||||
public static String getDeviceSubscriptionStatus(String deviceSubscriptionStatusFilter, String deviceSubscriptionStatus) {
|
||||
return (deviceSubscriptionStatusFilter != null && !deviceSubscriptionStatusFilter.isEmpty()) ?
|
||||
deviceSubscriptionStatusFilter : deviceSubscriptionStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves subscription statistics based on the provided subscription statistics DTO and device count.
|
||||
*
|
||||
* @param subscriptionStatisticDTO SubscriptionStatisticDTO object.
|
||||
* @param allDeviceCount Total count of all devices.
|
||||
* @return SubscriptionStatistics object.
|
||||
*/
|
||||
public static SubscriptionStatistics getSubscriptionStatistics(SubscriptionStatisticDTO subscriptionStatisticDTO, int allDeviceCount) {
|
||||
SubscriptionStatistics subscriptionStatistics = new SubscriptionStatistics();
|
||||
subscriptionStatistics.setCompletedPercentage(
|
||||
getPercentage(subscriptionStatisticDTO.getCompletedDeviceCount(), allDeviceCount));
|
||||
subscriptionStatistics.setPendingPercentage(
|
||||
getPercentage(subscriptionStatisticDTO.getPendingDevicesCount(), allDeviceCount));
|
||||
subscriptionStatistics.setFailedPercentage(
|
||||
getPercentage(subscriptionStatisticDTO.getFailedDevicesCount(), allDeviceCount));
|
||||
subscriptionStatistics.setNewDevicesPercentage(getPercentage((allDeviceCount -
|
||||
subscriptionStatisticDTO.getCompletedDeviceCount() -
|
||||
subscriptionStatisticDTO.getPendingDevicesCount() -
|
||||
subscriptionStatisticDTO.getFailedDevicesCount()), allDeviceCount));
|
||||
return subscriptionStatistics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the percentages.
|
||||
*
|
||||
* @param numerator Numerator value.
|
||||
* @param denominator Denominator value.
|
||||
* @return Calculated percentage.
|
||||
*/
|
||||
public static float getPercentage(int numerator, int denominator) {
|
||||
if (denominator <= 0) {
|
||||
return 0.0f;
|
||||
}
|
||||
return ((float) numerator / (float) denominator) * 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves database subscription statuses based on the provided device subscription status.
|
||||
*
|
||||
* @param deviceSubscriptionStatus Device subscription status.
|
||||
* @return List of database subscription statuses.
|
||||
*/
|
||||
public static List<String> getDBSubscriptionStatus(String deviceSubscriptionStatus) {
|
||||
return SubscriptionMetadata.deviceSubscriptionStatusToDBSubscriptionStatusMap.get(deviceSubscriptionStatus);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.core.util.subscription.mgt;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.DeviceBasedSubscriptionManagementHelperServiceImpl;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.GroupBasedSubscriptionManagementHelperServiceImpl;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.RoleBasedSubscriptionManagementHelperServiceImpl;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.UserBasedSubscriptionManagementHelperServiceImpl;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SubscriptionManagementServiceProvider {
|
||||
private SubscriptionManagementServiceProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the appropriate SubscriptionManagementHelperService based on the provided SubscriptionInfo.
|
||||
*
|
||||
* @param subscriptionInfo SubscriptionInfo object containing the subscription type.
|
||||
* @return SubscriptionManagementHelperService implementation based on the subscription type.
|
||||
*/
|
||||
public SubscriptionManagementHelperService getSubscriptionManagementHelperService(SubscriptionInfo subscriptionInfo) {
|
||||
return getSubscriptionManagementHelperService(subscriptionInfo.getSubscriptionType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the appropriate SubscriptionManagementHelperService based on the subscription type.
|
||||
*
|
||||
* @param subscriptionType Type of the subscription.
|
||||
* @return SubscriptionManagementHelperService implementation based on the subscription type.
|
||||
*/
|
||||
private SubscriptionManagementHelperService getSubscriptionManagementHelperService(String subscriptionType) {
|
||||
if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.ROLE))
|
||||
return RoleBasedSubscriptionManagementHelperServiceImpl.getInstance();
|
||||
if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.GROUP))
|
||||
return GroupBasedSubscriptionManagementHelperServiceImpl.getInstance();
|
||||
if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.USER))
|
||||
return UserBasedSubscriptionManagementHelperServiceImpl.getInstance();
|
||||
if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.DEVICE))
|
||||
return DeviceBasedSubscriptionManagementHelperServiceImpl.getInstance();
|
||||
throw new UnsupportedOperationException("Subscription type: " + subscriptionType + " not supports");
|
||||
}
|
||||
|
||||
private static class SubscriptionManagementProviderServiceHolder {
|
||||
private static final SubscriptionManagementServiceProvider INSTANCE = new SubscriptionManagementServiceProvider();
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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.core.util.subscription.mgt.impl;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
||||
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.exception.ApplicationManagementException;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeviceBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
|
||||
private static final Log log = LogFactory.getLog(DeviceBasedSubscriptionManagementHelperServiceImpl.class);
|
||||
|
||||
private DeviceBasedSubscriptionManagementHelperServiceImpl() {
|
||||
}
|
||||
|
||||
public static DeviceBasedSubscriptionManagementHelperServiceImpl getInstance() {
|
||||
return DeviceBasedSubscriptionManagementHelperServiceImpl.DeviceBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException {
|
||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
||||
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS;
|
||||
int deviceCount = 0;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
|
||||
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
if (applicationReleaseDTO == null) {
|
||||
String msg = "Couldn't find an application release for application release UUID: " +
|
||||
subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
|
||||
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
if (applicationDTO == null) {
|
||||
String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
|
||||
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
||||
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
||||
|
||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
||||
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
||||
getId(), isUnsubscribe, tenantId, null, null,
|
||||
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||
|
||||
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
||||
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||
|
||||
List<Integer> newDeviceIds = deviceManagementProviderService.getDevicesNotInGivenIdList(deviceIdsOfSubscription,
|
||||
new PaginationRequest(offset, limit));
|
||||
|
||||
deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
||||
|
||||
deviceCount = deviceManagementProviderService.getDeviceCountNotInGivenIdList(deviceIdsOfSubscription);
|
||||
} else {
|
||||
deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
|
||||
getId(), isUnsubscribe, tenantId, dbSubscriptionStatus, null,
|
||||
deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||
|
||||
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
|
||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
|
||||
}
|
||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
|
||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error encountered while getting device details";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException | DBConnectionException e) {
|
||||
String msg = "Error encountered while connecting to the database";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException {
|
||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
|
||||
throws ApplicationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class DeviceBasedSubscriptionManagementHelperServiceImplHolder {
|
||||
private static final DeviceBasedSubscriptionManagementHelperServiceImpl INSTANCE
|
||||
= new DeviceBasedSubscriptionManagementHelperServiceImpl();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* 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.core.util.subscription.mgt.impl;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
||||
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.SubscriptionStatisticDTO;
|
||||
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.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.Device;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.service.GroupManagementProviderService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
|
||||
private static final Log log = LogFactory.getLog(GroupBasedSubscriptionManagementHelperServiceImpl.class);
|
||||
|
||||
private GroupBasedSubscriptionManagementHelperServiceImpl() {
|
||||
}
|
||||
|
||||
public static GroupBasedSubscriptionManagementHelperServiceImpl getInstance() {
|
||||
return GroupBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException {
|
||||
|
||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
||||
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS;
|
||||
int deviceCount = 0;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
|
||||
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
|
||||
if (applicationReleaseDTO == null) {
|
||||
String msg = "Couldn't find an application release for application release UUID: " +
|
||||
subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
|
||||
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
if (applicationDTO == null) {
|
||||
String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
|
||||
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
||||
|
||||
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
|
||||
GroupDetailsDTO groupDetailsDTO;
|
||||
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
||||
|
||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
||||
List<Integer> allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
|
||||
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
|
||||
deviceSubscriptionFilterCriteria.getDeviceStatus(), -1, -1).getDeviceIds();
|
||||
|
||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||
isUnsubscribe, tenantId, allDeviceIdsOwnByGroup, null,
|
||||
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||
|
||||
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
||||
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||
|
||||
for (Integer deviceId : deviceIdsOfSubscription) {
|
||||
allDeviceIdsOwnByGroup.remove(deviceId);
|
||||
}
|
||||
|
||||
List<Integer> paginatedNewDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(allDeviceIdsOwnByGroup,
|
||||
new PaginationRequest(offset, limit));
|
||||
deviceSubscriptionDTOS = paginatedNewDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
||||
|
||||
deviceCount = allDeviceIdsOwnByGroup.size();
|
||||
} else {
|
||||
groupDetailsDTO = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
|
||||
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
|
||||
deviceSubscriptionFilterCriteria.getDeviceStatus(), offset, limit);
|
||||
List<Integer> paginatedDeviceIdsOwnByGroup = groupDetailsDTO.getDeviceIds();
|
||||
|
||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||
isUnsubscribe, tenantId, paginatedDeviceIdsOwnByGroup, dbSubscriptionStatus,
|
||||
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||
|
||||
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
|
||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
|
||||
}
|
||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
|
||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error encountered while retrieving group details for group: " + subscriptionInfo.getIdentifier();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException | DBConnectionException e) {
|
||||
String msg = "Error encountered while connecting to the database";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException {
|
||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
||||
final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
|
||||
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
if (applicationReleaseDTO == null) {
|
||||
String msg = "Couldn't find an application release for application release UUID: " +
|
||||
subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
|
||||
getGroupsSubscriptionDetailsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
|
||||
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getGroupUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
|
||||
subscriptionDAO.getGroupSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
|
||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
|
||||
} catch (DBConnectionException | ApplicationManagementDAOException e) {
|
||||
String msg = "Error encountered while connecting to the database";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
|
||||
throws ApplicationManagementException {
|
||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
List<Device> devices = HelperUtil.getGroupManagementProviderService().
|
||||
getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false);
|
||||
List<Integer> deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList());
|
||||
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
|
||||
getSubscriptionStatistic(deviceIdsOwnByGroup, null, isUnsubscribe, tenantId);
|
||||
int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier());
|
||||
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
private static class GroupBasedSubscriptionManagementHelperServiceImplHolder {
|
||||
private static final GroupBasedSubscriptionManagementHelperServiceImpl INSTANCE
|
||||
= new GroupBasedSubscriptionManagementHelperServiceImpl();
|
||||
}
|
||||
}
|
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* 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.core.util.subscription.mgt.impl;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
||||
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.SubscriptionStatisticDTO;
|
||||
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.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.Device;
|
||||
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.exceptions.DeviceManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.api.UserStoreManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RoleBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
|
||||
private static final Log log = LogFactory.getLog(RoleBasedSubscriptionManagementHelperServiceImpl.class);
|
||||
|
||||
private RoleBasedSubscriptionManagementHelperServiceImpl() {
|
||||
}
|
||||
|
||||
public static RoleBasedSubscriptionManagementHelperServiceImpl getInstance() {
|
||||
return RoleBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException {
|
||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
||||
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS;
|
||||
int deviceCount = 0;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
List<Integer> deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
|
||||
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
|
||||
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
if (applicationReleaseDTO == null) {
|
||||
String msg = "Couldn't find an application release for application release UUID: " +
|
||||
subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
|
||||
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
if (applicationDTO == null) {
|
||||
String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
|
||||
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
||||
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
||||
|
||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||
isUnsubscribe, tenantId, deviceIdsOwnByRole, null,
|
||||
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||
|
||||
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
||||
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
||||
|
||||
for (Integer deviceId : deviceIdsOfSubscription) {
|
||||
deviceIdsOwnByRole.remove(deviceId);
|
||||
}
|
||||
|
||||
List<Integer> paginatedNewDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByRole,
|
||||
new PaginationRequest(offset, limit));
|
||||
deviceSubscriptionDTOS = paginatedNewDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
||||
deviceCount = deviceIdsOwnByRole.size();
|
||||
} else {
|
||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
||||
isUnsubscribe, tenantId, deviceIdsOwnByRole, dbSubscriptionStatus,
|
||||
subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
||||
|
||||
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
|
||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
|
||||
}
|
||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.
|
||||
getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
|
||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
|
||||
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error encountered while getting the user management store for tenant id " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error encountered while getting device details";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException | DBConnectionException e) {
|
||||
String msg = "Error encountered while connecting to the database";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException {
|
||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
||||
final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
|
||||
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
|
||||
if (applicationReleaseDTO == null) {
|
||||
String msg = "Couldn't find an application release for application release UUID: " +
|
||||
subscriptionInfo.getApplicationUUID();
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
|
||||
getRoleSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
|
||||
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getRoleUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
|
||||
subscriptionDAO.getRoleSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
|
||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
|
||||
} catch (DBConnectionException | ApplicationManagementDAOException e) {
|
||||
String msg = "Error encountered while connecting to the database";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
|
||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
List<Integer> deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
|
||||
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
|
||||
getSubscriptionStatistic(deviceIdsOwnByRole, null, isUnsubscribe, tenantId);
|
||||
int allDeviceCount = deviceIdsOwnByRole.size();
|
||||
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
|
||||
} catch (DeviceManagementException | ApplicationManagementDAOException | UserStoreException e) {
|
||||
String msg = "Error encountered while getting subscription statistics for role: " + subscriptionInfo.getIdentifier();
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Integer> getDeviceIdsOwnByRole(String roleName, int tenantId) throws UserStoreException, DeviceManagementException {
|
||||
UserStoreManager userStoreManager = DataHolder.getInstance().getRealmService().
|
||||
getTenantUserRealm(tenantId).getUserStoreManager();
|
||||
String[] usersWithRole =
|
||||
userStoreManager.getUserListOfRole(roleName);
|
||||
List<Device> deviceListOwnByRole = new ArrayList<>();
|
||||
for (String user : usersWithRole) {
|
||||
PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
|
||||
paginationRequest.setOwner(user);
|
||||
paginationRequest.setStatusList(Arrays.asList("ACTIVE", "INACTIVE", "UNREACHABLE"));
|
||||
PaginationResult ownDeviceIds = HelperUtil.getDeviceManagementProviderService().
|
||||
getAllDevicesIdList(paginationRequest);
|
||||
if (ownDeviceIds.getData() != null) {
|
||||
deviceListOwnByRole.addAll((List<Device>) ownDeviceIds.getData());
|
||||
}
|
||||
}
|
||||
return deviceListOwnByRole.stream().map(Device::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static class RoleBasedSubscriptionManagementHelperServiceImplHolder {
|
||||
private static final RoleBasedSubscriptionManagementHelperServiceImpl INSTANCE
|
||||
= new RoleBasedSubscriptionManagementHelperServiceImpl();
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
|||||||
/*
|
|||||||
* 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.core.util.subscription.mgt.impl;
|
|||||||
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
|||||||
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.SubscriptionStatisticDTO;
|
|||||||
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.core.exception.ApplicationManagementDAOException;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
|
|||||||
import io.entgra.device.mgt.core.device.mgt.common.Device;
|
|||||||
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.exceptions.DeviceManagementException;
|
|||||||
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
|||||||
import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|||||||
|
|||||||
import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
|||||||
import java.util.List;
|
|||||||
import java.util.Objects;
|
|||||||
import java.util.stream.Collectors;
|
|||||||
|
|||||||
tcdlpds
commented 4 months ago
Review
In these Files contain repeating code blocks, so think a better approach to have reusable source. Either you can have service methods or common util methods to reuse in these classes. |
|||||||
public class UserBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
|
|||||||
private static final Log log = LogFactory.getLog(UserBasedSubscriptionManagementHelperServiceImpl.class);
|
|||||||
|
|||||||
private UserBasedSubscriptionManagementHelperServiceImpl() {
|
|||||||
}
|
|||||||
|
|||||||
public static UserBasedSubscriptionManagementHelperServiceImpl getInstance() {
|
|||||||
return UserBasedSubscriptionManagementHelperServiceImpl.UserBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
|||||||
throws ApplicationManagementException {
|
|||||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
|||||||
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS;
|
|||||||
int deviceCount = 0;
|
|||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|||||||
|
|||||||
try {
|
|||||||
ConnectionManagerUtil.openDBConnection();
|
|||||||
List<Integer> deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
|
|||||||
|
|||||||
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
|
|||||||
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
|
|||||||
if (applicationReleaseDTO == null) {
|
|||||||
String msg = "Couldn't find an application release for application release UUID: " +
|
|||||||
subscriptionInfo.getApplicationUUID();
|
|||||||
log.error(msg);
|
|||||||
throw new NotFoundException(msg);
|
|||||||
}
|
|||||||
|
|||||||
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
|
|||||||
if (applicationDTO == null) {
|
|||||||
String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
|
|||||||
log.error(msg);
|
|||||||
throw new NotFoundException(msg);
|
|||||||
}
|
|||||||
|
|||||||
String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
|
|||||||
DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
|
|||||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
|||||||
List<String> dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
|
|||||||
|
|||||||
if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
|
|||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
|||||||
isUnsubscribe, tenantId, deviceIdsOwnByUser, null,
|
|||||||
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
|||||||
|
|||||||
List<Integer> deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
|
|||||||
map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
|
|||||||
|
|||||||
for (Integer deviceId : deviceIdsOfSubscription) {
|
|||||||
deviceIdsOwnByUser.remove(deviceId);
|
|||||||
}
|
|||||||
List<Integer> paginatedNewDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByUser,
|
|||||||
new PaginationRequest(offset, limit));
|
|||||||
deviceSubscriptionDTOS = paginatedNewDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
|||||||
|
|||||||
deviceCount = deviceIdsOwnByUser.size();
|
|||||||
} else {
|
|||||||
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
|
|||||||
isUnsubscribe, tenantId, deviceIdsOwnByUser, dbSubscriptionStatus,
|
|||||||
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
|
|||||||
|
|||||||
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
|
|||||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
|
|||||||
}
|
|||||||
List<DeviceSubscription> deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
|
|||||||
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
|
|||||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
|
|||||||
} catch (DeviceManagementException e) {
|
|||||||
String msg = "Error encountered while getting device details";
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementException(msg, e);
|
|||||||
} catch (ApplicationManagementDAOException | DBConnectionException e) {
|
|||||||
String msg = "Error encountered while connecting to the database";
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementException(msg, e);
|
|||||||
} finally {
|
|||||||
ConnectionManagerUtil.closeDBConnection();
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
|||||||
throws ApplicationManagementException {
|
|||||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
|||||||
final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|||||||
try {
|
|||||||
ConnectionManagerUtil.openDBConnection();
|
|||||||
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
|
|||||||
getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
|
|||||||
if (applicationReleaseDTO == null) {
|
|||||||
String msg = "Couldn't find an application release for application release UUID: " +
|
|||||||
subscriptionInfo.getApplicationUUID();
|
|||||||
log.error(msg);
|
|||||||
throw new NotFoundException(msg);
|
|||||||
}
|
|||||||
List<SubscriptionEntity> subscriptionEntities = subscriptionDAO.
|
|||||||
getUserSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
|
|||||||
int subscriptionCount = isUnsubscribe ? subscriptionDAO.getUserUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
|
|||||||
subscriptionDAO.getUserSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
|
|||||||
return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
|
|||||||
} catch (DBConnectionException | ApplicationManagementDAOException e) {
|
|||||||
String msg = "Error encountered while connecting to the database";
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementException(msg, e);
|
|||||||
} finally {
|
|||||||
ConnectionManagerUtil.closeDBConnection();
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
@Override
|
|||||||
public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
|
|||||||
final boolean isUnsubscribe = Objects.equals("unsubscribe", subscriptionInfo.getSubscriptionStatus());
|
|||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|||||||
try {
|
|||||||
ConnectionManagerUtil.openDBConnection();
|
|||||||
List<Integer> deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
|
|||||||
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
|
|||||||
getSubscriptionStatistic(deviceIdsOwnByUser, null, isUnsubscribe, tenantId);
|
|||||||
int allDeviceCount = deviceIdsOwnByUser.size();
|
|||||||
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
|
|||||||
} catch (DeviceManagementException | ApplicationManagementDAOException e) {
|
|||||||
String msg = "Error encountered while getting subscription statistics for user: " + subscriptionInfo.getIdentifier();
|
|||||||
log.error(msg, e);
|
|||||||
throw new ApplicationManagementException(msg, e);
|
|||||||
} finally {
|
|||||||
ConnectionManagerUtil.closeDBConnection();
|
|||||||
}
|
|||||||
}
|
|||||||
|
|||||||
@SuppressWarnings("unchecked")
|
|||||||
private List<Integer> getDeviceIdsOwnByUser(String username) throws DeviceManagementException {
|
|||||||
List<Device> deviceListOwnByUser = new ArrayList<>();
|
|||||||
PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
|
|||||||
paginationRequest.setOwner(username);
|
|||||||
paginationRequest.setStatusList(Arrays.asList("ACTIVE", "INACTIVE", "UNREACHABLE"));
|
|||||||
PaginationResult ownDeviceIds = HelperUtil.getDeviceManagementProviderService().
|
|||||||
getAllDevicesIdList(paginationRequest);
|
|||||||
if (ownDeviceIds.getData() != null) {
|
|||||||
deviceListOwnByUser.addAll((List<Device>) ownDeviceIds.getData());
|
|||||||
}
|
|||||||
return deviceListOwnByUser.stream().map(Device::getId).collect(Collectors.toList());
|
|||||||
}
|
|||||||
|
|||||||
private static class UserBasedSubscriptionManagementHelperServiceImplHolder {
|
|||||||
private static final UserBasedSubscriptionManagementHelperServiceImpl INSTANCE
|
|||||||
= new UserBasedSubscriptionManagementHelperServiceImpl();
|
|||||||
}
|
|||||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.core.util.subscription.mgt.service;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||
|
||||
public interface SubscriptionManagementHelperService {
|
||||
SubscriptionDAO subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
|
||||
ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||
ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
||||
|
||||
SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
|
||||
throws ApplicationManagementException;
|
||||
}
|
Loading…
Reference in new issue
Don't we have a constant file to have this?