Search in sources :

Example 1 with BindingInfo

use of org.eclipse.smarthome.core.binding.BindingInfo 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 BindingInfo

use of org.eclipse.smarthome.core.binding.BindingInfo 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 3 with BindingInfo

use of org.eclipse.smarthome.core.binding.BindingInfo in project smarthome by eclipse.

the class BindingInfoXmlProvider method addingObject.

@Override
public synchronized void addingObject(BindingInfoXmlResult bindingInfoXmlResult) {
    if (bindingInfoXmlResult != null) {
        ConfigDescription configDescription = bindingInfoXmlResult.getConfigDescription();
        if (configDescription != null) {
            try {
                this.configDescriptionProvider.add(this.bundle, configDescription);
            } catch (Exception ex) {
                this.logger.error("Could not register ConfigDescription!", ex);
            }
        }
        BindingInfo bindingInfo = bindingInfoXmlResult.getBindingInfo();
        this.bindingInfoProvider.add(bundle, bindingInfo);
    }
}
Also used : BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription)

Example 4 with BindingInfo

use of org.eclipse.smarthome.core.binding.BindingInfo in project smarthome by eclipse.

the class BindingResource method getAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all bindings.", response = BindingInfoDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = BindingInfoDTO.class, responseContainer = "Set") })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language) {
    final Locale locale = LocaleUtil.getLocale(language);
    Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(locale);
    return Response.ok(new Stream2JSONInputStream(bindingInfos.stream().map(b -> map(b, locale)))).build();
}
Also used : Locale(java.util.Locale) PathParam(javax.ws.rs.PathParam) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) BindingInfoDTO(org.eclipse.smarthome.core.binding.dto.BindingInfoDTO) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Component(org.osgi.service.component.annotations.Component) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) Map(java.util.Map) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) HeaderParam(javax.ws.rs.HeaderParam) ConfigurationService(org.eclipse.smarthome.io.rest.core.config.ConfigurationService) URI(java.net.URI) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) Configuration(org.eclipse.smarthome.config.core.Configuration) RESTResource(org.eclipse.smarthome.io.rest.RESTResource) Context(javax.ws.rs.core.Context) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) ConfigDescriptionRegistry(org.eclipse.smarthome.config.core.ConfigDescriptionRegistry) Role(org.eclipse.smarthome.core.auth.Role) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) BindingInfoRegistry(org.eclipse.smarthome.core.binding.BindingInfoRegistry) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) ConfigUtil(org.eclipse.smarthome.config.core.ConfigUtil) LocaleUtil(org.eclipse.smarthome.io.rest.LocaleUtil) BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) 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)4 BindingInfo (org.eclipse.smarthome.core.binding.BindingInfo)4 URI (java.net.URI)2 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Set (java.util.Set)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 HeaderParam (javax.ws.rs.HeaderParam)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1