use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class GenericMetadataProvider method removeMetadata.
/**
* Removes all meta-data for a given item name
*
* @param itemName
*/
public void removeMetadata(String itemName) {
Set<Metadata> toBeRemoved;
try {
lock.writeLock().lock();
toBeRemoved = metadata.stream().filter(MetadataPredicates.ofItem(itemName)).collect(toSet());
metadata.removeAll(toBeRemoved);
} finally {
lock.writeLock().unlock();
}
for (Metadata m : toBeRemoved) {
notifyListenersAboutRemovedElement(m);
}
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class GenericItemProvider2Test method testMetadataUpdate.
@Test
public void testMetadataUpdate() {
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s { meta=\"foo\" }".getBytes()));
Metadata metadata1 = metadataRegistry.get(new MetadataKey("meta", "s"));
assertNotNull(metadata1);
assertEquals("foo", metadata1.getValue());
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s { meta=\"bar\" }".getBytes()));
Metadata metadata2 = metadataRegistry.get(new MetadataKey("meta", "s"));
assertNotNull(metadata2);
assertEquals("bar", metadata2.getValue());
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s".getBytes()));
Metadata metadata3 = metadataRegistry.get(new MetadataKey("meta", "s"));
assertNull(metadata3);
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class GenericItemProvider2Test method testMetadata_simple.
@Test
public void testMetadata_simple() {
String model = "Switch simple { namespace=\"value\" } ";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
Item item = itemRegistry.get("simple");
assertNotNull(item);
Metadata res = metadataRegistry.get(new MetadataKey("namespace", "simple"));
assertNotNull(res);
assertEquals("value", res.getValue());
assertNotNull(res.getConfiguration());
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class GenericItemProvider2Test method testMetadata_configured.
@Test
public void testMetadata_configured() {
String model = //
"Switch simple { namespace=\"value\" } " + "Switch configured { foo=\"bar\" [ answer=42 ] } ";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
Item item = itemRegistry.get("configured");
assertNotNull(item);
Metadata res = metadataRegistry.get(new MetadataKey("foo", "configured"));
assertNotNull(res);
assertEquals("bar", res.getValue());
assertEquals(new BigDecimal(42), res.getConfiguration().get("answer"));
modelRepository.removeModel(TESTMODEL_NAME);
res = metadataRegistry.get(new MetadataKey("foo", "configured"));
assertNull(res);
}
use of org.eclipse.smarthome.core.items.Metadata in project smarthome by eclipse.
the class ItemResource method addMetadata.
private void addMetadata(EnrichedItemDTO dto, Set<String> namespaces, @Nullable Predicate<Metadata> filter) {
Map<String, Object> metadata = new HashMap<>();
for (String namespace : namespaces) {
MetadataKey key = new MetadataKey(namespace, dto.name);
Metadata md = metadataRegistry.get(key);
if (md != null && (filter == null || filter.test(md))) {
MetadataDTO mdDto = new MetadataDTO();
mdDto.value = md.getValue();
mdDto.config = md.getConfiguration().isEmpty() ? null : md.getConfiguration();
metadata.put(namespace, mdDto);
}
}
if (dto instanceof EnrichedGroupItemDTO) {
for (EnrichedItemDTO member : ((EnrichedGroupItemDTO) dto).members) {
addMetadata(member, namespaces, filter);
}
}
if (!metadata.isEmpty()) {
// we only set it in the dto if there is really data available
dto.metadata = metadata;
}
}
Aggregations