From 76c697453e8762d76c8d1ce306092b0872b2b8ac Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 13 May 2015 17:44:54 +0530 Subject: [PATCH 1/2] Change platforms to lower case --- .../main/java/org/wso2/carbon/device/mgt/common/Platform.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Platform.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Platform.java index b911702ac5f..2b7f9b9ceca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Platform.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Platform.java @@ -20,5 +20,5 @@ package org.wso2.carbon.device.mgt.common; public enum Platform { - ANDROID, IOS, WINDOWS; + android, ios, windows; } From 9b5f6bc171e9dfbb721f1c2c62a365099ecd95a1 Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 13 May 2015 18:25:52 +0530 Subject: [PATCH 2/2] Change next operations to join profile operations --- .../mgt/dao/impl/OperationDAOImpl.java | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java index c19f157ef82..9b996e10693 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java @@ -466,39 +466,66 @@ public class OperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; ResultSet rs = null; + + ByteArrayInputStream bais; + ObjectInputStream ois; + try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement( - "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS,o.OPERATION_CODE " + - " FROM DM_OPERATION o " + - "INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID " + - "FROM DM_DEVICE d INNER JOIN DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND " + - "dm.NAME = ? AND d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN " + - "DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois ON o.STATUS=? AND" + - " o.ID = ois.OP_ID " + + "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " + + "po.OPERATION_DETAILS,co.ENABLED from " + + "(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " + + "OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o " + + "INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " + + "where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION " + + "po ON " + + "o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " + "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); + stmt.setString(1, deviceId.getType()); stmt.setString(2, deviceId.getId()); stmt.setString(3, Operation.Status.PENDING.toString()); rs = stmt.executeQuery(); - Operation operation = null; if (rs.next()) { - operation = new Operation(); - operation.setType(this.getType(rs.getString("TYPE"))); - operation.setStatus(this.getStatus(rs.getString("STATUS"))); - operation.setId(rs.getInt("ID")); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); - if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { - operation.setReceivedTimeStamp(""); + if (rs.getBytes("OPERATION_DETAILS") != null) { + byte[] operationDetails; + operationDetails = rs.getBytes("OPERATION_DETAILS"); + bais = new ByteArrayInputStream(operationDetails); + ois = new ObjectInputStream(bais); + operation = (ProfileOperation) ois.readObject(); } else { - operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); + operation = new Operation(); + operation.setType(this.getType(rs.getString("TYPE"))); + operation.setStatus(this.getStatus(rs.getString("STATUS"))); + operation.setId(rs.getInt("ID")); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { + operation.setReceivedTimeStamp(""); + } else { + operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); + } + operation.setCode(rs.getString("OPERATION_CODE")); + if (rs.getObject("ENABLED") != null) { + operation.setEnabled(rs.getBoolean("ENABLED")); + } } - operation.setCode(rs.getString("OPERATION_CODE")); } return operation; - } catch (SQLException e) { + } catch (IOException ex) { + String errorMsg = "IO error occurred while de serializing the next profile operation available for the " + + "device:" + deviceId; + log.error(errorMsg); + throw new OperationManagementDAOException(errorMsg, ex); + } catch (ClassNotFoundException ex) { + String errorMsg = "class not found error occurred while de serializing the profile operation available " + + "for the device:" + deviceId; + log.error(errorMsg); + throw new OperationManagementDAOException(errorMsg, ex); + + }catch (SQLException e) { throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); } finally { OperationManagementDAOUtil.cleanupResources(stmt, rs);