package org.gcube.data.spd.client.proxies; import java.util.List; import java.util.concurrent.TimeUnit; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.gcube.common.clients.Call; import org.gcube.common.clients.delegates.ProxyDelegate; import org.gcube.data.spd.client.ResultElementRecordIterator; import org.gcube.data.spd.client.ResultLocator; import org.gcube.data.spd.client.Utils; import org.gcube.data.spd.model.PluginDescription; import org.gcube.data.spd.model.exceptions.InvalidQueryException; import org.gcube.data.spd.model.products.ResultElement; import org.gcube.data.spd.model.service.exceptions.UnsupportedCapabilityException; import org.gcube.data.spd.model.service.exceptions.UnsupportedPluginException; import org.gcube.data.spd.model.service.types.PluginDescriptions; import org.gcube.data.streams.Stream; import org.gcube.data.streams.dsl.Streams; public class DefaultManager implements ManagerClient { private final ProxyDelegate delegate; public DefaultManager(ProxyDelegate config){ this.delegate = config; } @Override public Stream search(final String query) throws InvalidQueryException, UnsupportedPluginException, UnsupportedCapabilityException { Call call = new Call() { @Override public ResultLocator call(WebTarget manager) throws Exception { Response response = manager.path("search").queryParam("query", query).request().get(Response.class); String host = manager.getUri().getHost(); int port = manager.getUri().getPort(); return new ResultLocator(host, port, Utils.getLocatorFromResponse(response)); } }; try { ResultLocator result = delegate.make(call); ResultElementRecordIterator ri = new ResultElementRecordIterator(result, 2, TimeUnit.MINUTES); return Streams.convert(ri); }catch(Exception e) { throw new RuntimeException(e); } } @Override public List getPluginsDescription() { Call> call = new Call>() { @Override public List call(WebTarget manager) throws Exception { return manager.path("providers").request().get(PluginDescriptions.class).getDescriptions(); } }; try { return delegate.make(call); }catch(Exception e) { throw new RuntimeException(e); } } }