1
|
package eu.dnetlib.data.mdstore.modular;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.stream.Stream;
|
5
|
|
6
|
import eu.dnetlib.data.mdstore.modular.connector.MDStore;
|
7
|
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
|
8
|
import eu.dnetlib.enabling.resultset.factory.ResultSetFactory;
|
9
|
import eu.dnetlib.enabling.tools.DnetStreamSupport;
|
10
|
import eu.dnetlib.rmi.common.ResultSet;
|
11
|
import eu.dnetlib.rmi.data.DocumentNotFoundException;
|
12
|
import eu.dnetlib.rmi.data.MDStoreServiceException;
|
13
|
import org.apache.commons.logging.Log;
|
14
|
import org.apache.commons.logging.LogFactory;
|
15
|
import org.springframework.beans.factory.annotation.Required;
|
16
|
|
17
|
public class MDStoreRetriever {
|
18
|
|
19
|
/**
|
20
|
* Logger
|
21
|
*/
|
22
|
private static final Log log = LogFactory.getLog(MDStoreRetriever.class);
|
23
|
|
24
|
private MDStoreDao dao;
|
25
|
|
26
|
private ResultSetFactory resultSetFactory;
|
27
|
|
28
|
public ResultSet<String> deliver(final String mdId, final String from, final String until, final String recordFilter) throws MDStoreServiceException {
|
29
|
final MDStore mdStore = dao.readMDStore(mdId);
|
30
|
return getResultSetFactory().createResultSet(mdStore.deliver(from, until, recordFilter));
|
31
|
}
|
32
|
|
33
|
public Iterable<String> deliver(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
|
34
|
return () -> getMdIds(format, layout, interpretation).stream().map(mdId -> {
|
35
|
log.debug("bulk deliver of mdId: " + mdId);
|
36
|
try {
|
37
|
return DnetStreamSupport.generateStreamFromIterator(dao.readMDStore(mdId).iterate().iterator());
|
38
|
} catch (Throwable e) {
|
39
|
throw new RuntimeException(e);
|
40
|
}
|
41
|
}).reduce(Stream::concat).orElseGet(Stream::empty).iterator();
|
42
|
}
|
43
|
|
44
|
private List<String> getMdIds(final String format, final String layout, final String interpretation) {
|
45
|
try {
|
46
|
return dao.listMDStores(format, layout, interpretation);
|
47
|
} catch (MDStoreServiceException e) {
|
48
|
throw new RuntimeException(e);
|
49
|
}
|
50
|
}
|
51
|
|
52
|
public String deliverRecord(final String mdId, final String recordId) throws MDStoreServiceException, DocumentNotFoundException {
|
53
|
return dao.getMDStore(mdId).getRecord(recordId);
|
54
|
}
|
55
|
|
56
|
public MDStoreDao getDao() {
|
57
|
return dao;
|
58
|
}
|
59
|
|
60
|
@Required
|
61
|
public void setDao(final MDStoreDao dao) {
|
62
|
this.dao = dao;
|
63
|
}
|
64
|
|
65
|
public ResultSetFactory getResultSetFactory() {
|
66
|
return resultSetFactory;
|
67
|
}
|
68
|
|
69
|
@Required
|
70
|
public void setResultSetFactory(final ResultSetFactory resultSetFactory) {
|
71
|
this.resultSetFactory = resultSetFactory;
|
72
|
}
|
73
|
|
74
|
}
|