use of org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO in project smarthome by eclipse.
the class ConfigurableServiceResource method getServicesByFilter.
private List<ConfigurableServiceDTO> getServicesByFilter(String filter) {
List<ConfigurableServiceDTO> services = new ArrayList<>();
ServiceReference<?>[] serviceReferences = null;
try {
serviceReferences = RESTCoreActivator.getBundleContext().getServiceReferences((String) null, filter);
} catch (InvalidSyntaxException ex) {
logger.error("Cannot get service references because the syntax of the filter '{}' is invalid.", filter);
}
if (serviceReferences != null) {
for (ServiceReference<?> serviceReference : serviceReferences) {
String id = getServiceId(serviceReference);
String label = (String) serviceReference.getProperty(ConfigurableService.SERVICE_PROPERTY_LABEL);
if (label == null) {
// for multi context services the label can be changed and must be read from config
// admin.
label = configurationService.getProperty(id, ConfigConstants.SERVICE_CONTEXT);
}
String category = (String) serviceReference.getProperty(ConfigurableService.SERVICE_PROPERTY_CATEGORY);
String configDescriptionURI = (String) serviceReference.getProperty(ConfigurableService.SERVICE_PROPERTY_DESCRIPTION_URI);
if (configDescriptionURI == null) {
String factoryPid = (String) serviceReference.getProperty(ConfigurationAdmin.SERVICE_FACTORYPID);
configDescriptionURI = getConfigDescriptionByFactoryPid(factoryPid);
}
boolean multiple = Boolean.parseBoolean((String) serviceReference.getProperty(ConfigurableService.SERVICE_PROPERTY_FACTORY_SERVICE));
services.add(new ConfigurableServiceDTO(id, label, category, configDescriptionURI, multiple));
}
}
return services;
}
use of org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO in project smarthome by eclipse.
the class ConfigurableServiceResource method normalizeConfiguration.
private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, String serviceId) {
if (properties == null || properties.isEmpty()) {
return properties;
}
ConfigurableServiceDTO service = getServiceById(serviceId);
if (service == null) {
return properties;
}
URI uri;
try {
uri = new URI(service.configDescriptionURI);
} catch (URISyntaxException e) {
logger.warn("Not a valid URI: {}", service.configDescriptionURI);
return properties;
}
ConfigDescription configDesc = configDescRegistry.getConfigDescription(uri);
if (configDesc == null) {
return properties;
}
return ConfigUtil.normalizeTypes(properties, Collections.singletonList(configDesc));
}
use of org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO in project smarthome by eclipse.
the class ConfigurableServiceResource method getServiceById.
private ConfigurableServiceDTO getServiceById(String serviceId) {
ConfigurableServiceDTO multiService = getMultiConfigServiceById(serviceId);
if (multiService != null) {
return multiService;
}
List<ConfigurableServiceDTO> configurableServices = getConfigurableServices();
for (ConfigurableServiceDTO configurableService : configurableServices) {
if (configurableService.id.equals(serviceId)) {
return configurableService;
}
}
return null;
}
Aggregations