revert-70aa11f8
manoj 10 years ago
commit f2c33f9421

@ -589,4 +589,14 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
} }
return devicesOfRole; 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; 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;
}
} }

@ -67,7 +67,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
List<DeviceType> deviceTypes = null; List<DeviceType> deviceTypes = new ArrayList<DeviceType>();;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE"; 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(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
deviceTypes = new ArrayList<DeviceType>();
DeviceType deviceType = new DeviceType(); DeviceType deviceType = new DeviceType();
deviceType.setId(rs.getInt("DEVICE_TYPE_ID")); deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
deviceType.setName(rs.getString("DEVICE_TYPE")); deviceType.setName(rs.getString("DEVICE_TYPE"));

@ -70,4 +70,10 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
*/ */
List<Device> getAllDevicesOfRole(String roleName) throws DeviceManagementException; 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() return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getAllDevicesOfRole(roleName); .getAllDevicesOfRole(roleName);
} }
@Override
public int getDeviceCount() throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getDeviceCount();
}
} }

@ -179,7 +179,7 @@ public final class DeviceManagerUtil {
getURITemplates(config.getEndpoint(), APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN)); getURITemplates(config.getEndpoint(), APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN));
api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY); api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY);
api.addAvailableTiers(provider.getTiers()); api.addAvailableTiers(provider.getTiers());
api.setEndpointSecured(false); api.setEndpointSecured(true);
api.setStatus(APIStatus.PUBLISHED); api.setStatus(APIStatus.PUBLISHED);
api.setTransports(config.getTransports()); api.setTransports(config.getTransports());

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

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

@ -98,7 +98,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
deviceIdentifiers.add(deviceIdentifier); deviceIdentifiers.add(deviceIdentifier);
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList(); List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
for (ProfileFeature feature : effectiveFeatures) { for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -111,9 +111,6 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
addOperation(operation, deviceIdentifiers); addOperation(operation, deviceIdentifiers);
} }
} else { } else {
return null; return null;
} }
@ -142,10 +139,9 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
deviceIdentifiers.add(deviceIdentifier); deviceIdentifiers.add(deviceIdentifier);
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
if (!effectiveFeatures.isEmpty()) { if (!effectiveFeatures.isEmpty()) {
PolicyOperation policyOperation = new PolicyOperation();
for (ProfileFeature feature : effectiveFeatures) { for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -154,12 +150,10 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
operation.setStatus(Operation.Status.PENDING); operation.setStatus(Operation.Status.PENDING);
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
operation.setEnabled(true); operation.setEnabled(true);
profileOperationList.add(operation);
PolicyManagementDataHolder.getInstance().getDeviceManagementService(). PolicyManagementDataHolder.getInstance().getDeviceManagementService().
addOperation(policyOperation, deviceIdentifiers); addOperation(operation, deviceIdentifiers);
} }
} else { } else {
return null; return null;
} }
@ -202,4 +196,9 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
public PolicyEvaluationPoint getPEP() throws PolicyManagementException { public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
} }
@Override
public int getPolicyCount() throws PolicyManagementException {
return policyAdministratorPoint.getPolicyCount();
}
} }

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

@ -1343,4 +1343,32 @@ public class PolicyDAOImpl implements PolicyDAO {
return priority; 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(ID) AS POLICY_COUNT FROM DM_POLICY";
stmt = conn.prepareStatement(query);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
policyCount = resultSet.getInt("POLICY_COUNT");
}
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();
}
}
} }

@ -204,5 +204,9 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
return featureManager.deleteFeature(featureId); return featureManager.deleteFeature(featureId);
} }
@Override
public int getPolicyCount() throws PolicyManagementException {
return policyManager.getPolicyCount();
}
} }

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

@ -33,6 +33,7 @@ import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.List; import java.util.List;
public class PolicyManagerImpl implements PolicyManager { public class PolicyManagerImpl implements PolicyManager {
@ -494,6 +495,7 @@ public class PolicyManagerImpl implements PolicyManager {
// policyDAO.getTimesOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy);
// policyDAO.getLocationsOfPolicy(policy); // policyDAO.getLocationsOfPolicy(policy);
} }
Collections.sort(policyList);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
String msg = "Error occurred while getting all the policies."; String msg = "Error occurred while getting all the policies.";
@ -525,6 +527,7 @@ public class PolicyManagerImpl implements PolicyManager {
} }
} }
Collections.sort(policies);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
String msg = "Error occurred while getting the policies for device identifier (" + String msg = "Error occurred while getting the policies for device identifier (" +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")"; deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")";
@ -560,6 +563,7 @@ public class PolicyManagerImpl implements PolicyManager {
} }
} }
Collections.sort(policies);
// } catch (PolicyManagerDAOException e) { // } catch (PolicyManagerDAOException e) {
// String msg = "Error occurred while getting all the policies."; // String msg = "Error occurred while getting all the policies.";
// log.error(msg, e); // log.error(msg, e);
@ -603,6 +607,7 @@ public class PolicyManagerImpl implements PolicyManager {
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} }
Collections.sort(policies);
return policies; return policies;
} }
@ -629,6 +634,7 @@ public class PolicyManagerImpl implements PolicyManager {
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} }
Collections.sort(policies);
return policies; return policies;
} }
@ -726,4 +732,17 @@ public class PolicyManagerImpl implements PolicyManager {
throw new PolicyManagementException(msg, e); 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 { public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
return policyManagerService.getPEP(); return policyManagerService.getPEP();
} }
@Override
public int getPolicyCount() throws PolicyManagementException {
return policyManagerService.getPolicyCount();
}
} }

Loading…
Cancel
Save