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 7eb690c10e7..d89362df1b5 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 2588668b534..0379cd9ede3 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 9300e49c1b8..1d97328c4a8 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/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index f2f0ac89372..814f7d44a4d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -67,7 +67,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; - List deviceTypes = null; + List deviceTypes = new ArrayList();; try { conn = this.getConnection(); String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE"; @@ -75,7 +75,6 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { rs = stmt.executeQuery(); while (rs.next()) { - deviceTypes = new ArrayList(); DeviceType deviceType = new DeviceType(); deviceType.setId(rs.getInt("DEVICE_TYPE_ID")); deviceType.setName(rs.getString("DEVICE_TYPE")); 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 9a8ad08398c..6b9820068ef 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 cb2d363fb69..a76cc2f9ede 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/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 308ed6813fb..126d60b543e 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/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 c207516a4d9..1910ee46158 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 @@ -146,4 +146,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 118566f188f..0214e344481 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 fdbdeff5fab..879c8906af6 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 @@ -98,7 +98,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { deviceIdentifiers.add(deviceIdentifier); List effectiveFeatures = policy.getProfile().getProfileFeaturesList(); - + List profileOperationList = new ArrayList(); for (ProfileFeature feature : effectiveFeatures) { ProfileOperation operation = new ProfileOperation(); @@ -111,9 +111,6 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { addOperation(operation, deviceIdentifiers); } - - - } else { return null; } @@ -142,10 +139,9 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { List deviceIdentifiers = new ArrayList(); deviceIdentifiers.add(deviceIdentifier); + List profileOperationList = new ArrayList(); if (!effectiveFeatures.isEmpty()) { - PolicyOperation policyOperation = new PolicyOperation(); - for (ProfileFeature feature : effectiveFeatures) { ProfileOperation operation = new ProfileOperation(); @@ -154,12 +150,10 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { operation.setStatus(Operation.Status.PENDING); operation.setType(Operation.Type.PROFILE); operation.setEnabled(true); - - + profileOperationList.add(operation); PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + addOperation(operation, deviceIdentifiers); } - } else { return null; } @@ -202,4 +196,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 d84236c3525..a5af43affc3 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 @@ -107,4 +107,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 3fd6cca1f79..7e040700637 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 @@ -1343,4 +1343,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 2dad3095452..2041d997130 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 @@ -204,5 +204,9 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { return featureManager.deleteFeature(featureId); } + @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 f1d78cb1d30..b5cc7282123 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 @@ -67,4 +67,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 d9fac30acc6..4a338a7e0f8 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 @@ -732,4 +732,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 a45bcbd0fe8..46b51c73529 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(); + } }