Search in sources :

Example 1 with ConfigDescription

use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.

the class BindingInfoConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    BindingInfoXmlResult bindingInfoXmlResult = null;
    BindingInfo bindingInfo = null;
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    String id = attributes.get("id");
    // set automatically extracted URI for a possible 'config-description' section
    context.put("config-description.uri", "binding:" + id);
    // read values
    List<?> nodes = (List<?>) context.convertAnother(context, List.class);
    NodeIterator nodeIterator = new NodeIterator(nodes);
    String name = (String) nodeIterator.nextValue("name", true);
    String description = (String) nodeIterator.nextValue("description", false);
    String author = (String) nodeIterator.nextValue("author", false);
    String serviceId = (String) nodeIterator.nextValue("service-id", false);
    URI configDescriptionURI = readConfigDescriptionURI(nodeIterator);
    ConfigDescription configDescription = null;
    if (configDescriptionURI == null) {
        configDescription = readConfigDescription(nodeIterator);
        if (configDescription != null) {
            configDescriptionURI = configDescription.getUID();
        }
    }
    nodeIterator.assertEndOfType();
    // create object
    bindingInfo = new BindingInfo(id, name, description, author, serviceId, configDescriptionURI);
    bindingInfoXmlResult = new BindingInfoXmlResult(bindingInfo, configDescription);
    return bindingInfoXmlResult;
}
Also used : NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) List(java.util.List) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URI(java.net.URI)

Example 2 with ConfigDescription

use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.

the class ConfigDescriptionConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    ConfigDescription configDescription = null;
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    String uriText = attributes.get("uri");
    if (uriText == null) {
        // the URI could be overridden by a context field if it could be
        // automatically extracted
        uriText = (String) context.get("config-description.uri");
    }
    URI uri = null;
    try {
        uri = new URI(uriText);
    } catch (NullPointerException | URISyntaxException ex) {
        throw new ConversionException("The URI '" + uriText + "' in node '" + reader.getNodeName() + "' is invalid!", ex);
    }
    // create the lists to hold parameters and groups
    List<ConfigDescriptionParameter> configDescriptionParams = new ArrayList<ConfigDescriptionParameter>();
    List<ConfigDescriptionParameterGroup> configDescriptionGroups = new ArrayList<ConfigDescriptionParameterGroup>();
    // read values
    List<?> nodes = (List<?>) context.convertAnother(context, List.class);
    NodeIterator nodeIterator = new NodeIterator(nodes);
    // respective arrays
    while (nodeIterator.hasNext() == true) {
        Object node = nodeIterator.next();
        if (node instanceof ConfigDescriptionParameter) {
            configDescriptionParams.add((ConfigDescriptionParameter) node);
        }
        if (node instanceof ConfigDescriptionParameterGroup) {
            configDescriptionGroups.add((ConfigDescriptionParameterGroup) node);
        }
    }
    ConverterAssertion.assertEndOfType(reader);
    // create object
    configDescription = new ConfigDescription(uri, configDescriptionParams, configDescriptionGroups);
    return configDescription;
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) ArrayList(java.util.ArrayList) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ConfigDescriptionParameterGroup(org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup) ArrayList(java.util.ArrayList) List(java.util.List) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 3 with ConfigDescription

use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.

the class BindingResource method normalizeConfiguration.

private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, String bindingId) {
    if (properties == null || properties.isEmpty()) {
        return properties;
    }
    BindingInfo bindingInfo = this.bindingInfoRegistry.getBindingInfo(bindingId);
    if (bindingInfo == null || bindingInfo.getConfigDescriptionURI() == null) {
        return properties;
    }
    ConfigDescription configDesc = configDescRegistry.getConfigDescription(bindingInfo.getConfigDescriptionURI());
    if (configDesc == null) {
        return properties;
    }
    return ConfigUtil.normalizeTypes(properties, Collections.singletonList(configDesc));
}
Also used : BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription)

Example 4 with ConfigDescription

use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.

the class ChannelTypeResource method convertToChannelTypeDTO.

private ChannelTypeDTO convertToChannelTypeDTO(ChannelType channelType, Locale locale) {
    final ConfigDescription configDescription;
    if (channelType.getConfigDescriptionURI() != null) {
        configDescription = this.configDescriptionRegistry.getConfigDescription(channelType.getConfigDescriptionURI(), locale);
    } else {
        configDescription = null;
    }
    List<ConfigDescriptionParameterDTO> parameters;
    List<ConfigDescriptionParameterGroupDTO> parameterGroups;
    if (configDescription != null) {
        ConfigDescriptionDTO configDescriptionDTO = ConfigDescriptionDTOMapper.map(configDescription);
        parameters = configDescriptionDTO.parameters;
        parameterGroups = configDescriptionDTO.parameterGroups;
    } else {
        parameters = new ArrayList<>(0);
        parameterGroups = new ArrayList<>(0);
    }
    return new ChannelTypeDTO(channelType.getUID().toString(), channelType.getLabel(), channelType.getDescription(), channelType.getCategory(), channelType.getItemType(), channelType.getKind(), parameters, parameterGroups, channelType.getState(), channelType.getTags(), channelType.isAdvanced());
}
Also used : ConfigDescriptionParameterDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionDTO) ChannelTypeDTO(org.eclipse.smarthome.core.thing.dto.ChannelTypeDTO) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription)

Example 5 with ConfigDescription

use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.

the class ConfigDescriptionResource method getAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets all available config descriptions.", response = ConfigDescriptionDTO.class, responseContainer = "List")
@ApiResponses(value = @ApiResponse(code = 200, message = "OK", response = ConfigDescriptionDTO.class, responseContainer = "List"))
public Response getAll(@HeaderParam("Accept-Language") @ApiParam(value = "Accept-Language") String language) {
    Locale locale = LocaleUtil.getLocale(language);
    Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions(locale);
    return Response.ok(new Stream2JSONInputStream(configDescriptions.stream().map(ConfigDescriptionDTOMapper::map))).build();
}
Also used : Locale(java.util.Locale) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)22 URI (java.net.URI)10 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)9 ArrayList (java.util.ArrayList)5 List (java.util.List)3 ConfigDescriptionParameterGroup (org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup)3 BindingInfo (org.eclipse.smarthome.core.binding.BindingInfo)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Test (org.junit.Test)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URISyntaxException (java.net.URISyntaxException)2 Locale (java.util.Locale)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 ConfigDescriptionDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionDTO)2 ConfigDescriptionParameterDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterDTO)2 ConfigDescriptionParameterGroupDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterGroupDTO)2 NodeIterator (org.eclipse.smarthome.config.xml.util.NodeIterator)2 ThingType (org.eclipse.smarthome.core.thing.type.ThingType)2