|
|
@ -24,8 +24,11 @@ import org.wso2.carbon.apimgt.api.APIManagementException;
|
|
|
|
import org.wso2.carbon.apimgt.api.APIProvider;
|
|
|
|
import org.wso2.carbon.apimgt.api.APIProvider;
|
|
|
|
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
|
|
|
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
|
|
|
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
|
|
|
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil;
|
|
|
|
|
|
|
|
import org.wso2.carbon.core.ServerStartupObserver;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.MobileDeviceManagementStartupObserver;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.APIConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.APIConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
|
|
@ -55,10 +58,10 @@ import java.util.List;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class MobileDeviceManagementServiceComponent {
|
|
|
|
public class MobileDeviceManagementServiceComponent {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String SETUP_COMMAND = "setup";
|
|
|
|
|
|
|
|
private ServiceRegistration androidServiceRegRef;
|
|
|
|
private ServiceRegistration androidServiceRegRef;
|
|
|
|
private ServiceRegistration iOSServiceRegRef;
|
|
|
|
private ServiceRegistration iOSServiceRegRef;
|
|
|
|
private ServiceRegistration windowsServiceRegRef;
|
|
|
|
private ServiceRegistration windowsServiceRegRef;
|
|
|
|
|
|
|
|
private ServiceRegistration serverStartupObserverRef;
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
|
|
|
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
|
|
|
|
|
|
|
|
|
|
|
@ -78,7 +81,7 @@ public class MobileDeviceManagementServiceComponent {
|
|
|
|
|
|
|
|
|
|
|
|
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
|
|
|
|
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
|
|
|
|
MobileDeviceManagementDAOFactory.init();
|
|
|
|
MobileDeviceManagementDAOFactory.init();
|
|
|
|
String setupOption = System.getProperty(SETUP_COMMAND);
|
|
|
|
String setupOption = System.getProperty("setup");
|
|
|
|
if (setupOption != null) {
|
|
|
|
if (setupOption != null) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug(
|
|
|
|
log.debug(
|
|
|
@ -89,9 +92,7 @@ public class MobileDeviceManagementServiceComponent {
|
|
|
|
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(
|
|
|
|
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(
|
|
|
|
MobileDeviceManagementDAOFactory.getDataSource());
|
|
|
|
MobileDeviceManagementDAOFactory.getDataSource());
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
log.error(
|
|
|
|
log.error("Exception occurred while initializing mobile device management database schema", e);
|
|
|
|
"Exception occurred while initializing mobile device management database schema",
|
|
|
|
|
|
|
|
e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -105,18 +106,13 @@ public class MobileDeviceManagementServiceComponent {
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
new WindowsDeviceManagerService(), null);
|
|
|
|
new WindowsDeviceManagerService(), null);
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize all API configurations with corresponding API Providers */
|
|
|
|
serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class,
|
|
|
|
this.initAPIConfigs();
|
|
|
|
new MobileDeviceManagementStartupObserver(), null);
|
|
|
|
/* Publish all mobile device management related JAX-RS services as APIs */
|
|
|
|
|
|
|
|
this.publishAPIs();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug(
|
|
|
|
log.debug("Mobile Device Management Service Component has been successfully activated");
|
|
|
|
"Mobile Device Management Service Component has been successfully activated");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
} catch (Throwable e) {
|
|
|
|
log.error("Error occurred while activating Mobile Device Management Service Component",
|
|
|
|
log.error("Error occurred while activating Mobile Device Management Service Component", e);
|
|
|
|
e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -125,11 +121,10 @@ public class MobileDeviceManagementServiceComponent {
|
|
|
|
log.debug("De-activating Mobile Device Management Service Component");
|
|
|
|
log.debug("De-activating Mobile Device Management Service Component");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
BundleContext bundleContext = ctx.getBundleContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
androidServiceRegRef.unregister();
|
|
|
|
androidServiceRegRef.unregister();
|
|
|
|
iOSServiceRegRef.unregister();
|
|
|
|
iOSServiceRegRef.unregister();
|
|
|
|
windowsServiceRegRef.unregister();
|
|
|
|
windowsServiceRegRef.unregister();
|
|
|
|
|
|
|
|
serverStartupObserverRef.unregister();
|
|
|
|
|
|
|
|
|
|
|
|
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
|
|
|
|
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
|
|
|
|
services */
|
|
|
|
services */
|
|
|
@ -143,32 +138,6 @@ public class MobileDeviceManagementServiceComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initAPIConfigs() throws DeviceManagementException {
|
|
|
|
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
APIProvider provider =
|
|
|
|
|
|
|
|
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
|
|
|
|
|
|
|
apiConfig.init(provider);
|
|
|
|
|
|
|
|
} catch (APIManagementException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Error occurred while initializing API Config '" +
|
|
|
|
|
|
|
|
apiConfig.getName() + "'", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void publishAPIs() throws DeviceManagementException {
|
|
|
|
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
|
|
|
|
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void removeAPIs() throws DeviceManagementException {
|
|
|
|
private void removeAPIs() throws DeviceManagementException {
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|