use of org.eclipse.smarthome.core.items.GenericItem in project smarthome by eclipse.
the class ItemResource method removeMember.
@DELETE
@RolesAllowed({ Role.ADMIN })
@Path("/{itemName: [a-zA-Z_0-9]*}/members/{memberItemName: [a-zA-Z_0-9]*}")
@ApiOperation(value = "Removes an existing member from 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 removeMember(@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.removeGroupName(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.GenericItem in project smarthome by eclipse.
the class SitemapResource method waitForChanges.
/**
* This method only returns when a change has occurred to any item on the
* page to display or if the timeout is reached
*
* @param widgets
* the widgets of the page to observe
* @return true if the timeout is reached
*/
private boolean waitForChanges(EList<Widget> widgets) {
long startTime = (new Date()).getTime();
boolean timeout = false;
BlockingStateChangeListener listener = new BlockingStateChangeListener();
// let's get all items for these widgets
Set<GenericItem> items = getAllItems(widgets);
for (GenericItem item : items) {
item.addStateChangeListener(listener);
}
while (!listener.hasChangeOccurred() && !timeout) {
timeout = (new Date()).getTime() - startTime > TIMEOUT_IN_MS;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
timeout = true;
break;
}
}
for (GenericItem item : items) {
item.removeStateChangeListener(listener);
}
return timeout;
}
Aggregations