forked from community/device-mgt-core
commit
cafa88a866
@ -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,69 @@
|
||||
/*
|
||||
* 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 String SUBSCRIPTION_STATUS_UNSUBSCRIBED = "unsubscribed";
|
||||
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 REPEATED = "REPEATED";
|
||||
}
|
||||
|
||||
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.REPEATED);
|
||||
}
|
||||
|
||||
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, Collections.singletonList(DeviceSubscriptionStatus.IN_PROGRESS));
|
||||
statusMap.put(DeviceSubscriptionStatus.REPEATED, Collections.singletonList(DeviceSubscriptionStatus.REPEATED));
|
||||
statusMap.put(DeviceSubscriptionStatus.ERROR, DBSubscriptionStatus.ERROR_STATUS_LIST);
|
||||
statusMap.put(DeviceSubscriptionStatus.INVALID,Collections.singletonList(DeviceSubscriptionStatus.INVALID));
|
||||
statusMap.put(DeviceSubscriptionStatus.UNAUTHORIZED,Collections.singletonList(DeviceSubscriptionStatus.UNAUTHORIZED));
|
||||
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;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -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,71 @@
|
||||
/*
|
||||
* 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() {
|
||||
}
|
||||
|
||||
public static SubscriptionManagementServiceProvider getInstance() {
|
||||
return SubscriptionManagementProviderServiceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,143 @@
|
||||
/*
|
||||
* 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.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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, 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);
|
||||
|
||||
deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
||||
} 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,220 @@
|
||||
/*
|
||||
* 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.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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, 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> newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(allDeviceIdsOwnByGroup);
|
||||
deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
||||
} 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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, 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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
|
||||
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<Device> devices = HelperUtil.getGroupManagementProviderService().
|
||||
getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false);
|
||||
List<Integer> deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList());
|
||||
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
|
||||
getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
|
||||
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,227 @@
|
||||
/*
|
||||
* 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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, 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> newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByRole);
|
||||
deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
||||
} 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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, 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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
|
||||
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<Integer> deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
|
||||
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
|
||||
getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
|
||||
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,212 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, 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> newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByUser);
|
||||
deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
|
||||
|
||||
} 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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, 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(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
|
||||
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<Integer> deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
|
||||
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
|
||||
getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
|
||||
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;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue