Implemented device count and policy count

revert-70aa11f8
mharindu 9 years ago
parent ed9eebca52
commit 89d0fa0894

@ -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);
}
}
}

@ -60,5 +60,10 @@ public interface DeviceDAO {
*/
List<Device> getDeviceListOfUser(String username , int tenantId) throws DeviceManagementDAOException;
/**
* Get the count of devices
* @return device count
* @throws DeviceManagementDAOException
*/
int getDeviceCount() throws DeviceManagementDAOException;
}

@ -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;
}
}

@ -70,4 +70,10 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
*/
List<Device> getAllDevicesOfRole(String roleName) throws DeviceManagementException;
/**
* Method to get the count of all types of devices.
* @return device count
* @throws DeviceManagementException
*/
int getDeviceCount() throws DeviceManagementException;
}

@ -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();
}
}

@ -144,4 +144,5 @@ public interface PolicyAdministratorPoint {
boolean deleteFeature(int featureId) throws FeatureManagementException;
int getPolicyCount() throws PolicyManagementException;
}

@ -63,4 +63,6 @@ public interface PolicyManagerService {
PolicyInformationPoint getPIP() throws PolicyManagementException;
PolicyEvaluationPoint getPEP() throws PolicyManagementException;
int getPolicyCount() throws PolicyManagementException;
}

@ -95,7 +95,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
PolicyOperation policyOperation = new PolicyOperation();
ProfileOperation policyOperation = new ProfileOperation();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
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<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
@ -140,7 +140,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
getEffectiveFeatures(deviceIdentifier);
if (!effectiveFeatures.isEmpty()) {
PolicyOperation policyOperation = new PolicyOperation();
ProfileOperation profileOperation = new ProfileOperation();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
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<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
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();
}
}

@ -103,4 +103,6 @@ public interface PolicyDAO {
throws PolicyManagerDAOException;
boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException;
int getPolicyCount() throws PolicyManagerDAOException;
}

@ -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();
}
}
}

@ -214,4 +214,9 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
throw new FeatureManagementException(msg, e);
}
}
@Override
public int getPolicyCount() throws PolicyManagementException {
return policyManager.getPolicyCount();
}
}

@ -65,4 +65,6 @@ public interface PolicyManager {
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
int getPolicyCount() throws PolicyManagementException;
}

@ -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);
}
}
}

@ -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();
}
}

Loading…
Cancel
Save