Search in sources :

Example 1 with ConfigurableServiceDTO

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;
}
Also used : ArrayList(java.util.ArrayList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ConfigurableServiceDTO(org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with ConfigurableServiceDTO

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));
}
Also used : ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URISyntaxException(java.net.URISyntaxException) ConfigurableServiceDTO(org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO) URI(java.net.URI)

Example 3 with ConfigurableServiceDTO

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;
}
Also used : ConfigurableServiceDTO(org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO)

Aggregations

ConfigurableServiceDTO (org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO)3 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1