mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
App Manager integration
This commit is contained in:
parent
79c268cb41
commit
a04658af14
@ -66,8 +66,12 @@ public interface ApplicationManager {
|
||||
throws ApplicationManagementException;
|
||||
|
||||
|
||||
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
|
||||
void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
|
||||
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;
|
||||
|
||||
public interface ApplicationManagementProviderService extends ApplicationManager {
|
||||
public interface ApplicationManagementProviderService extends ApplicationManager{
|
||||
|
||||
void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier,
|
||||
List<Application> applications) throws ApplicationManagementException;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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<DeviceIdentifier> deviceIds)
|
||||
public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> 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<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);
|
||||
}
|
||||
|
||||
public DeviceManagementPluginRepository getPluginRepository() {
|
||||
return pluginRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApplicationListInstalledInDevice(
|
||||
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 {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
||||
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
|
||||
|
||||
private static final Object LOCK = new Object();
|
||||
private static List<PluginInitializationListener> 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
|
||||
}
|
||||
|
||||
@ -77,7 +77,19 @@ public class TestDeviceManagementService implements DeviceManagementService {
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<AppManagementConfig>
|
||||
<Enabled>true</Enabled>
|
||||
<AppManagerUrl>http:/www.google.com</AppManagerUrl>
|
||||
</AppManagementConfig>
|
||||
<AppManagementConfig>
|
||||
<Enabled>true</Enabled>
|
||||
<AppManagerUrl>http:/www.google.com</AppManagerUrl>
|
||||
</AppManagementConfig>
|
||||
|
||||
@ -20,4 +20,6 @@
|
||||
<AppManagementConfig>
|
||||
<Enabled>true</Enabled>
|
||||
<AppManagerUrl>http:/www.google.com</AppManagerUrl>
|
||||
<ConsumerKey>http:/www.google.com</ConsumerKey>
|
||||
<ConsumerSecret>http:/www.google.com</ConsumerSecret>
|
||||
</AppManagementConfig>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user