Search in sources :

Example 1 with ItemNotFoundException

use of org.eclipse.smarthome.core.items.ItemNotFoundException 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();
    }
}
Also used : ActiveItem(org.eclipse.smarthome.core.items.ActiveItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) RollershutterItem(org.eclipse.smarthome.core.library.items.RollershutterItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GenericItem(org.eclipse.smarthome.core.items.GenericItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ItemNotFoundException

use of org.eclipse.smarthome.core.items.ItemNotFoundException 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;
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) Frame(org.eclipse.smarthome.model.sitemap.Frame) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) HashSet(java.util.HashSet) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 3 with ItemNotFoundException

use of org.eclipse.smarthome.core.items.ItemNotFoundException 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
        }
    }
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 4 with ItemNotFoundException

use of org.eclipse.smarthome.core.items.ItemNotFoundException in project smarthome by eclipse.

the class StatusConsoleCommandExtension method execute.

@Override
public void execute(String[] args, Console console) {
    if (args.length > 0) {
        String itemName = args[0];
        try {
            Item item = this.itemRegistry.getItemByPattern(itemName);
            console.println(item.getState().toString());
        } catch (ItemNotFoundException e) {
            console.println("Error: Item '" + itemName + "' does not exist.");
        } catch (ItemNotUniqueException e) {
            console.print("Error: Multiple items match this pattern: ");
            for (Item item : e.getMatchingItems()) {
                console.print(item.getName() + " ");
            }
        }
    } else {
        printUsage(console);
    }
}
Also used : Item(org.eclipse.smarthome.core.items.Item) ItemNotUniqueException(org.eclipse.smarthome.core.items.ItemNotUniqueException) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 5 with ItemNotFoundException

use of org.eclipse.smarthome.core.items.ItemNotFoundException in project smarthome by eclipse.

the class UpdateConsoleCommandExtension method execute.

@Override
public void execute(String[] args, Console console) {
    if (args.length > 0) {
        String itemName = args[0];
        try {
            Item item = this.itemRegistry.getItemByPattern(itemName);
            if (args.length > 1) {
                String stateName = args[1];
                State state = TypeParser.parseState(item.getAcceptedDataTypes(), stateName);
                if (state != null) {
                    eventPublisher.post(ItemEventFactory.createStateEvent(item.getName(), state));
                    console.println("Update has been sent successfully.");
                } else {
                    console.println("Error: State '" + stateName + "' is not valid for item '" + itemName + "'");
                    console.print("Valid data types are: ( ");
                    for (Class<? extends State> acceptedType : item.getAcceptedDataTypes()) {
                        console.print(acceptedType.getSimpleName() + " ");
                    }
                    console.println(")");
                }
            } else {
                printUsage(console);
            }
        } catch (ItemNotFoundException e) {
            console.println("Error: Item '" + itemName + "' does not exist.");
        } catch (ItemNotUniqueException e) {
            console.print("Error: Multiple items match this pattern: ");
            for (Item item : e.getMatchingItems()) {
                console.print(item.getName() + " ");
            }
        }
    } else {
        printUsage(console);
    }
}
Also used : Item(org.eclipse.smarthome.core.items.Item) State(org.eclipse.smarthome.core.types.State) ItemNotUniqueException(org.eclipse.smarthome.core.items.ItemNotUniqueException) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Aggregations

ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)41 Item (org.eclipse.smarthome.core.items.Item)36 GroupItem (org.eclipse.smarthome.core.items.GroupItem)22 GenericItem (org.eclipse.smarthome.core.items.GenericItem)17 State (org.eclipse.smarthome.core.types.State)15 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)8 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)8 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)8 Command (org.eclipse.smarthome.core.types.Command)7 ItemNotUniqueException (org.eclipse.smarthome.core.items.ItemNotUniqueException)5 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)5 Mapping (org.eclipse.smarthome.model.sitemap.Mapping)5 Date (java.util.Date)4 CallItem (org.eclipse.smarthome.core.library.items.CallItem)4 DateTimeItem (org.eclipse.smarthome.core.library.items.DateTimeItem)4 StringItem (org.eclipse.smarthome.core.library.items.StringItem)4 Widget (org.eclipse.smarthome.model.sitemap.Widget)4 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)3 ContactItem (org.eclipse.smarthome.core.library.items.ContactItem)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3