APP Manager Integration

revert-70aa11f8
manoj 10 years ago
parent 2d5f8fe937
commit 2ae89bef59

@ -17,7 +17,9 @@
*/ */
package org.wso2.carbon.device.mgt.common; package org.wso2.carbon.device.mgt.common;
public class DeviceIdentifier { import java.io.Serializable;
public class DeviceIdentifier implements Serializable{
private String id; private String id;
private String type; private String type;
@ -29,7 +31,6 @@ public class DeviceIdentifier {
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
public String getId() { public String getId() {
return id; return id;
} }

@ -15,11 +15,12 @@
* 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.app.mgt; package org.wso2.carbon.device.mgt.common.app.mgt;
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.core.app.mgt.oauth.dto.Credential; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.dto.Application; import java.util.List;
/** /**
* This will handle the Application management side of MDM by acting a bridge between * This will handle the Application management side of MDM by acting a bridge between
@ -68,4 +69,7 @@ public interface AppManagerConnector {
*/ */
Credential getClientCredentials() throws AppManagerConnectorException; Credential getClientCredentials() throws AppManagerConnectorException;
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) throws
AppManagerConnectorException;
} }

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.core.app.mgt; package org.wso2.carbon.device.mgt.common.app.mgt;
/** /**
* Handles the exceptions related to Application management. * Handles the exceptions related to Application management.

@ -18,7 +18,10 @@
package org.wso2.carbon.device.mgt.common.spi; package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import java.util.List; import java.util.List;
@ -31,14 +34,14 @@ public interface DeviceManager {
/** /**
* Method to retrieve the provider type that implements DeviceManager interface. * Method to retrieve the provider type that implements DeviceManager interface.
* *
* @return Returns provider type * @return Returns provider type
*/ */
String getProviderType(); String getProviderType();
/** /**
* Method to return feature manager implementation associated with a particular platform-specific plugin. * Method to return feature manager implementation associated with a particular platform-specific plugin.
* *
* @return Returns an instance of feature manager * @return Returns an instance of feature manager
*/ */
FeatureManager getFeatureManager(); FeatureManager getFeatureManager();
@ -110,7 +113,7 @@ public interface DeviceManager {
* Method to retrieve metadata of a device corresponding to a particular type that carries a specific identifier. * Method to retrieve metadata of a device corresponding to a particular type that carries a specific identifier.
* *
* @param deviceId Fully qualified device identifier * @param deviceId Fully qualified device identifier
* @return Metadata corresponding to a particular device * @return Metadata corresponding to a particular device
* @throws DeviceManagementException If some unusual behaviour is observed obtaining the device object * @throws DeviceManagementException If some unusual behaviour is observed obtaining the device object
*/ */
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
@ -133,5 +136,4 @@ public interface DeviceManager {
*/ */
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
} }

@ -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.DeviceManager; import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.HashMap; import java.util.HashMap;
@ -26,13 +26,13 @@ import java.util.Map;
public class DeviceManagementRepository { public class DeviceManagementRepository {
private Map<String, DeviceManager> providers; private Map<String, DeviceMgtService> providers;
public DeviceManagementRepository() { public DeviceManagementRepository() {
providers = new HashMap<String, DeviceManager>(); providers = new HashMap<String, DeviceMgtService>();
} }
public void addDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException { public void addDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getProviderType();
try { try {
DeviceManagerUtil.registerDeviceType(deviceType); DeviceManagerUtil.registerDeviceType(deviceType);
@ -43,7 +43,7 @@ public class DeviceManagementRepository {
providers.put(deviceType, provider); providers.put(deviceType, provider);
} }
public void removeDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException { public void removeDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getProviderType();
try { try {
DeviceManagerUtil.unregisterDeviceType(deviceType); DeviceManagerUtil.unregisterDeviceType(deviceType);
@ -54,7 +54,7 @@ public class DeviceManagementRepository {
providers.remove(deviceType); providers.remove(deviceType);
} }
public DeviceManager getDeviceManagementProvider(String type) { public DeviceMgtService getDeviceManagementProvider(String type) {
return providers.get(type); return providers.get(type);
} }

@ -22,10 +22,8 @@ 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.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.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.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
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;
@ -37,9 +35,8 @@ 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.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.Status; import org.wso2.carbon.device.mgt.core.dto.Status;
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.EmailServiceDataHolder; import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
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.service.DeviceManagementService; 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;
@ -54,8 +51,6 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private DeviceManagementRepository pluginRepository; private DeviceManagementRepository pluginRepository;
private OperationManager operationManager;
private LicenseManager licenseManager;
private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class); private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class);
@ -63,15 +58,11 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
this.pluginRepository = pluginRepository; this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.operationManager = new OperationManagerImpl();
this.licenseManager = new LicenseManagerImpl();
} }
public DeviceManagementServiceProviderImpl(){ public DeviceManagementServiceProviderImpl() {
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.operationManager = new OperationManagerImpl();
this.licenseManager = new LicenseManagerImpl();
} }
@Override @Override
@ -104,7 +95,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
} }
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " + throw new DeviceManagementException("Error occurred while obtaining the device for id " +
"'" + deviceId.getId() + "' and type:"+deviceId.getType(), e); "'" + deviceId.getId() + "' and type:" + deviceId.getType(), e);
} }
return convertedDevice; return convertedDevice;
} }
@ -256,7 +247,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
} }
@Override @Override
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties)
throws DeviceManagementException {
List<NotificationMessages> notificationMessages = DeviceConfigurationManager.getInstance() List<NotificationMessages> notificationMessages = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig().getNotificationMessagesList(); .getNotificationMessagesConfig().getNotificationMessagesList();
@ -267,9 +259,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
String url = ""; String url = "";
String subject = ""; String subject = "";
for(NotificationMessages notificationMessage : notificationMessages){ for (NotificationMessages notificationMessage : notificationMessages) {
if (DeviceManagementConstants.EmailNotifications.ENROL_NOTIFICATION_TYPE. if (DeviceManagementConstants.EmailNotifications.ENROL_NOTIFICATION_TYPE.
equals(notificationMessage.getType())) { equals(notificationMessage.getType())) {
messageHeader = notificationMessage.getHeader(); messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody(); messageBody = notificationMessage.getBody();
messageFooter = notificationMessage.getFooter(); messageFooter = notificationMessage.getFooter();
@ -283,18 +275,18 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
try { try {
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}", messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}",
URLEncoder.encode(emailMessageProperties.getFirstName(), URLEncoder.encode(emailMessageProperties.getFirstName(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{" messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{"
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator")); messageBuilder.append(messageHeader).append(System.getProperty("line.separator"));
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter); messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter);
} catch (IOException e) { } catch (IOException e) {
log.error("IO error in processing enrol email message "+emailMessageProperties); log.error("IO error in processing enrol email message " + emailMessageProperties);
throw new DeviceManagementException("Error replacing tags in email template '" + throw new DeviceManagementException("Error replacing tags in email template '" +
emailMessageProperties.getSubject() + "'", e); emailMessageProperties.getSubject() + "'", e);
} }
@ -314,9 +306,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
String url = ""; String url = "";
String subject = ""; String subject = "";
for(NotificationMessages notificationMessage : notificationMessages){ for (NotificationMessages notificationMessage : notificationMessages) {
if (DeviceManagementConstants.EmailNotifications.USER_REGISTRATION_NOTIFICATION_TYPE. if (DeviceManagementConstants.EmailNotifications.USER_REGISTRATION_NOTIFICATION_TYPE.
equals(notificationMessage.getType())) { equals(notificationMessage.getType())) {
messageHeader = notificationMessage.getHeader(); messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody(); messageBody = notificationMessage.getBody();
messageFooter = notificationMessage.getFooter(); messageFooter = notificationMessage.getFooter();
@ -350,7 +342,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter); messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter);
} catch (IOException e) { } catch (IOException e) {
log.error("IO error in processing enrol email message "+emailMessageProperties); log.error("IO error in processing enrol email message " + emailMessageProperties);
throw new DeviceManagementException("Error replacing tags in email template '" + throw new DeviceManagementException("Error replacing tags in email template '" +
emailMessageProperties.getSubject() + "'", e); emailMessageProperties.getSubject() + "'", e);
} }
@ -402,12 +394,12 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override @Override
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
return licenseManager.getLicense(deviceType, languageCode); return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
} }
@Override @Override
public boolean addLicense(String type, License license) throws LicenseManagementException { public boolean addLicense(String type, License license) throws LicenseManagementException {
return licenseManager.addLicense(type, license); return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(type, license);
} }
public DeviceDAO getDeviceDAO() { public DeviceDAO getDeviceDAO() {
@ -425,55 +417,58 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override @Override
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
OperationManagementException { OperationManagementException {
return operationManager.addOperation(operation, devices); return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
} }
@Override @Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException { public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
return operationManager.getOperations(deviceId); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperations(deviceId);
} }
@Override @Override
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException { public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId)
return operationManager.getPendingOperations(deviceId); throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getPendingOperations(deviceId);
} }
@Override @Override
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
return operationManager.getNextPendingOperation(deviceId); return DeviceManagementDataHolder.getInstance().getOperationManager().getNextPendingOperation(deviceId);
} }
@Override @Override
public void updateOperation(int operationId, Operation.Status operationStatus) public void updateOperation(int operationId, Operation.Status operationStatus)
throws OperationManagementException { throws OperationManagementException {
operationManager.updateOperation(operationId, operationStatus); DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(operationId, operationStatus);
} }
@Override @Override
public void deleteOperation(int operationId) throws OperationManagementException { public void deleteOperation(int operationId) throws OperationManagementException {
operationManager.deleteOperation(operationId); DeviceManagementDataHolder.getInstance().getOperationManager().deleteOperation(operationId);
} }
@Override @Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId) public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
throws OperationManagementException { throws OperationManagementException {
return operationManager.getOperationByDeviceAndOperationId(deviceId, operationId); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByDeviceAndOperationId(
deviceId, operationId);
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(DeviceIdentifier identifier, public List<? extends Operation> getOperationsByDeviceAndStatus(DeviceIdentifier identifier,
Operation.Status status) throws OperationManagementException, DeviceManagementException { Operation.Status status) throws OperationManagementException, DeviceManagementException {
return operationManager.getOperationsByDeviceAndStatus(identifier, status); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsByDeviceAndStatus(identifier,
status);
} }
@Override @Override
public Operation getOperation(int operationId) throws OperationManagementException { public Operation getOperation(int operationId) throws OperationManagementException {
return operationManager.getOperation(operationId); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId);
} }
@Override @Override
public List<? extends Operation> getOperationsForStatus(Operation.Status status) public List<? extends Operation> getOperationsForStatus(Operation.Status status)
throws OperationManagementException { throws OperationManagementException {
return operationManager.getOperationsForStatus(status); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsForStatus(status);
} }
} }

@ -17,16 +17,20 @@
*/ */
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.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.core.app.mgt.oauth.dto.Credential; import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.core.dto.Application; import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import java.util.List;
public class AppManagementServiceImpl implements AppManagerConnector { public class AppManagementServiceImpl implements AppManagerConnector {
@Override @Override
public Application[] getApplicationList(String domain, int pageNumber, public Application[] getApplicationList(String domain, int pageNumber, int size) throws AppManagerConnectorException {
int size) throws AppManagerConnectorException {
return DeviceManagementDataHolder.getInstance().getAppManager().getApplicationList(domain, pageNumber, size); return DeviceManagementDataHolder.getInstance().getAppManager().getApplicationList(domain, pageNumber, size);
} }
@ -48,4 +52,10 @@ public class AppManagementServiceImpl implements AppManagerConnector {
return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials(); return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials();
} }
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException {
DeviceManagementDataHolder.getInstance().getAppManager().installApplication(operation, deviceIdentifiers);
}
} }

@ -18,12 +18,26 @@
*/ */
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.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 AppManagerConnectorFactory {
private static DeviceManagementRepository pluginRepository;
public DeviceManagementRepository getPluginRepository() {
return pluginRepository;
}
public void setPluginRepository(DeviceManagementRepository pluginRepository) {
this.pluginRepository = pluginRepository;
}
public static AppManagerConnector getConnector(AppManagementConfig config) { public static AppManagerConnector getConnector(AppManagementConfig config) {
return new RemoteAppManagerConnector(config); return new RemoteAppManagerConnector(config, pluginRepository);
} }
} }

@ -23,19 +23,25 @@ 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.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.AppManagerConnectorException;
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.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.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
import org.wso2.carbon.device.mgt.core.dto.Application;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.List;
/** /**
* Implements AppManagerConnector interface * Implements AppManagerConnector interface
@ -45,12 +51,14 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
private ConfigurationContext configCtx; private ConfigurationContext configCtx;
private ServiceAuthenticator authenticator; private ServiceAuthenticator authenticator;
private String oAuthAdminServiceUrl; private String oAuthAdminServiceUrl;
private DeviceManagementRepository pluginRepository;
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(RemoteAppManagerConnector.class);
public RemoteAppManagerConnector(AppManagementConfig appManagementConfig) { public RemoteAppManagerConnector(AppManagementConfig appManagementConfig, DeviceManagementRepository pluginRepository) {
IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getDeviceManagementConfigRepository().getIdentityConfigurations(); getDeviceManagementConfigRepository().getIdentityConfigurations();
this.authenticator = this.authenticator =
@ -63,6 +71,7 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " + throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " +
"Please check if an appropriate axis2.xml is provided", e); "Please check if an appropriate axis2.xml is provided", e);
} }
this.pluginRepository = pluginRepository;
} }
@Override @Override
@ -93,6 +102,16 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
return credential; return credential;
} }
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException {
for(DeviceIdentifier deviceIdentifier:deviceIdentifiers){
DeviceMgtService dms = this.getPluginRepository().getDeviceManagementProvider(deviceIdentifier.getType());
dms.installApplication(operation,deviceIdentifiers);
}
}
private OAuthConsumerAppDTO getAppInfo() throws AppManagerConnectorException { private OAuthConsumerAppDTO getAppInfo() throws AppManagerConnectorException {
OAuthConsumerAppDTO appInfo = null; OAuthConsumerAppDTO appInfo = null;
try { try {
@ -133,4 +152,7 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
throw new AppManagerConnectorException(msg, e); throw new AppManagerConnectorException(msg, e);
} }
public DeviceManagementRepository getPluginRepository() {
return pluginRepository;
}
} }

@ -19,8 +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.core.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException;
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;

@ -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.core.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
/** /**
* Authenticate a given service client. * Authenticate a given service client.

@ -20,8 +20,9 @@
package org.wso2.carbon.device.mgt.core.internal; package org.wso2.carbon.device.mgt.core.internal;
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.core.api.mgt.APIPublisherService; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnector; 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.DeviceManagementService;
@ -40,6 +41,7 @@ public class DeviceManagementDataHolder {
private APIPublisherService apiPublisherService; private APIPublisherService apiPublisherService;
private AppManagerConnector appManager; private AppManagerConnector appManager;
private AppManagementConfig appManagerConfig; private AppManagementConfig appManagerConfig;
private OperationManager operationManager;
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
@ -126,4 +128,11 @@ public class DeviceManagementDataHolder {
this.appManagerConfig = appManagerConfig; this.appManagerConfig = appManagerConfig;
} }
public OperationManager getOperationManager() {
return operationManager;
}
public void setOperationManager(OperationManager operationManager) {
this.operationManager = operationManager;
}
} }

@ -27,7 +27,10 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
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.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
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.DeviceManagementServiceProviderImpl;
@ -35,8 +38,8 @@ 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.AppManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnector; import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector; import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector;
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;
@ -47,6 +50,7 @@ import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager;
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.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.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.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
@ -67,7 +71,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.DeviceManager" * interface="org.wso2.carbon.device.mgt.common.spi.DeviceMgtService"
* cardinality="0..n" * cardinality="0..n"
* policy="dynamic" * policy="dynamic"
* bind="setDeviceManager" * bind="setDeviceManager"
@ -98,14 +102,13 @@ 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<DeviceManager> deviceManagers = new ArrayList<DeviceManager>(); private List<DeviceMgtService> deviceManagers = new ArrayList<DeviceMgtService>();
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing device management core bundle"); log.debug("Initializing device management core bundle");
} }
/* Initializing Device Management Configuration */ /* Initializing Device Management Configuration */
DeviceConfigurationManager.getInstance().initConfig(); DeviceConfigurationManager.getInstance().initConfig();
DeviceManagementConfig config = DeviceManagementConfig config =
@ -114,15 +117,16 @@ public class DeviceManagementServiceComponent {
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig(); DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
DeviceManagementDAOFactory.init(dsConfig); DeviceManagementDAOFactory.init(dsConfig);
DeviceManagementService deviceManagementProvider =
new DeviceManagementServiceProviderImpl(this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
/* Initializing license manager */ /* Initializing license manager */
this.initLicenseManager(); this.initLicenseManager();
/*Initialize Operation Manager*/
this.initOperationsManager();
/* Initializing app manager connector */ /* Initializing app manager connector */
this.initAppManagerConnector(); this.initAppManagerConnector();
DeviceManagementService deviceManagementProvider =
new DeviceManagementServiceProviderImpl(this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
OperationManagementDAOFactory.init(dsConfig); OperationManagementDAOFactory.init(dsConfig);
/* If -Dsetup option enabled then create device management database schema */ /* If -Dsetup option enabled then create device management database schema */
@ -138,7 +142,7 @@ public class DeviceManagementServiceComponent {
} }
synchronized (LOCK) { synchronized (LOCK) {
for (DeviceManager deviceManager : deviceManagers) { for (DeviceMgtService deviceManager : deviceManagers) {
this.registerDeviceManagementProvider(deviceManager); this.registerDeviceManagementProvider(deviceManager);
} }
this.isInitialized = true; this.isInitialized = true;
@ -169,21 +173,20 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig); DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig);
} }
private void initOperationsManager() throws OperationManagementException {
OperationManager operationManager = new OperationManagerImpl();
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
}
private void initAppManagerConnector() throws AppManagerConnectorException { private void initAppManagerConnector() throws AppManagerConnectorException {
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); RemoteAppManagerConnector appManager = new RemoteAppManagerConnector(appConfig,this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setAppManager(appManager); DeviceManagementDataHolder.getInstance().setAppManager(appManager);
} }
// private void initAPIProviders() throws DeviceManagementException {
// for (APIConfig config : APIPublisherConfig.getInstance().getApiConfigs()) {
// config.init();
// }
// }
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 DeviceManagementServiceImpl");
@ -231,7 +234,7 @@ public class DeviceManagementServiceComponent {
} }
} }
private void registerDeviceManagementProvider(DeviceManager deviceManager) { private void registerDeviceManagementProvider(DeviceMgtService deviceManager) {
try { try {
this.getPluginRepository().addDeviceManagementProvider(deviceManager); this.getPluginRepository().addDeviceManagementProvider(deviceManager);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -245,7 +248,7 @@ public class DeviceManagementServiceComponent {
* *
* @param deviceManager An instance of DeviceManager * @param deviceManager An instance of DeviceManager
*/ */
protected void setDeviceManager(DeviceManager deviceManager) { protected void setDeviceManager(DeviceMgtService 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() + "'");
} }
@ -262,7 +265,7 @@ public class DeviceManagementServiceComponent {
* *
* @param deviceManager An Instance of DeviceManager * @param deviceManager An Instance of DeviceManager
*/ */
protected void unsetDeviceManager(DeviceManager deviceManager) { protected void unsetDeviceManager(DeviceMgtService deviceManager) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'");
} }

@ -18,6 +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.spi.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;

@ -23,7 +23,7 @@ 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.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import java.util.List; import java.util.List;
public class DeviceManagementServiceImpl implements DeviceManagementService { public class DeviceManagementServiceImpl implements DeviceManagementService {

@ -22,6 +22,7 @@ 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.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
public class DeviceManagementRepositoryTests { public class DeviceManagementRepositoryTests {
@ -34,7 +35,7 @@ public class DeviceManagementRepositoryTests {
@Test @Test
public void testAddDeviceManagementService() { public void testAddDeviceManagementService() {
DeviceManager sourceProvider = new TestDeviceManager(); DeviceMgtService sourceProvider = new TestDeviceManager();
try { try {
this.getRepository().addDeviceManagementProvider(sourceProvider); this.getRepository().addDeviceManagementProvider(sourceProvider);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -47,7 +48,7 @@ public class DeviceManagementRepositoryTests {
@Test(dependsOnMethods = "testAddDeviceManagementService") @Test(dependsOnMethods = "testAddDeviceManagementService")
public void testRemoveDeviceManagementService() { public void testRemoveDeviceManagementService() {
DeviceManager sourceProvider = new TestDeviceManager(); DeviceMgtService sourceProvider = new TestDeviceManager();
try { try {
this.getRepository().removeDeviceManagementProvider(sourceProvider); this.getRepository().removeDeviceManagementProvider(sourceProvider);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {

@ -17,15 +17,15 @@
*/ */
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.*;
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.DeviceManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import java.util.List; import java.util.List;
public class TestDeviceManager implements DeviceManager { public class TestDeviceManager implements DeviceMgtService {
public static final String DEVICE_TYPE_TEST = "Test"; public static final String DEVICE_TYPE_TEST = "Test";
@ -89,4 +89,9 @@ public class TestDeviceManager implements DeviceManager {
return false; return false;
} }
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException {
}
} }

Loading…
Cancel
Save