Project

General

Profile

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

    
3
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
4
import eu.dnetlib.msro.workflows.graph.Arc;
5
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
6
import eu.dnetlib.msro.workflows.procs.Env;
7
import eu.dnetlib.rmi.enabling.ISLookUpDocumentNotFoundException;
8
import eu.dnetlib.rmi.enabling.ISLookUpService;
9
import org.apache.commons.lang3.StringUtils;
10
import org.springframework.beans.factory.annotation.Autowired;
11

    
12
public class VerifyMDStoreJobNode extends SimpleJobNode {
13

    
14
	private String format;
15
	private String layout;
16
	private String interpretation;
17
	private String outputPrefix;
18
	private String onFailed;
19

    
20
	@Autowired
21
	private UniqueServiceLocator serviceLocator;
22

    
23
	@Override
24
	protected String execute(final Env env) throws Exception {
25

    
26
		final String query = String.format(
27
				"collection('/db/DRIVER/MDStoreDSResources/MDStoreDSResourceType')[normalize-space(.//METADATA_FORMAT) = '%s' and normalize-space(.//METADATA_FORMAT_LAYOUT = '%s') and normalize-space(.//METADATA_FORMAT_INTERPRETATION) = '%s']//RESOURCE_IDENTIFIER/@value/string()",
28
				format.trim(), layout.trim(), interpretation.trim());
29

    
30
		try {
31
			final String id = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query);
32

    
33
			env.setAttribute(outputPrefix + "format", format);
34
			env.setAttribute(outputPrefix + "layout", layout);
35
			env.setAttribute(outputPrefix + "interpretation", interpretation);
36
			env.setAttribute(outputPrefix + "id", id);
37

    
38
			return Arc.DEFAULT_ARC;
39
		} catch (final ISLookUpDocumentNotFoundException e) {
40
			if (StringUtils.isNotBlank(onFailed)) {
41
				return onFailed;
42
			} else {
43
				throw e;
44
			}
45
		}
46
	}
47

    
48
	public String getFormat() {
49
		return format;
50
	}
51

    
52
	public void setFormat(final String format) {
53
		this.format = format;
54
	}
55

    
56
	public String getLayout() {
57
		return layout;
58
	}
59

    
60
	public void setLayout(final String layout) {
61
		this.layout = layout;
62
	}
63

    
64
	public String getInterpretation() {
65
		return interpretation;
66
	}
67

    
68
	public void setInterpretation(final String interpretation) {
69
		this.interpretation = interpretation;
70
	}
71

    
72
	public String getOutputPrefix() {
73
		return outputPrefix;
74
	}
75

    
76
	public void setOutputPrefix(final String outputPrefix) {
77
		this.outputPrefix = outputPrefix;
78
	}
79

    
80
	public String getOnFailed() {
81
		return onFailed;
82
	}
83

    
84
	public void setOnFailed(final String onFailed) {
85
		this.onFailed = onFailed;
86
	}
87

    
88
}
(10-10/10)