1
|
package eu.dnetlib.msro.workflows.actions;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import com.google.common.collect.Lists;
|
7
|
import com.google.common.collect.Maps;
|
8
|
import com.google.gson.Gson;
|
9
|
import com.googlecode.sarasvati.Arc;
|
10
|
import com.googlecode.sarasvati.NodeToken;
|
11
|
import eu.dnetlib.actionmanager.set.RawSet;
|
12
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
13
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
14
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
15
|
import eu.dnetlib.msro.workflows.dedup.conf.DedupConfigurationOrchestration;
|
16
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
17
|
import org.apache.commons.lang.StringUtils;
|
18
|
import org.apache.commons.logging.Log;
|
19
|
import org.apache.commons.logging.LogFactory;
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
21
|
|
22
|
/**
|
23
|
* The Class PrepareConfiguredActionSetJobNode.
|
24
|
*/
|
25
|
public class PrepareConfiguredActionSetJobNode extends SimpleJobNode {
|
26
|
|
27
|
/**
|
28
|
* logger.
|
29
|
*/
|
30
|
private static final Log log = LogFactory.getLog(PrepareConfiguredActionSetJobNode.class);
|
31
|
|
32
|
/**
|
33
|
* The dedup config sequence param.
|
34
|
*/
|
35
|
private String dedupConfigSequenceParam;
|
36
|
|
37
|
/**
|
38
|
* The job property.
|
39
|
*/
|
40
|
private String jobProperty;
|
41
|
|
42
|
/**
|
43
|
* The action set path param name.
|
44
|
*/
|
45
|
private String actionSetPathParam;
|
46
|
|
47
|
/**
|
48
|
* The service locator.
|
49
|
*/
|
50
|
@Autowired
|
51
|
private UniqueServiceLocator serviceLocator;
|
52
|
|
53
|
/*
|
54
|
* (non-Javadoc)
|
55
|
*
|
56
|
* @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken)
|
57
|
*/
|
58
|
@Override
|
59
|
protected String execute(final NodeToken token) throws Exception {
|
60
|
|
61
|
final List<Map<String, String>> setList = Lists.newArrayList();
|
62
|
|
63
|
final Map<String, String> set = Maps.newHashMap();
|
64
|
|
65
|
final String actionSetId = getActionSetId(token);
|
66
|
final ISLookUpService isLookUpService = serviceLocator.getService(ISLookUpService.class);
|
67
|
final String basePath = isLookUpService.getResourceProfileByQuery(
|
68
|
"/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='ActionManagerServiceResourceType']//SERVICE_PROPERTIES/PROPERTY[@key='basePath']/@value/string()");
|
69
|
if (StringUtils.isBlank(basePath)) {
|
70
|
throw new IllegalStateException("missing basePath in ActionManagerService");
|
71
|
}
|
72
|
|
73
|
final String actionSetDirectory = isLookUpService.getResourceProfileByQuery(
|
74
|
"/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='ActionManagerSetDSResourceType' and .//SET/@id = '"+actionSetId+"']//SET/@ directory/string()");
|
75
|
|
76
|
if (StringUtils.isBlank(actionSetDirectory)) {
|
77
|
throw new IllegalStateException("missing directory in ActionSet profile: " + actionSetId);
|
78
|
}
|
79
|
|
80
|
final String rawSetId = RawSet.newInstance().getId();
|
81
|
set.put("rawset", rawSetId);
|
82
|
set.put("creationDate", DateUtils.now_ISO8601());
|
83
|
set.put("set", actionSetId);
|
84
|
set.put("enabled", "true");
|
85
|
set.put("jobProperty", getJobProperty());
|
86
|
|
87
|
token.getEnv().setAttribute(set.get("jobProperty"), set.get("rawset"));
|
88
|
|
89
|
final String path = basePath + "/" + actionSetDirectory + "/" + rawSetId;
|
90
|
log.info("using action set path: " + path);
|
91
|
token.getEnv().setAttribute(getActionSetPathParam(), path);
|
92
|
|
93
|
setList.add(set);
|
94
|
final String sets = new Gson().toJson(setList);
|
95
|
log.debug("built set: " + sets);
|
96
|
|
97
|
token.getEnv().setAttribute("sets", sets);
|
98
|
|
99
|
return Arc.DEFAULT_ARC;
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Gets the action set id.
|
104
|
*
|
105
|
* @param token the token
|
106
|
* @return the action set id
|
107
|
*/
|
108
|
private String getActionSetId(final NodeToken token) {
|
109
|
final String json = token.getEnv().getAttribute(getDedupConfigSequenceParam());
|
110
|
final DedupConfigurationOrchestration dco = DedupConfigurationOrchestration.fromJSON(json);
|
111
|
final String actionSetId = dco.getActionSetId();
|
112
|
log.info("found actionSetId in workflow env: " + actionSetId);
|
113
|
return actionSetId;
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Gets the dedup config sequence param.
|
118
|
*
|
119
|
* @return the dedup config sequence param
|
120
|
*/
|
121
|
public String getDedupConfigSequenceParam() {
|
122
|
return dedupConfigSequenceParam;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Sets the dedup config sequence param.
|
127
|
*
|
128
|
* @param dedupConfigSequenceParam the new dedup config sequence param
|
129
|
*/
|
130
|
public void setDedupConfigSequenceParam(final String dedupConfigSequenceParam) {
|
131
|
this.dedupConfigSequenceParam = dedupConfigSequenceParam;
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Gets the job property.
|
136
|
*
|
137
|
* @return the job property
|
138
|
*/
|
139
|
public String getJobProperty() {
|
140
|
return jobProperty;
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* Sets the job property.
|
145
|
*
|
146
|
* @param jobProperty the new job property
|
147
|
*/
|
148
|
public void setJobProperty(final String jobProperty) {
|
149
|
this.jobProperty = jobProperty;
|
150
|
}
|
151
|
|
152
|
public String getActionSetPathParam() {
|
153
|
return actionSetPathParam;
|
154
|
}
|
155
|
|
156
|
public void setActionSetPathParam(final String actionSetPathParam) {
|
157
|
this.actionSetPathParam = actionSetPathParam;
|
158
|
}
|
159
|
}
|