Project

General

Profile

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

    
3
import java.util.List;
4

    
5
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
6
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
7
import eu.dnetlib.msro.workflows.procs.Env;
8
import eu.dnetlib.msro.workflows.procs.Token;
9
import eu.dnetlib.rmi.enabling.ISLookUpService;
10
import eu.dnetlib.rmi.manager.MSROException;
11
import eu.dnetlib.rmi.provision.IndexService;
12

    
13
/**
14
 * Created by sandro on 10/25/16.
15
 */
16
public class RefreshSchemaJobNode extends BlackboardJobNode {
17

    
18
	private String format;
19

    
20
	private String layout;
21

    
22
	private String interpretation;
23

    
24
	@Override
25
	protected String obtainServiceId(final Env env) {
26
		return getServiceLocator().getServiceId(IndexService.class);
27
	}
28

    
29
	@Override
30
	protected void prepareJob(final BlackboardJob job, final Token token) throws Exception {
31
		final String query = "for $x in collection('/db/DRIVER/MDFormatDSResources/MDFormatDSResourceType') "
32
				+ "where $x//NAME='%s' and $x//LAYOUT/@name='%s' and $x//INTERPRETATION='%s' "
33
				+ "return $x//RESOURCE_IDENTIFIER/@value/string()";
34
		final ISLookUpService service = getServiceLocator().getService(ISLookUpService.class);
35

    
36
		final List<String> results = service.quickSearchProfile(String.format(query, format, layout, interpretation));
37
		if (results == null || results.size() != 1) throw new MSROException(
38
				"Error on getting mdformat profile the xquery return unexpected values, xquery " + String.format(query, format, layout, interpretation));
39

    
40
		job.setAction("REFRESH_SCHEMA");
41
		job.getParameters().put("profileId", results.get(0));
42

    
43
	}
44

    
45
	public String getFormat() {
46
		return format;
47
	}
48

    
49
	public void setFormat(final String format) {
50
		this.format = format;
51
	}
52

    
53
	public String getLayout() {
54
		return layout;
55
	}
56

    
57
	public void setLayout(final String layout) {
58

    
59
		this.layout = layout;
60
	}
61

    
62
	public String getInterpretation() {
63
		return interpretation;
64
	}
65

    
66
	public void setInterpretation(final String interpretation) {
67
		this.interpretation = interpretation;
68
	}
69
}
(4-4/5)