use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.
the class PersistentInboxTest method configureConfigDescriptionRegistryMock.
private void configureConfigDescriptionRegistryMock(String paramName, Type type) throws URISyntaxException {
URI configDescriptionURI = new URI("thing-type:test:test");
ThingType thingType = ThingTypeBuilder.instance(THING_TYPE_UID, "Test").withConfigDescriptionURI(configDescriptionURI).build();
ConfigDescriptionParameter param = ConfigDescriptionParameterBuilder.create(paramName, type).build();
ConfigDescription configDesc = new ConfigDescription(configDescriptionURI, Collections.singletonList(param));
when(thingTypeRegistry.getThingType(THING_TYPE_UID)).thenReturn(thingType);
when(configDescriptionRegistry.getConfigDescription(eq(configDescriptionURI))).thenReturn(configDesc);
}
use of org.eclipse.smarthome.config.core.ConfigDescription 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);
}
}
use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.
the class ThingManager method isComplete.
/**
* Determines if all 'required' configuration parameters are available in the configuration
*
* @param prototype the "prototype", i.e. thing type or channel type
* @param targetUID the UID of the thing or channel entity
* @param configDescriptionURIFunction a function to determine the the config description UID for the given
* prototype
* @param configuration the current configuration
* @return true if all required configuration parameters are given, false otherwise
*/
private <T extends Identifiable<?>> boolean isComplete(T prototype, UID targetUID, Function<T, URI> configDescriptionURIFunction, Configuration configuration) {
if (prototype == null) {
logger.debug("Prototype for '{}' is not known, assuming it is initializable", targetUID);
return true;
}
ConfigDescription description = resolve(configDescriptionURIFunction.apply(prototype), null);
if (description == null) {
logger.debug("Config description for '{}' is not resolvable, assuming '{}' is initializable", prototype.getUID(), targetUID);
return true;
}
List<String> requiredParameters = getRequiredParameters(description);
Set<String> propertyKeys = configuration.getProperties().keySet();
if (logger.isDebugEnabled()) {
logger.debug("Configuration of '{}' needs {}, has {}.", targetUID, requiredParameters, propertyKeys);
}
return propertyKeys.containsAll(requiredParameters);
}
use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.
the class ItemChannelLinkConfigDescriptionProvider method getConfigDescription.
@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
if (SCHEME.equals(uri.getScheme())) {
ItemChannelLink link = itemChannelLinkRegistry.get(uri.getSchemeSpecificPart());
if (link == null) {
return null;
}
Item item = itemRegistry.get(link.getItemName());
if (item == null) {
return null;
}
Thing thing = thingRegistry.get(link.getLinkedUID().getThingUID());
if (thing == null) {
return null;
}
Channel channel = thing.getChannel(link.getLinkedUID().getId());
if (channel == null) {
return null;
}
ConfigDescriptionParameter paramProfile = ConfigDescriptionParameterBuilder.create(PARAM_PROFILE, Type.TEXT).withLabel("Profile").withDescription("the profile to use").withRequired(false).withLimitToOptions(true).withOptions(getOptions(link, item, channel, locale)).build();
return new ConfigDescription(uri, Collections.singletonList(paramProfile));
}
return null;
}
use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.
the class ConfigDescriptionResource method getByURI.
@GET
@Path("/{uri}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a config description by URI.", response = ConfigDescriptionDTO.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ConfigDescriptionDTO.class), @ApiResponse(code = 400, message = "Invalid URI syntax"), @ApiResponse(code = 404, message = "Not found") })
public Response getByURI(@HeaderParam("Accept-Language") @ApiParam(value = "Accept-Language") String language, @PathParam("uri") @ApiParam(value = "uri") String uri) {
Locale locale = LocaleUtil.getLocale(language);
URI uriObject = UriBuilder.fromPath(uri).build();
ConfigDescription configDescription = this.configDescriptionRegistry.getConfigDescription(uriObject, locale);
return configDescription != null ? Response.ok(ConfigDescriptionDTOMapper.map(configDescription)).build() : JSONResponse.createErrorResponse(Status.NOT_FOUND, "Configuration not found: " + uri);
}
Aggregations