From 2ae89bef5972c413696fb19d3251c2e33962a529 Mon Sep 17 00:00:00 2001 From: manoj Date: Mon, 11 May 2015 12:30:07 +0530 Subject: [PATCH] APP Manager Integration --- .../device/mgt/common/DeviceIdentifier.java | 5 +- .../common}/app/mgt/AppManagerConnector.java | 10 ++- .../app/mgt/AppManagerConnectorException.java | 2 +- .../device/mgt/common/spi/DeviceManager.java | 12 ++-- .../mgt/core/DeviceManagementRepository.java | 12 ++-- .../DeviceManagementServiceProviderImpl.java | 65 +++++++++---------- .../app/mgt/AppManagementServiceImpl.java | 18 +++-- .../app/mgt/AppManagerConnectorFactory.java | 16 ++++- .../app/mgt/RemoteAppManagerConnector.java | 28 +++++++- .../AppManagementConfigurationManager.java | 3 +- .../app/mgt/oauth/ServiceAuthenticator.java | 2 +- .../internal/DeviceManagementDataHolder.java | 11 +++- .../DeviceManagementServiceComponent.java | 43 ++++++------ .../core/service/DeviceManagementService.java | 1 + .../service/DeviceManagementServiceImpl.java | 2 +- .../core/DeviceManagementRepositoryTests.java | 5 +- .../device/mgt/core/TestDeviceManager.java | 17 +++-- 17 files changed, 159 insertions(+), 93 deletions(-) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/app/mgt/AppManagerConnector.java (88%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/app/mgt/AppManagerConnectorException.java (96%) 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 351fd1656b..66682fe6d9 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 @@ -17,7 +17,9 @@ */ package org.wso2.carbon.device.mgt.common; -public class DeviceIdentifier { +import java.io.Serializable; + +public class DeviceIdentifier implements Serializable{ private String id; private String type; @@ -29,7 +31,6 @@ public class DeviceIdentifier { public void setType(String type) { this.type = type; } - public String getId() { return id; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnector.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/AppManagerConnector.java similarity index 88% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnector.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/AppManagerConnector.java index df40342059..4223fae097 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnector.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/AppManagerConnector.java @@ -15,11 +15,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.app.mgt; +package org.wso2.carbon.device.mgt.common.app.mgt; +import org.wso2.carbon.device.mgt.common.Credential; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential; -import org.wso2.carbon.device.mgt.core.dto.Application; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import java.util.List; /** * This will handle the Application management side of MDM by acting a bridge between @@ -68,4 +69,7 @@ public interface AppManagerConnector { */ Credential getClientCredentials() throws AppManagerConnectorException; + void installApplication(Operation operation, List deviceIdentifiers) throws + AppManagerConnectorException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/AppManagerConnectorException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/AppManagerConnectorException.java index 3965d7570b..d6ba58a434 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/AppManagerConnectorException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.core.app.mgt; +package org.wso2.carbon.device.mgt.common.app.mgt; /** * Handles the exceptions related to Application management. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java index ab42c1894d..b90d04f550 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java @@ -18,7 +18,10 @@ package org.wso2.carbon.device.mgt.common.spi; -import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.FeatureManager; import java.util.List; @@ -31,14 +34,14 @@ public interface DeviceManager { /** * Method to retrieve the provider type that implements DeviceManager interface. * - * @return Returns provider type + * @return Returns provider type */ String getProviderType(); /** * Method to return feature manager implementation associated with a particular platform-specific plugin. * - * @return Returns an instance of feature manager + * @return Returns an instance of feature manager */ FeatureManager getFeatureManager(); @@ -110,7 +113,7 @@ public interface DeviceManager { * Method to retrieve metadata of a device corresponding to a particular type that carries a specific identifier. * * @param deviceId Fully qualified device identifier - * @return Metadata corresponding to a particular device + * @return Metadata corresponding to a particular device * @throws DeviceManagementException If some unusual behaviour is observed obtaining the device object */ Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; @@ -133,5 +136,4 @@ public interface DeviceManager { */ boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java index e2cd42c791..8b8e22b75e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java @@ -18,7 +18,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.spi.DeviceManager; +import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.util.HashMap; @@ -26,13 +26,13 @@ import java.util.Map; public class DeviceManagementRepository { - private Map providers; + private Map providers; public DeviceManagementRepository() { - providers = new HashMap(); + providers = new HashMap(); } - public void addDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException { + public void addDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException { String deviceType = provider.getProviderType(); try { DeviceManagerUtil.registerDeviceType(deviceType); @@ -43,7 +43,7 @@ public class DeviceManagementRepository { providers.put(deviceType, provider); } - public void removeDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException { + public void removeDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException { String deviceType = provider.getProviderType(); try { DeviceManagerUtil.unregisterDeviceType(deviceType); @@ -54,7 +54,7 @@ public class DeviceManagementRepository { providers.remove(deviceType); } - public DeviceManager getDeviceManagementProvider(String type) { + public DeviceMgtService getDeviceManagementProvider(String type) { return providers.get(type); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index e294a7bcf5..de39d9fbf3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -22,10 +22,8 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.*; 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.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; -import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages; @@ -37,9 +35,8 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.Status; import org.wso2.carbon.device.mgt.core.email.EmailConstants; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; @@ -54,8 +51,6 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; private DeviceManagementRepository pluginRepository; - private OperationManager operationManager; - private LicenseManager licenseManager; private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class); @@ -63,15 +58,11 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ this.pluginRepository = pluginRepository; this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - this.operationManager = new OperationManagerImpl(); - this.licenseManager = new LicenseManagerImpl(); } - public DeviceManagementServiceProviderImpl(){ + public DeviceManagementServiceProviderImpl() { this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - this.operationManager = new OperationManagerImpl(); - this.licenseManager = new LicenseManagerImpl(); } @Override @@ -104,7 +95,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceId.getId() + "' and type:"+deviceId.getType(), e); + "'" + deviceId.getId() + "' and type:" + deviceId.getType(), e); } return convertedDevice; } @@ -256,7 +247,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } @Override - public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { + public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) + throws DeviceManagementException { List notificationMessages = DeviceConfigurationManager.getInstance() .getNotificationMessagesConfig().getNotificationMessagesList(); @@ -267,9 +259,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ String url = ""; String subject = ""; - for(NotificationMessages notificationMessage : notificationMessages){ + for (NotificationMessages notificationMessage : notificationMessages) { if (DeviceManagementConstants.EmailNotifications.ENROL_NOTIFICATION_TYPE. - equals(notificationMessage.getType())) { + equals(notificationMessage.getType())) { messageHeader = notificationMessage.getHeader(); messageBody = notificationMessage.getBody(); messageFooter = notificationMessage.getFooter(); @@ -283,18 +275,18 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ try { messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}", - URLEncoder.encode(emailMessageProperties.getFirstName(), - EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); + URLEncoder.encode(emailMessageProperties.getFirstName(), + EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); - messageBuilder.append(messageHeader).append(System.getProperty("line.separator")); + messageBuilder.append(messageHeader).append(System.getProperty("line.separator")); messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter); } catch (IOException e) { - log.error("IO error in processing enrol email message "+emailMessageProperties); + log.error("IO error in processing enrol email message " + emailMessageProperties); throw new DeviceManagementException("Error replacing tags in email template '" + emailMessageProperties.getSubject() + "'", e); } @@ -314,9 +306,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ String url = ""; String subject = ""; - for(NotificationMessages notificationMessage : notificationMessages){ + for (NotificationMessages notificationMessage : notificationMessages) { if (DeviceManagementConstants.EmailNotifications.USER_REGISTRATION_NOTIFICATION_TYPE. - equals(notificationMessage.getType())) { + equals(notificationMessage.getType())) { messageHeader = notificationMessage.getHeader(); messageBody = notificationMessage.getBody(); messageFooter = notificationMessage.getFooter(); @@ -350,7 +342,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter); } catch (IOException e) { - log.error("IO error in processing enrol email message "+emailMessageProperties); + log.error("IO error in processing enrol email message " + emailMessageProperties); throw new DeviceManagementException("Error replacing tags in email template '" + emailMessageProperties.getSubject() + "'", e); } @@ -402,12 +394,12 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ @Override public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { - return licenseManager.getLicense(deviceType, languageCode); + return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode); } @Override public boolean addLicense(String type, License license) throws LicenseManagementException { - return licenseManager.addLicense(type, license); + return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(type, license); } public DeviceDAO getDeviceDAO() { @@ -425,55 +417,58 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ @Override public boolean addOperation(Operation operation, List devices) throws OperationManagementException { - return operationManager.addOperation(operation, devices); + return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices); } @Override public List getOperations(DeviceIdentifier deviceId) throws OperationManagementException { - return operationManager.getOperations(deviceId); + return DeviceManagementDataHolder.getInstance().getOperationManager().getOperations(deviceId); } @Override - public List getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException { - return operationManager.getPendingOperations(deviceId); + public List getPendingOperations(DeviceIdentifier deviceId) + throws OperationManagementException { + return DeviceManagementDataHolder.getInstance().getOperationManager().getPendingOperations(deviceId); } @Override public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { - return operationManager.getNextPendingOperation(deviceId); + return DeviceManagementDataHolder.getInstance().getOperationManager().getNextPendingOperation(deviceId); } @Override public void updateOperation(int operationId, Operation.Status operationStatus) throws OperationManagementException { - operationManager.updateOperation(operationId, operationStatus); + DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(operationId, operationStatus); } @Override public void deleteOperation(int operationId) throws OperationManagementException { - operationManager.deleteOperation(operationId); + DeviceManagementDataHolder.getInstance().getOperationManager().deleteOperation(operationId); } @Override public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId) throws OperationManagementException { - return operationManager.getOperationByDeviceAndOperationId(deviceId, operationId); + return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByDeviceAndOperationId( + deviceId, operationId); } @Override public List getOperationsByDeviceAndStatus(DeviceIdentifier identifier, Operation.Status status) throws OperationManagementException, DeviceManagementException { - return operationManager.getOperationsByDeviceAndStatus(identifier, status); + return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsByDeviceAndStatus(identifier, + status); } @Override public Operation getOperation(int operationId) throws OperationManagementException { - return operationManager.getOperation(operationId); + return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId); } @Override public List getOperationsForStatus(Operation.Status status) throws OperationManagementException { - return operationManager.getOperationsForStatus(status); + return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsForStatus(status); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java index fb653337ba..2823f6f521 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java @@ -17,16 +17,20 @@ */ package org.wso2.carbon.device.mgt.core.app.mgt; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.Credential; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential; -import org.wso2.carbon.device.mgt.core.dto.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; +import java.util.List; + public class AppManagementServiceImpl implements AppManagerConnector { @Override - public Application[] getApplicationList(String domain, int pageNumber, - int size) throws AppManagerConnectorException { + public Application[] getApplicationList(String domain, int pageNumber, int size) throws AppManagerConnectorException { return DeviceManagementDataHolder.getInstance().getAppManager().getApplicationList(domain, pageNumber, size); } @@ -48,4 +52,10 @@ public class AppManagementServiceImpl implements AppManagerConnector { return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials(); } + @Override + public void installApplication(Operation operation, List deviceIdentifiers) + throws AppManagerConnectorException { + DeviceManagementDataHolder.getInstance().getAppManager().installApplication(operation, deviceIdentifiers); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorFactory.java index 755c7f3148..884aa46dd5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorFactory.java @@ -18,12 +18,26 @@ */ package org.wso2.carbon.device.mgt.core.app.mgt; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; +import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; public class AppManagerConnectorFactory { + private static DeviceManagementRepository pluginRepository; + + public DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } + + public void setPluginRepository(DeviceManagementRepository pluginRepository) { + this.pluginRepository = pluginRepository; + } + + + public static AppManagerConnector getConnector(AppManagementConfig config) { - return new RemoteAppManagerConnector(config); + return new RemoteAppManagerConnector(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/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 548d9bef1a..b6c0f978a7 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 @@ -23,19 +23,25 @@ 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.device.mgt.common.Credential; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; 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.app.mgt.oauth.dto.Credential; 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.dto.Application; 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; import java.rmi.RemoteException; +import java.util.List; /** * Implements AppManagerConnector interface @@ -45,12 +51,14 @@ public class RemoteAppManagerConnector implements AppManagerConnector { private ConfigurationContext configCtx; private ServiceAuthenticator authenticator; private String oAuthAdminServiceUrl; + private DeviceManagementRepository pluginRepository; private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1"; private static final Log log = LogFactory.getLog(RemoteAppManagerConnector.class); - public RemoteAppManagerConnector(AppManagementConfig appManagementConfig) { + public RemoteAppManagerConnector(AppManagementConfig appManagementConfig, DeviceManagementRepository pluginRepository) { + IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). getDeviceManagementConfigRepository().getIdentityConfigurations(); this.authenticator = @@ -63,6 +71,7 @@ public class RemoteAppManagerConnector implements AppManagerConnector { throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " + "Please check if an appropriate axis2.xml is provided", e); } + this.pluginRepository = pluginRepository; } @Override @@ -93,6 +102,16 @@ public class RemoteAppManagerConnector implements AppManagerConnector { return credential; } + @Override + public void installApplication(Operation operation, List deviceIdentifiers) + throws AppManagerConnectorException { + + for(DeviceIdentifier deviceIdentifier:deviceIdentifiers){ + DeviceMgtService dms = this.getPluginRepository().getDeviceManagementProvider(deviceIdentifier.getType()); + dms.installApplication(operation,deviceIdentifiers); + } + } + private OAuthConsumerAppDTO getAppInfo() throws AppManagerConnectorException { OAuthConsumerAppDTO appInfo = null; try { @@ -133,4 +152,7 @@ public class RemoteAppManagerConnector implements AppManagerConnector { throw new AppManagerConnectorException(msg, e); } + public DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java index a2168cb343..88ef88e717 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java @@ -19,8 +19,7 @@ package org.wso2.carbon.device.mgt.core.app.mgt.config; import org.w3c.dom.Document; -import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; -import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.utils.CarbonUtils; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java index cacf5d8f81..abe3d3ba3f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.core.app.mgt.oauth; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.transport.http.HttpTransportProperties; -import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; /** * Authenticate a given service client. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 59bf153b06..30a619ea1e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -20,8 +20,9 @@ package org.wso2.carbon.device.mgt.core.internal; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; -import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnector; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; @@ -40,6 +41,7 @@ public class DeviceManagementDataHolder { private APIPublisherService apiPublisherService; private AppManagerConnector appManager; private AppManagementConfig appManagerConfig; + private OperationManager operationManager; private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); @@ -126,4 +128,11 @@ public class DeviceManagementDataHolder { this.appManagerConfig = appManagerConfig; } + public OperationManager getOperationManager() { + return operationManager; + } + + public void setOperationManager(OperationManager operationManager) { + this.operationManager = operationManager; + } } 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 edea9cf9f6..ab985dcda2 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 @@ -27,7 +27,10 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; +import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; @@ -35,8 +38,8 @@ 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.AppManagementServiceImpl; -import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnector; -import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager; @@ -47,6 +50,7 @@ import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; @@ -67,7 +71,7 @@ import java.util.List; * bind="setRealmService" * unbind="unsetRealmService" * @scr.reference name="device.manager.service" - * interface="org.wso2.carbon.device.mgt.common.spi.DeviceManager" + * interface="org.wso2.carbon.device.mgt.common.spi.DeviceMgtService" * cardinality="0..n" * policy="dynamic" * bind="setDeviceManager" @@ -98,14 +102,13 @@ public class DeviceManagementServiceComponent { private static final Object LOCK = new Object(); private boolean isInitialized; - private List deviceManagers = new ArrayList(); + private List deviceManagers = new ArrayList(); protected void activate(ComponentContext componentContext) { try { if (log.isDebugEnabled()) { log.debug("Initializing device management core bundle"); } - /* Initializing Device Management Configuration */ DeviceConfigurationManager.getInstance().initConfig(); DeviceManagementConfig config = @@ -114,15 +117,16 @@ public class DeviceManagementServiceComponent { DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig(); DeviceManagementDAOFactory.init(dsConfig); - DeviceManagementService deviceManagementProvider = - new DeviceManagementServiceProviderImpl(this.getPluginRepository()); - DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider); - /* Initializing license manager */ this.initLicenseManager(); + /*Initialize Operation Manager*/ + this.initOperationsManager(); /* Initializing app manager connector */ this.initAppManagerConnector(); + DeviceManagementService deviceManagementProvider = + new DeviceManagementServiceProviderImpl(this.getPluginRepository()); + DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider); OperationManagementDAOFactory.init(dsConfig); /* If -Dsetup option enabled then create device management database schema */ @@ -138,7 +142,7 @@ public class DeviceManagementServiceComponent { } synchronized (LOCK) { - for (DeviceManager deviceManager : deviceManagers) { + for (DeviceMgtService deviceManager : deviceManagers) { this.registerDeviceManagementProvider(deviceManager); } this.isInitialized = true; @@ -169,21 +173,20 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig); } + private void initOperationsManager() throws OperationManagementException { + OperationManager operationManager = new OperationManagerImpl(); + DeviceManagementDataHolder.getInstance().setOperationManager(operationManager); + } + private void initAppManagerConnector() throws AppManagerConnectorException { AppManagementConfigurationManager.getInstance().initConfig(); AppManagementConfig appConfig = AppManagementConfigurationManager.getInstance().getAppManagementConfig(); DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig); - RemoteAppManagerConnector appManager = new RemoteAppManagerConnector(appConfig); + RemoteAppManagerConnector appManager = new RemoteAppManagerConnector(appConfig,this.getPluginRepository()); DeviceManagementDataHolder.getInstance().setAppManager(appManager); } -// private void initAPIProviders() throws DeviceManagementException { -// for (APIConfig config : APIPublisherConfig.getInstance().getApiConfigs()) { -// config.init(); -// } -// } - private void registerServices(ComponentContext componentContext) { if (log.isDebugEnabled()) { log.debug("Registering OSGi service DeviceManagementServiceImpl"); @@ -231,7 +234,7 @@ public class DeviceManagementServiceComponent { } } - private void registerDeviceManagementProvider(DeviceManager deviceManager) { + private void registerDeviceManagementProvider(DeviceMgtService deviceManager) { try { this.getPluginRepository().addDeviceManagementProvider(deviceManager); } catch (DeviceManagementException e) { @@ -245,7 +248,7 @@ public class DeviceManagementServiceComponent { * * @param deviceManager An instance of DeviceManager */ - protected void setDeviceManager(DeviceManager deviceManager) { + protected void setDeviceManager(DeviceMgtService deviceManager) { if (log.isDebugEnabled()) { log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'"); } @@ -262,7 +265,7 @@ public class DeviceManagementServiceComponent { * * @param deviceManager An Instance of DeviceManager */ - protected void unsetDeviceManager(DeviceManager deviceManager) { + protected void unsetDeviceManager(DeviceMgtService deviceManager) { if (log.isDebugEnabled()) { log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 812e165c19..7a3af5b836 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index bb662a14c5..582fbe7214 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -23,7 +23,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; + import java.util.List; public class DeviceManagementServiceImpl implements DeviceManagementService { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java index 2b85365f2d..fdfd98ed28 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java @@ -22,6 +22,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; +import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; public class DeviceManagementRepositoryTests { @@ -34,7 +35,7 @@ public class DeviceManagementRepositoryTests { @Test public void testAddDeviceManagementService() { - DeviceManager sourceProvider = new TestDeviceManager(); + DeviceMgtService sourceProvider = new TestDeviceManager(); try { this.getRepository().addDeviceManagementProvider(sourceProvider); } catch (DeviceManagementException e) { @@ -47,7 +48,7 @@ public class DeviceManagementRepositoryTests { @Test(dependsOnMethods = "testAddDeviceManagementService") public void testRemoveDeviceManagementService() { - DeviceManager sourceProvider = new TestDeviceManager(); + DeviceMgtService sourceProvider = new TestDeviceManager(); try { this.getRepository().removeDeviceManagementProvider(sourceProvider); } catch (DeviceManagementException e) { 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 4c44ee0c59..4e89656757 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 @@ -17,15 +17,15 @@ */ package org.wso2.carbon.device.mgt.core; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.common.spi.DeviceManager; +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; import java.util.List; -public class TestDeviceManager implements DeviceManager { +public class TestDeviceManager implements DeviceMgtService { public static final String DEVICE_TYPE_TEST = "Test"; @@ -89,4 +89,9 @@ public class TestDeviceManager implements DeviceManager { return false; } + @Override + public void installApplication(Operation operation, List deviceIdentifiers) + throws AppManagerConnectorException { + + } }