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();
}
}
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;
}
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
}
}
}
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);
}
}
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);
}
}
Aggregations