All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testobject.rest.api.resource.DeviceDescriptorsResource Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
package org.testobject.rest.api.resource;

import org.testobject.rest.api.model.DeviceDescriptor;
import org.testobject.rest.api.model.DeviceDescriptor.DeviceContainer;

import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.stream.Collectors;

public class DeviceDescriptorsResource {

	private final WebTarget target;

	public DeviceDescriptorsResource(WebTarget target) {
		this.target = target;
	}

	public List getAvailableDeviceDescriptorIds() {
		return target
				.path("descriptors")
				.path("availableDescriptors")
				.request(MediaType.APPLICATION_JSON)
				.get(new GenericType>() {
				});
	}

	public List getAvailableDeviceDescriptors() {
		List deviceDescriptors = target
				.path("descriptors")
				.request(MediaType.APPLICATION_JSON)
				.get(new GenericType>() {
				});

		return filterAvailable(deviceDescriptors);
	}

	private List filterAvailable(List descriptors) {
		List availableDescriptorIds = getAvailableDeviceDescriptorIds();

		return descriptors.stream()
				.filter(deviceContainer -> availableDescriptorIds.contains(deviceContainer.id))
				.map(deviceContainer -> new DeviceDescriptor(deviceContainer, true))
				.collect(Collectors.toList());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy