Code cleanup

revert-70aa11f8
prabathabey 10 years ago
parent 67c3c7f9a5
commit c13975191e

@ -1,44 +0,0 @@
/*
*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common;
/**
* DTO of the consumer key and secret
*/
public class Credential {
String consumerKey;
String consumerSecret;
public String getConsumerKey() {
return consumerKey;
}
public void setConsumerKey(String consumerKey) {
this.consumerKey = consumerKey;
}
public String getConsumerSecret() {
return consumerSecret;
}
public void setConsumerSecret(String consumerSecret) {
this.consumerSecret = consumerSecret;
}
}

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.common.spi; package org.wso2.carbon.device.mgt.common;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;

@ -1,77 +0,0 @@
/*
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.app.mgt;
import org.wso2.carbon.device.mgt.common.Application;
import org.wso2.carbon.device.mgt.common.Credential;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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
* MDM and App manager product.
*/
public interface AppManagerConnector {
/**
* This will communicate with App manager and retrieve the list of apps in the store, when
* the domain is given. The list is broken down into pages and retrieved.
*
* @param domain Tenant domain of the app list to be retrieved.
* @param pageNumber Page number of the list.
* @param size Number of items in one page.
* @return The list of applications belongs to a domain.
* @throws AppManagerConnectorException
*/
Application[] getApplicationList(String domain, int pageNumber, int size) throws AppManagerConnectorException;
/**
* Updates the application, install/uninstall status of the a certain application, on a device.
*
* @param deviceId Device id of the device that the status belongs to.
* @param application Application details of the app being updated.
* @param status Installed/Uninstalled
*/
void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
String status) throws AppManagerConnectorException;
/**
* Retrieve the status of an application on a device. Whether it is installed or not.
*
* @param deviceId Device id of the device that the status belongs to.
* @param application Application details of the app being searched.
* @return Status of the application on the device.
*/
String getApplicationStatus(DeviceIdentifier deviceId, Application application) throws AppManagerConnectorException;
/**
* Create a new application and return client Id and secret.
*
* @return consumer Id and consumer key.
* * @throws AppManagerConnectorException
*/
Credential getClientCredentials() throws AppManagerConnectorException;
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) throws
AppManagerConnectorException;
}

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.common; package org.wso2.carbon.device.mgt.common.app.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Platform; import org.wso2.carbon.device.mgt.common.Platform;

@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.common.app.mgt;
/** /**
* Handles the exceptions related to Application management. * Handles the exceptions related to Application management.
*/ */
public class AppManagerConnectorException extends Exception { public class ApplicationManagementException extends Exception {
private static final long serialVersionUID = -8933142342423122660L; private static final long serialVersionUID = -8933142342423122660L;
private String errorMessage; private String errorMessage;
@ -34,26 +34,26 @@ public class AppManagerConnectorException extends Exception {
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
} }
public AppManagerConnectorException(String msg, Exception nestedEx) { public ApplicationManagementException(String msg, Exception nestedEx) {
super(msg, nestedEx); super(msg, nestedEx);
setErrorMessage(msg); setErrorMessage(msg);
} }
public AppManagerConnectorException(String message, Throwable cause) { public ApplicationManagementException(String message, Throwable cause) {
super(message, cause); super(message, cause);
setErrorMessage(message); setErrorMessage(message);
} }
public AppManagerConnectorException(String msg) { public ApplicationManagementException(String msg) {
super(msg); super(msg);
setErrorMessage(msg); setErrorMessage(msg);
} }
public AppManagerConnectorException() { public ApplicationManagementException() {
super(); super();
} }
public AppManagerConnectorException(Throwable cause) { public ApplicationManagementException(Throwable cause) {
super(cause); super(cause);
} }

@ -0,0 +1,71 @@
/*
*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.app.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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
* MDM and App manager product.
*/
public interface ApplicationManager {
/**
* This will communicate with App manager and retrieve the list of apps in the store, when
* the domain is given. The list is broken down into pages and retrieved.
*
* @param domain Tenant domain of the app list to be retrieved.
* @param pageNumber Page number of the list.
* @param size Number of items in one page.
* @return The list of applications belongs to a domain.
* @throws ApplicationManagementException
*/
Application[] getApplications(String domain, int pageNumber, int size) throws ApplicationManagementException;
/**
* Updates the application, install/uninstall status of the a certain application, on a device.
*
* @param deviceId Device id of the device that the status belongs to.
* @param application Application details of the app being updated.
* @param status Installed/Uninstalled
*/
void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
String status) throws ApplicationManagementException;
/**
* Retrieve the status of an application on a device. Whether it is installed or not.
*
* @param deviceId Device id of the device that the status belongs to.
* @param application Application details of the app being searched.
* @return Status of the application on the device.
*/
String getApplicationStatus(DeviceIdentifier deviceId,
Application application) throws ApplicationManagementException;
void installApplication(Operation operation,
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException;
}

@ -1,33 +0,0 @@
/*
*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List;
public interface AppManager {
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException;
}

@ -0,0 +1,30 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
/**
* Composite interface that acts as the SPI exposing all device management as well as application management
* functionalities
*/
public interface DeviceManagementService extends DeviceManager, ApplicationManager {
}

@ -1,24 +0,0 @@
/*
*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.spi;
public interface DeviceMgtService extends DeviceManager, AppManager {
}

@ -18,7 +18,7 @@
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.Collection; import java.util.Collection;
@ -27,13 +27,13 @@ import java.util.Map;
public class DeviceManagementRepository { public class DeviceManagementRepository {
private Map<String, DeviceMgtService> providers; private Map<String, DeviceManagementService> providers;
public DeviceManagementRepository() { public DeviceManagementRepository() {
providers = new HashMap<String, DeviceMgtService>(); providers = new HashMap<String, DeviceManagementService>();
} }
public void addDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException { public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getProviderType();
try { try {
DeviceManagerUtil.registerDeviceType(deviceType); DeviceManagerUtil.registerDeviceType(deviceType);
@ -44,16 +44,16 @@ public class DeviceManagementRepository {
providers.put(deviceType, provider); providers.put(deviceType, provider);
} }
public void removeDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException { public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getProviderType();
providers.remove(deviceType); providers.remove(deviceType);
} }
public DeviceMgtService getDeviceManagementProvider(String type) { public DeviceManagementService getDeviceManagementProvider(String type) {
return providers.get(type); return providers.get(type);
} }
public Collection<DeviceMgtService> getDeviceManagementProviders(){ public Collection<DeviceManagementService> getDeviceManagementProviders(){
return providers.values(); return providers.values();
} }

@ -20,51 +20,47 @@ package org.wso2.carbon.device.mgt.core.app.mgt;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
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.operation.mgt.OperationManagementException; 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.internal.DeviceManagementDataHolder;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class AppManagementServiceImpl implements AppManagerConnector { public class ApplicationManagementServiceImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(AppManagementServiceImpl.class); private static final Log log = LogFactory.getLog(ApplicationManagementServiceImpl.class);
@Override @Override
public Application[] getApplicationList(String domain, int pageNumber, int size) throws AppManagerConnectorException { public Application[] getApplications(String domain, int pageNumber,
return DeviceManagementDataHolder.getInstance().getAppManager().getApplicationList(domain, pageNumber, size); int size) throws ApplicationManagementException {
return DeviceManagementDataHolder.getInstance().getAppManager().getApplications(domain, pageNumber, size);
} }
@Override @Override
public void updateApplicationStatus( public void updateApplicationStatus(
DeviceIdentifier deviceId, Application application, String status) throws AppManagerConnectorException { DeviceIdentifier deviceId, Application application, String status) throws ApplicationManagementException {
DeviceManagementDataHolder.getInstance().getAppManager().updateApplicationStatus(deviceId, application, status); DeviceManagementDataHolder.getInstance().getAppManager().updateApplicationStatus(deviceId, application, status);
} }
@Override @Override
public String getApplicationStatus(DeviceIdentifier deviceId, public String getApplicationStatus(DeviceIdentifier deviceId,
Application application) throws AppManagerConnectorException { Application application) throws ApplicationManagementException {
return null; return null;
} }
@Override
public Credential getClientCredentials() throws AppManagerConnectorException {
return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials();
}
@Override @Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException { throws ApplicationManagementException {
try { try {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation,
deviceIdentifiers); deviceIdentifiers);
} catch (OperationManagementException opMgtEx) { } catch (OperationManagementException opMgtEx) {
String errorMsg = "Error occurred when add operations at install application"; String errorMsg = "Error occurred when add operations at install application";
log.error(errorMsg, opMgtEx); log.error(errorMsg, opMgtEx);
throw new AppManagerConnectorException(); throw new ApplicationManagementException();
} }
DeviceManagementDataHolder.getInstance().getAppManager().installApplication(operation, deviceIdentifiers); DeviceManagementDataHolder.getInstance().getAppManager().installApplication(operation, deviceIdentifiers);
} }

@ -18,11 +18,11 @@
*/ */
package org.wso2.carbon.device.mgt.core.app.mgt; 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.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; 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.config.AppManagementConfig;
public class AppManagerConnectorFactory { public class ApplicationManagerFactory {
private static DeviceManagementRepository pluginRepository; private static DeviceManagementRepository pluginRepository;
@ -36,8 +36,8 @@ public class AppManagerConnectorFactory {
public static AppManagerConnector getConnector(AppManagementConfig config) { public static ApplicationManager getConnector(AppManagementConfig config) {
return new RemoteAppManagerConnector(config, pluginRepository); return new RemoteApplicationManager(config, pluginRepository);
} }
} }

@ -23,13 +23,12 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Application; 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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
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.DeviceMgtService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; 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.config.AppManagementConfig;
@ -46,7 +45,7 @@ import java.util.List;
/** /**
* Implements AppManagerConnector interface * Implements AppManagerConnector interface
*/ */
public class RemoteAppManagerConnector implements AppManagerConnector { public class RemoteApplicationManager implements ApplicationManager {
private ConfigurationContext configCtx; private ConfigurationContext configCtx;
private ServiceAuthenticator authenticator; private ServiceAuthenticator authenticator;
@ -55,9 +54,9 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
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(RemoteAppManagerConnector.class); private static final Log log = LogFactory.getLog(RemoteApplicationManager.class);
public RemoteAppManagerConnector(AppManagementConfig appManagementConfig, DeviceManagementRepository pluginRepository) { public RemoteApplicationManager(AppManagementConfig appManagementConfig, DeviceManagementRepository pluginRepository) {
IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getDeviceManagementConfigRepository().getIdentityConfigurations(); getDeviceManagementConfigRepository().getIdentityConfigurations();
@ -75,44 +74,35 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
} }
@Override @Override
public Application[] getApplicationList(String domain, int pageNumber, public Application[] getApplications(String domain, int pageNumber,
int size) throws AppManagerConnectorException { int size) throws ApplicationManagementException {
return new Application[0]; return new Application[0];
} }
@Override @Override
public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, public void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
String status) throws AppManagerConnectorException{ String status) throws ApplicationManagementException {
} }
@Override @Override
public String getApplicationStatus(DeviceIdentifier deviceId, public String getApplicationStatus(DeviceIdentifier deviceId,
Application application) throws AppManagerConnectorException { Application application) throws ApplicationManagementException {
return null; return null;
} }
@Override
public Credential getClientCredentials() throws AppManagerConnectorException {
OAuthConsumerAppDTO appInfo = this.getAppInfo();
Credential credential = new Credential();
credential.setConsumerKey(appInfo.getOauthConsumerKey());
credential.setConsumerSecret(appInfo.getOauthConsumerSecret());
return credential;
}
@Override @Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException { throws ApplicationManagementException {
for(DeviceIdentifier deviceIdentifier:deviceIdentifiers){ for(DeviceIdentifier deviceIdentifier:deviceIdentifiers){
DeviceMgtService dms = this.getPluginRepository().getDeviceManagementProvider(deviceIdentifier.getType()); DeviceManagementService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceIdentifier.getType());
dms.installApplication(operation,deviceIdentifiers); dms.installApplication(operation,deviceIdentifiers);
} }
} }
private OAuthConsumerAppDTO getAppInfo() throws AppManagerConnectorException { private OAuthConsumerAppDTO getAppInfo() throws ApplicationManagementException {
OAuthConsumerAppDTO appInfo = null; OAuthConsumerAppDTO appInfo = null;
try { try {
OAuthAdminServiceStub oAuthAdminServiceStub = OAuthAdminServiceStub oAuthAdminServiceStub =
@ -147,9 +137,9 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
return appDTO; return appDTO;
} }
private void handleException(String msg, Exception e) throws AppManagerConnectorException { private void handleException(String msg, Exception e) throws ApplicationManagementException {
log.error(msg, e); log.error(msg, e);
throw new AppManagerConnectorException(msg, e); throw new ApplicationManagementException(msg, e);
} }
public DeviceManagementRepository getPluginRepository() { public DeviceManagementRepository getPluginRepository() {

@ -19,7 +19,7 @@
package org.wso2.carbon.device.mgt.core.app.mgt.config; package org.wso2.carbon.device.mgt.core.app.mgt.config;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
@ -47,7 +47,7 @@ public class AppManagementConfigurationManager {
return appManagementConfigManager; return appManagementConfigManager;
} }
public synchronized void initConfig() throws AppManagerConnectorException { public synchronized void initConfig() throws ApplicationManagementException {
try { try {
File appManagementConfig = File appManagementConfig =
new File(AppManagementConfigurationManager.APP_MANAGER_CONFIG_PATH); new File(AppManagementConfigurationManager.APP_MANAGER_CONFIG_PATH);
@ -60,7 +60,7 @@ public class AppManagementConfigurationManager {
} catch (Exception e) { } catch (Exception e) {
/* Catches generic exception as there's no specific task to be carried out catching a particular /* Catches generic exception as there's no specific task to be carried out catching a particular
exception */ exception */
throw new AppManagerConnectorException( throw new ApplicationManagementException(
"Error occurred while initializing application management Configurations", e); "Error occurred while initializing application management Configurations", e);
} }
} }

@ -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.Options;
import org.apache.axis2.client.ServiceClient; import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HttpTransportProperties; import org.apache.axis2.transport.http.HttpTransportProperties;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
/** /**
* Authenticate a given service client. * Authenticate a given service client.
@ -36,7 +36,7 @@ public class ServiceAuthenticator {
this.password = password; this.password = password;
} }
public void authenticate(ServiceClient client) throws AppManagerConnectorException { public void authenticate(ServiceClient client) throws ApplicationManagementException {
Options option = client.getOptions(); Options option = client.getOptions();
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername(username); auth.setUsername(username);

@ -19,28 +19,28 @@
package org.wso2.carbon.device.mgt.core.internal; package org.wso2.carbon.device.mgt.core.internal;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; 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.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
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.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.user.core.UserManager;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager; import org.wso2.carbon.user.core.tenant.TenantManager;
import org.wso2.carbon.device.mgt.user.core.UserManager;
public class DeviceManagementDataHolder { public class DeviceManagementDataHolder {
private RealmService realmService; private RealmService realmService;
private TenantManager tenantManager; private TenantManager tenantManager;
private DeviceManagementService deviceManagerProvider; private DeviceManagementProviderService deviceManagerProvider;
private LicenseManager licenseManager; private LicenseManager licenseManager;
private RegistryService registryService; private RegistryService registryService;
private LicenseConfig licenseConfig; private LicenseConfig licenseConfig;
private APIPublisherService apiPublisherService; private APIPublisherService apiPublisherService;
private AppManagerConnector appManager; private ApplicationManager appManager;
private AppManagementConfig appManagerConfig; private AppManagementConfig appManagerConfig;
private OperationManager operationManager; private OperationManager operationManager;
private UserManager userManager; private UserManager userManager;
@ -74,11 +74,11 @@ public class DeviceManagementDataHolder {
return tenantManager; return tenantManager;
} }
public DeviceManagementService getDeviceManagementProvider() { public DeviceManagementProviderService getDeviceManagementProvider() {
return deviceManagerProvider; return deviceManagerProvider;
} }
public void setDeviceManagementProvider(DeviceManagementService deviceManagerProvider) { public void setDeviceManagementProvider(DeviceManagementProviderService deviceManagerProvider) {
this.deviceManagerProvider = deviceManagerProvider; this.deviceManagerProvider = deviceManagerProvider;
} }
@ -114,11 +114,11 @@ public class DeviceManagementDataHolder {
this.apiPublisherService = apiPublisherService; this.apiPublisherService = apiPublisherService;
} }
public AppManagerConnector getAppManager() { public ApplicationManager getAppManager() {
return appManager; return appManager;
} }
public void setAppManager(AppManagerConnector appManager) { public void setAppManager(ApplicationManager appManager) {
this.appManager = appManager; this.appManager = appManager;
} }

@ -24,22 +24,21 @@ import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.core.ServerStartupObserver; 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.app.mgt.AppManagerConnector; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.license.mgt.License; 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.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; 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.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; 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.APIPublisherServiceImpl;
import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver; 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.ApplicationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector; import org.wso2.carbon.device.mgt.core.app.mgt.RemoteApplicationManager;
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.config.AppManagementConfigurationManager; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
@ -51,11 +50,10 @@ 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.license.mgt.LicenseManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; 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.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.device.mgt.user.core.UserManager; import org.wso2.carbon.device.mgt.user.core.UserManager;
import org.wso2.carbon.device.mgt.user.core.service.UserManagementService;
import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
@ -72,7 +70,7 @@ import java.util.List;
* bind="setRealmService" * bind="setRealmService"
* unbind="unsetRealmService" * unbind="unsetRealmService"
* @scr.reference name="device.manager.service" * @scr.reference name="device.manager.service"
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceMgtService" * interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagementService"
* cardinality="0..n" * cardinality="0..n"
* policy="dynamic" * policy="dynamic"
* bind="setDeviceManager" * bind="setDeviceManager"
@ -109,7 +107,7 @@ public class DeviceManagementServiceComponent {
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private boolean isInitialized; private boolean isInitialized;
private List<DeviceMgtService> deviceManagers = new ArrayList<DeviceMgtService>(); private List<DeviceManagementService> deviceManagementServices = new ArrayList<DeviceManagementService>();
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
try { try {
@ -131,8 +129,8 @@ public class DeviceManagementServiceComponent {
/* Initializing app manager connector */ /* Initializing app manager connector */
this.initAppManagerConnector(); this.initAppManagerConnector();
DeviceManagementService deviceManagementProvider = DeviceManagementProviderService deviceManagementProvider =
new DeviceManagementServiceProviderImpl(this.getPluginRepository()); new DeviceManagementProviderServiceImpl(this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
OperationManagementDAOFactory.init(dsConfig); OperationManagementDAOFactory.init(dsConfig);
@ -149,8 +147,8 @@ public class DeviceManagementServiceComponent {
} }
synchronized (LOCK) { synchronized (LOCK) {
for (DeviceMgtService deviceManager : deviceManagers) { for (DeviceManagementService deviceManagementService : deviceManagementServices) {
this.registerDeviceManagementProvider(deviceManager); this.registerDeviceManagementProvider(deviceManagementService);
} }
this.isInitialized = true; this.isInitialized = true;
} }
@ -185,23 +183,23 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager); DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
} }
private void initAppManagerConnector() throws AppManagerConnectorException { private void initAppManagerConnector() throws ApplicationManagementException {
AppManagementConfigurationManager.getInstance().initConfig(); AppManagementConfigurationManager.getInstance().initConfig();
AppManagementConfig appConfig = AppManagementConfig appConfig =
AppManagementConfigurationManager.getInstance().getAppManagementConfig(); AppManagementConfigurationManager.getInstance().getAppManagementConfig();
DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig); DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig);
RemoteAppManagerConnector appManager = new RemoteAppManagerConnector(appConfig, this.getPluginRepository()); RemoteApplicationManager appManager = new RemoteApplicationManager(appConfig, this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setAppManager(appManager); DeviceManagementDataHolder.getInstance().setAppManager(appManager);
} }
private void registerServices(ComponentContext componentContext) { private void registerServices(ComponentContext componentContext) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Registering OSGi service DeviceManagementServiceImpl"); log.debug("Registering OSGi service DeviceManagementProviderServiceImpl");
} }
/* Registering Device Management Service */ /* Registering Device Management Service */
BundleContext bundleContext = componentContext.getBundleContext(); BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(DeviceManagementService.class.getName(), bundleContext.registerService(DeviceManagementProviderService.class.getName(),
new DeviceManagementServiceImpl(), null); new DeviceManagementProviderServiceImpl(), null);
APIPublisherService publisher = new APIPublisherServiceImpl(); APIPublisherService publisher = new APIPublisherServiceImpl();
DeviceManagementDataHolder.getInstance().setApiPublisherService(publisher); DeviceManagementDataHolder.getInstance().setApiPublisherService(publisher);
@ -210,7 +208,7 @@ public class DeviceManagementServiceComponent {
bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null); bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null);
/* Registering App Management service */ /* Registering App Management service */
bundleContext.registerService(AppManagerConnector.class.getName(), new AppManagementServiceImpl(), null); bundleContext.registerService(ApplicationManager.class.getName(), new ApplicationManagementServiceImpl(), null);
} }
private void setupDeviceManagementSchema(DataSourceConfig config) private void setupDeviceManagementSchema(DataSourceConfig config)
@ -241,12 +239,12 @@ public class DeviceManagementServiceComponent {
} }
} }
private void registerDeviceManagementProvider(DeviceMgtService deviceManager) { private void registerDeviceManagementProvider(DeviceManagementService deviceManagementService) {
try { try {
this.getPluginRepository().addDeviceManagementProvider(deviceManager); this.getPluginRepository().addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while adding device management provider '" + log.error("Error occurred while adding device management provider '" +
deviceManager.getProviderType() + "'"); deviceManagementService.getProviderType() + "'");
} }
} }
@ -255,7 +253,7 @@ public class DeviceManagementServiceComponent {
* *
* @param deviceManager An instance of DeviceManager * @param deviceManager An instance of DeviceManager
*/ */
protected void setDeviceManager(DeviceMgtService deviceManager) { protected void setDeviceManager(DeviceManagementService deviceManager) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'"); log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'");
} }
@ -263,7 +261,7 @@ public class DeviceManagementServiceComponent {
if (isInitialized) { if (isInitialized) {
this.registerDeviceManagementProvider(deviceManager); this.registerDeviceManagementProvider(deviceManager);
} }
deviceManagers.add(deviceManager); deviceManagementServices.add(deviceManager);
} }
} }
@ -272,7 +270,7 @@ public class DeviceManagementServiceComponent {
* *
* @param deviceManager An Instance of DeviceManager * @param deviceManager An Instance of DeviceManager
*/ */
protected void unsetDeviceManager(DeviceMgtService deviceManager) { protected void unsetDeviceManager(DeviceManagementService deviceManager) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Un setting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); log.debug("Un setting Device Management Service Provider : '" + deviceManager.getProviderType() + "'");
} }

@ -24,7 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; 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.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.governance.api.exception.GovernanceException; import org.wso2.carbon.governance.api.exception.GovernanceException;
import org.wso2.carbon.governance.api.generic.GenericArtifactFilter; import org.wso2.carbon.governance.api.generic.GenericArtifactFilter;
@ -39,7 +39,7 @@ import java.util.Locale;
public class LicenseManagerImpl implements LicenseManager { public class LicenseManagerImpl implements LicenseManager {
private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class); private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
@Override @Override

@ -0,0 +1,22 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.operation.mgt;
public interface OperationManagementServiceProvider {
}

@ -20,20 +20,21 @@ package org.wso2.carbon.device.mgt.core.operation.mgt;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
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.operation.mgt.OperationManagementException; 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.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
import org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationCreateTimeComparator; import org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationCreateTimeComparator;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -54,7 +55,7 @@ public class OperationManagerImpl implements OperationManager {
private OperationDAO policyOperationDAO; private OperationDAO policyOperationDAO;
private OperationMappingDAO operationMappingDAO; private OperationMappingDAO operationMappingDAO;
private OperationDAO operationDAO; private OperationDAO operationDAO;
private DeviceManagementService deviceManagementService; private DeviceDAO deviceDAO;
public OperationManagerImpl() { public OperationManagerImpl() {
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
@ -63,16 +64,16 @@ public class OperationManagerImpl implements OperationManager {
policyOperationDAO = OperationManagementDAOFactory.getPolicyOperationDAO(); policyOperationDAO = OperationManagementDAOFactory.getPolicyOperationDAO();
operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO(); operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO();
operationDAO = OperationManagementDAOFactory.getOperationDAO(); operationDAO = OperationManagementDAOFactory.getOperationDAO();
deviceManagementService = new DeviceManagementServiceImpl(); deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
} }
@Override @Override
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws public boolean addOperation(Operation operation,
OperationManagementException { List<DeviceIdentifier> deviceIdentifiers) throws OperationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("operation:[" + operation.toString() + "]"); log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : devices) { for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType() log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType()
+ "]"); + "]");
} }
@ -83,10 +84,10 @@ public class OperationManagerImpl implements OperationManager {
OperationDAOUtil.convertOperation(operation); OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
org.wso2.carbon.device.mgt.common.Device device;
for (DeviceIdentifier deviceIdentifier : devices) { Device device;
device = deviceManagementService.getCoreDevice(deviceIdentifier); for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
device = deviceDAO.getDevice(deviceIdentifier);
if (device == null) { if (device == null) {
String errorMsg = "The operation not added for device.The device not found for " + String errorMsg = "The operation not added for device.The device not found for " +
"device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" + "device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" +
@ -99,22 +100,19 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
return true; return true;
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
log.error("Error occurred while adding operation: ", e);
try { try {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
} catch (OperationManagementDAOException e1) { } catch (OperationManagementDAOException e1) {
log.warn("Error occurred while roll-backing the transaction", e1); log.warn("Error occurred while roll-backing the transaction", e1);
} }
throw new OperationManagementException("Error occurred while adding operation", e); throw new OperationManagementException("Error occurred while adding operation", e);
} catch (DeviceManagementException deviceMgtEx) { } catch (DeviceManagementDAOException e) {
try { try {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
} catch (OperationManagementDAOException e1) { } catch (OperationManagementDAOException e1) {
log.warn("Error occurred while roll-backing the transaction", e1); log.warn("Error occurred while roll-backing the transaction", e1);
} }
String errorMsg = "Error occurred fetching devices "; throw new OperationManagementException("Error occurred while retrieving device metadata", e);
log.error(deviceMgtEx.getErrorMessage(), deviceMgtEx);
throw new OperationManagementException(errorMsg, deviceMgtEx);
} }
} }
@ -124,16 +122,12 @@ public class OperationManagerImpl implements OperationManager {
try { try {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
org.wso2.carbon.device.mgt.common.Device device; Device device = null;
try { try {
device = deviceManagementService.getCoreDevice(deviceIdentifier); device = deviceDAO.getDevice(deviceIdentifier);
} catch (DeviceManagementException deviceMgtEx) { } catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while retrieving the device " + e.printStackTrace();
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" +
deviceIdentifier.getId();
log.error(errorMsg, deviceMgtEx);
throw new OperationManagementException(errorMsg, deviceMgtEx);
} }
if (device == null) { if (device == null) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
@ -163,7 +157,7 @@ public class OperationManagerImpl implements OperationManager {
+ "]"); + "]");
} }
org.wso2.carbon.device.mgt.common.Device device; Device device;
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
@ -171,7 +165,7 @@ public class OperationManagerImpl implements OperationManager {
try { try {
device = deviceManagementService.getCoreDevice(deviceIdentifier); device = deviceDAO.getDevice(deviceIdentifier);
if (device == null) { if (device == null) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
@ -197,16 +191,16 @@ public class OperationManagerImpl implements OperationManager {
} }
Collections.sort(operations, new OperationCreateTimeComparator()); Collections.sort(operations, new OperationCreateTimeComparator());
return operations; return operations;
} catch (DeviceManagementException deviceMgtException) {
String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
+ deviceIdentifier.getId();
log.error(errorMsg, deviceMgtException);
throw new OperationManagementException(errorMsg, deviceMgtException);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"pending operations assigned for '" + deviceIdentifier.getType() + "' device '" + "pending operations assigned for '" + deviceIdentifier.getType() + "' device '" +
deviceIdentifier.getId() + "'", e); deviceIdentifier.getId() + "'", e);
} catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
+ deviceIdentifier.getId();
log.error(errorMsg, e);
throw new OperationManagementException(errorMsg, e);
} }
} }
@ -220,7 +214,7 @@ public class OperationManagerImpl implements OperationManager {
Operation operation = null; Operation operation = null;
Device device; Device device;
try { try {
device = deviceManagementService.getCoreDevice(deviceIdentifier); device = deviceDAO.getDevice(deviceIdentifier);
if (device == null) { if (device == null) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
@ -249,14 +243,14 @@ public class OperationManagerImpl implements OperationManager {
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} }
return operation; return operation;
} catch (DeviceManagementException deviceMgtException) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
} catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while retrieving the device " + String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" "for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
+ deviceIdentifier.getId(); + deviceIdentifier.getId();
log.error(errorMsg, deviceMgtException); log.error(errorMsg, e);
throw new OperationManagementException(errorMsg, deviceMgtException); throw new OperationManagementException(errorMsg, e);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
} }
} }
@ -277,7 +271,7 @@ public class OperationManagerImpl implements OperationManager {
} }
dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf
(operationStatus.toString())); (operationStatus.toString()));
Device device = deviceManagementService.getCoreDevice(deviceIdentifier); Device device = deviceDAO.getDevice(deviceIdentifier);
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
operationDAO.updateOperation(dtoOperation); operationDAO.updateOperation(dtoOperation);
@ -285,11 +279,6 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
.valueOf(operationStatus.toString())); .valueOf(operationStatus.toString()));
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
} catch (DeviceManagementException ex) {
log.error("Error occurred while fetch the device for device identifier: " + deviceIdentifier.getId() + " " +
"type:" + deviceIdentifier.getType(), ex);
throw new OperationManagementException("Error occurred while update operation", ex);
} catch (OperationManagementDAOException ex) { } catch (OperationManagementDAOException ex) {
try { try {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
@ -298,6 +287,10 @@ public class OperationManagerImpl implements OperationManager {
} }
log.error("Error occurred while updating the operation: " + operationId + " status:" + operationStatus, ex); log.error("Error occurred while updating the operation: " + operationId + " status:" + operationStatus, ex);
throw new OperationManagementException("Error occurred while update operation", ex); throw new OperationManagementException("Error occurred while update operation", ex);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while fetch the device for device identifier: " + deviceIdentifier.getId() + " " +
"type:" + deviceIdentifier.getType(), e);
throw new OperationManagementException("Error occurred while update operation", e);
} }
} }
@ -331,7 +324,7 @@ public class OperationManagerImpl implements OperationManager {
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int operationId) public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int operationId)
throws OperationManagementException { throws OperationManagementException {
org.wso2.carbon.device.mgt.common.Device device; Device device;
Operation operation; Operation operation;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -342,7 +335,7 @@ public class OperationManagerImpl implements OperationManager {
} }
try { try {
device = deviceManagementService.getCoreDevice(deviceIdentifier); device = deviceDAO.getDevice(deviceIdentifier);
if (device == null) { if (device == null) {
throw new OperationManagementException("Device not found for given device identifier:" + throw new OperationManagementException("Device not found for given device identifier:" +
deviceIdentifier.getId() + " type:" + deviceIdentifier.getType()); deviceIdentifier.getId() + " type:" + deviceIdentifier.getType());
@ -373,16 +366,16 @@ public class OperationManagerImpl implements OperationManager {
" device" + " Id:" + device.getId()); " device" + " Id:" + device.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (DeviceManagementException deviceMgtException) {
String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
+ deviceIdentifier.getId();
log.error(errorMsg, deviceMgtException);
throw new OperationManagementException(errorMsg, deviceMgtException);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceIdentifier.getType() + "' device '" + deviceIdentifier.getId() "operations assigned for '" + deviceIdentifier.getType() + "' device '" + deviceIdentifier.getId()
+ "'", e); + "'", e);
} catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
+ deviceIdentifier.getId();
log.error(errorMsg, e);
throw new OperationManagementException(errorMsg, e);
} }
return operation; return operation;
} }
@ -396,7 +389,7 @@ public class OperationManagerImpl implements OperationManager {
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>(); new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>();
org.wso2.carbon.device.mgt.common.Device device = deviceManagementService.getCoreDevice(identifier); Device device = deviceDAO.getDevice(identifier);
if (device == null) { if (device == null) {
throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " + throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " +
@ -423,15 +416,15 @@ public class OperationManagerImpl implements OperationManager {
operations.add(operation); operations.add(operation);
} }
return operations; return operations;
} catch (DeviceManagementException deviceMgtException) {
String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + identifier.getType() + "' and device Id '" + identifier.getId();
log.error(errorMsg, deviceMgtException);
throw new OperationManagementException(errorMsg, deviceMgtException);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + identifier.getType() + "' device '" + "operations assigned for '" + identifier.getType() + "' device '" +
identifier.getId() + "' and status:" + status.toString(), e); identifier.getId() + "' and status:" + status.toString(), e);
} catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + identifier.getType() + "' and device Id '" + identifier.getId();
log.error(errorMsg, e);
throw new OperationManagementException(errorMsg, e);
} }
} }

@ -18,8 +18,7 @@
package org.wso2.carbon.device.mgt.core.service; package org.wso2.carbon.device.mgt.core.service;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector; import org.wso2.carbon.device.mgt.common.DeviceManager;
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.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import java.util.List; import java.util.List;
@ -28,7 +27,7 @@ import java.util.List;
* Proxy class for all Device Management related operations that take the corresponding plugin type in * Proxy class for all Device Management related operations that take the corresponding plugin type in
* and resolve the appropriate plugin implementation * and resolve the appropriate plugin implementation
*/ */
public interface DeviceManagementService extends DeviceManager, LicenseManager, OperationManager { public interface DeviceManagementProviderService extends DeviceManager, LicenseManager, OperationManager {
List<Device> getAllDevices(String type) throws DeviceManagementException; List<Device> getAllDevices(String type) throws DeviceManagementException;
@ -42,14 +41,6 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
FeatureManager getFeatureManager(String type) throws DeviceManagementException; FeatureManager getFeatureManager(String type) throws DeviceManagementException;
/**
* This method returns core device details.
* @param deviceId
* @return
* @throws DeviceManagementException
*/
Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
/** /**
* Method to get the list of devices owned by an user. * Method to get the list of devices owned by an user.
* *
@ -87,4 +78,5 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
* device list * device list
*/ */
List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementException; List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementException;
} }

@ -15,16 +15,17 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core.service;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.license.mgt.License; 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.LicenseManagementException;
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.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
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.email.NotificationMessages; import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
@ -32,11 +33,10 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; 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.*;
import org.wso2.carbon.device.mgt.core.email.EmailConstants; 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.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder; import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.io.IOException; import java.io.IOException;
@ -45,21 +45,21 @@ import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DeviceManagementServiceProviderImpl implements DeviceManagementService { public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService {
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private DeviceManagementRepository pluginRepository; private DeviceManagementRepository pluginRepository;
private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class); private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
public DeviceManagementServiceProviderImpl(DeviceManagementRepository pluginRepository) { public DeviceManagementProviderServiceImpl(DeviceManagementRepository pluginRepository) {
this.pluginRepository = pluginRepository; this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
} }
public DeviceManagementServiceProviderImpl() { public DeviceManagementProviderServiceImpl() {
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
} }
@ -81,24 +81,6 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
return dms.getFeatureManager(); return dms.getFeatureManager();
} }
@Override
public Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device convertedDevice = null;
try {
DeviceType deviceType = this.getDeviceTypeDAO().getDeviceType(deviceId.getType());
org.wso2.carbon.device.mgt.core.dto.Device device = this.getDeviceDAO().getDevice(deviceId);
if (device != null) {
convertedDevice = DeviceManagementDAOUtil.convertDevice(device,
this.getDeviceTypeDAO().getDeviceType(deviceType.getId()));
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
"'" + deviceId.getId() + "' and type:" + deviceId.getType(), e);
}
return convertedDevice;
}
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
@ -253,8 +235,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties)
throws DeviceManagementException { throws DeviceManagementException {
List<NotificationMessages> notificationMessages = DeviceConfigurationManager.getInstance() List<NotificationMessages> notificationMessages =
.getNotificationMessagesConfig().getNotificationMessagesList(); DeviceConfigurationManager.getInstance().getNotificationMessagesConfig().getNotificationMessagesList();
String messageHeader = ""; String messageHeader = "";
String messageBody = ""; String messageBody = "";
@ -265,8 +247,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
String subject = ""; String subject = "";
for (NotificationMessages notificationMessage : notificationMessages) { for (NotificationMessages notificationMessage : notificationMessages) {
if (DeviceManagementConstants.EmailNotifications.ENROL_NOTIFICATION_TYPE. if (org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailNotifications.ENROL_NOTIFICATION_TYPE.equals(
equals(notificationMessage.getType())) { notificationMessage.getType())) {
messageHeader = notificationMessage.getHeader(); messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody(); messageBody = notificationMessage.getBody();
messageFooter1 = notificationMessage.getFooterLine1(); messageFooter1 = notificationMessage.getFooterLine1();
@ -322,7 +304,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
String subject = ""; String subject = "";
for (NotificationMessages notificationMessage : notificationMessages) { for (NotificationMessages notificationMessage : notificationMessages) {
if (DeviceManagementConstants.EmailNotifications.USER_REGISTRATION_NOTIFICATION_TYPE. if (org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailNotifications.USER_REGISTRATION_NOTIFICATION_TYPE.
equals(notificationMessage.getType())) { equals(notificationMessage.getType())) {
messageHeader = notificationMessage.getHeader(); messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody(); messageBody = notificationMessage.getBody();
@ -499,7 +481,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
public List<Device> getAllDevicesOfUser(String userName) public List<Device> getAllDevicesOfUser(String userName)
throws DeviceManagementException { throws DeviceManagementException {
List<Device> devicesOfUser = new ArrayList<Device>(); List<Device> devicesOfUser = new ArrayList<Device>();
List<org.wso2.carbon.device.mgt.core.dto.Device> devicesList; List<org.wso2.carbon.device.mgt.core.dto.Device> devices;
Device convertedDevice; Device convertedDevice;
DeviceIdentifier deviceIdentifier; DeviceIdentifier deviceIdentifier;
DeviceManager dms; DeviceManager dms;
@ -508,15 +490,15 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
int tenantId = DeviceManagerUtil.getTenantId(); int tenantId = DeviceManagerUtil.getTenantId();
//Fetch the DeviceList from Core //Fetch the DeviceList from Core
try { try {
devicesList = this.getDeviceDAO().getDeviceListOfUser(userName, tenantId); devices = this.getDeviceDAO().getDeviceListOfUser(userName, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the devices of user '" throw new DeviceManagementException("Error occurred while obtaining the devices of user '"
+ userName + "'", e); + userName + "'", e);
} }
//Fetch the DeviceList from device plugin dbs & append the properties //Fetch the DeviceList from device plugin dbs & append the properties
for (int x = 0; x < devicesList.size(); x++) { for (org.wso2.carbon.device.mgt.core.dto.Device aDevicesList : devices) {
device = devicesList.get(x); device = aDevicesList;
try { try {
//TODO : Possible improvement if DeviceTypes have been cached //TODO : Possible improvement if DeviceTypes have been cached
device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId())); device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId()));

@ -1,224 +0,0 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.service;
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.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import java.util.List;
public class DeviceManagementServiceImpl implements DeviceManagementService {
@Override
public String getProviderType() {
return null;
}
@Override
public FeatureManager getFeatureManager() {
return null;
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().enrollDevice(device);
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().modifyEnrollment(device);
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().disenrollDevice(deviceId);
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().isEnrolled(deviceId);
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().isActive(deviceId);
}
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().setActive(deviceId, status);
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getAllDevices();
}
@Override
public List<Device> getAllDevices(String type) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getAllDevices(type);
}
public List<Device> getDeviceListOfUser(String username) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDeviceListOfUser(username);
}
public FeatureManager getFeatureManager(String type) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeatureManager(type);
}
@Override
public Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getCoreDevice(deviceId);
}
@Override
public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId)
throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId);
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
updateDeviceInfo(deviceIdentifier, device);
}
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().setOwnership(deviceId,
ownershipType);
}
@Override
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().isClaimable(deviceId);
}
@Override
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getLicense(deviceType,
languageCode);
}
@Override
public boolean addLicense(String type, License license) throws LicenseManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addLicense(type, license);
}
@Override
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices)
throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, devices);
}
@Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperations(deviceId);
}
@Override
public List<? extends Operation> getPendingOperations(
DeviceIdentifier deviceId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getPendingOperations(deviceId);
}
@Override
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getNextPendingOperation(deviceId);
}
@Override
public void updateOperation(DeviceIdentifier deviceId, int operationId, Operation.Status operationStatus) throws
OperationManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().updateOperation(deviceId, operationId,
operationStatus);
}
@Override
public void deleteOperation(int operationId) throws OperationManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().deleteOperation(operationId);
}
@Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId,
int operationId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getOperationByDeviceAndOperationId(deviceId, operationId);
}
@Override
public List<? extends Operation> getOperationsByDeviceAndStatus(DeviceIdentifier identifier,
Operation.Status status) throws OperationManagementException, DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperationsByDeviceAndStatus
(identifier, status);
}
@Override
public Operation getOperation(int operationId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperation(operationId);
}
@Override
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties)
throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendEnrolmentInvitation(emailMessageProperties);
}
@Override
public void sendRegistrationEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendRegistrationEmail(emailMessageProperties);
}
@Override
public List<Device> getAllDevicesOfUser(String userName)
throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getAllDevicesOfUser(userName);
}
@Override
public List<Device> getAllDevicesOfRole(String roleName)
throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getAllDevicesOfRole(roleName);
}
@Override
public int getDeviceCount() throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getDeviceCount();
}
@Override
public List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getDevicesByName(deviceName, tenantId);
}
}

@ -21,8 +21,8 @@ import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
public class DeviceManagementRepositoryTests { public class DeviceManagementRepositoryTests {
@ -35,7 +35,7 @@ public class DeviceManagementRepositoryTests {
@Test @Test
public void testAddDeviceManagementService() { public void testAddDeviceManagementService() {
DeviceMgtService sourceProvider = new TestDeviceManager(); DeviceManagementService sourceProvider = new TestDeviceManager();
try { try {
this.getRepository().addDeviceManagementProvider(sourceProvider); this.getRepository().addDeviceManagementProvider(sourceProvider);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -48,7 +48,7 @@ public class DeviceManagementRepositoryTests {
@Test(dependsOnMethods = "testAddDeviceManagementService") @Test(dependsOnMethods = "testAddDeviceManagementService")
public void testRemoveDeviceManagementService() { public void testRemoveDeviceManagementService() {
DeviceMgtService sourceProvider = new TestDeviceManager(); DeviceManagementService sourceProvider = new TestDeviceManager();
try { try {
this.getRepository().removeDeviceManagementProvider(sourceProvider); this.getRepository().removeDeviceManagementProvider(sourceProvider);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; 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.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -59,7 +60,7 @@ public class DeviceOperationManagementTests extends DeviceManagementBaseTest {
private void initOperationManager() { private void initOperationManager() {
this.operationManager = new OperationManagerImpl(); this.operationManager = new OperationManagerImpl();
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(new DeviceManagementServiceProviderImpl()); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(new DeviceManagementProviderServiceImpl());
} }
@Test @Test

@ -18,13 +18,16 @@
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*; 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.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.DeviceMgtService; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import java.util.List; import java.util.List;
public class TestDeviceManager implements DeviceMgtService { public class TestDeviceManager implements DeviceManagementService {
public static final String DEVICE_TYPE_TEST = "Test"; public static final String DEVICE_TYPE_TEST = "Test";
@ -93,9 +96,27 @@ public class TestDeviceManager implements DeviceMgtService {
return false; return false;
} }
@Override
public Application[] getApplications(String domain, int pageNumber,
int size) throws ApplicationManagementException {
return new Application[0];
}
@Override
public void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
String status) throws ApplicationManagementException {
}
@Override
public String getApplicationStatus(DeviceIdentifier deviceId,
Application application) throws ApplicationManagementException {
return null;
}
@Override @Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException { throws ApplicationManagementException {
} }
} }

@ -25,7 +25,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
@ -46,7 +46,7 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
PolicyManager policyManager; PolicyManager policyManager;
FeatureManager featureManager; FeatureManager featureManager;
DeviceManagementService deviceManagementService; DeviceManagementProviderService deviceManagementService;
public PolicyInformationPointImpl() { public PolicyInformationPointImpl() {
deviceManagementService = deviceManagementService =
@ -143,7 +143,7 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
return finalPolicies; return finalPolicies;
} }
private DeviceManagementService getDeviceManagementService() { private DeviceManagementProviderService getDeviceManagementService() {
return PolicyManagementDataHolder.getInstance().getDeviceManagementService(); return PolicyManagementDataHolder.getInstance().getDeviceManagementService();
} }

@ -18,7 +18,7 @@
package org.wso2.carbon.policy.mgt.core.internal; package org.wso2.carbon.policy.mgt.core.internal;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
@ -30,7 +30,7 @@ public class PolicyManagementDataHolder {
private TenantManager tenantManager; private TenantManager tenantManager;
private PolicyEvaluationPoint policyEvaluationPoint; private PolicyEvaluationPoint policyEvaluationPoint;
private PolicyInformationPoint policyInformationPoint; private PolicyInformationPoint policyInformationPoint;
private DeviceManagementService deviceManagementService; private DeviceManagementProviderService deviceManagementService;
private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder(); private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder();
private PolicyManagementDataHolder() {} private PolicyManagementDataHolder() {}
@ -75,11 +75,11 @@ public class PolicyManagementDataHolder {
this.policyInformationPoint = policyInformationPoint; this.policyInformationPoint = policyInformationPoint;
} }
public DeviceManagementService getDeviceManagementService() { public DeviceManagementProviderService getDeviceManagementService() {
return deviceManagementService; return deviceManagementService;
} }
public void setDeviceManagementService(DeviceManagementService deviceManagementService) { public void setDeviceManagementService(DeviceManagementProviderService deviceManagementService) {
this.deviceManagementService = deviceManagementService; this.deviceManagementService = deviceManagementService;
} }
} }

@ -21,7 +21,7 @@ package org.wso2.carbon.policy.mgt.core.internal;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl; import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
@ -46,7 +46,7 @@ import org.wso2.carbon.user.core.service.RealmService;
* bind="setPEPService" * bind="setPEPService"
* unbind="unsetPEPService" * unbind="unsetPEPService"
* @scr.reference name="org.wso2.carbon.device.manager" * @scr.reference name="org.wso2.carbon.device.manager"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementService" * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1" * cardinality="1..1"
* policy="dynamic" * policy="dynamic"
* bind="setDeviceManagementService" * bind="setDeviceManagementService"
@ -129,14 +129,14 @@ public class PolicyManagementServiceComponent {
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null); PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null);
} }
protected void setDeviceManagementService(DeviceManagementService deviceManagerService) { protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service"); log.debug("Setting Device Management Service");
} }
PolicyManagementDataHolder.getInstance().setDeviceManagementService(deviceManagerService); PolicyManagementDataHolder.getInstance().setDeviceManagementService(deviceManagerService);
} }
protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) { protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Unsetting Device Management Service"); log.debug("Unsetting Device Management Service");
} }

Loading…
Cancel
Save