Fixing device management API structure

4.x.x
prabathabey 10 years ago
parent 8073d46f58
commit fd6793a9af

@ -24,13 +24,6 @@ import java.util.List;
* device type plugin implementation intended to be managed through CDM.
*/
public interface DeviceManager {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
*/
String getProviderType();
/**
* Method to return feature manager implementation associated with a particular platform-specific plugin.
*

@ -18,6 +18,7 @@
*/
package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
@ -25,6 +26,19 @@ 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 {
public interface DeviceManagementService extends ApplicationManager {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
*/
String getType();
void init() throws DeviceManagementException;
DeviceManager getDeviceManager();
ApplicationManager getApplicationManager();
}

@ -34,7 +34,7 @@ public class DeviceManagementPluginRepository {
}
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType();
String deviceType = provider.getType();
try {
DeviceManagerUtil.registerDeviceType(deviceType);
} catch (DeviceManagementException e) {
@ -45,7 +45,7 @@ public class DeviceManagementPluginRepository {
}
public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType();
String deviceType = provider.getType();
providers.remove(deviceType);
}

@ -203,7 +203,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
pluginRepository.addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) {
log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e);
deviceManagementService.getType() + "'", e);
}
}
@ -213,7 +213,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
pluginRepository.removeDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e);
deviceManagementService.getType() + "'", e);
}
}
}

@ -242,7 +242,7 @@ public class DeviceManagementServiceComponent {
protected void setDeviceManagementService(DeviceManagementService deviceManagementService) {
if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" +
deviceManagementService.getProviderType() + "'");
deviceManagementService.getType() + "'");
}
synchronized (LOCK) {
deviceManagers.add(deviceManagementService);
@ -260,7 +260,7 @@ public class DeviceManagementServiceComponent {
protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) {
if (log.isDebugEnabled()) {
log.debug("Un setting Device Management Service Provider : '" +
deviceManagementService.getProviderType() + "'");
deviceManagementService.getType() + "'");
}
for (PluginInitializationListener listener : listeners) {
listener.unregisterDeviceManagementService(deviceManagementService);

@ -21,7 +21,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
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;
@ -68,11 +67,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementServiceComponent.registerPluginInitializationListener(this);
}
@Override
public String getProviderType() {
return null;
}
@Override
public FeatureManager getFeatureManager() {
return null;
@ -81,14 +75,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public FeatureManager getFeatureManager(String type) {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(type);
this.getPluginRepository().getDeviceManagementService(type).getDeviceManager();
return dms.getFeatureManager();
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType());
this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
boolean status = dms.enrollDevice(device);
try {
if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) {
@ -134,7 +128,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType());
this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
boolean status = dms.modifyEnrollment(device);
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -167,7 +161,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
try {
Device device = deviceDAO.getDevice(deviceId,tenantId);
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
@ -188,14 +182,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isEnrolled(deviceId);
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isActive(deviceId);
}
@ -203,7 +197,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.setActive(deviceId, status);
}
@ -227,7 +221,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
for (Device device : allDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
@ -257,7 +252,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (Device device : allDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
@ -407,7 +403,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
}
if (device != null) {
DeviceManager dms = this.getPluginRepository().getDeviceManagementService(deviceId.getType());
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
Device pluginSpecificInfo = dms.getDevice(deviceId);
device.setProperties(pluginSpecificInfo.getProperties());
device.setFeatures(pluginSpecificInfo.getFeatures());
@ -418,7 +415,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType());
this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
return dms.updateDeviceInfo(deviceIdentifier, device);
}
@ -426,14 +423,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.setOwnership(deviceId, ownershipType);
}
@Override
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isClaimable(deviceId);
}
@ -552,7 +549,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (Device device : userDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
@ -594,7 +592,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
for (Device device : userDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
@ -641,7 +640,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
for (Device device : allDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
@ -673,7 +673,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
pluginRepository.addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) {
log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e);
deviceManagementService.getType() + "'", e);
}
}
@ -683,7 +683,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
pluginRepository.removeDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e);
deviceManagementService.getType() + "'", e);
}
}

@ -41,9 +41,9 @@ public class DeviceManagementRepositoryTests {
} catch (DeviceManagementException e) {
Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e);
}
DeviceManager targetProvider =
DeviceManagementService targetProvider =
this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST);
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType());
Assert.assertEquals(targetProvider.getType(), sourceProvider.getType());
}
@Test(dependsOnMethods = "testAddDeviceManagementService")
@ -54,7 +54,7 @@ public class DeviceManagementRepositoryTests {
} catch (DeviceManagementException e) {
Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e);
}
DeviceManager targetProvider =
DeviceManagementService targetProvider =
this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST);
Assert.assertNull(targetProvider);
}

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@ -29,77 +30,27 @@ public class TestDeviceManagementService implements DeviceManagementService {
public static final String DEVICE_TYPE_TEST = "Test";
@Override
public String getProviderType() {
return TestDeviceManagementService.DEVICE_TYPE_TEST;
}
@Override
public FeatureManager getFeatureManager() {
return null;
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
public String getType() {
return TestDeviceManagementService.DEVICE_TYPE_TEST;
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
public void init() throws DeviceManagementException {
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
return false;
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
public DeviceManager getDeviceManager() {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
public ApplicationManager getApplicationManager() {
return null;
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
return false;
}
@Override
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
@Override
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
EnrolmentInfo.Status status) throws DeviceManagementException {
return false;
}
@Override
public Application[] getApplications(String domain, int pageNumber,
int size) throws ApplicationManagementException {
@ -119,8 +70,9 @@ public class TestDeviceManagementService implements DeviceManagementService {
}
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws ApplicationManagementException {
public void installApplication(Operation operation,
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
}
}

@ -48,4 +48,5 @@ public class UnregistrationProfile {
public void setUserId(String userId) {
this.userId = userId;
}
}

Loading…
Cancel
Save