Fixing the database issue which causes the deviceids slelect did not work

revert-70aa11f8
geethkokila 9 years ago
parent 7023537fcd
commit 813f9072d8

@ -140,7 +140,7 @@ public interface PolicyDAO {
Policy getAppliedPolicy(int deviceId, int enrollmentId) throws PolicyManagerDAOException; Policy getAppliedPolicy(int deviceId, int enrollmentId) throws PolicyManagerDAOException;
HashMap<Integer, Integer> getAppliedPolicyIds(List<Integer> deviceIds) throws PolicyManagerDAOException; HashMap<Integer, Integer> getAppliedPolicyIds() throws PolicyManagerDAOException;
HashMap<Integer, Integer> getAppliedPolicyIdsDeviceIds() throws PolicyManagerDAOException; HashMap<Integer, Integer> getAppliedPolicyIdsDeviceIds() throws PolicyManagerDAOException;
} }

@ -1563,7 +1563,7 @@ public class PolicyDAOImpl implements PolicyDAO {
} }
@Override @Override
public HashMap<Integer, Integer> getAppliedPolicyIds(List<Integer> deviceIds) throws PolicyManagerDAOException { public HashMap<Integer, Integer> getAppliedPolicyIds() throws PolicyManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -1571,10 +1571,9 @@ public class PolicyDAOImpl implements PolicyDAO {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?"; String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE TENANT_ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setString(1, PolicyManagerUtil.makeString(deviceIds)); stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery(); resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {

@ -229,7 +229,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
//int tenantId = PolicyManagerUtil.getTenantId(); //int tenantId = PolicyManagerUtil.getTenantId();
Map<Integer, Device> deviceIds = new HashMap<>(); Map<Integer, Device> deviceIds = new HashMap<>();
List<ComplianceData> complianceDatas = new ArrayList<>(); List<ComplianceData> complianceDatas = new ArrayList<>();
HashMap<Integer, Integer> devicePolicyIdMap; HashMap<Integer, Integer> devicePolicyIdMap = null;
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
@ -247,7 +247,13 @@ public class MonitoringManagerImpl implements MonitoringManager {
} }
List<Integer> deviceIDs = new ArrayList<>(deviceIds.keySet()); List<Integer> deviceIDs = new ArrayList<>(deviceIds.keySet());
devicePolicyIdMap = policyDAO.getAppliedPolicyIds(deviceIDs); HashMap<Integer, Integer> temp = policyDAO.getAppliedPolicyIds();
for (Integer id : deviceIDs) {
if (temp != null && temp.containsKey(id)) {
devicePolicyIdMap.put(id, temp.get(id));
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new PolicyComplianceException("SQL error occurred while getting monitoring details.", e); throw new PolicyComplianceException("SQL error occurred while getting monitoring details.", e);
} catch (MonitoringDAOException e) { } catch (MonitoringDAOException e) {
@ -380,19 +386,19 @@ public class MonitoringManagerImpl implements MonitoringManager {
monitoringOperation.setEnabled(true); monitoringOperation.setEnabled(true);
monitoringOperation.setType(Operation.Type.COMMAND); monitoringOperation.setType(Operation.Type.COMMAND);
monitoringOperation.setCode(OPERATION_MONITOR); monitoringOperation.setCode(OPERATION_MONITOR);
CommandOperation infoOperation = new CommandOperation(); // CommandOperation infoOperation = new CommandOperation();
infoOperation.setEnabled(true); // infoOperation.setEnabled(true);
infoOperation.setType(Operation.Type.COMMAND); // infoOperation.setType(Operation.Type.COMMAND);
infoOperation.setCode(OPERATION_INFO); // infoOperation.setCode(OPERATION_INFO);
CommandOperation appListOperation = new CommandOperation(); // CommandOperation appListOperation = new CommandOperation();
appListOperation.setEnabled(true); // appListOperation.setEnabled(true);
appListOperation.setType(Operation.Type.COMMAND); // appListOperation.setType(Operation.Type.COMMAND);
appListOperation.setCode(OPERATION_APP_LIST); // appListOperation.setCode(OPERATION_APP_LIST);
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
service.addOperation(monitoringOperation, deviceIdentifiers); service.addOperation(monitoringOperation, deviceIdentifiers);
service.addOperation(infoOperation, deviceIdentifiers); // service.addOperation(infoOperation, deviceIdentifiers);
service.addOperation(appListOperation, deviceIdentifiers); // service.addOperation(appListOperation, deviceIdentifiers);
} }
private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) { private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) {

@ -31,12 +31,8 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.ntask.common.TaskException;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
@ -127,7 +123,7 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
List<Device> devices = service.getAllDevices(ANDROID); List<Device> devices = service.getAllDevices(ANDROID);
monitoringManager.addMonitoringOperation(devices); // monitoringManager.addMonitoringOperation(devices);
log.debug("Compliance operations adding done."); log.debug("Compliance operations adding done.");

@ -22,7 +22,7 @@
<suite name="CDM-core-initializer"> <suite name="CDM-core-initializer">
<parameter name="useDefaultListeners" value="false"/> <parameter name="useDefaultListeners" value="false"/>
<test name="DAO Unit Tests" preserve-order="true"> <test name="DAO Unit Tests" preserve-order="true" parallel="false">
<parameter name="dbType" value="H2"/> <parameter name="dbType" value="H2"/>
<classes> <classes>
<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/> <class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>

Loading…
Cancel
Save