Search in sources :

Example 1 with ProfileType

use of org.eclipse.smarthome.core.thing.profiles.ProfileType in project smarthome by eclipse.

the class ChannelTypeResource method getLinkableItemTypes.

@GET
@Path("/{channelTypeUID}/linkableItemTypes")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the item types the given trigger channel type UID can be linked to.", response = String.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class, responseContainer = "Set"), @ApiResponse(code = 204, message = "No content: channel type has no linkable items or is no trigger channel."), @ApiResponse(code = 404, message = "Given channel type UID not found.") })
public Response getLinkableItemTypes(@PathParam("channelTypeUID") @ApiParam(value = "channelTypeUID") String channelTypeUID) {
    ChannelTypeUID ctUID = new ChannelTypeUID(channelTypeUID);
    ChannelType channelType = channelTypeRegistry.getChannelType(ctUID);
    if (channelType == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (channelType.getKind() != ChannelKind.TRIGGER) {
        return Response.noContent().build();
    }
    Set<String> result = new HashSet<>();
    for (ProfileType profileType : profileTypeRegistry.getProfileTypes()) {
        if (profileType instanceof TriggerProfileType) {
            if (((TriggerProfileType) profileType).getSupportedChannelTypeUIDs().contains(ctUID)) {
                for (String itemType : profileType.getSupportedItemTypes()) {
                    result.add(itemType);
                }
            }
        }
    }
    if (result.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(result).build();
}
Also used : ProfileType(org.eclipse.smarthome.core.thing.profiles.ProfileType) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashSet (java.util.HashSet)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ProfileType (org.eclipse.smarthome.core.thing.profiles.ProfileType)1 TriggerProfileType (org.eclipse.smarthome.core.thing.profiles.TriggerProfileType)1 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1