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;
}
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;
}
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));
}
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());
}
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();
}
Aggregations