From 3d69503e96e1c3d68b1f9b1c6d50fb9503091c05 Mon Sep 17 00:00:00 2001 From: mharindu Date: Wed, 20 May 2015 14:25:17 +0530 Subject: [PATCH 1/2] Merged --- .../carbon/device/mgt/core/util/DeviceManagerUtil.java | 2 +- .../src/main/resources/conf/user-api-publisher-config.xml | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 308ed6813f..126d60b543 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -179,7 +179,7 @@ public final class DeviceManagerUtil { getURITemplates(config.getEndpoint(), APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN)); api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY); api.addAvailableTiers(provider.getTiers()); - api.setEndpointSecured(false); + api.setEndpointSecured(true); api.setStatus(APIStatus.PUBLISHED); api.setTransports(config.getTransports()); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml index 12a46052c0..f252dcb019 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/user-api-publisher-config.xml @@ -50,5 +50,13 @@ http://localhost:9763/operations http,https + + deviceList + admin + devices + 1.0.0 + http://localhost:9763/devices + http,https + From 89d0fa08943583d75ab6ca2de0b602ca56b23eb7 Mon Sep 17 00:00:00 2001 From: mharindu Date: Fri, 22 May 2015 01:23:03 +0530 Subject: [PATCH 2/2] Implemented device count and policy count --- .../DeviceManagementServiceProviderImpl.java | 10 +++++++ .../carbon/device/mgt/core/dao/DeviceDAO.java | 7 ++++- .../mgt/core/dao/impl/DeviceDAOImpl.java | 29 +++++++++++++++++++ .../core/service/DeviceManagementService.java | 6 ++++ .../service/DeviceManagementServiceImpl.java | 6 ++++ .../mgt/common/PolicyAdministratorPoint.java | 1 + .../policy/mgt/core/PolicyManagerService.java | 2 ++ .../mgt/core/PolicyManagerServiceImpl.java | 17 +++++++---- .../carbon/policy/mgt/core/dao/PolicyDAO.java | 2 ++ .../mgt/core/dao/impl/PolicyDAOImpl.java | 28 ++++++++++++++++++ .../impl/PolicyAdministratorPointImpl.java | 5 ++++ .../policy/mgt/core/mgt/PolicyManager.java | 2 ++ .../mgt/core/mgt/impl/PolicyManagerImpl.java | 13 +++++++++ .../core/service/PolicyManagementService.java | 5 ++++ 14 files changed, 126 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 7eb690c10e..d89362df1b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -571,4 +571,14 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } return devicesOfRole; } + + @Override + public int getDeviceCount() throws DeviceManagementException { + try { + int deviceCount = this.deviceDAO.getDeviceCount(); + return deviceCount; + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while obtaining devices all devices", e); + } + } } 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 2588668b53..0379cd9ede 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 @@ -60,5 +60,10 @@ public interface DeviceDAO { */ List getDeviceListOfUser(String username , int tenantId) throws DeviceManagementDAOException; - + /** + * Get the count of devices + * @return device count + * @throws DeviceManagementDAOException + */ + int getDeviceCount() throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 9300e49c1b..1d97328c4a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -301,4 +301,33 @@ public class DeviceDAOImpl implements DeviceDAO { } } + /** + * Get device count of all devices. + * @return device count + * @throws DeviceManagementDAOException + */ + @Override + public int getDeviceCount() throws DeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + int deviceCount = 0; + try { + conn = this.getConnection(); + String selectDBQueryForType = "SELECT COUNT(DM_DEVICE.ID) FROM DM_DEVICE"; + stmt = conn.prepareStatement(selectDBQueryForType); + resultSet = stmt.executeQuery(); + while (resultSet.next()) { + deviceCount = resultSet.getInt(0); + } + } catch (SQLException e) { + String msg = "Error occurred while getting count of devices"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return deviceCount; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 9a8ad08398..6b9820068e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -70,4 +70,10 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager, */ List getAllDevicesOfRole(String roleName) throws DeviceManagementException; + /** + * Method to get the count of all types of devices. + * @return device count + * @throws DeviceManagementException + */ + int getDeviceCount() throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index cb2d363fb6..a76cc2f9ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -205,4 +205,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() .getAllDevicesOfRole(roleName); } + + @Override + public int getDeviceCount() throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .getDeviceCount(); + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index 07c4e66f1d..7b6fb9a41c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java @@ -144,4 +144,5 @@ public interface PolicyAdministratorPoint { boolean deleteFeature(int featureId) throws FeatureManagementException; + int getPolicyCount() throws PolicyManagementException; } 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 118566f188..0214e34448 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 @@ -63,4 +63,6 @@ public interface PolicyManagerService { PolicyInformationPoint getPIP() throws PolicyManagementException; PolicyEvaluationPoint getPEP() throws PolicyManagementException; + + int getPolicyCount() throws PolicyManagementException; } 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 b3c4644b9b..6f9cac8e9e 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 @@ -95,7 +95,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { List effectiveFeatures = policy.getProfile().getProfileFeaturesList(); - PolicyOperation policyOperation = new PolicyOperation(); + ProfileOperation policyOperation = new ProfileOperation(); List profileOperationList = new ArrayList(); for (ProfileFeature feature : effectiveFeatures) { @@ -105,7 +105,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { operation.setPayLoad(feature.getContent()); profileOperationList.add(operation); } - policyOperation.setProfileOperations(profileOperationList); + policyOperation.setPayLoad(profileOperationList); policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); List deviceIdentifiers = new ArrayList(); @@ -140,7 +140,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { getEffectiveFeatures(deviceIdentifier); if (!effectiveFeatures.isEmpty()) { - PolicyOperation policyOperation = new PolicyOperation(); + ProfileOperation profileOperation = new ProfileOperation(); List profileOperationList = new ArrayList(); for (ProfileFeature feature : effectiveFeatures) { @@ -150,14 +150,14 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { operation.setPayLoad(feature.getContent()); profileOperationList.add(operation); } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); + profileOperation.setPayLoad(profileOperationList); + profileOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); List deviceIdentifiers = new ArrayList(); deviceIdentifiers.add(deviceIdentifier); PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + addOperation(profileOperation, deviceIdentifiers); } else { return null; } @@ -200,4 +200,9 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { public PolicyEvaluationPoint getPEP() throws PolicyManagementException { return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); } + + @Override + public int getPolicyCount() throws PolicyManagementException { + return policyAdministratorPoint.getPolicyCount(); + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java index 408ab11abf..53329412d4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -103,4 +103,6 @@ public interface PolicyDAO { throws PolicyManagerDAOException; boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException; + + int getPolicyCount() throws PolicyManagerDAOException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index 2a5b175755..c488bf515d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -1286,4 +1286,32 @@ public class PolicyDAOImpl implements PolicyDAO { return priority; } + @Override + public int getPolicyCount() throws PolicyManagerDAOException { + + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + int policyCount = 0; + try { + conn = this.getConnection(); + String query = "SELECT COUNT(DM_POLICY.ID) FROM DM_POLICY"; + stmt = conn.prepareStatement(query); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + policyCount = resultSet.getInt(0); + } + return policyCount; + + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); + this.closeConnection(); + } + } + } 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 c61b9802a2..112b3cc4e5 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 @@ -214,4 +214,9 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { throw new FeatureManagementException(msg, e); } } + + @Override + public int getPolicyCount() throws PolicyManagementException { + return policyManager.getPolicyCount(); + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java index dfe9ff7e9d..54d58eae2e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java @@ -65,4 +65,6 @@ public interface PolicyManager { boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; + + int getPolicyCount() throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index d275eb3c9a..3afdfc25b6 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -705,4 +705,17 @@ public class PolicyManagerImpl implements PolicyManager { throw new PolicyManagementException(msg, e); } } + + @Override + public int getPolicyCount() throws PolicyManagementException { + int policyCount = 0; + try { + policyCount = policyDAO.getPolicyCount(); + return policyCount; + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while getting policy count"; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java index a45bcbd0fe..46b51c7352 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java @@ -117,4 +117,9 @@ public class PolicyManagementService implements PolicyManagerService { public PolicyEvaluationPoint getPEP() throws PolicyManagementException { return policyManagerService.getPEP(); } + + @Override + public int getPolicyCount() throws PolicyManagementException { + return policyManagerService.getPolicyCount(); + } }