From 1a1700d219e1740197030cf4bfa4a9d6bd864b5c Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 27 Mar 2015 12:56:21 +0530 Subject: [PATCH] Code cleanup --- .../device/mgt/core/api/mgt/APIConfig.java | 4 +++ .../mgt/core/api/mgt/APIPublisherService.java | 25 +++++++++++++++++++ .../core/api/mgt/APIPublisherServiceImpl.java | 4 +++ .../mgt/APIRegistrationStartupObserver.java | 10 ++++++++ .../operation/mgt/OperationManagerImpl.java | 6 ++--- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIConfig.java index fa693508b18..834bb9e77f6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIConfig.java @@ -24,6 +24,10 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +/** + * This bean class carries the properties used by some API that needs to be published within the underlying + * API-Management infrastructure. + */ @XmlRootElement(name = "API") public class APIConfig { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherService.java index 908a2ae32c4..77e961470eb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherService.java @@ -24,12 +24,37 @@ import org.wso2.carbon.apimgt.api.model.APIIdentifier; import java.util.List; +/** + * This interface represents all methods related to API manipulation that's done as part of API-Management tasks. + * + * Note: Ideally, this has to come from the API-Management components. However, due to lack of clean APIs + * (as OSGi declarative services, etc) provided for API publishing and related tasks, this was introduced at the device + * management core implementation layer. + */ public interface APIPublisherService { + /** + * This method registers an API within the underlying API-Management infrastructure. + * + * @param api An instance of the bean that passes metadata related to the API being published + * @throws APIManagementException Is thrown if some unexpected event occurs while publishing the API + */ void publishAPI(API api) throws APIManagementException; + /** + * This method removes an API that's already published within the underlying API-Management infrastructure. + * + * @param id An instance of the bean that carries API identification related metadata + * @throws APIManagementException Is thrown if some unexpected event occurs while removing the API + */ void removeAPI(APIIdentifier id) throws APIManagementException; + /** + * This method registers a collection of APIs within the underlying API-Management infrastructure. + * + * @param apis A list of the beans that passes metadata related to the APIs being published + * @throws APIManagementException Is thrown if some unexpected event occurs while publishing the APIs + */ void publishAPIs(List apis) throws APIManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherServiceImpl.java index eae11d973f2..129e141f7f3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherServiceImpl.java @@ -28,6 +28,10 @@ import org.wso2.carbon.apimgt.impl.APIManagerFactory; import java.util.List; +/** + * This class represents the concrete implementation of the APIPublisherService that corresponds to providing all + * API publishing related operations. + */ public class APIPublisherServiceImpl implements APIPublisherService { private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIRegistrationStartupObserver.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIRegistrationStartupObserver.java index 9bce7ef4273..45677318464 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIRegistrationStartupObserver.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIRegistrationStartupObserver.java @@ -30,6 +30,16 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.util.List; +/** + * This particular class corresponding to the ServerStartupObserver written for publishing the set of APIs used by + * the device management related components. + * + * Note: Using this particular approach is not a must, had there been a proper programming interface provided by the + * underlying API-Management infrastructure for manipulating the APIs. Even though, there's one, its concrete + * implementation consumes a set of OSGi declarative services for initializing some of its internal states, which + * prevents us from, simply, instantiating the APIPublisher implementation and using for device management related + * tasks. The aforesaid complication lead us to go for this alternative approach to get the same done. + */ public class APIRegistrationStartupObserver implements ServerStartupObserver { private static final Log log = LogFactory.getLog(APIRegistrationStartupObserver.class); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index ddde9b64ffa..ec0b99a55a0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -27,6 +27,7 @@ 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.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; @@ -64,9 +65,8 @@ public class OperationManagerImpl implements OperationManager { try { OperationManagementDAOFactory.beginTransaction(); int operationId = this.lookupOperationDAO(operation).addOperation(operation); - for(Iterator i = devices.iterator(); i.hasNext(); ) { - DeviceIdentifier deviceIdentifier = i.next(); - org.wso2.carbon.device.mgt.core.dto.Device device = deviceDAO.getDevice(deviceIdentifier); + for (DeviceIdentifier deviceIdentifier : devices) { + Device device = deviceDAO.getDevice(deviceIdentifier); operationMappingDAO.addOperationMapping(operationId, device.getId()); } OperationManagementDAOFactory.commitTransaction();