From d444f4ce0c106219b22632788a0f4bb05b26838f Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 29 May 2015 16:52:02 +0530 Subject: [PATCH] Adding an interface method to DeviceManager.java to support claimable devices --- .../carbon/device/mgt/common/DeviceIdentifier.java | 7 +++++++ .../carbon/device/mgt/common/spi/DeviceManager.java | 2 ++ .../core/DeviceManagementServiceProviderImpl.java | 13 ++++++++++++- .../core/service/DeviceManagementServiceImpl.java | 8 ++++++++ .../carbon/device/mgt/core/TestDeviceManager.java | 5 +++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 66682fe6d9..2cc27e6236 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -24,6 +24,13 @@ public class DeviceIdentifier implements Serializable{ private String id; private String type; + public DeviceIdentifier() {} + + public DeviceIdentifier(String id, String type) { + this.id = id; + this.type = type; + } + public String getType() { return type; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java index 0eb13dee00..0535062f30 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java @@ -134,4 +134,6 @@ public interface DeviceManager { */ boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; + boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 3242ebec9b..e5bdc05d41 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -108,7 +108,11 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ try { org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device); DeviceType deviceType = this.getDeviceTypeDAO().getDeviceType(device.getType()); - deviceDto.setStatus(Status.ACTIVE); + if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), deviceType.getName()))) { + deviceDto.setStatus(Status.INACTIVE); + } else { + deviceDto.setStatus(Status.ACTIVE); + } deviceDto.setDeviceTypeId(deviceType.getId()); this.getDeviceDAO().addDevice(deviceDto); } catch (DeviceManagementDAOException e) { @@ -410,6 +414,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ return dms.setOwnership(deviceId, ownershipType); } + @Override + public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isClaimable(deviceId); + } + @Override public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index 3b15a36389..0a5a9d4c9f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -110,6 +110,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { 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, @@ -217,4 +222,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() .getDevicesByName(deviceName, tenantId); } + + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java index 5f76d4f862..4812e6cd08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -88,6 +88,11 @@ public class TestDeviceManager implements DeviceMgtService { return false; } + @Override + public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + @Override public void installApplication(Operation operation, List deviceIdentifiers) throws AppManagerConnectorException {