Project

General

Profile

« Previous | Next » 

Revision 57157

Added by Enrico Ottonello over 4 years ago

solr 772 integration

View differences:

DocumentFeeder.java
1 1
package eu.dnetlib.index.feed;
2 2

  
3 3
import java.util.concurrent.Callable;
4
import java.util.stream.Stream;
4 5

  
5 6
import eu.dnetlib.clients.index.model.document.IndexDocument;
6 7
import eu.dnetlib.clients.index.utils.IndexFieldUtility;
7 8
import eu.dnetlib.index.IndexCollection;
9
import eu.dnetlib.rmi.provision.IndexServiceException;
10

  
8 11
import org.apache.commons.logging.Log;
9 12
import org.apache.commons.logging.LogFactory;
10 13

  
......
23 26
	 */
24 27
	private IndexCollection indexCollection;
25 28

  
26
	/**
27
	 * The records.
28
	 */
29
	private Iterable<IndexDocument> records;
30

  
31
	/**
32
	 * Instantiates a new document feeder.
33
	 *
34
	 * @param indexCollection the index collection
35
	 * @param records         the records
36
	 */
37
	public DocumentFeeder(final IndexCollection indexCollection, final Iterable<IndexDocument> records) {
29
	private Stream<IndexDocument> docStream;
30
	
31
	public DocumentFeeder(final IndexCollection indexCollection, final Stream<IndexDocument> docStream) {
38 32
		this.indexCollection = indexCollection;
39
		this.records = records;
33
		this.docStream = docStream;
40 34
	}
41 35

  
42 36
	/**
......
45 39
	 * @see Callable#call()
46 40
	 */
47 41
	@Override
48
	public FeedResult call() throws Exception {
42
	public FeedResult call() {
49 43
		final FeedResult res = new FeedResult(System.currentTimeMillis());
50
		for (IndexDocument doc : records) {
51
			boolean rsp;
44
		docStream.forEach(doc->{
52 45
			switch (doc.getStatus()) {
53

  
46
			
54 47
			case OK:
55
				rsp = indexCollection.add(doc);
48
				boolean rsp = false;
49
				try {
50
					rsp = indexCollection.add(doc);
51
				} catch (IndexServiceException e) {
52
					log.error(e);
53
				}
56 54
				if (rsp) {
57 55
					res.add();
58 56
				} else {
......
73 71
			default:
74 72
				throw new IllegalStateException("unknow document status");
75 73
			}
76
		}
74
		});
77 75
		return res;
78 76
	}
79

  
77
	
80 78
}

Also available in: Unified diff