Search in sources :

Example 1 with MetadataDTO

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;
    }
}
Also used : HashMap(java.util.HashMap) EnrichedItemDTO(org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO) Metadata(org.eclipse.smarthome.core.items.Metadata) JsonObject(com.google.gson.JsonObject) MetadataKey(org.eclipse.smarthome.core.items.MetadataKey) MetadataDTO(org.eclipse.smarthome.core.items.dto.MetadataDTO) EnrichedGroupItemDTO(org.eclipse.smarthome.io.rest.core.item.EnrichedGroupItemDTO)

Example 2 with MetadataDTO

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());
}
Also used : Response(javax.ws.rs.core.Response) MetadataDTO(org.eclipse.smarthome.core.items.dto.MetadataDTO) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 3 with MetadataDTO

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());
}
Also used : Response(javax.ws.rs.core.Response) MetadataDTO(org.eclipse.smarthome.core.items.dto.MetadataDTO) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 4 with MetadataDTO

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());
}
Also used : MetadataDTO(org.eclipse.smarthome.core.items.dto.MetadataDTO) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 5 with MetadataDTO

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());
}
Also used : Response(javax.ws.rs.core.Response) MetadataDTO(org.eclipse.smarthome.core.items.dto.MetadataDTO) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

MetadataDTO (org.eclipse.smarthome.core.items.dto.MetadataDTO)6 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)5 Test (org.junit.Test)5 Response (javax.ws.rs.core.Response)3 JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 Metadata (org.eclipse.smarthome.core.items.Metadata)1 MetadataKey (org.eclipse.smarthome.core.items.MetadataKey)1 EnrichedGroupItemDTO (org.eclipse.smarthome.io.rest.core.item.EnrichedGroupItemDTO)1 EnrichedItemDTO (org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO)1