From add470c483a45b0456254d2abcdd4c148b43527e Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 30 Mar 2015 12:26:29 +0530 Subject: [PATCH] Fixing AppManager connector initialization issue at server start up and adding support for retrieving the complete operation list for a given device --- .../app/mgt/RemoteAppManagerConnector.java | 8 ++--- .../core/operation/mgt/dao/OperationDAO.java | 4 ++- .../mgt/dao/impl/CommandOperationDAOImpl.java | 7 ++++- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 7 ++++- .../mgt/dao/impl/OperationDAOImpl.java | 29 ++++++++++++++++++- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 2 +- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteAppManagerConnector.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteAppManagerConnector.java index c1446c09c6..548d9bef1a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteAppManagerConnector.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteAppManagerConnector.java @@ -44,8 +44,6 @@ public class RemoteAppManagerConnector implements AppManagerConnector { private ConfigurationContext configCtx; private ServiceAuthenticator authenticator; - private AppManagementConfig appManagementConfig; - private IdentityConfigurations identityConfig; private String oAuthAdminServiceUrl; private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1"; @@ -53,12 +51,10 @@ public class RemoteAppManagerConnector implements AppManagerConnector { private static final Log log = LogFactory.getLog(RemoteAppManagerConnector.class); public RemoteAppManagerConnector(AppManagementConfig appManagementConfig) { - this.appManagementConfig = appManagementConfig; + IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). + getDeviceManagementConfigRepository().getIdentityConfigurations(); this.authenticator = new ServiceAuthenticator(identityConfig.getAdminUsername(), identityConfig.getAdminPassword()); - this.identityConfig = - DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). - getDeviceManagementConfigRepository().getIdentityConfigurations(); this.oAuthAdminServiceUrl = identityConfig.getServerUrl() + DeviceManagementConstants.AppManagement.OAUTH_ADMIN_SERVICE; try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index 2b2fe05740..6a958c0cb6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -33,7 +33,9 @@ public interface OperationDAO { Operation getOperation(int operationId) throws OperationManagementDAOException; - List getOperations() throws OperationManagementDAOException; + Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException; + + List getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException; List getOperations(String status) throws OperationManagementDAOException; 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/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index 4560b2bde6..781da88c7e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -70,7 +70,12 @@ public class CommandOperationDAOImpl extends OperationDAOImpl { } @Override - public List getOperations() throws OperationManagementDAOException { + public Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException { + return null; + } + + @Override + public List getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException { return null; } 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/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index bab2c47fad..c44929be65 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -47,7 +47,12 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl { } @Override - public List getOperations() throws OperationManagementDAOException { + public Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException { + return null; + } + + @Override + public List getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException { return null; } 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 aaa00252ff..0571ebb7fa 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 @@ -28,6 +28,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Date; import java.sql.SQLException; import java.util.List; @@ -75,7 +76,33 @@ public class OperationDAOImpl implements OperationDAO { } @Override - public List getOperations() throws OperationManagementDAOException { + public Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException { + + return null; + } + + @Override + public List getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS 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.ID = ois.OP_ID"; + try { + PreparedStatement stmt = conn.prepareStatement(sql); + stmt.setString(1, deviceId.getType()); + stmt.setString(2, deviceId.getId()); + + List operations = new ArrayList(); + ResultSet rs = stmt.executeQuery(); + while (rs.next()) { + Operation operation = new Operation(); + //operation.setType(); + } + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while retrieving the operation list " + + "available for the '" + deviceId.getType() + "' with id '" + deviceId.getId() + "'" , e); + } return null; } 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/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index d573fc4f9f..d716fa3529 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -137,7 +137,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { } @Override - public List getOperations() throws OperationManagementDAOException { + public List getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException { return null; }