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.products.TaxonomyItem; import org.gcube.data.spd.model.service.exceptions.InvalidIdentifierException; import org.gcube.data.spd.model.service.exceptions.UnsupportedCapabilityException; import org.gcube.data.spd.model.service.exceptions.UnsupportedPluginException; import org.gcube.data.streams.Stream; import org.gcube.data.streams.dsl.Streams; public class DefaultClassification implements ClassificationClient{ private final ProxyDelegate delegate; public DefaultClassification(ProxyDelegate config){ this.delegate = config; } @Override public Stream getTaxonChildrenById(final String id) throws UnsupportedPluginException, UnsupportedCapabilityException, InvalidIdentifierException { Call call = new Call() { @Override public ResultLocator call(WebTarget manager) throws Exception { Response response = manager.path("children").path(id).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); } } //TODO @Override public Stream getTaxaByIds(final List ids) { return null; /*Call> call = new Call>() { @Override public ChunkedInput call(WebTarget manager) throws Exception { return null; } }; try { return null; }catch(Exception e) { throw new RuntimeException(e); }*/ } @Override public Stream getTaxonTreeById(final String id) throws UnsupportedPluginException, UnsupportedCapabilityException, InvalidIdentifierException { Call call = new Call() { @Override public ResultLocator call(WebTarget manager) throws Exception { Response response = manager.path("tree").path(id).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 Stream getSynonymsById(final String id) throws UnsupportedPluginException, UnsupportedCapabilityException, InvalidIdentifierException { Call call = new Call() { @Override public ResultLocator call(WebTarget manager) throws Exception { Response response = manager.path("synonyms").path(id).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); } } }