Search in sources :

Example 1 with EnrichedItemDTO

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();
}
Also used : Locale(java.util.Locale) EnrichedItemDTO(org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with EnrichedItemDTO

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."));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) EnrichedItemDTO(org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) StateDescription(org.eclipse.smarthome.core.types.StateDescription) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

EnrichedItemDTO (org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Locale (java.util.Locale)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)1 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)1 StateDescription (org.eclipse.smarthome.core.types.StateDescription)1 Stream2JSONInputStream (org.eclipse.smarthome.io.rest.Stream2JSONInputStream)1 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)1 Test (org.junit.Test)1