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