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