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

    
14
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
15
import eu.dnetlib.msro.workflows.graph.Arc;
16
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
17
import eu.dnetlib.msro.workflows.procs.Env;
18

    
19
public class FetchMultipleMDStores extends SimpleJobNode {
20

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

    
23
	@Resource
24
	private UniqueServiceLocator serviceLocator;
25

    
26
	private List<String> mdId;
27

    
28
	private String eprParam;
29

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

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

    
42
	@Override
43
	protected String execute(final Env env) throws Exception {
44

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

    
56
		final MultipleMdStoreIterable iter = new MultipleMdStoreIterable(this.serviceLocator, getMdId(), this.resultSetClientFactory);
57
		final W3CEndpointReference epr = this.resultSetFactory.createIterableResultSet(iter);
58
		env.setAttribute(getEprParam(), epr.toString());
59
		return Arc.DEFAULT_ARC;
60
	}
61

    
62
	public List<String> getMdId() {
63
		return this.mdId;
64
	}
65

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

    
70
	public String getEprParam() {
71
		return this.eprParam;
72
	}
73

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

    
78
}
(2-2/5)