From a115cff4db0c04d194a3f8898a304a27ea958dbb Mon Sep 17 00:00:00 2001 From: madhawap Date: Mon, 12 Jun 2017 09:46:50 +0530 Subject: [PATCH 1/3] reformatting code --- .../core/task/impl/DeviceTaskManagerImpl.java | 20 ++++++++++++------- .../impl/DeviceTaskManagerServiceImpl.java | 1 - 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java index 83850b31823..ebcd3d58866 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java @@ -92,13 +92,19 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { operations = this.getValidOperationNames(); //list operations for each device type devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type if (!devices.isEmpty()) { - for (String str : operations) { - CommandOperation operation = new CommandOperation(); - operation.setEnabled(true); - operation.setType(Operation.Type.COMMAND); - operation.setCode(str); - deviceManagementProviderService.addOperation(deviceType, operation, - DeviceManagerUtil.getValidDeviceIdentifiers(devices)); + if (operations != null) { + for (String str : operations) { + CommandOperation operation = new CommandOperation(); + operation.setEnabled(true); + operation.setType(Operation.Type.COMMAND); + operation.setCode(str); + deviceManagementProviderService.addOperation(deviceType, operation, + DeviceManagerUtil.getValidDeviceIdentifiers(devices)); + } + } else { + if (log.isDebugEnabled()) { + log.debug("No operations are available."); + } } } else { if (log.isDebugEnabled()) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java index d23939f866b..b8119222dbe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java @@ -53,7 +53,6 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { log.info("Task adding for " + deviceType); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - try { TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService(); taskService.registerTaskType(TASK_TYPE); From b78a11d3d9a2843712d6a8d9471b0de5b5949909 Mon Sep 17 00:00:00 2001 From: madhawap Date: Mon, 12 Jun 2017 09:49:54 +0530 Subject: [PATCH 2/3] reformatting code --- .../src/main/resources/conf/cdm-config.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index ec27d993e3a..152e94359b5 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -54,10 +54,6 @@ Simple - - - - 20 From 648659a78156ceb76177baeb94636c6d1bd92472 Mon Sep 17 00:00:00 2001 From: madhawap Date: Fri, 16 Jun 2017 13:12:06 +0530 Subject: [PATCH 3/3] Sets values taken from system varibales to iot-api-config.xml iot-api-config.xml consists with system varibales like iot.core.host, iot.keymanager.host etc. But values set to those varibales were not pass into these places. This commit fixes that --- .../carbon/apimgt/handlers/utils/Utils.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/utils/Utils.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/utils/Utils.java index d3c8ad3a9f2..e7d239a1ee9 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/utils/Utils.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/utils/Utils.java @@ -44,6 +44,8 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Contains util methods for synapse gateway authentication handler @@ -62,21 +64,47 @@ public class Utils { public static IOTServerConfiguration initConfig() { try { - String IOTServerAPIConfigurationPath = - CarbonUtils.getCarbonConfigDirPath() + File.separator + IOT_APIS_CONFIG_FILE; + String IOTServerAPIConfigurationPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + + IOT_APIS_CONFIG_FILE; File file = new File(IOTServerAPIConfigurationPath); Document doc = Utils.convertToDocument(file); JAXBContext fileContext = JAXBContext.newInstance(IOTServerConfiguration.class); Unmarshaller unmarshaller = fileContext.createUnmarshaller(); - return (IOTServerConfiguration) unmarshaller.unmarshal(doc); + IOTServerConfiguration iotServerConfiguration = (IOTServerConfiguration) unmarshaller.unmarshal( + doc); + iotServerConfiguration.setHostname(replaceProperties(iotServerConfiguration.getHostname())); + iotServerConfiguration.setVerificationEndpoint( + replaceProperties(iotServerConfiguration.getVerificationEndpoint())); + iotServerConfiguration.setDynamicClientRegistrationEndpoint( + replaceProperties(iotServerConfiguration.getDynamicClientRegistrationEndpoint())); + iotServerConfiguration.setOauthTokenEndpoint( + replaceProperties(iotServerConfiguration.getOauthTokenEndpoint())); + return iotServerConfiguration; } catch (JAXBException | APIMCertificateMGTException e) { log.error("Error occurred while initializing Data Source config", e); return null; } } + /** + * This method gets the values from system variables and sets to xml. + */ + public static String replaceProperties(String text) { + String regex = "\\$\\{(.*?)\\}"; + Pattern pattern = Pattern.compile(regex); + Matcher matchPattern = pattern.matcher(text); + while (matchPattern.find()) { + String sysPropertyName = matchPattern.group(1); + String sysPropertyValue = System.getProperty(sysPropertyName); + if (sysPropertyValue != null && !sysPropertyName.isEmpty()) { + text = text.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue); + } + } + return text; + } + /** * This class build the iot-api-config.xml file. * @param file