Search in sources :

Example 1 with ConfigDescriptionParameterDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO in project openhab-core by openhab.

the class ChannelTypeResource method convertToChannelTypeDTO.

private ChannelTypeDTO convertToChannelTypeDTO(ChannelType channelType, Locale locale) {
    final URI descURI = channelType.getConfigDescriptionURI();
    final ConfigDescription configDescription = descURI == null ? null : configDescriptionRegistry.getConfigDescription(descURI, locale);
    final ConfigDescriptionDTO configDescriptionDTO = configDescription == null ? null : ConfigDescriptionDTOMapper.map(configDescription);
    final List<ConfigDescriptionParameterDTO> parameters = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameters;
    final List<ConfigDescriptionParameterGroupDTO> parameterGroups = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameterGroups;
    return new ChannelTypeDTO(channelType.getUID().toString(), channelType.getLabel(), channelType.getDescription(), channelType.getCategory(), channelType.getItemType(), channelType.getKind(), parameters, parameterGroups, channelType.getState(), channelType.getTags(), channelType.isAdvanced(), channelType.getCommandDescription());
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ChannelTypeDTO(org.openhab.core.thing.dto.ChannelTypeDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) URI(java.net.URI)

Example 2 with ConfigDescriptionParameterDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO in project openhab-core by openhab.

the class ThingTypeResource method convertToThingTypeDTO.

private ThingTypeDTO convertToThingTypeDTO(ThingType thingType, Locale locale) {
    final ConfigDescription configDescription;
    final URI descURI = thingType.getConfigDescriptionURI();
    configDescription = descURI == null ? null : configDescriptionRegistry.getConfigDescription(descURI, locale);
    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);
    }
    final List<ChannelDefinitionDTO> channelDefinitions = convertToChannelDefinitionDTOs(thingType.getChannelDefinitions(), locale);
    return new ThingTypeDTO(thingType.getUID().toString(), thingType.getLabel(), thingType.getDescription(), thingType.getCategory(), thingType.isListed(), parameters, channelDefinitions, convertToChannelGroupDefinitionDTOs(thingType.getChannelGroupDefinitions(), locale), thingType.getSupportedBridgeTypeUIDs(), thingType.getProperties(), thingType instanceof BridgeType, parameterGroups, thingType.getExtensibleChannelTypeIds());
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ChannelDefinitionDTO(org.openhab.core.thing.dto.ChannelDefinitionDTO) ThingTypeDTO(org.openhab.core.thing.dto.ThingTypeDTO) StrippedThingTypeDTO(org.openhab.core.thing.dto.StrippedThingTypeDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) URI(java.net.URI) BridgeType(org.openhab.core.thing.type.BridgeType)

Example 3 with ConfigDescriptionParameterDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapper method mapEnrichedParameters.

/**
 * Maps configuration description parameters into enriched DTO objects.
 *
 * @param parameters the configuration description parameters (not null)
 * @return the parameter enriched DTO objects
 */
public static List<ConfigDescriptionParameterDTO> mapEnrichedParameters(List<ConfigDescriptionParameter> parameters) {
    List<ConfigDescriptionParameterDTO> configDescriptionParameterBeans = new ArrayList<>(parameters.size());
    for (ConfigDescriptionParameter configDescriptionParameter : parameters) {
        ConfigDescriptionParameterDTO configDescriptionParameterBean = new EnrichedConfigDescriptionParameterDTO(configDescriptionParameter.getName(), configDescriptionParameter.getType(), configDescriptionParameter.getMinimum(), configDescriptionParameter.getMaximum(), configDescriptionParameter.getStepSize(), configDescriptionParameter.getPattern(), configDescriptionParameter.isRequired(), configDescriptionParameter.isReadOnly(), configDescriptionParameter.isMultiple(), configDescriptionParameter.getContext(), configDescriptionParameter.getDefault(), configDescriptionParameter.getLabel(), configDescriptionParameter.getDescription(), mapOptions(configDescriptionParameter.getOptions()), mapFilterCriteria(configDescriptionParameter.getFilterCriteria()), configDescriptionParameter.getGroupName(), configDescriptionParameter.isAdvanced(), configDescriptionParameter.getLimitToOptions(), configDescriptionParameter.getMultipleLimit(), configDescriptionParameter.getUnit(), configDescriptionParameter.getUnitLabel(), configDescriptionParameter.isVerifyable());
        configDescriptionParameterBeans.add(configDescriptionParameterBean);
    }
    return configDescriptionParameterBeans;
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter)

Example 4 with ConfigDescriptionParameterDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapperTest method testThatDefaultValuesAreAList.

@Test
public void testThatDefaultValuesAreAList() {
    ConfigDescriptionParameter configDescriptionParameter = ConfigDescriptionParameterBuilder.create(CONFIG_PARAMETER_NAME, Type.TEXT).withDefault(CONFIG_PARAMETER_DEFAULT_VALUE).withMultiple(true).build();
    ConfigDescription configDescription = ConfigDescriptionBuilder.create(CONFIG_URI).withParameter(configDescriptionParameter).build();
    ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription);
    assertThat(cddto.parameters, hasSize(1));
    ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0);
    assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class));
    assertThat(cdpdto.defaultValue, is(CONFIG_PARAMETER_DEFAULT_VALUE));
    EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto;
    assertThat(ecdpdto.defaultValues, is(notNullValue()));
    assertThat(ecdpdto.defaultValues, hasSize(3));
    assertThat(ecdpdto.defaultValues, is(equalTo(List.of("first value", "second value", "third value"))));
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigDescriptionParameterDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapperTest method testThatDefaultValueIsNotAList.

@Test
public void testThatDefaultValueIsNotAList() {
    ConfigDescriptionParameter configDescriptionParameter = ConfigDescriptionParameterBuilder.create(CONFIG_PARAMETER_NAME, Type.TEXT).withDefault(CONFIG_PARAMETER_DEFAULT_VALUE).build();
    ConfigDescription configDescription = ConfigDescriptionBuilder.create(CONFIG_URI).withParameter(configDescriptionParameter).build();
    ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription);
    assertThat(cddto.parameters, hasSize(1));
    ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0);
    assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class));
    assertThat(cdpdto.defaultValue, is(CONFIG_PARAMETER_DEFAULT_VALUE));
    EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto;
    assertThat(ecdpdto.defaultValues, is(nullValue()));
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigDescriptionParameterDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO)6 ConfigDescription (org.openhab.core.config.core.ConfigDescription)5 ConfigDescriptionDTO (org.openhab.core.config.core.dto.ConfigDescriptionDTO)5 ConfigDescriptionParameter (org.openhab.core.config.core.ConfigDescriptionParameter)4 Test (org.junit.jupiter.api.Test)3 URI (java.net.URI)2 ConfigDescriptionParameterGroupDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO)2 ArrayList (java.util.ArrayList)1 ChannelDefinitionDTO (org.openhab.core.thing.dto.ChannelDefinitionDTO)1 ChannelTypeDTO (org.openhab.core.thing.dto.ChannelTypeDTO)1 StrippedThingTypeDTO (org.openhab.core.thing.dto.StrippedThingTypeDTO)1 ThingTypeDTO (org.openhab.core.thing.dto.ThingTypeDTO)1 BridgeType (org.openhab.core.thing.type.BridgeType)1