1
|
package eu.dnetlib.enabling.resultSetManager;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import org.springframework.beans.factory.annotation.Required;
|
6
|
import org.springframework.web.bind.annotation.PathVariable;
|
7
|
|
8
|
import com.google.common.collect.Lists;
|
9
|
import com.google.gson.Gson;
|
10
|
|
11
|
import eu.dnetlib.rmi.objects.resultSet.ResultSetResponse;
|
12
|
import eu.dnetlib.rmi.soap.exceptions.ResultSetException;
|
13
|
|
14
|
public class ResultSetServiceCore {
|
15
|
|
16
|
private ResultSetRegistry registry;
|
17
|
|
18
|
public ResultSetResponse getNextResults(@PathVariable final String rsId, @PathVariable final int n) throws ResultSetException {
|
19
|
final ResultSetIterator<?> iter = registry.findIterator(rsId);
|
20
|
|
21
|
final int from = iter.position();
|
22
|
final Gson gson = new Gson();
|
23
|
|
24
|
final List<String> elements = Lists.newArrayList();
|
25
|
for (Object o : iter.getNextElements(n)) {
|
26
|
elements.add(gson.toJson(o));
|
27
|
}
|
28
|
|
29
|
final int to = iter.position();
|
30
|
final boolean end = iter.isFinished();
|
31
|
final int total = iter.getTotal();
|
32
|
|
33
|
return new ResultSetResponse(from, to, end, total, elements);
|
34
|
}
|
35
|
|
36
|
public ResultSetRegistry getRegistry() {
|
37
|
return registry;
|
38
|
}
|
39
|
|
40
|
@Required
|
41
|
public void setRegistry(final ResultSetRegistry registry) {
|
42
|
this.registry = registry;
|
43
|
}
|
44
|
}
|