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