Project

General

Profile

1
package eu.dnetlib.data.mdstore.modular;
2

    
3
import com.google.common.base.Function;
4
import com.google.common.collect.Lists;
5
import eu.dnetlib.data.mdstore.DocumentNotFoundException;
6
import eu.dnetlib.data.mdstore.MDStoreService;
7
import eu.dnetlib.data.mdstore.MDStoreServiceException;
8
import eu.dnetlib.enabling.resultset.IterableResultSetFactory;
9
import eu.dnetlib.enabling.tools.AbstractBaseService;
10
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
11
import org.springframework.beans.factory.annotation.Required;
12

    
13
import javax.xml.ws.wsaddressing.W3CEndpointReference;
14
import java.util.List;
15
import java.util.Map;
16

    
17
public class ModularMDStoreService extends AbstractBaseService implements MDStoreService {
18

    
19
	/**
20
	 * notification handler.
21
	 */
22
	private NotificationHandler notificationHandler;
23

    
24
	private MDStoreFeeder feeder;
25

    
26
	private MDStoreRetriever retriever;
27

    
28
	private IterableResultSetFactory iterableResultSetFactory;
29

    
30

    
31
    public List<String> getMDStoreRecords(final String mdId, final int pageSize, final int offset, final Map<String, String> queryParam) throws MDStoreServiceException {
32

    
33
        return retriever.getMDStoreRecords(mdId, pageSize, offset, queryParam);
34

    
35
    }
36

    
37
	@Override
38
	public W3CEndpointReference deliverMDRecords(final String mdId, final String from, final String until, final String recordFilter)
39
			throws MDStoreServiceException {
40
		return retriever.deliver(mdId, from, until, recordFilter);
41
	}
42

    
43
	@Override
44
	public W3CEndpointReference bulkDeliverMDRecords(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
45
		return getIterableResultSetFactory().createIterableResultSet(retriever.deliver(format, layout, interpretation));
46
	}
47

    
48
	@Override
49
	public String deliverRecord(final String mdId, final String recordId) throws MDStoreServiceException, DocumentNotFoundException {
50
		return retriever.deliverRecord(mdId, recordId);
51
	}
52

    
53
	@Override
54
	public List<String> getListOfMDStores() throws MDStoreServiceException {
55
		return (Lists.transform(retriever.getDao().listMDStores(), new Function<MDStoreDescription, String>() {
56

    
57
			@Override
58
			public String apply(final MDStoreDescription input) {
59
				return input.getId();
60
			}
61
		}));
62
	}
63

    
64
	@Override
65
	public List<String> listMDStores(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
66
		return retriever.getDao().listMDStores(format, layout, interpretation);
67
	}
68

    
69
	@Override
70
	public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
71
		getNotificationHandler().notified(subscriptionId, topic, isId, message);
72
	}
73

    
74
	@Override
75
	public boolean storeMDRecordsFromRS(final String mdId, final String rsId, final String storingType) throws MDStoreServiceException {
76
		throw new MDStoreServiceException("not implemented, use the Blackboard asynchronous equivalent");
77
	}
78

    
79
	@Override
80
	public int size(final String mdId) throws MDStoreServiceException {
81
		return this.getRetriever().getDao().getCachedSize(mdId);
82
	}
83

    
84
	@Override
85
	public int size(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
86
		return this.getRetriever().getDao().getSumOfSizes(format, layout, interpretation);
87
	}
88

    
89
	public NotificationHandler getNotificationHandler() {
90
		return notificationHandler;
91
	}
92

    
93
	@Required
94
	public void setNotificationHandler(final NotificationHandler notificationHandler) {
95
		this.notificationHandler = notificationHandler;
96
	}
97

    
98
	public MDStoreFeeder getFeeder() {
99
		return feeder;
100
	}
101

    
102
	public void setFeeder(final MDStoreFeeder feeder) {
103
		this.feeder = feeder;
104
	}
105

    
106
	public MDStoreRetriever getRetriever() {
107
		return retriever;
108
	}
109

    
110
	public void setRetriever(final MDStoreRetriever retriever) {
111
		this.retriever = retriever;
112
	}
113

    
114
	public IterableResultSetFactory getIterableResultSetFactory() {
115
		return iterableResultSetFactory;
116
	}
117

    
118
	@Required
119
	public void setIterableResultSetFactory(final IterableResultSetFactory iterableResultSetFactory) {
120
		this.iterableResultSetFactory = iterableResultSetFactory;
121
	}
122

    
123
}
(9-9/13)