From 4f7b3177614b7ffab252780b4ea07f5aacf8ccd4 Mon Sep 17 00:00:00 2001 From: rajitha Date: Wed, 22 Mar 2023 22:50:57 +0530 Subject: [PATCH 1/2] Add functionality to mark previous policy bundles as repeated --- .../PolicyEnforcementDelegatorImpl.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java index 3667f258c6..74e5d8e7f1 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java @@ -44,6 +44,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; +import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; @@ -96,6 +98,7 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato */ if (devicePolicy == null || devicePolicy.getId() != policy.getId() || updatedPolicyIds.contains (policy.getId())) { + this.markPreviousPolicyBundlesRepeated(device); this.addPolicyRevokeOperation(deviceIdentifiers); this.addPolicyOperation(deviceIdentifiers, policy); } @@ -202,4 +205,29 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato throw new PolicyDelegationException(msg, e); } } + + /** + * Update the previous pending policy operation's status as REPEATED + * @param device Device + * @throws PolicyDelegationException throws when getting pending operations + */ + public void markPreviousPolicyBundlesRepeated(Device device) throws PolicyDelegationException { + DeviceManagementProviderService deviceManagerService = PolicyManagementDataHolder.getInstance(). + getDeviceManagementService(); + try { + List operations = deviceManagerService.getPendingOperations(device); + for(Operation operation : operations) { + String operationCode = operation.getCode(); + if(PolicyOperation.POLICY_OPERATION_CODE.equals(operationCode) || + OperationMgtConstants.OperationCodes.POLICY_REVOKE.equals(operationCode)) { + operation.setStatus(Operation.Status.REPEATED); + deviceManagerService.updateOperation(device, operation); + } + } + } catch (OperationManagementException e) { + String msg = "Error occurred while retrieving pending operations of device id "+device.getId(); + log.error(msg, e); + throw new PolicyDelegationException(msg, e); + } + } } From 19750486dec1d3dc3a414a9be23eef02b9a88ce3 Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Thu, 30 Mar 2023 23:20:15 +0530 Subject: [PATCH 2/2] Add improvements --- .../carbon/device/mgt/core/config/ui/HubspotChat.java | 9 --------- .../src/main/resources/conf/mdm-ui-config.xml | 1 - 2 files changed, 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java index 728176e1db..ec22d125a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java @@ -25,7 +25,6 @@ public class HubspotChat { private String trackingUrl; private String accessToken; private String senderActorId; - private long channelAccountId; @XmlElement(name = "EnableHubspot") public boolean isEnableHubspot() { @@ -61,12 +60,4 @@ public class HubspotChat { public void setSenderActorId(String senderActorId) { this.senderActorId = senderActorId; } - @XmlElement(name = "ChannelAccountId") - public long getChannelAccountId() { - return channelAccountId; - } - - public void setChannelAccountId(long channelAccountId) { - this.channelAccountId = channelAccountId; - } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index 4867c665c0..1c33bddfdb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -31,7 +31,6 @@ access_token sender_actorId - channel_AccountId false