use of org.eclipse.smarthome.core.items.dto.MetadataDTO 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;
}
}
use of org.eclipse.smarthome.core.items.dto.MetadataDTO in project smarthome by eclipse.
the class ItemResourceOSGiTest method testAddMetadata_nonExistingItem.
@Test
public void testAddMetadata_nonExistingItem() {
MetadataDTO dto = new MetadataDTO();
dto.value = "some value";
Response response = itemResource.addMetadata("nonExisting", "foo", dto);
assertEquals(404, response.getStatus());
}
use of org.eclipse.smarthome.core.items.dto.MetadataDTO in project smarthome by eclipse.
the class ItemResourceOSGiTest method testAddMetadata_ValueNull.
@Test
public void testAddMetadata_ValueNull() {
MetadataDTO dto = new MetadataDTO();
dto.value = null;
Response response = itemResource.addMetadata(ITEM_NAME1, "foo", dto);
assertEquals(400, response.getStatus());
}
use of org.eclipse.smarthome.core.items.dto.MetadataDTO in project smarthome by eclipse.
the class ItemResourceOSGiTest method testAddMetadata_update.
@Test
public void testAddMetadata_update() {
MetadataDTO dto = new MetadataDTO();
dto.value = "some value";
assertEquals(201, itemResource.addMetadata(ITEM_NAME1, "namespace", dto).getStatus());
MetadataDTO dto2 = new MetadataDTO();
dto2.value = "new value";
assertEquals(200, itemResource.addMetadata(ITEM_NAME1, "namespace", dto2).getStatus());
}
use of org.eclipse.smarthome.core.items.dto.MetadataDTO in project smarthome by eclipse.
the class ItemResourceOSGiTest method testAddMetadata_ValueEmtpy.
@Test
public void testAddMetadata_ValueEmtpy() {
MetadataDTO dto = new MetadataDTO();
dto.value = "";
Response response = itemResource.addMetadata(ITEM_NAME1, "foo", dto);
assertEquals(400, response.getStatus());
}
Aggregations