use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemResource method getItemData.
@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Path("/{itemname: [a-zA-Z_0-9]*}")
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Gets a single item.", response = EnrichedItemDTO.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = EnrichedItemDTO.class), @ApiResponse(code = 404, message = "Item not found") })
public Response getItemData(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("itemname") @ApiParam(value = "item name", required = true) String itemname) {
final Locale locale = LocaleUtil.getLocale(language);
logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
// get item
Item item = getItem(itemname);
// if it exists
if (item != null) {
logger.debug("Received HTTP GET request at '{}'.", uriInfo.getPath());
return getItemResponse(Status.OK, item, locale, null);
} else {
logger.info("Received HTTP GET request at '{}' for the unknown item '{}'.", uriInfo.getPath(), itemname);
return getItemNotFoundResponse(itemname);
}
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemResource method addMember.
@PUT
@RolesAllowed({ Role.ADMIN })
@Path("/{itemName: [a-zA-Z_0-9]*}/members/{memberItemName: [a-zA-Z_0-9]*}")
@ApiOperation(value = "Adds a new member to a group item.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Item or member item not found or item is not of type group item."), @ApiResponse(code = 405, message = "Member item is not editable.") })
public Response addMember(@PathParam("itemName") @ApiParam(value = "item name", required = true) String itemName, @PathParam("memberItemName") @ApiParam(value = "member item name", required = true) String memberItemName) {
try {
Item item = itemRegistry.getItem(itemName);
if (!(item instanceof GroupItem)) {
return Response.status(Status.NOT_FOUND).build();
}
GroupItem groupItem = (GroupItem) item;
Item memberItem = itemRegistry.getItem(memberItemName);
if (!(memberItem instanceof GenericItem)) {
return Response.status(Status.NOT_FOUND).build();
}
if (managedItemProvider.get(memberItemName) == null) {
return Response.status(Status.METHOD_NOT_ALLOWED).build();
}
GenericItem genericMemberItem = (GenericItem) memberItem;
genericMemberItem.addGroupName(groupItem.getName());
managedItemProvider.update(genericMemberItem);
return Response.ok(null, MediaType.TEXT_PLAIN).build();
} catch (ItemNotFoundException e) {
return Response.status(Status.NOT_FOUND).build();
}
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class EnrichedItemDTOMapper method map.
private static EnrichedItemDTO map(Item item, ItemDTO itemDTO, URI uri, boolean drillDown, Predicate<Item> itemFilter, Locale locale) {
String state = item.getState().toFullString();
String transformedState = considerTransformation(state, item.getStateDescription(locale));
if (transformedState != null && transformedState.equals(state)) {
transformedState = null;
}
StateDescription stateDescription = considerTransformation(item.getStateDescription(locale));
String link = null != uri ? uri.toASCIIString() + ItemResource.PATH_ITEMS + "/" + itemDTO.name : null;
EnrichedItemDTO enrichedItemDTO = null;
if (item instanceof GroupItem) {
GroupItem groupItem = (GroupItem) item;
EnrichedItemDTO[] memberDTOs;
if (drillDown) {
Collection<EnrichedItemDTO> members = new LinkedHashSet<>();
for (Item member : groupItem.getMembers()) {
if (itemFilter == null || itemFilter.test(member)) {
members.add(map(member, drillDown, itemFilter, uri, locale));
}
}
memberDTOs = members.toArray(new EnrichedItemDTO[members.size()]);
} else {
memberDTOs = new EnrichedItemDTO[0];
}
enrichedItemDTO = new EnrichedGroupItemDTO(itemDTO, memberDTOs, link, state, transformedState, stateDescription);
} else {
enrichedItemDTO = new EnrichedItemDTO(itemDTO, link, state, transformedState, stateDescription);
}
return enrichedItemDTO;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class SitemapResource method getAllItems.
/**
* Collects all items that are represented by a given list of widgets
*
* @param widgets
* the widget list to get the items for added to all bundles containing REST resources
* @return all items that are represented by the list of widgets
*/
private Set<GenericItem> getAllItems(EList<Widget> widgets) {
Set<GenericItem> items = new HashSet<GenericItem>();
if (itemUIRegistry != null) {
for (Widget widget : widgets) {
String itemName = widget.getItem();
if (itemName != null) {
try {
Item item = itemUIRegistry.getItem(itemName);
if (item instanceof GenericItem) {
items.add((GenericItem) item);
}
} catch (ItemNotFoundException e) {
// ignore
}
}
// Consider all items inside the frame
if (widget instanceof Frame) {
items.addAll(getAllItems(((Frame) widget).getChildren()));
}
// Consider items involved in any visibility, labelcolor and valuecolor condition
items.addAll(getItemsInVisibilityCond(widget.getVisibility()));
items.addAll(getItemsInColorCond(widget.getLabelColor()));
items.addAll(getItemsInColorCond(widget.getValueColor()));
}
}
return items;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class PageChangeListener method addItemWithName.
private void addItemWithName(Set<Item> items, String itemName) {
if (itemName != null) {
try {
Item item = itemUIRegistry.getItem(itemName);
items.add(item);
} catch (ItemNotFoundException e) {
// ignore
}
}
}
Aggregations