merged from trunk
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/information-system/discovery-client/1.0@67597 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
baa2e55c92
commit
ec5cd1ea03
6
pom.xml
6
pom.xml
|
@ -27,12 +27,6 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.access</groupId>
|
||||
<artifactId>streams</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.gcube.resources.discovery.client.api;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.data.streams.Stream;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
|
||||
/**
|
||||
|
@ -27,15 +26,4 @@ public interface DiscoveryClient<R> {
|
|||
* tolerance to parsing errors before raising this exception.
|
||||
*/
|
||||
List<R> submit(Query query) throws DiscoveryException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Submits a {@link Query} for remote execution and returns a {@link Stream} of typed results.
|
||||
* <p>
|
||||
* Parsing errors may and should be delivered as {@link InvalidResultException}s during stream iteration.
|
||||
*
|
||||
* @param query the query
|
||||
* @return the results
|
||||
* @throws DiscoveryException if the query cannot be submitted
|
||||
*/
|
||||
Stream<R> submitForStream(Query query) throws DiscoveryException;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package org.gcube.resources.discovery.client.impl;
|
||||
|
||||
import static org.gcube.data.streams.dsl.Streams.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.data.streams.Stream;
|
||||
import org.gcube.data.streams.exceptions.StreamSkipSignal;
|
||||
import org.gcube.data.streams.exceptions.StreamStopSignal;
|
||||
import org.gcube.data.streams.generators.Generator;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryException;
|
||||
import org.gcube.resources.discovery.client.api.InvalidResultException;
|
||||
|
@ -71,31 +65,4 @@ public class DelegateClient<R> implements DiscoveryClient<R> {
|
|||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Result parsing errors are only logged as long as they do results are successfully parsed. Otherwise, the
|
||||
* client flags the parsing errors as likely due to the parser itself.
|
||||
*/
|
||||
public Stream<R> submitForStream(Query query) throws DiscoveryException {
|
||||
|
||||
Stream<String> unparsed = inner.submitForStream(query);
|
||||
|
||||
return pipe(unparsed).through(new ParsingGenerator());
|
||||
|
||||
}
|
||||
|
||||
//helper
|
||||
private class ParsingGenerator implements Generator<String,R> {
|
||||
|
||||
public R yield(String result) throws StreamSkipSignal, StreamStopSignal {
|
||||
try {
|
||||
return parser.parse(result);
|
||||
}
|
||||
catch(Exception e) {
|
||||
throw new InvalidResultException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue