Project

General

Profile

« Previous | Next » 

Revision 59803

added check for same rumption token and empty records list - both times throw runtime eception

View differences:

modules/dnet-modular-collector-service/trunk/src/main/java/eu/dnetlib/data/collector/plugins/oai/OaiIterator.java
35 35
	private String token;
36 36
	private boolean started;
37 37
	private HttpConnector httpConnector;
38
	private String prev_token = null;
38 39

  
39 40
	public OaiIterator(final String baseUrl, final String mdFormat, final String set, final String fromDate, final String untilDate, final HttpConnector httpConnector) {
40 41
		this.baseUrl = baseUrl;
......
51 52
			this.started = true;
52 53
			try {
53 54
				this.token = firstPage();
55
				prev_token = token;
54 56
			} catch (CollectorServiceException e) {
55 57
				throw new RuntimeException(e);
56 58
			}
......
73 75
			while (queue.isEmpty() && (token != null) && !token.isEmpty()) {
74 76
				try {
75 77
					token = otherPages(token);
78
					if(prev_token.equals(token)){
79
						throw new RuntimeException("OAI Iterator Exception: got the same resumption token twice");
80
					}
81
					prev_token = token;
76 82
				} catch (CollectorServiceException e) {
77 83
					throw new RuntimeException(e);
78 84
				}
......
156 162
                throw new CollectorServiceException(code + " - " + errorNode.getText());
157 163
            }
158 164
        }
159

  
165
		int added_records = 0;
160 166
        for (Object o : doc.selectNodes("//*[local-name()='ListRecords']/*[local-name()='record']")) {
161 167
            queue.add(((Node) o).asXML());
168
            added_records++;
162 169
        }
170
        if(added_records == 0){
171
        	throw new RuntimeException("OAI Iterator Exception: Empty records list for " + url);
172
		}
163 173

  
164 174
        return doc.valueOf("//*[local-name()='resumptionToken']");
165 175

  

Also available in: Unified diff