mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
commit
74db075dff
@ -44,6 +44,8 @@ import java.net.URI;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains util methods for synapse gateway authentication handler
|
* Contains util methods for synapse gateway authentication handler
|
||||||
@ -62,21 +64,47 @@ public class Utils {
|
|||||||
public static IOTServerConfiguration initConfig() {
|
public static IOTServerConfiguration initConfig() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String IOTServerAPIConfigurationPath =
|
String IOTServerAPIConfigurationPath = CarbonUtils.getCarbonConfigDirPath() + File.separator
|
||||||
CarbonUtils.getCarbonConfigDirPath() + File.separator + IOT_APIS_CONFIG_FILE;
|
+ IOT_APIS_CONFIG_FILE;
|
||||||
File file = new File(IOTServerAPIConfigurationPath);
|
File file = new File(IOTServerAPIConfigurationPath);
|
||||||
Document doc = Utils.convertToDocument(file);
|
Document doc = Utils.convertToDocument(file);
|
||||||
|
|
||||||
JAXBContext fileContext = JAXBContext.newInstance(IOTServerConfiguration.class);
|
JAXBContext fileContext = JAXBContext.newInstance(IOTServerConfiguration.class);
|
||||||
Unmarshaller unmarshaller = fileContext.createUnmarshaller();
|
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) {
|
} catch (JAXBException | APIMCertificateMGTException e) {
|
||||||
log.error("Error occurred while initializing Data Source config", e);
|
log.error("Error occurred while initializing Data Source config", e);
|
||||||
return null;
|
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.
|
* This class build the iot-api-config.xml file.
|
||||||
* @param file
|
* @param file
|
||||||
|
|||||||
@ -92,6 +92,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||||||
operations = this.getValidOperationNames(); //list operations for each device type
|
operations = this.getValidOperationNames(); //list operations for each device type
|
||||||
devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type
|
devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type
|
||||||
if (!devices.isEmpty()) {
|
if (!devices.isEmpty()) {
|
||||||
|
if (operations != null) {
|
||||||
for (String str : operations) {
|
for (String str : operations) {
|
||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setEnabled(true);
|
operation.setEnabled(true);
|
||||||
@ -100,6 +101,11 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||||||
deviceManagementProviderService.addOperation(deviceType, operation,
|
deviceManagementProviderService.addOperation(deviceType, operation,
|
||||||
DeviceManagerUtil.getValidDeviceIdentifiers(devices));
|
DeviceManagerUtil.getValidDeviceIdentifiers(devices));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No operations are available.");
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("No devices are available to perform the operations.");
|
log.debug("No devices are available to perform the operations.");
|
||||||
|
|||||||
@ -53,7 +53,6 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||||||
log.info("Task adding for " + deviceType);
|
log.info("Task adding for " + deviceType);
|
||||||
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
|
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
|
||||||
taskService.registerTaskType(TASK_TYPE);
|
taskService.registerTaskType(TASK_TYPE);
|
||||||
|
|||||||
@ -54,10 +54,6 @@
|
|||||||
<!--Merged -> Merged policy evaluation point -->
|
<!--Merged -> Merged policy evaluation point -->
|
||||||
<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>
|
<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>
|
||||||
</PolicyConfiguration>
|
</PolicyConfiguration>
|
||||||
<!--<TaskConfiguration>-->
|
|
||||||
<!--<Enable>true</Enable>-->
|
|
||||||
<!--<Frequency>600000</Frequency>-->
|
|
||||||
<!--</TaskConfiguration>-->
|
|
||||||
<!-- Default Page size configuration for paginated DM APIs-->
|
<!-- Default Page size configuration for paginated DM APIs-->
|
||||||
<PaginationConfiguration>
|
<PaginationConfiguration>
|
||||||
<DeviceListPageSize>20</DeviceListPageSize>
|
<DeviceListPageSize>20</DeviceListPageSize>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user