1
|
package eu.dnetlib.msro.workflows.nodes.mdstore;
|
2
|
|
3
|
import java.util.Iterator;
|
4
|
import java.util.List;
|
5
|
|
6
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
7
|
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
|
10
|
import eu.dnetlib.data.mdstore.MDStoreService;
|
11
|
import eu.dnetlib.data.mdstore.MDStoreServiceException;
|
12
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
13
|
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
|
14
|
|
15
|
// TODO: Auto-generated Javadoc
|
16
|
/**
|
17
|
* The Class MultipleMdStoreIterator.
|
18
|
*/
|
19
|
public class MultipleMdStoreIterator implements Iterable<String>, Iterator<String> {
|
20
|
|
21
|
/** The service locator. */
|
22
|
private UniqueServiceLocator serviceLocator;
|
23
|
|
24
|
/** The md i ds. */
|
25
|
private List<String> mdIDs;
|
26
|
|
27
|
/** The current id. */
|
28
|
private String currentId = null;
|
29
|
|
30
|
/** The current iterator. */
|
31
|
private Iterator<String> currentIterator;
|
32
|
|
33
|
/** The result set client factory. */
|
34
|
@Autowired
|
35
|
private ResultSetClientFactory resultSetClientFactory;
|
36
|
|
37
|
/**
|
38
|
* Instantiates a new multiple md store iterator.
|
39
|
*
|
40
|
* @param mdstoreLocator
|
41
|
* the mdstore locator
|
42
|
* @param mdIds
|
43
|
* the md ids
|
44
|
*/
|
45
|
public MultipleMdStoreIterator(final UniqueServiceLocator serviceLocator, final List<String> mdIds,
|
46
|
final ResultSetClientFactory resultSetClientFactory) {
|
47
|
this.serviceLocator = serviceLocator;
|
48
|
this.mdIDs = mdIds;
|
49
|
this.resultSetClientFactory = resultSetClientFactory;
|
50
|
|
51
|
}
|
52
|
|
53
|
/*
|
54
|
* (non-Javadoc)
|
55
|
*
|
56
|
* @see java.lang.Iterable#iterator()
|
57
|
*/
|
58
|
@Override
|
59
|
public Iterator<String> iterator() {
|
60
|
getNextMDStoreRecords();
|
61
|
return this;
|
62
|
|
63
|
}
|
64
|
|
65
|
/*
|
66
|
* (non-Javadoc)
|
67
|
*
|
68
|
* @see java.util.Iterator#hasNext()
|
69
|
*/
|
70
|
@Override
|
71
|
public boolean hasNext() {
|
72
|
if (currentId == null || currentIterator == null) { return false; }
|
73
|
if (!currentIterator.hasNext()) {
|
74
|
getNextMDStoreRecords();
|
75
|
}
|
76
|
return currentIterator.hasNext();
|
77
|
}
|
78
|
|
79
|
/*
|
80
|
* (non-Javadoc)
|
81
|
*
|
82
|
* @see java.util.Iterator#next()
|
83
|
*/
|
84
|
@Override
|
85
|
public String next() {
|
86
|
return currentIterator.next();
|
87
|
}
|
88
|
|
89
|
/*
|
90
|
* (non-Javadoc)
|
91
|
*
|
92
|
* @see java.util.Iterator#remove()
|
93
|
*/
|
94
|
@Override
|
95
|
public void remove() {
|
96
|
currentIterator.remove();
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Gets the next md store records.
|
101
|
*
|
102
|
* @return the next md store records
|
103
|
*/
|
104
|
private void getNextMDStoreRecords() {
|
105
|
if (mdIDs.size() > 0) {
|
106
|
currentId = mdIDs.remove(0);
|
107
|
currentIterator = getIterableResultset(currentId);
|
108
|
}
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* Gets the iterable resultset.
|
113
|
*
|
114
|
* @param id
|
115
|
* the id
|
116
|
* @return the iterable resultset
|
117
|
*/
|
118
|
private Iterator<String> getIterableResultset(final String id) {
|
119
|
try {
|
120
|
W3CEndpointReference epr = serviceLocator.getService(MDStoreService.class).deliverMDRecords(id, "", "", "");
|
121
|
Iterable<String> input = resultSetClientFactory.getClient(epr);
|
122
|
return input.iterator();
|
123
|
} catch (MDStoreServiceException e) {
|
124
|
return null;
|
125
|
}
|
126
|
}
|
127
|
}
|