From 82cbbef83b9c8b457c75684df888e178126e071b Mon Sep 17 00:00:00 2001 From: manoj Date: Mon, 22 Jun 2015 21:21:50 +0530 Subject: [PATCH] Application list saving method and device operation response saving --- .../device/mgt/common/DeviceIdentifier.java | 7 +++ .../common/app/mgt/ApplicationManager.java | 17 ++++--- .../mgt/common/operation/mgt/Operation.java | 15 +++++- .../operation/mgt/OperationManager.java | 3 +- .../mgt/ApplicationManagementServiceImpl.java | 6 +++ .../app/mgt/ApplicationManagerFactory.java | 2 +- ...pplicationManagerProviderServiceImpl.java} | 51 ++++++++++++++----- .../carbon/device/mgt/core/dao/DeviceDAO.java | 2 + .../mgt/core/dao/impl/DeviceDAOImpl.java | 23 +++++++++ .../mgt/core/dto/operation/mgt/Operation.java | 12 +++-- .../DeviceManagementServiceComponent.java | 8 +-- .../operation/mgt/OperationManagerImpl.java | 35 ++++++------- .../core/operation/mgt/dao/OperationDAO.java | 6 ++- .../mgt/dao/impl/OperationDAOImpl.java | 21 ++++++++ .../DeviceManagementProviderService.java | 10 ++++ .../DeviceManagementProviderServiceImpl.java | 19 ++++--- .../device/mgt/core/TestDeviceManager.java | 6 +++ .../src/main/resources/dbscripts/cdm/h2.sql | 20 ++++++++ 18 files changed, 202 insertions(+), 61 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/{RemoteApplicationManager.java => ApplicationManagerProviderServiceImpl.java} (75%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 2cc27e6236..3c5e240502 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -46,4 +46,11 @@ public class DeviceIdentifier implements Serializable{ this.id = id; } + @Override + public String toString() { + return "DeviceIdentifier{" + + "id='" + id + '\'' + + ", type='" + type + '\'' + + '}'; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java index 4790de961f..27560bf683 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java @@ -41,7 +41,8 @@ public interface ApplicationManager { * @throws ApplicationManagementException */ - Application[] getApplications(String domain, int pageNumber, int size) throws ApplicationManagementException; + Application[] getApplications(String domain, int pageNumber, int size) + throws ApplicationManagementException; /** @@ -51,8 +52,8 @@ public interface ApplicationManager { * @param application Application details of the app being updated. * @param status Installed/Uninstalled */ - void updateApplicationStatus(DeviceIdentifier deviceId, Application application, - String status) throws ApplicationManagementException; + void updateApplicationStatus(DeviceIdentifier deviceId, Application application, String status) + throws ApplicationManagementException; /** * Retrieve the status of an application on a device. Whether it is installed or not. @@ -61,11 +62,13 @@ public interface ApplicationManager { * @param application Application details of the app being searched. * @return Status of the application on the device. */ - String getApplicationStatus(DeviceIdentifier deviceId, - Application application) throws ApplicationManagementException; + String getApplicationStatus(DeviceIdentifier deviceId, Application application) + throws ApplicationManagementException; - void installApplication(Operation operation, - List deviceIdentifiers) throws ApplicationManagementException; + void installApplication(Operation operation, List deviceIdentifiers) + throws ApplicationManagementException; + void updateApplicationsForDevice(DeviceIdentifier deviceIdentifier, List applications) + throws ApplicationManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 82f6039442..c30e8c478b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -43,6 +43,7 @@ public class Operation implements Serializable { private String createdTimeStamp; private boolean isEnabled; private Object payLoad; + private Object operationResponse; @Override public boolean equals(Object o) { @@ -73,6 +74,10 @@ public class Operation implements Serializable { if (payLoad != null ? !payLoad.equals(operation.payLoad) : operation.payLoad != null) { return false; } + if (operationResponse != null ? !operationResponse + .equals(operation.operationResponse) : operation.operationResponse != null) { + return false; + } if (properties != null ? !properties.equals(operation.properties) : operation.properties != null) { return false; } @@ -85,7 +90,6 @@ public class Operation implements Serializable { if (type != operation.type) { return false; } - return true; } @@ -100,6 +104,7 @@ public class Operation implements Serializable { result = 31 * result + (createdTimeStamp != null ? createdTimeStamp.hashCode() : 0); result = 31 * result + (isEnabled ? 1 : 0); result = 31 * result + (payLoad != null ? payLoad.hashCode() : 0); + result = 31 * result + (operationResponse != null ? operationResponse.hashCode() : 0); return result; } @@ -178,6 +183,14 @@ public class Operation implements Serializable { this.payLoad = payLoad; } + public Object getOperationResponse() { + return operationResponse; + } + + public void setOperationResponse(Object operationResponse) { + this.operationResponse = operationResponse; + } + @Override public String toString() { return "Operation{" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index 03e5e520c7..c14f0e0e21 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -59,8 +59,7 @@ public interface OperationManager { public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException; - public void updateOperation(DeviceIdentifier deviceId, int operationId, Operation.Status operationStatus) throws - OperationManagementException; + public void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException; public void deleteOperation(int operationId) throws OperationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementServiceImpl.java index d1aa9295d1..4814713f9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementServiceImpl.java @@ -65,4 +65,10 @@ public class ApplicationManagementServiceImpl implements ApplicationManager { DeviceManagementDataHolder.getInstance().getAppManager().installApplication(operation, deviceIdentifiers); } + @Override + public void updateApplicationsForDevice(DeviceIdentifier deviceIdentifier, List applications) + throws ApplicationManagementException { + + DeviceManagementDataHolder.getInstance().getAppManager().updateApplicationsForDevice(deviceIdentifier,applications); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java index 875e2f5ee5..e89563622e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java @@ -31,7 +31,7 @@ public class ApplicationManagerFactory { } public static ApplicationManager getConnector(AppManagementConfig config) { - return new RemoteApplicationManager(config, pluginRepository); + return new ApplicationManagerProviderServiceImpl(config, pluginRepository); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteApplicationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java similarity index 75% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteApplicationManager.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 493ae79d37..e08f6dedc0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteApplicationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -23,8 +23,10 @@ import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -35,6 +37,9 @@ import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; +import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; @@ -43,21 +48,23 @@ import java.rmi.RemoteException; import java.util.List; /** - * Implements AppManagerConnector interface + * Implements Application Manager interface + * */ -public class RemoteApplicationManager implements ApplicationManager { +public class ApplicationManagerProviderServiceImpl implements ApplicationManager { private ConfigurationContext configCtx; private ServiceAuthenticator authenticator; private String oAuthAdminServiceUrl; private DeviceManagementPluginRepository pluginRepository; + private DeviceDAO deviceDAO; private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1"; - private static final Log log = LogFactory.getLog(RemoteApplicationManager.class); + private static final Log log = LogFactory.getLog(ApplicationManagerProviderServiceImpl.class); - public RemoteApplicationManager(AppManagementConfig appManagementConfig, - DeviceManagementPluginRepository pluginRepository) { + public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig, + DeviceManagementPluginRepository pluginRepository) { IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). getDeviceManagementConfigRepository().getIdentityConfigurations(); @@ -72,11 +79,12 @@ public class RemoteApplicationManager implements ApplicationManager { "Please check if an appropriate axis2.xml is provided", e); } this.pluginRepository = pluginRepository; + this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); } @Override - public Application[] getApplications(String domain, int pageNumber, - int size) throws ApplicationManagementException { + public Application[] getApplications(String domain, int pageNumber, int size) + throws ApplicationManagementException { return new Application[0]; } @@ -88,7 +96,7 @@ public class RemoteApplicationManager implements ApplicationManager { @Override public String getApplicationStatus(DeviceIdentifier deviceId, - Application application) throws ApplicationManagementException { + Application application) throws ApplicationManagementException { return null; } @@ -96,11 +104,26 @@ public class RemoteApplicationManager implements ApplicationManager { public void installApplication(Operation operation, List deviceIds) throws ApplicationManagementException { - for(DeviceIdentifier deviceId: deviceIds){ - DeviceManagementService dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); - dms.installApplication(operation, deviceIds); - } + for (DeviceIdentifier deviceId : deviceIds) { + DeviceManagementService dms = + this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + dms.installApplication(operation, deviceIds); + } + } + + @Override + public void updateApplicationsForDevice(DeviceIdentifier deviceIdentifier, List applications) + throws ApplicationManagementException { + + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); + deviceDAO.addDeviceApplications(device.getId(), applications); + }catch (DeviceManagementDAOException deviceDaoEx){ + String errorMsg = "Error occurred saving application list to the device"; + log.error(errorMsg+":"+deviceIdentifier.toString()); + throw new ApplicationManagementException(errorMsg, deviceDaoEx); + } } private OAuthConsumerAppDTO getAppInfo() throws ApplicationManagementException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index a4ff6ad0d0..85af19c9b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.dao; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; import java.util.List; @@ -76,4 +77,5 @@ public interface DeviceDAO { */ List getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException; + void addDeviceApplications(int id, Object applications) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 8196b52b67..cbb17b90c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.OwnerShip; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; @@ -309,6 +310,28 @@ public class DeviceDAOImpl implements DeviceDAO { return deviceList; } + @Override + public void addDeviceApplications(int deviceId, Object appList) throws DeviceManagementDAOException { + + Connection conn; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String sql = "INSERT INTO DM_DEVICE_APPLICATIONS(DEVICE_ID, APPLICATIONS) " + + "VALUES (?, ?)"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, deviceId); + stmt.setObject(2, appList); + stmt.executeUpdate(); + + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while update application list for device " + + "'" + deviceId + "'", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, null); + } + } + private Device loadDevice(ResultSet rs) throws SQLException { Device device = new Device(); DeviceType deviceType = new DeviceType(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java index 02373c9c61..37e0736eb5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java @@ -23,7 +23,6 @@ import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Properties; -@XmlRootElement public class Operation implements Serializable { public enum Type { @@ -43,8 +42,8 @@ public class Operation implements Serializable { private String createdTimeStamp; private boolean isEnabled; private Object payLoad; + private Object operationResponse; - @XmlElement public String getCode() { return code; } @@ -53,7 +52,6 @@ public class Operation implements Serializable { this.code = code; } - @XmlElement public Properties getProperties() { return properties; } @@ -62,7 +60,6 @@ public class Operation implements Serializable { this.properties = properties; } - @XmlElement public Type getType() { return type; } @@ -119,5 +116,12 @@ public class Operation implements Serializable { this.payLoad = payLoad; } + public Object getOperationResponse() { + return operationResponse; + } + + public void setOperationResponse(Object operationResponse) { + this.operationResponse = operationResponse; + } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index a45280f843..baa49db7a3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -24,7 +24,6 @@ import org.osgi.service.component.ComponentContext; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.core.ServerStartupObserver; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.license.mgt.License; @@ -39,7 +38,7 @@ import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl; import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementServiceImpl; -import org.wso2.carbon.device.mgt.core.app.mgt.RemoteApplicationManager; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; @@ -54,15 +53,12 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF 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.util.DeviceManagementSchemaInitializer; -import org.wso2.carbon.device.mgt.user.core.UserManager; import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; /** * @scr.component name="org.wso2.carbon.device.manager" immediate="true" @@ -183,7 +179,7 @@ public class DeviceManagementServiceComponent { AppManagementConfig appConfig = AppManagementConfigurationManager.getInstance().getAppManagementConfig(); DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig); - RemoteApplicationManager appManager = new RemoteApplicationManager(appConfig, this.getPluginRepository()); + ApplicationManagerProviderServiceImpl appManager = new ApplicationManagerProviderServiceImpl(appConfig, this.getPluginRepository()); DeviceManagementDataHolder.getInstance().setAppManager(appManager); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 38a24616d2..148e32a124 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -258,38 +258,39 @@ public class OperationManagerImpl implements OperationManager { } @Override - public void updateOperation(DeviceIdentifier deviceId, int operationId, Operation.Status operationStatus) - throws OperationManagementException { + public void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException { + + int operationId = operation.getId(); if (log.isDebugEnabled()) { - log.debug("operation Id:" + operationId + " status:" + operationStatus); + log.debug("operation Id:" + operationId + " status:" + operation.getStatus()); } try { - org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = - operationDAO.getOperation(operationId); - if (dtoOperation == null) { - throw new OperationManagementException("Operation not found for operation id:" + operationId); - } - dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf - (operationStatus.toString())); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); Device device = deviceDAO.getDevice(deviceId, tenantId); - OperationManagementDAOFactory.beginTransaction(); - operationDAO.updateOperation(dtoOperation); - operationDAO.updateOperationStatus(device.getId(), operationId, - org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status - .valueOf(operationStatus.toString())); - OperationManagementDAOFactory.commitTransaction(); + if (operation.getStatus() !=null) { + OperationManagementDAOFactory.beginTransaction(); + operationDAO.updateOperationStatus(device.getId(), operationId, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status + .valueOf(operation.getStatus().toString())); + OperationManagementDAOFactory.commitTransaction(); + } + + if (operation.getOperationResponse() != null){ + OperationManagementDAOFactory.beginTransaction(); + operationDAO.addOperationResponse(device.getId(), operationId, operation.getOperationResponse()); + OperationManagementDAOFactory.commitTransaction(); + } } catch (OperationManagementDAOException ex) { try { OperationManagementDAOFactory.rollbackTransaction(); } catch (OperationManagementDAOException e1) { log.warn("Error occurred while roll-backing the update operation transaction", e1); } - log.error("Error occurred while updating the operation: " + operationId + " status:" + operationStatus, ex); + log.error("Error occurred while updating the operation: " + operationId + " status:" + operation.getStatus(), ex); throw new OperationManagementException("Error occurred while update operation", ex); } catch (DeviceManagementDAOException e) { log.error("Error occurred while fetch the device for device identifier: " + deviceId.getId() + " " + 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 91fb369f19..6cb4058a85 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 @@ -42,7 +42,9 @@ public interface OperationDAO { Operation getNextOperation(int deviceId) throws OperationManagementDAOException; - void updateOperationStatus(int deviceId, int operationId,Operation.Status status) throws - OperationManagementDAOException; + void updateOperationStatus(int deviceId, int operationId,Operation.Status status) + throws OperationManagementDAOException; + void addOperationResponse(int deviceId, int operationId, Object operationResponse) + 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/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 0d471b1a9d..48edd3111f 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 @@ -106,6 +106,27 @@ public class OperationDAOImpl implements OperationDAO { } + @Override + public void addOperationResponse(int deviceId, int operationId, Object operationResponse) + throws OperationManagementDAOException { + + PreparedStatement stmt = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + + stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," + + "OPERATION_RESPONSE) VALUES(?, ?, ?)"); + stmt.setInt(1, operationId); + stmt.setInt(2, deviceId); + stmt.setObject(3, operationResponse); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while inserting operation response", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt); + } + } + @Override public void deleteOperation(int id) throws OperationManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 34b1f91ad9..b1f3e28947 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import java.util.List; @@ -77,4 +78,13 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM */ List getDevicesByName(String deviceName) throws DeviceManagementException; + /** + * The method to get application list installed for the device. + * + * @param deviceIdentifier + * @return + * @throws DeviceManagementException + */ + List getApplicationListForDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index a480385016..a9dfd64fe7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -44,8 +45,7 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; -public class DeviceManagementProviderServiceImpl implements - DeviceManagementProviderService, PluginInitializationListener { +public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener { private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; @@ -349,7 +349,8 @@ public class DeviceManagementProviderServiceImpl implements EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); messageBuilder.append(messageHeader).append(System.getProperty("line.separator")); - messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter1.trim()); + messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append( + messageFooter1.trim()); messageBuilder.append(System.getProperty("line.separator")).append(messageFooter2.trim()); messageBuilder.append(System.getProperty("line.separator")).append(messageFooter3.trim()); @@ -475,10 +476,8 @@ public class DeviceManagementProviderServiceImpl implements } @Override - public void updateOperation(DeviceIdentifier deviceId, int operationId, Operation.Status operationStatus) - throws OperationManagementException { - DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(deviceId, operationId, - operationStatus); + public void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException { + DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(deviceId, operation); } @Override @@ -630,6 +629,12 @@ public class DeviceManagementProviderServiceImpl implements } + @Override + public List getApplicationListForDevice(DeviceIdentifier deviceIdentifier) + throws DeviceManagementException { + return null; + } + @Override public void registerDeviceManagementService(DeviceManagementService deviceManagementService) { try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java index 29fe4ea006..a6ba1dc0ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -124,4 +124,10 @@ public class TestDeviceManager implements DeviceManagementService { throws ApplicationManagementException { } + + @Override + public void updateApplicationsForDevice(DeviceIdentifier deviceIdentifier, List applications) + throws ApplicationManagementException { + + } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index c8d332cde4..b4bfe487a2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -76,6 +76,26 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); +CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NOT NULL, + OPERATION_RESPONSE BLOB DEFAULT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_operation_response_device FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES + DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATIONS ( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INTEGER NOT NULL, + APPLICATIONS BLOB DEFAULT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_applications_device FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, +); --- POLICY RELATED TABLES ----