use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class ItemResource method getItems.
@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available items.", response = EnrichedItemDTO.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = EnrichedItemDTO.class, responseContainer = "List") })
public Response getItems(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") @Nullable String language, @QueryParam("type") @ApiParam(value = "item type filter", required = false) @Nullable String type, @QueryParam("tags") @ApiParam(value = "item tag filter", required = false) @Nullable String tags, @QueryParam("metadata") @ApiParam(value = "metadata selector", required = false) @Nullable String namespaceSelector, @DefaultValue("false") @QueryParam("recursive") @ApiParam(value = "get member items recursively", required = false) boolean recursive, @QueryParam("fields") @ApiParam(value = "limit output to the given fields (comma separated)", required = false) @Nullable String fields) {
final Locale locale = localeService.getLocale(language);
final Set<String> namespaces = splitAndFilterNamespaces(namespaceSelector, locale);
logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
Stream<EnrichedItemDTO> itemStream = //
getItems(type, tags).stream().map(//
item -> EnrichedItemDTOMapper.map(item, recursive, null, uriInfo.getBaseUri(), locale)).peek(//
dto -> addMetadata(dto, namespaces, null)).peek(dto -> dto.editable = isEditable(dto.name));
itemStream = dtoMapper.limitToFields(itemStream, fields);
return Response.ok(new Stream2JSONInputStream(itemStream)).build();
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class ItemResourceOSGiTest method testRemoveMetadata_unmanagedMetadata.
@Test
public void testRemoveMetadata_unmanagedMetadata() {
MetadataProvider provider = mock(MetadataProvider.class);
when(provider.getAll()).thenReturn(Collections.singleton(new Metadata(new MetadataKey("namespace", ITEM_NAME1), "some value", null)));
registerService(provider);
Response response = itemResource.removeMetadata(ITEM_NAME1, "namespace");
assertEquals(409, response.getStatus());
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class MetadataRegistryImplTest method testGet.
@Test
public void testGet() throws Exception {
MetadataKey key = new MetadataKey("namespace", "itemName");
registry.added(managedProvider, new Metadata(key, "value", Collections.emptyMap()));
registry.added(managedProvider, new Metadata(new MetadataKey("other", "itemName"), "other", Collections.emptyMap()));
registry.added(managedProvider, new Metadata(new MetadataKey("namespace", "other"), "other", Collections.emptyMap()));
Metadata res = registry.get(key);
assertNotNull(res);
assertEquals("value", res.getValue());
assertEquals("namespace", res.getUID().getNamespace());
assertEquals("itemName", res.getUID().getItemName());
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class AbstractItemEventSubscriberOSGiTest method setup.
@Before
public void setup() {
initMocks(this);
eventPublisher = getService(EventPublisher.class);
assertNotNull(eventPublisher);
when(itemProvider.getAll()).thenReturn(Collections.singletonList(new SwitchItem(ITEM_NAME)));
registerService(itemProvider);
EventSubscriber itemEventSubscriber = new AbstractItemEventSubscriber() {
@Override
protected void receiveCommand(ItemCommandEvent event) {
commandEvent = event;
}
@Override
protected void receiveUpdate(ItemStateEvent event) {
updateEvent = event;
}
};
registerService(itemEventSubscriber, EventSubscriber.class.getName());
when(mockMetadataProvider.getAll()).thenReturn(Collections.singletonList(new Metadata(new MetadataKey("autoupdate", ITEM_NAME), Boolean.toString(false), null)));
registerService(mockMetadataProvider);
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class GenericMetadataProvider method addMetadata.
/**
* Adds metadata to this provider
*
* @param bindingType
* @param itemName
* @param configuration
*/
public void addMetadata(String bindingType, String itemName, String value, @Nullable Map<String, Object> configuration) {
MetadataKey key = new MetadataKey(bindingType, itemName);
Metadata md = new Metadata(key, value, configuration);
try {
lock.writeLock().lock();
metadata.add(md);
} finally {
lock.writeLock().unlock();
}
notifyListenersAboutAddedElement(md);
}
Aggregations