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 a341768d17f..bf660566f82 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 @@ -66,8 +66,12 @@ public interface ApplicationManager { throws ApplicationManagementException; - void installApplication(Operation operation, List deviceIdentifiers) + void installApplicationForDevices(Operation operation, List deviceIdentifiers) throws ApplicationManagementException; + void installApplicationForUsers(Operation operation, List userNameList) + throws ApplicationManagementException; + void installApplicationForUserRoles(Operation operation, List userRoleList) + throws ApplicationManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java index e13f0cbfbf5..0ea859a1406 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java @@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import java.util.List; -public interface ApplicationManagementProviderService extends ApplicationManager { +public interface ApplicationManagementProviderService extends ApplicationManager{ void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, List applications) throws ApplicationManagementException; 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 e89563622e5..f0a11ad25dc 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 @@ -24,14 +24,8 @@ import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; public class ApplicationManagerFactory { - private static DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); - - public DeviceManagementPluginRepository getPluginRepository() { - return pluginRepository; - } - public static ApplicationManager getConnector(AppManagementConfig config) { - return new ApplicationManagerProviderServiceImpl(config, pluginRepository); + return new ApplicationManagerProviderServiceImpl(config); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index ea0ce55365d..6f63f034192 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -31,15 +31,14 @@ import org.wso2.carbon.device.mgt.common.TransactionManagementException; 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.operation.mgt.Operation; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; 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.*; -import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; 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; @@ -52,13 +51,11 @@ import java.util.List; /** * Implements Application Manager interface */ -public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService, - PluginInitializationListener { +public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService { private ConfigurationContext configCtx; private ServiceAuthenticator authenticator; private String oAuthAdminServiceUrl; - private DeviceManagementPluginRepository pluginRepository; private DeviceDAO deviceDAO; private ApplicationDAO applicationDAO; private ApplicationMappingDAO applicationMappingDAO; @@ -66,8 +63,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1"; private static final Log log = LogFactory.getLog(ApplicationManagerProviderServiceImpl.class); - public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig, - DeviceManagementPluginRepository pluginRepository) { + public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig) { IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). getDeviceManagementConfigRepository().getIdentityConfigurations(); @@ -81,14 +77,12 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " + "Please check if an appropriate axis2.xml is provided", e); } - this.pluginRepository = pluginRepository; this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO(); } - ApplicationManagerProviderServiceImpl(DeviceManagementPluginRepository pluginRepository) { - this.pluginRepository = pluginRepository; + ApplicationManagerProviderServiceImpl() { this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO(); @@ -102,24 +96,105 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem @Override public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, - String status) throws ApplicationManagementException { + String status) throws ApplicationManagementException { } @Override public String getApplicationStatus(DeviceIdentifier deviceId, - Application application) throws ApplicationManagementException { + Application application) throws ApplicationManagementException { return null; } @Override - public void installApplication(Operation operation, List deviceIds) + public void installApplicationForDevices(Operation operation, List deviceIds) throws ApplicationManagementException { - for (DeviceIdentifier deviceId : deviceIds) { - DeviceManagementService dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); - dms.installApplication(operation, deviceIds); + try { + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, deviceIds); + } catch (OperationManagementException opeEx) { + String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); + log.error(errorMsg, opeEx); + throw new ApplicationManagementException(errorMsg, opeEx); + } + } + + @Override + public void installApplicationForUsers(Operation operation, List userNameList) + throws ApplicationManagementException { + + String userName = null; + try { + List deviceList; + List deviceIdentifierList = new ArrayList<>(); + DeviceIdentifier deviceIdentifier; + + + + for (String user : userNameList) { + userName = user; + deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevicesOfUser + (user); + for (Device device : deviceList) { + deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(Integer.toString(device.getId())); + deviceIdentifier.setType(device.getType()); + + deviceIdentifierList.add(deviceIdentifier); + } + } + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .addOperation(operation, deviceIdentifierList); + + } catch (DeviceManagementException devEx) { + String errorMsg = "Error in get devices for user: "+userName+ " in app installation:" + devEx.getErrorMessage(); + log.error(errorMsg, devEx); + throw new ApplicationManagementException(errorMsg, devEx); + + } catch (OperationManagementException opeEx) { + String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); + log.error(errorMsg, opeEx); + throw new ApplicationManagementException(errorMsg, opeEx); + + } + } + + @Override + public void installApplicationForUserRoles(Operation operation, List userRoleList) + throws ApplicationManagementException { + + String userRole = null; + try { + List deviceList; + List deviceIdentifierList = new ArrayList<>(); + DeviceIdentifier deviceIdentifier; + + for (String role : userRoleList) { + userRole = role; + deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .getAllDevicesOfRole(userRole); + for (Device device : deviceList) { + deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(Integer.toString(device.getId())); + deviceIdentifier.setType(device.getType()); + + deviceIdentifierList.add(deviceIdentifier); + } + } + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .addOperation(operation, deviceIdentifierList); + + } catch (DeviceManagementException devEx) { + String errorMsg = "Error in get devices for user role "+userRole+ " in app installation:" + + devEx.getErrorMessage(); + log.error(errorMsg, devEx); + throw new ApplicationManagementException(errorMsg, devEx); + + } catch (OperationManagementException opeEx) { + String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); + log.error(errorMsg, opeEx); + throw new ApplicationManagementException(errorMsg, opeEx); + } } @@ -167,10 +242,6 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem throw new ApplicationManagementException(msg, e); } - public DeviceManagementPluginRepository getPluginRepository() { - return pluginRepository; - } - @Override public void updateApplicationListInstalledInDevice( DeviceIdentifier deviceIdentifier, List applications) throws ApplicationManagementException { @@ -256,24 +327,4 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem } } - @Override - public void registerDeviceManagementService(DeviceManagementService deviceManagementService) { - try { - pluginRepository.addDeviceManagementProvider(deviceManagementService); - } catch (DeviceManagementException e) { - log.error("Error occurred while registering device management plugin '" + - deviceManagementService.getType() + "'", e); - } - } - - @Override - public void unregisterDeviceManagementService(DeviceManagementService deviceManagementService) { - try { - pluginRepository.removeDeviceManagementProvider(deviceManagementService); - } catch (DeviceManagementException e) { - log.error("Error occurred while un-registering device management plugin '" + - deviceManagementService.getType() + "'", e); - } - } - } 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 646ca8b7965..7aa6bcf5383 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 @@ -101,7 +101,6 @@ import java.util.List; public class DeviceManagementServiceComponent { private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); - private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); private static final Object LOCK = new Object(); private static List listeners = new ArrayList<>(); @@ -208,7 +207,7 @@ public class DeviceManagementServiceComponent { AppManagementConfig appConfig = AppManagementConfigurationManager.getInstance().getAppManagementConfig(); bundleContext.registerService(ApplicationManagementProviderService.class.getName(), - new ApplicationManagerProviderServiceImpl(appConfig, pluginRepository), null); + new ApplicationManagerProviderServiceImpl(appConfig), null); } catch (ApplicationManagementException e) { log.error("Application management service not registered.", e); } @@ -309,10 +308,6 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setRegistryService(null); } - private DeviceManagementPluginRepository getPluginRepository() { - return pluginRepository; - } - protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { //do nothing } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index 0c3386fddf1..fa878e6327b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -77,7 +77,19 @@ public class TestDeviceManagementService implements DeviceManagementService { } @Override - public void installApplication(Operation operation, List deviceIdentifiers) + public void installApplicationForDevices(Operation operation, List deviceIdentifiers) + throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUsers(Operation operation, List userNameList) + throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUserRoles(Operation operation, List userRoleList) throws ApplicationManagementException { } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java index c5b69b3a176..b98745f8a2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java @@ -83,7 +83,7 @@ public class ApplicationManagementProviderServiceTest { deviceId.setType(device.getType()); AppManagementConfig appManagementConfig = new AppManagementConfig(); - appMgtProvider = new ApplicationManagerProviderServiceImpl(deviceManagementPluginRepository); + appMgtProvider = new ApplicationManagerProviderServiceImpl(); try { appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml index ef7a146cdd1..44b57d20d18 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml @@ -17,7 +17,7 @@ ~ under the License. --> - - true - http:/www.google.com - + + true + http:/www.google.com + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml index ef7a146cdd1..0297d0fca0d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml @@ -20,4 +20,6 @@ true http:/www.google.com + http:/www.google.com + http:/www.google.com