Project

General

Profile

1
package eu.dnetlib.msro.workflows.nodes.mdstore;
2

    
3
import java.util.List;
4

    
5
import javax.annotation.Resource;
6
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7

    
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.springframework.beans.factory.annotation.Autowired;
11

    
12
import com.google.gson.Gson;
13
import com.googlecode.sarasvati.Arc;
14
import com.googlecode.sarasvati.NodeToken;
15

    
16
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
17
import eu.dnetlib.enabling.resultset.IterableResultSetFactory;
18
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
19
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
20

    
21
public class FetchMultipleMDStores extends SimpleJobNode {
22

    
23
	private static final Log log = LogFactory.getLog(FetchMultipleMDStores.class); // NOPMD by marko on 11/24/08 5:02 PM
24

    
25
	@Resource
26
	private UniqueServiceLocator serviceLocator;
27

    
28
	private List<String> mdId;
29

    
30
	private String eprParam;
31

    
32
	/** The result set factory. */
33
	@Resource(name = "iterableResultSetFactory")
34
	private IterableResultSetFactory resultSetFactory;
35

    
36
	/** The result set client factory. */
37
	@Autowired
38
	private ResultSetClientFactory resultSetClientFactory;
39

    
40
	@Override
41
	protected String execute(final NodeToken token) throws Exception {
42

    
43
		if (getMdId() == null) {
44
			final String mdIdsJson = token.getEnv().getAttribute("mdId");
45
			@SuppressWarnings("unchecked")
46
			final List<String> mdIds = new Gson().fromJson(mdIdsJson, List.class);
47
			log.info(String.format("fetching records for %s mdstores", mdIds.size()));
48
			if (log.isDebugEnabled()) {
49
				log.debug(String.format("fetching records for mdstores: %s", mdIdsJson));
50
			}
51
			setMdId(mdIds);
52
		}
53

    
54
		final MultipleMdStoreIterable iter = new MultipleMdStoreIterable(serviceLocator, getMdId(), resultSetClientFactory);
55
		final W3CEndpointReference epr = resultSetFactory.createIterableResultSet(iter);
56
		token.getEnv().setAttribute(getEprParam(), epr.toString());
57
		return Arc.DEFAULT_ARC;
58
	}
59

    
60
	public List<String> getMdId() {
61
		return mdId;
62
	}
63

    
64
	public void setMdId(final List<String> mdId) {
65
		this.mdId = mdId;
66
	}
67

    
68
	public String getEprParam() {
69
		return eprParam;
70
	}
71

    
72
	public void setEprParam(final String eprParam) {
73
		this.eprParam = eprParam;
74
	}
75

    
76
}
(2-2/5)