1
|
package eu.dnetlib.msro.workflows.nodes.dedup;
|
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.ISLookUpException;
|
8
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
9
|
import org.apache.commons.lang3.StringUtils;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
|
12
|
import java.io.ByteArrayOutputStream;
|
13
|
import java.util.List;
|
14
|
import java.util.zip.GZIPOutputStream;
|
15
|
|
16
|
public class FindDedupConfigurationJobNode extends SimpleJobNode {
|
17
|
|
18
|
|
19
|
private String configName;
|
20
|
|
21
|
@Autowired
|
22
|
UniqueServiceLocator uniqueServiceLocator;
|
23
|
|
24
|
private final static String query ="for $x in collection('/db/DRIVER/DedupConfigurationDSResources/DedupConfigurationDSResourceType') where $x//RESOURCE_IDENTIFIER/@value ='%s' return $x//DEDUPLICATION/text()";
|
25
|
|
26
|
@Override
|
27
|
protected String execute(Env env) throws Exception {
|
28
|
|
29
|
|
30
|
if (StringUtils.isBlank(configName)) throw new IllegalArgumentException("missing configuration sequence");
|
31
|
|
32
|
env.setAttribute("dconf", getProfile());
|
33
|
return Arc.DEFAULT_ARC;
|
34
|
}
|
35
|
|
36
|
|
37
|
private String getProfile() throws Exception {
|
38
|
ISLookUpService service = uniqueServiceLocator.getService(ISLookUpService.class);
|
39
|
|
40
|
List<String> resourceProfile = service.quickSearchProfile(String.format(query,configName));
|
41
|
|
42
|
|
43
|
if (resourceProfile.size()!= 1) throw new IllegalStateException("Query should return on result query:"+String.format(query,configName));
|
44
|
|
45
|
return compressArgument(resourceProfile.get(0));
|
46
|
|
47
|
|
48
|
}
|
49
|
|
50
|
private static String compressArgument(final String value) throws Exception{
|
51
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
52
|
GZIPOutputStream gzip = new GZIPOutputStream(out);
|
53
|
gzip.write(value.getBytes());
|
54
|
gzip.close();
|
55
|
return java.util.Base64.getEncoder().encodeToString(out.toByteArray());
|
56
|
}
|
57
|
|
58
|
public String getConfigName() {
|
59
|
return configName;
|
60
|
}
|
61
|
|
62
|
public void setConfigName(String configName) {
|
63
|
this.configName = configName;
|
64
|
}
|
65
|
|
66
|
|
67
|
}
|