App Manager integration

revert-70aa11f8
manoj 9 years ago
parent 79c268cb41
commit a04658af14

@ -66,8 +66,12 @@ public interface ApplicationManager {
throws ApplicationManagementException; throws ApplicationManagementException;
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws ApplicationManagementException; throws ApplicationManagementException;
void installApplicationForUsers(Operation operation, List<String> userNameList)
throws ApplicationManagementException;
void installApplicationForUserRoles(Operation operation, List<String> userRoleList)
throws ApplicationManagementException;
} }

@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import java.util.List; import java.util.List;
public interface ApplicationManagementProviderService extends ApplicationManager { public interface ApplicationManagementProviderService extends ApplicationManager{
void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier,
List<Application> applications) throws ApplicationManagementException; List<Application> applications) throws ApplicationManagementException;

@ -24,14 +24,8 @@ import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
public class ApplicationManagerFactory { public class ApplicationManagerFactory {
private static DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
public DeviceManagementPluginRepository getPluginRepository() {
return pluginRepository;
}
public static ApplicationManager getConnector(AppManagementConfig config) { public static ApplicationManager getConnector(AppManagementConfig config) {
return new ApplicationManagerProviderServiceImpl(config, pluginRepository); return new ApplicationManagerProviderServiceImpl(config);
} }
} }

@ -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.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; 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.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.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.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; 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.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; 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.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.OAuthAdminServiceException;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
@ -52,13 +51,11 @@ import java.util.List;
/** /**
* Implements Application Manager interface * Implements Application Manager interface
*/ */
public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService, public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService {
PluginInitializationListener {
private ConfigurationContext configCtx; private ConfigurationContext configCtx;
private ServiceAuthenticator authenticator; private ServiceAuthenticator authenticator;
private String oAuthAdminServiceUrl; private String oAuthAdminServiceUrl;
private DeviceManagementPluginRepository pluginRepository;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private ApplicationDAO applicationDAO; private ApplicationDAO applicationDAO;
private ApplicationMappingDAO applicationMappingDAO; 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 String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1";
private static final Log log = LogFactory.getLog(ApplicationManagerProviderServiceImpl.class); private static final Log log = LogFactory.getLog(ApplicationManagerProviderServiceImpl.class);
public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig, public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig) {
DeviceManagementPluginRepository pluginRepository) {
IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getDeviceManagementConfigRepository().getIdentityConfigurations(); getDeviceManagementConfigRepository().getIdentityConfigurations();
@ -81,14 +77,12 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " + throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " +
"Please check if an appropriate axis2.xml is provided", e); "Please check if an appropriate axis2.xml is provided", e);
} }
this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO(); this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO();
} }
ApplicationManagerProviderServiceImpl(DeviceManagementPluginRepository pluginRepository) { ApplicationManagerProviderServiceImpl() {
this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO(); this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO();
@ -113,13 +107,94 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
} }
@Override @Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIds) public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIds)
throws ApplicationManagementException { throws ApplicationManagementException {
for (DeviceIdentifier deviceId : deviceIds) { try {
DeviceManagementService dms = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, deviceIds);
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); } catch (OperationManagementException opeEx) {
dms.installApplication(operation, deviceIds); 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<String> userNameList)
throws ApplicationManagementException {
String userName = null;
try {
List<Device> deviceList;
List<DeviceIdentifier> 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<String> userRoleList)
throws ApplicationManagementException {
String userRole = null;
try {
List<Device> deviceList;
List<DeviceIdentifier> 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); throw new ApplicationManagementException(msg, e);
} }
public DeviceManagementPluginRepository getPluginRepository() {
return pluginRepository;
}
@Override @Override
public void updateApplicationListInstalledInDevice( public void updateApplicationListInstalledInDevice(
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException { DeviceIdentifier deviceIdentifier, List<Application> 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);
}
}
} }

@ -101,7 +101,6 @@ import java.util.List;
public class DeviceManagementServiceComponent { public class DeviceManagementServiceComponent {
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static List<PluginInitializationListener> listeners = new ArrayList<>(); private static List<PluginInitializationListener> listeners = new ArrayList<>();
@ -208,7 +207,7 @@ public class DeviceManagementServiceComponent {
AppManagementConfig appConfig = AppManagementConfig appConfig =
AppManagementConfigurationManager.getInstance().getAppManagementConfig(); AppManagementConfigurationManager.getInstance().getAppManagementConfig();
bundleContext.registerService(ApplicationManagementProviderService.class.getName(), bundleContext.registerService(ApplicationManagementProviderService.class.getName(),
new ApplicationManagerProviderServiceImpl(appConfig, pluginRepository), null); new ApplicationManagerProviderServiceImpl(appConfig), null);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application management service not registered.", e); log.error("Application management service not registered.", e);
} }
@ -309,10 +308,6 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setRegistryService(null); DeviceManagementDataHolder.getInstance().setRegistryService(null);
} }
private DeviceManagementPluginRepository getPluginRepository() {
return pluginRepository;
}
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
//do nothing //do nothing
} }

@ -77,7 +77,19 @@ public class TestDeviceManagementService implements DeviceManagementService {
} }
@Override @Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws ApplicationManagementException {
}
@Override
public void installApplicationForUsers(Operation operation, List<String> userNameList)
throws ApplicationManagementException {
}
@Override
public void installApplicationForUserRoles(Operation operation, List<String> userRoleList)
throws ApplicationManagementException { throws ApplicationManagementException {
} }

@ -83,7 +83,7 @@ public class ApplicationManagementProviderServiceTest {
deviceId.setType(device.getType()); deviceId.setType(device.getType());
AppManagementConfig appManagementConfig = new AppManagementConfig(); AppManagementConfig appManagementConfig = new AppManagementConfig();
appMgtProvider = new ApplicationManagerProviderServiceImpl(deviceManagementPluginRepository); appMgtProvider = new ApplicationManagerProviderServiceImpl();
try { try {
appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications); appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications);

@ -17,7 +17,7 @@
~ under the License. ~ under the License.
--> -->
<AppManagementConfig> <AppManagementConfig>
<Enabled>true</Enabled> <Enabled>true</Enabled>
<AppManagerUrl>http:/www.google.com</AppManagerUrl> <AppManagerUrl>http:/www.google.com</AppManagerUrl>
</AppManagementConfig> </AppManagementConfig>

@ -20,4 +20,6 @@
<AppManagementConfig> <AppManagementConfig>
<Enabled>true</Enabled> <Enabled>true</Enabled>
<AppManagerUrl>http:/www.google.com</AppManagerUrl> <AppManagerUrl>http:/www.google.com</AppManagerUrl>
<ConsumerKey>http:/www.google.com</ConsumerKey>
<ConsumerSecret>http:/www.google.com</ConsumerSecret>
</AppManagementConfig> </AppManagementConfig>

Loading…
Cancel
Save