mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Code cleanup
This commit is contained in:
parent
9a1ffa6ab7
commit
1a1700d219
@ -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 {
|
||||
|
||||
|
||||
@ -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<API> apis) throws APIManagementException;
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<DeviceIdentifier> 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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user