Search in sources :

Example 26 with GenericItem

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();
    }
}
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) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 with GenericItem

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;
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Date(java.util.Date)

Aggregations

GenericItem (org.eclipse.smarthome.core.items.GenericItem)27 GroupItem (org.eclipse.smarthome.core.items.GroupItem)10 Item (org.eclipse.smarthome.core.items.Item)10 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)6 Test (org.junit.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Path (javax.ws.rs.Path)2 ActiveItem (org.eclipse.smarthome.core.items.ActiveItem)2 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)2 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)2 ModelGroupItem (org.eclipse.smarthome.model.items.ModelGroupItem)2 ModelNormalItem (org.eclipse.smarthome.model.items.ModelNormalItem)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1