1
|
package eu.dnetlib.msro.worker.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
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
|
10
|
import eu.dnetlib.common.services.locators.DnetServiceLocator;
|
11
|
import eu.dnetlib.data.resultSet.client.ResultSetClientFactory;
|
12
|
import eu.dnetlib.rmi.objects.resultSet.ResultSet;
|
13
|
import eu.dnetlib.rmi.soap.MDStoreService;
|
14
|
import eu.dnetlib.rmi.soap.exceptions.MDStoreServiceException;
|
15
|
|
16
|
/**
|
17
|
* The Class MultipleMdStoreIterator.
|
18
|
*/
|
19
|
public class MultipleMdStoreIterator implements Iterator<String> {
|
20
|
|
21
|
private static final Log log = LogFactory.getLog(MultipleMdStoreIterator.class); // NOPMD by marko on 11/24/08 5:02 PM
|
22
|
|
23
|
/** The service locator. */
|
24
|
@Autowired
|
25
|
private DnetServiceLocator serviceLocator;
|
26
|
|
27
|
/** The md ids. */
|
28
|
private List<String> mdIDs;
|
29
|
|
30
|
/** The current id. */
|
31
|
private String currentId = null;
|
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 DnetServiceLocator serviceLocator, final List<String> mdIds, final ResultSetClientFactory resultSetClientFactory) {
|
49
|
this.serviceLocator = serviceLocator;
|
50
|
this.mdIDs = mdIds;
|
51
|
this.resultSetClientFactory = resultSetClientFactory;
|
52
|
getNextMDStoreRecords();
|
53
|
|
54
|
}
|
55
|
|
56
|
/*
|
57
|
* (non-Javadoc)
|
58
|
*
|
59
|
* @see java.util.Iterator#hasNext()
|
60
|
*/
|
61
|
@Override
|
62
|
public boolean hasNext() {
|
63
|
if (currentId == null || currentIterator == null) { return false; }
|
64
|
return currentIterator.hasNext();
|
65
|
}
|
66
|
|
67
|
/*
|
68
|
* (non-Javadoc)
|
69
|
*
|
70
|
* @see java.util.Iterator#next()
|
71
|
*/
|
72
|
@Override
|
73
|
public String next() {
|
74
|
String nextElement = currentIterator.next();
|
75
|
if (!currentIterator.hasNext()) {
|
76
|
getNextMDStoreRecords();
|
77
|
}
|
78
|
return nextElement;
|
79
|
}
|
80
|
|
81
|
/*
|
82
|
* (non-Javadoc)
|
83
|
*
|
84
|
* @see java.util.Iterator#remove()
|
85
|
*/
|
86
|
@Override
|
87
|
public void remove() {
|
88
|
currentIterator.remove();
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Gets the next md store records.
|
93
|
*
|
94
|
* @return the next md store records
|
95
|
*/
|
96
|
private void getNextMDStoreRecords() {
|
97
|
if (mdIDs.size() > 0) {
|
98
|
currentId = mdIDs.remove(0);
|
99
|
currentIterator = getIterableResultset(currentId);
|
100
|
}
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Gets the iterable resultset.
|
105
|
*
|
106
|
* @param id
|
107
|
* the id
|
108
|
* @return the iterable resultset
|
109
|
*/
|
110
|
private Iterator<String> getIterableResultset(final String id) {
|
111
|
try {
|
112
|
ResultSet<String> rs = serviceLocator.getService(MDStoreService.class, id).deliverMDRecords(id, "", "", "");
|
113
|
Iterable<String> input = resultSetClientFactory.getClient(rs, String.class, 20);
|
114
|
return input.iterator();
|
115
|
} catch (MDStoreServiceException e) {
|
116
|
log.error(e);
|
117
|
return null;
|
118
|
}
|
119
|
}
|
120
|
}
|