1
|
package eu.dnetlib.msro.workflows.nodes.mdstore;
|
2
|
|
3
|
import java.util.Iterator;
|
4
|
import java.util.List;
|
5
|
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
|
9
|
import com.google.common.base.Function;
|
10
|
import com.google.common.collect.Iterables;
|
11
|
|
12
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
13
|
import eu.dnetlib.enabling.resultset.client.ResultSetClient;
|
14
|
import eu.dnetlib.rmi.common.ResultSet;
|
15
|
import eu.dnetlib.rmi.data.MDStoreService;
|
16
|
import eu.dnetlib.rmi.data.MDStoreServiceException;
|
17
|
|
18
|
// TODO: Auto-generated Javadoc
|
19
|
/**
|
20
|
* The Class MultipleMdStoreIterator.
|
21
|
*/
|
22
|
public class MultipleMdStoreIterator implements Iterator<String> {
|
23
|
|
24
|
private static final Log log = LogFactory.getLog(MultipleMdStoreIterator.class); // NOPMD by marko on 11/24/08 5:02 PM
|
25
|
|
26
|
/** The current iterator. */
|
27
|
private Iterator<String> currentIterator;
|
28
|
|
29
|
/**
|
30
|
* Instantiates a new multiple md store iterator.
|
31
|
*
|
32
|
* @param mdstoreLocator
|
33
|
* the mdstore locator
|
34
|
* @param mdIds
|
35
|
* the md ids
|
36
|
*/
|
37
|
public MultipleMdStoreIterator(final UniqueServiceLocator serviceLocator, final List<String> mdIds, final ResultSetClient resultSetClient) {
|
38
|
|
39
|
log.info(String.format("iterating over mdIds: '%s'", mdIds));
|
40
|
|
41
|
this.currentIterator = Iterables.concat(Iterables.transform(mdIds, new Function<String, Iterable<String>>() {
|
42
|
|
43
|
@Override
|
44
|
public Iterable<String> apply(final String mdId) {
|
45
|
|
46
|
log.debug(String.format("current mdId '%s'", mdId));
|
47
|
try {
|
48
|
final ResultSet<String> rs = serviceLocator.getService(MDStoreService.class, mdId).deliverMDRecords(mdId, "", "", "");
|
49
|
return resultSetClient.iter(rs, String.class);
|
50
|
} catch (final MDStoreServiceException e) {
|
51
|
log.error(e);
|
52
|
throw new RuntimeException(String.format("unable to iterate over %s", mdId), e);
|
53
|
}
|
54
|
}
|
55
|
})).iterator();
|
56
|
}
|
57
|
|
58
|
/*
|
59
|
* (non-Javadoc)
|
60
|
*
|
61
|
* @see java.util.Iterator#hasNext()
|
62
|
*/
|
63
|
@Override
|
64
|
public boolean hasNext() {
|
65
|
if (this.currentIterator == null) { return false; }
|
66
|
|
67
|
return this.currentIterator.hasNext();
|
68
|
}
|
69
|
|
70
|
/*
|
71
|
* (non-Javadoc)
|
72
|
*
|
73
|
* @see java.util.Iterator#next()
|
74
|
*/
|
75
|
@Override
|
76
|
public String next() {
|
77
|
return this.currentIterator.next();
|
78
|
}
|
79
|
|
80
|
/*
|
81
|
* (non-Javadoc)
|
82
|
*
|
83
|
* @see java.util.Iterator#remove()
|
84
|
*/
|
85
|
@Override
|
86
|
public void remove() {
|
87
|
throw new UnsupportedOperationException("Cannot remove");
|
88
|
}
|
89
|
|
90
|
}
|