1
|
package eu.dnetlib.msro.workflows.nodes.mdstore;
|
2
|
|
3
|
import java.util.Iterator;
|
4
|
import java.util.List;
|
5
|
|
6
|
import javax.annotation.Resource;
|
7
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
8
|
|
9
|
import org.apache.commons.logging.Log;
|
10
|
import org.apache.commons.logging.LogFactory;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
|
13
|
import com.google.common.base.Function;
|
14
|
import com.google.common.collect.Iterables;
|
15
|
|
16
|
import eu.dnetlib.data.mdstore.MDStoreService;
|
17
|
import eu.dnetlib.data.mdstore.MDStoreServiceException;
|
18
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
19
|
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
|
20
|
|
21
|
// TODO: Auto-generated Javadoc
|
22
|
/**
|
23
|
* The Class MultipleMdStoreIterator.
|
24
|
*/
|
25
|
public class MultipleMdStoreIterator implements Iterator<String> {
|
26
|
|
27
|
private static final Log log = LogFactory.getLog(MultipleMdStoreIterator.class); // NOPMD by marko on 11/24/08 5:02 PM
|
28
|
|
29
|
/** The service locator. */
|
30
|
@Resource
|
31
|
private UniqueServiceLocator serviceLocator;
|
32
|
|
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
|
*
|
43
|
* @param mdstoreLocator
|
44
|
* the mdstore locator
|
45
|
* @param mdIds
|
46
|
* the md ids
|
47
|
*/
|
48
|
public MultipleMdStoreIterator(final UniqueServiceLocator serviceLocator, final List<String> mdIds, final ResultSetClientFactory resultSetClientFactory) {
|
49
|
this.serviceLocator = serviceLocator;
|
50
|
this.resultSetClientFactory = resultSetClientFactory;
|
51
|
|
52
|
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
|
}
|
70
|
|
71
|
/*
|
72
|
* (non-Javadoc)
|
73
|
*
|
74
|
* @see java.util.Iterator#hasNext()
|
75
|
*/
|
76
|
@Override
|
77
|
public boolean hasNext() {
|
78
|
if (currentIterator == null) return false;
|
79
|
|
80
|
return currentIterator.hasNext();
|
81
|
}
|
82
|
|
83
|
/*
|
84
|
* (non-Javadoc)
|
85
|
*
|
86
|
* @see java.util.Iterator#next()
|
87
|
*/
|
88
|
@Override
|
89
|
public String next() {
|
90
|
return currentIterator.next();
|
91
|
}
|
92
|
|
93
|
/*
|
94
|
* (non-Javadoc)
|
95
|
*
|
96
|
* @see java.util.Iterator#remove()
|
97
|
*/
|
98
|
@Override
|
99
|
public void remove() {
|
100
|
throw new UnsupportedOperationException("Cannot remove");
|
101
|
}
|
102
|
|
103
|
}
|