use of org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO in project smarthome by eclipse.
the class ItemResource method getItems.
@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available items.", response = EnrichedItemDTO.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = EnrichedItemDTO.class, responseContainer = "List") })
public Response getItems(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") @Nullable String language, @QueryParam("type") @ApiParam(value = "item type filter", required = false) @Nullable String type, @QueryParam("tags") @ApiParam(value = "item tag filter", required = false) @Nullable String tags, @DefaultValue("false") @QueryParam("recursive") @ApiParam(value = "get member items recursivly", required = false) boolean recursive, @QueryParam("fields") @ApiParam(value = "limit output to the given fields (comma separated)", required = false) @Nullable String fields) {
final Locale locale = LocaleUtil.getLocale(language);
logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
Stream<EnrichedItemDTO> itemStream = getItems(type, tags).stream().map(item -> EnrichedItemDTOMapper.map(item, recursive, null, uriInfo.getBaseUri(), locale));
itemStream = dtoMapper.limitToFields(itemStream, fields);
return Response.ok(new Stream2JSONInputStream(itemStream)).build();
}
use of org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO in project smarthome by eclipse.
the class EnrichedItemDTOMapperWithTransformOSGiTest method shouldConsiderTraformationWhenPresent.
@Test
public void shouldConsiderTraformationWhenPresent() {
NumberItem item1 = new NumberItem("Item1");
item1.setState(new DecimalType("12.34"));
item1.setStateDescriptionService(stateDescriptionService);
EnrichedItemDTO enrichedDTO = EnrichedItemDTOMapper.map(item1, false, null, null, null);
assertThat(enrichedDTO, is(notNullValue()));
assertThat(enrichedDTO.name, is("Item1"));
assertThat(enrichedDTO.state, is("12.34"));
StateDescription sd = enrichedDTO.stateDescription;
assertThat(sd.getMinimum(), is(BigDecimal.valueOf(0)));
assertThat(sd.getMaximum(), is(BigDecimal.valueOf(100)));
assertThat(sd.getStep(), is(BigDecimal.valueOf(10)));
assertThat(sd.getPattern(), is("%d °C"));
assertThat(sd.getOptions().get(0).getValue(), is("SOUND"));
assertThat(sd.getOptions().get(0).getLabel(), is("My great sound."));
}
Aggregations