Search in sources :

Example 1 with EnrichedThingDTO

use of org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO in project smarthome by eclipse.

the class ThingResource method getThingResponse.

/**
 * helper: create a Response holding a Thing and/or error information.
 *
 * @param status
 * @param thing
 * @param errormessage an optional error message (may be null), ignored if the status family is successful
 * @return Response
 */
private Response getThingResponse(Status status, Thing thing, Locale locale, String errormessage) {
    ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, locale);
    boolean managed = managedThingProvider.get(thing.getUID()) != null;
    EnrichedThingDTO enrichedThingDTO = thing != null ? EnrichedThingDTOMapper.map(thing, thingStatusInfo, this.getThingFirmwareStatus(thing.getUID()), getLinkedItemsMap(thing), managed) : null;
    return JSONResponse.createResponse(status, enrichedThingDTO, errormessage);
}
Also used : EnrichedThingDTO(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

Example 2 with EnrichedThingDTO

use of org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO in project smarthome by eclipse.

the class ThingResource method getAll.

@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available things.", response = EnrichedThingDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = EnrichedThingDTO.class, responseContainer = "Set") })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language) {
    final Locale locale = LocaleUtil.getLocale(language);
    Stream<EnrichedThingDTO> thingStream = thingRegistry.stream().map(t -> convertToEnrichedThingDTO(t, locale)).distinct();
    return Response.ok(new Stream2JSONInputStream(thingStream)).build();
}
Also used : Locale(java.util.Locale) Channel(org.eclipse.smarthome.core.thing.Channel) ItemFactory(org.eclipse.smarthome.core.items.ItemFactory) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) URISyntaxException(java.net.URISyntaxException) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) ConfigStatusService(org.eclipse.smarthome.config.core.status.ConfigStatusService) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) DefaultValue(javax.ws.rs.DefaultValue) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ManagedItemProvider(org.eclipse.smarthome.core.items.ManagedItemProvider) HeaderParam(javax.ws.rs.HeaderParam) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) Configuration(org.eclipse.smarthome.config.core.Configuration) DELETE(javax.ws.rs.DELETE) RESTResource(org.eclipse.smarthome.io.rest.RESTResource) Context(javax.ws.rs.core.Context) ConfigStatusInfo(org.eclipse.smarthome.config.core.status.ConfigStatusInfo) EnrichedThingDTO(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO) Collection(java.util.Collection) Set(java.util.Set) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) ConfigDescriptionRegistry(org.eclipse.smarthome.config.core.ConfigDescriptionRegistry) ThingTypeRegistry(org.eclipse.smarthome.core.thing.type.ThingTypeRegistry) Role(org.eclipse.smarthome.core.auth.Role) ManagedItemChannelLinkProvider(org.eclipse.smarthome.core.thing.link.ManagedItemChannelLinkProvider) List(java.util.List) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) Stream(java.util.stream.Stream) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) FirmwareStatusDTO(org.eclipse.smarthome.core.thing.firmware.dto.FirmwareStatusDTO) Entry(java.util.Map.Entry) JSONResponse(org.eclipse.smarthome.io.rest.JSONResponse) EnrichedThingDTOMapper(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTOMapper) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) UriInfo(javax.ws.rs.core.UriInfo) ThingDTOMapper(org.eclipse.smarthome.core.thing.dto.ThingDTOMapper) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ThingHelper(org.eclipse.smarthome.core.thing.util.ThingHelper) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) LocaleUtil(org.eclipse.smarthome.io.rest.LocaleUtil) ChannelDTOMapper(org.eclipse.smarthome.core.thing.dto.ChannelDTOMapper) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) FirmwareUID(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID) ChannelDTO(org.eclipse.smarthome.core.thing.dto.ChannelDTO) FirmwareUpdateService(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateService) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) ThingDTO(org.eclipse.smarthome.core.thing.dto.ThingDTO) POST(javax.ws.rs.POST) ConfigValidationException(org.eclipse.smarthome.config.core.validation.ConfigValidationException) ThingStatusInfoI18nLocalizationService(org.eclipse.smarthome.core.thing.i18n.ThingStatusInfoI18nLocalizationService) Logger(org.slf4j.Logger) IOException(java.io.IOException) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ChannelTypeRegistry(org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry) ApiResponse(io.swagger.annotations.ApiResponse) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) PUT(javax.ws.rs.PUT) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) ConfigUtil(org.eclipse.smarthome.config.core.ConfigUtil) EnrichedThingDTO(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO) 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)

Aggregations

ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)2 EnrichedThingDTO (org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO)2 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1