From 48337ee16cc40fd2f60506c38693f68ade7b2fc2 Mon Sep 17 00:00:00 2001 From: thusithakalugamage Date: Tue, 11 Oct 2016 18:35:47 +0530 Subject: [PATCH 1/6] [EMM-1618] - related improvements on remaining occurences --- .../app/pages/cdmf.page.devices/public/js/listing.js | 5 +++-- .../app/pages/cdmf.page.groups/public/js/listing.js | 3 ++- .../app/pages/cdmf.page.policies/public/js/policy-list.js | 5 +++-- .../app/pages/cdmf.page.roles/public/js/role-listing.js | 2 +- .../devicemgt/app/pages/cdmf.page.users/public/js/listing.js | 5 +++-- .../cdmf.unit.role.edit.permission/public/js/bottomJs.js | 3 ++- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index 820b1836462..0e384c7016c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -525,9 +525,10 @@ function showPopup() { * hide popup function. */ function hidePopup() { - $(modalPopupContent).html(''); + $(modalPopupContent).html(""); + $(modalPopupContent).removeClass("operation-data"); $(modalPopup).modal('hide'); - $('body').removeClass('modal-open').css('padding-right', '0px'); + $('body').removeClass('modal-open').css('padding-right','0px'); $('.modal-backdrop').remove(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index d3a5c5cc736..8ac28822d9e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -275,7 +275,8 @@ function showPopup() { * hide popup function. */ function hidePopup() { - $(modalPopupContent).html(''); + $(modalPopupContent).html(""); + $(modalPopupContent).removeClass("operation-data"); $(modalPopup).modal('hide'); $('body').removeClass('modal-open').css('padding-right','0px'); $('.modal-backdrop').remove(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js index 65445b3929a..219250b6ea2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js @@ -91,9 +91,10 @@ function showPopup() { * hide popup function. */ function hidePopup() { - $(modalPopupContent).html(''); + $(modalPopupContent).html(""); + $(modalPopupContent).removeClass("operation-data"); $(modalPopup).modal('hide'); - $('body').removeClass('modal-open').css('padding-right', '0px'); + $('body').removeClass('modal-open').css('padding-right','0px'); $('.modal-backdrop').remove(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index d5cb812ce26..6ac6050de22 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -72,7 +72,7 @@ function showPopup() { function hidePopup() { $(modalPopupContent).html(''); $(modalPopup).modal('hide'); - $('body').removeClass('modal-open').css('padding-right', '0px'); + $('body').removeClass('modal-open').css('padding-right','0px'); $('.modal-backdrop').remove(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 43d6de1a83d..f43d257bbf2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -73,9 +73,10 @@ function showPopup() { * hide popup function. */ function hidePopup() { - $(modalPopupContent).html(''); + $(modalPopupContent).html(""); + $(modalPopupContent).removeClass("operation-data"); $(modalPopup).modal('hide'); - $('body').removeClass('modal-open').css('padding-right', '0px'); + $('body').removeClass('modal-open').css('padding-right','0px'); $('.modal-backdrop').remove(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js index af3a8e56296..553f8857730 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js @@ -39,7 +39,8 @@ var apiBasePath = "/api/device-mgt/v1.0"; * hide popup function. */ function hidePopup() { - $(modalPopupContent).html(''); + $(modalPopupContent).html(""); + $(modalPopupContent).removeClass("operation-data"); $(modalPopup).modal('hide'); $('body').removeClass('modal-open').css('padding-right','0px'); $('.modal-backdrop').remove(); From 51910ee67a2be01ba2b793bf5591649210112a54 Mon Sep 17 00:00:00 2001 From: harshanl Date: Thu, 13 Oct 2016 17:11:36 +0530 Subject: [PATCH 2/6] EMM-1675:Added policy revoke operation --- .../operation/mgt/OperationMgtConstants.java | 7 +++ .../policy/mgt/core/PolicyManagerService.java | 2 +- .../mgt/core/PolicyManagerServiceImpl.java | 4 +- .../mgt/core/enforcement/DelegationTask.java | 35 +++++++------- .../PolicyEnforcementDelegator.java | 2 + .../PolicyEnforcementDelegatorImpl.java | 48 ++++++++++++++++--- .../impl/PolicyAdministratorPointImpl.java | 8 +++- .../mgt/core/mgt/MonitoringManager.java | 2 +- .../core/mgt/impl/MonitoringManagerImpl.java | 2 +- 9 files changed, 80 insertions(+), 30 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java index 24bb47c0906..cd39b730600 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java @@ -29,4 +29,11 @@ public class OperationMgtConstants { public static final String DEVICE_ID_SERVICE_NOT_FOUND = "Issue in retrieving device management service instance for device found at %s"; } + + public final class OperationCodes { + private OperationCodes() { + throw new AssertionError(); + } + public static final String POLICY_REVOKE = "POLICY_REVOKE"; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java index 81ccf0eca41..96d7aac4d2f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java @@ -77,5 +77,5 @@ public interface PolicyManagerService { ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; - boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; + boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index a3079fcb4c9..da127b70a97 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -201,7 +201,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { } @Override - public boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { - return monitoringManager.isCompliance(deviceIdentifier); + public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { + return monitoringManager.isCompliant(deviceIdentifier); } } \ No newline at end of file diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java index 9a7eab1c6d5..dea10f5fac2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java @@ -64,32 +64,33 @@ public class DelegationTask implements Task { if (!deviceTypes.isEmpty()) { DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance() .getDeviceManagementService(); - List devices = new ArrayList<>(); + List devices; + List toBeNotified; for (String deviceType : deviceTypes) { try { + devices = new ArrayList<>(); + toBeNotified = new ArrayList<>(); devices.addAll(service.getAllDevices(deviceType)); + //HashMap deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds(); + for (Device device : devices) { + // if (deviceIdPolicy.containsKey(device.getId())) { + toBeNotified.add(device); + // } + } + if (!toBeNotified.isEmpty()) { + PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified); + enforcementDelegator.delegate(); + } } catch (DeviceManagementException e) { - throw new PolicyManagementException("Error occurred while taking the devices", e); + throw new PolicyManagementException("Error occurred while fetching the devices", e); + } catch (PolicyDelegationException e) { + throw new PolicyManagementException("Error occurred while running the delegation task on " + + "device-type : " + deviceType, e); } } -// HashMap deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds(); - List toBeNotified = new ArrayList<>(); - - for (Device device : devices) { -// if (deviceIdPolicy.containsKey(device.getId())) { - toBeNotified.add(device); -// } - } - if (!toBeNotified.isEmpty()) { - PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified); - enforcementDelegator.delegate(); - } } - } catch (PolicyManagementException e) { log.error("Error occurred while getting the policies applied to devices.", e); - } catch (PolicyDelegationException e) { - log.error("Error occurred while running the delegation task.", e); } } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java index 218fe0398ed..e782308c069 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java @@ -31,4 +31,6 @@ public interface PolicyEnforcementDelegator { void addPolicyOperation(List deviceIdentifiers, Policy policy) throws PolicyDelegationException; + void addPolicyRevokeOperation(List deviceIdentifiers) throws PolicyDelegationException; + } 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 4e2051e8b1a..90f7acd8756 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 @@ -23,14 +23,18 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl; +import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; import java.util.ArrayList; @@ -58,7 +62,6 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato @Override public void delegate() throws PolicyDelegationException { - for (Device device : devices) { DeviceIdentifier identifier = new DeviceIdentifier(); identifier.setId(device.getDeviceIdentifier()); @@ -70,14 +73,17 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato List deviceIdentifiers = new ArrayList<>(); deviceIdentifiers.add(identifier); this.addPolicyOperation(deviceIdentifiers, policy); + } else { + //This means all the applicable policies have been removed. Hence sending policy-revoke operation. + List deviceIdentifiers = new ArrayList<>(); + deviceIdentifiers.add(identifier); + this.addPolicyRevokeOperation(deviceIdentifiers); } - } } @Override public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException { - try { PolicyManagerService policyManagerService = new PolicyManagerServiceImpl(); return policyManagerService.getPEP().getEffectivePolicy(identifier); @@ -96,11 +102,13 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato @Override public void addPolicyOperation(List deviceIdentifiers, Policy policy) throws PolicyDelegationException { - try { - //ToDo Need to fix this to fetch OSGi service - OperationManager operationManager = new OperationManagerImpl(); - operationManager.addOperation(PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers); + String type = null; + if (deviceIdentifiers.size() > 0) { + type = deviceIdentifiers.get(0).getType(); + } + PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type, + PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers); } catch (InvalidDeviceException e) { String msg = "Invalid DeviceIdentifiers found."; log.error(msg, e); @@ -110,7 +118,33 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato log.error(msg, e); throw new PolicyDelegationException(msg, e); } + } + @Override + public void addPolicyRevokeOperation(List deviceIdentifiers) throws PolicyDelegationException { + try { + String type = null; + if (deviceIdentifiers.size() > 0) { + type = deviceIdentifiers.get(0).getType(); + } + PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type, + this.getPolicyRevokeOperation(), deviceIdentifiers); + } catch (InvalidDeviceException e) { + String msg = "Invalid DeviceIdentifiers found."; + log.error(msg, e); + throw new PolicyDelegationException(msg, e); + } catch (OperationManagementException e) { + String msg = "Error occurred while adding the operation to device."; + log.error(msg, e); + throw new PolicyDelegationException(msg, e); + } } + private Operation getPolicyRevokeOperation() { + CommandOperation policyRevokeOperation = new CommandOperation(); + policyRevokeOperation.setEnabled(true); + policyRevokeOperation.setCode(OperationMgtConstants.OperationCodes.POLICY_REVOKE); + policyRevokeOperation.setType(Operation.Type.COMMAND); + return policyRevokeOperation; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index b96e8f1cd70..1f82cb780b5 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -114,7 +114,13 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public boolean deletePolicy(int policyId) throws PolicyManagementException { boolean bool =policyManager.deletePolicy(policyId); - PolicyCacheManagerImpl.getInstance().rePopulateCache(); + PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance(); + policyCacheManager.rePopulateCache(); + List appliedPolicies = policyCacheManager.getAllPolicies(); + //This means all the policies have been deleted. Hence triggering publishChanges to take immediate effect. + if (appliedPolicies.isEmpty()) { + this.publishChanges(); + } return bool; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java index 2b6e7d5eae7..3eb809d2ae0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java @@ -33,7 +33,7 @@ public interface MonitoringManager { throws PolicyComplianceException; - boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; + boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 91d16cb01a9..8643fd87342 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -171,7 +171,7 @@ public class MonitoringManagerImpl implements MonitoringManager { } @Override - public boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { + public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance().getDeviceManagementService(); From a89b50197f94ae012cb59ecaeea124d31c34de01 Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 14 Oct 2016 13:21:51 +0530 Subject: [PATCH 3/6] EMM-1757:Fixed admin device-detail view issue --- .../carbon/device/mgt/core/dao/DeviceDAO.java | 10 ++++++ .../core/dao/impl/AbstractDeviceDAOImpl.java | 31 +++++++++++++++++++ .../operation/mgt/OperationManagerImpl.java | 11 +++++++ 3 files changed, 52 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index cc1219c3a1f..c688b5997fa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -334,6 +334,16 @@ public interface DeviceDAO { EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve current enrollment of a given device. + * + * @param deviceId device id. + * @param tenantId tenant id. + * @return returns EnrolmentInfo object. + * @throws DeviceManagementDAOException + */ + EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; + /** * This method is used to retrieve current active enrollment of a given device and tenant id. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 648c7e2a424..f127f26022b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -794,6 +794,37 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } + @Override + public EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + EnrolmentInfo enrolmentInfo = null; + try { + conn = this.getConnection(); + String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " + + "DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " + + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + + "AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + + "AND TENANT_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, deviceId.getId()); + stmt.setString(2, deviceId.getType()); + stmt.setInt(3, tenantId); + stmt.setInt(4, tenantId); + rs = stmt.executeQuery(); + if (rs.next()) { + enrolmentInfo = DeviceManagementDAOUtil.loadMatchingEnrolment(rs); + } + return enrolmentInfo; + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " + + "of device '" + deviceId + "'", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + } + @Override public EnrolmentInfo getActiveEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException { Connection conn; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 94659189563..50407a85f4a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -927,6 +927,13 @@ public class OperationManagerImpl implements OperationManager { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); String user = this.getUser(); enrolmentInfo = deviceDAO.getEnrolment(deviceId, user, tenantId); + if (enrolmentInfo == null) { + boolean isAdminUser = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService(). + isDeviceAdminUser(); + if (isAdminUser) { + enrolmentInfo = deviceDAO.getEnrolment(deviceId, tenantId); + } + } } catch (DeviceManagementDAOException e) { throw new OperationManagementException("Error occurred while retrieving enrollment data of '" + deviceId.getType() + "' device carrying the identifier '" + @@ -934,6 +941,10 @@ public class OperationManagerImpl implements OperationManager { } catch (SQLException e) { throw new OperationManagementException( "Error occurred while opening a connection to the data source", e); + } catch (DeviceAccessAuthorizationException e) { + throw new OperationManagementException("Error occurred while checking the device access permissions for '" + + deviceId.getType() + "' device carrying the identifier '" + + deviceId.getId() + "'", e); } finally { DeviceManagementDAOFactory.closeConnection(); } From 47ca8942b61cb72df1bbae577888eac3908e8a6d Mon Sep 17 00:00:00 2001 From: thusithakalugamage Date: Fri, 14 Oct 2016 14:11:49 +0530 Subject: [PATCH 4/6] resolving conflicts - removing deprecated modal related methods --- .../cdmf.page.users/public/js/listing.js | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index d14157243ce..b7843fb74bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -39,9 +39,6 @@ $(function () { }); var apiBasePath = "/api/device-mgt/v1.0"; -var modalPopup = ".modal"; -var modalPopupContainer = modalPopup + " .modal-content"; -var modalPopupContent = modalPopup + " .modal-content"; var body = "body"; /** @@ -54,31 +51,6 @@ $(document).on('draw.dt', function () { $(".icon .text").res_text(0.2); }); -/* - * set popup maximum height function. - */ -function setPopupMaxHeight() { - $(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30))); - $(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2))); -} - -/* - * show popup function. - */ -function showPopup() { - $(modalPopup).modal('show'); -} - -/* - * hide popup function. - */ -function hidePopup() { - $(modalPopupContent).html(""); - $(modalPopupContent).removeClass("operation-data"); - $(modalPopup).modal('hide'); - $('body').removeClass('modal-open').css('padding-right','0px'); - $('.modal-backdrop').remove(); -} /** * Following click function would execute @@ -271,9 +243,6 @@ function removeUser(username) { ); }); - $("a#remove-user-cancel-link").click(function () { - hidePopup(); - }); } /** From 3aae81d9e431e51241da9829b1405b6807cb8ae8 Mon Sep 17 00:00:00 2001 From: thusithakalugamage Date: Fri, 14 Oct 2016 14:16:53 +0530 Subject: [PATCH 5/6] resolving conflicts - removing deprecated modal related methods --- .../devicemgt/app/pages/cdmf.page.users/public/js/listing.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index b7843fb74bb..d8dc9d48601 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -51,7 +51,6 @@ $(document).on('draw.dt', function () { $(".icon .text").res_text(0.2); }); - /** * Following click function would execute * when a user clicks on "Invite" link From 1af8184889c0f6792cb9c53a15a2919f8470dc8b Mon Sep 17 00:00:00 2001 From: kamidu Date: Fri, 14 Oct 2016 15:20:05 +0530 Subject: [PATCH 6/6] positioning modal content --- .../jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs | 1 + .../devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs index e0b66efd3e1..0e6d17780d3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs @@ -73,6 +73,7 @@ under the License. --}} + {{defineZone "bottomModalContent"}} {{defineZone "bottomLibJs"}} {{defineZone "bottomJs"}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs index 3a700a07137..5b2cf5ca29d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs @@ -16,7 +16,7 @@ under the License. }} -{{#zone "content"}} +{{#zone "bottomModalContent"}}