use of org.openhab.core.config.core.ConfigurableService in project openhab-core by openhab.
the class ConfigurableServiceResource method getServicesByFilter.
private List<ConfigurableServiceDTO> getServicesByFilter(String filter, Locale locale) {
List<ConfigurableServiceDTO> services = new ArrayList<>();
ServiceReference<?>[] serviceReferences = null;
try {
serviceReferences = bundleContext.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);
ConfigurableService configurableService = ConfigurableServiceUtil.asConfigurableService((key) -> serviceReference.getProperty(key));
String defaultLabel = configurableService.label();
if (defaultLabel.isEmpty()) {
// for multi context services the label can be changed and must be read
// from config admin.
defaultLabel = configurationService.getProperty(id, OpenHAB.SERVICE_CONTEXT);
}
String key = I18nUtil.stripConstantOr(defaultLabel, () -> inferKey(configurableService.description_uri(), "label"));
String label = i18nProvider.getText(serviceReference.getBundle(), key, defaultLabel, locale);
String category = configurableService.category();
String configDescriptionURI = configurableService.description_uri();
if (configDescriptionURI.isEmpty()) {
String factoryPid = (String) serviceReference.getProperty(ConfigurationAdmin.SERVICE_FACTORYPID);
configDescriptionURI = getConfigDescriptionByFactoryPid(factoryPid);
}
boolean multiple = configurableService.factory();
services.add(new ConfigurableServiceDTO(id, label == null ? defaultLabel : label, category, configDescriptionURI, multiple));
}
}
return services;
}
use of org.openhab.core.config.core.ConfigurableService in project openhab-core by openhab.
the class ConfigurableServiceResource method getConfigDescriptionByFactoryPid.
@Nullable
private String getConfigDescriptionByFactoryPid(String factoryPid) {
String configDescriptionURI = null;
String filter = "(" + Constants.SERVICE_PID + "=" + factoryPid + ")";
try {
ServiceReference<?>[] refs = bundleContext.getServiceReferences((String) null, filter);
if (refs != null && refs.length > 0) {
ConfigurableService configurableService = ConfigurableServiceUtil.asConfigurableService((key) -> refs[0].getProperty(key));
configDescriptionURI = configurableService.description_uri();
}
} catch (InvalidSyntaxException e) {
logger.error("Cannot get service references because the syntax of the filter '{}' is invalid.", filter);
}
return configDescriptionURI;
}
Aggregations