1
|
package eu.dnetlib.iis.export.actionmanager.actionset;
|
2
|
|
3
|
import static eu.dnetlib.iis.export.actionmanager.ExportWorkflowRuntimeParameters.EXPORT_ACTION_SETID;
|
4
|
|
5
|
import java.util.Collections;
|
6
|
import java.util.List;
|
7
|
import java.util.Map;
|
8
|
|
9
|
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
|
10
|
|
11
|
import org.apache.hadoop.conf.Configuration;
|
12
|
import org.apache.log4j.Logger;
|
13
|
|
14
|
import eu.dnetlib.actionmanager.rmi.ActionManagerService;
|
15
|
import eu.dnetlib.actionmanager.set.ActionManagerSet;
|
16
|
import eu.dnetlib.actionmanager.set.ActionManagerSet.ImpactTypes;
|
17
|
import eu.dnetlib.enabling.tools.JaxwsServiceResolverImpl;
|
18
|
import eu.dnetlib.iis.common.WorkflowRuntimeParameters;
|
19
|
import eu.dnetlib.iis.core.java.PortBindings;
|
20
|
import eu.dnetlib.iis.core.java.Process;
|
21
|
import eu.dnetlib.iis.core.java.ProcessUtils;
|
22
|
import eu.dnetlib.iis.core.java.porttype.PortType;
|
23
|
|
24
|
/**
|
25
|
* Simple process removing and recreating action set.
|
26
|
* @author mhorst
|
27
|
*
|
28
|
*/
|
29
|
public class ActionSetManagementProcess implements Process {
|
30
|
|
31
|
private final Logger log = Logger.getLogger(this.getClass());
|
32
|
|
33
|
public static final String PARAM_ACTION_MANAGER_SERVICE_LOCATION = "export.actionmanager.service.location";
|
34
|
|
35
|
public static final String PARAM_ACTION_SET_ID = EXPORT_ACTION_SETID;
|
36
|
|
37
|
|
38
|
@Override
|
39
|
public Map<String, PortType> getInputPorts() {
|
40
|
return Collections.emptyMap();
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
public Map<String, PortType> getOutputPorts() {
|
45
|
return Collections.emptyMap();
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
public void run(PortBindings portBindings, Configuration conf,
|
50
|
Map<String, String> parameters) throws Exception {
|
51
|
String actionManagerLocation = ProcessUtils.getParameterValue(
|
52
|
PARAM_ACTION_MANAGER_SERVICE_LOCATION,
|
53
|
conf, parameters);
|
54
|
String actionSetId = ProcessUtils.getParameterValue(
|
55
|
PARAM_ACTION_SET_ID,
|
56
|
conf, parameters);
|
57
|
if (actionManagerLocation!=null
|
58
|
&& !WorkflowRuntimeParameters.UNDEFINED_NONEMPTY_VALUE.equals(actionManagerLocation)
|
59
|
&& actionSetId!=null) {
|
60
|
W3CEndpointReferenceBuilder eprBuilder = new W3CEndpointReferenceBuilder();
|
61
|
eprBuilder.address(actionManagerLocation);
|
62
|
eprBuilder.build();
|
63
|
ActionManagerService actionManager = new JaxwsServiceResolverImpl().getService(
|
64
|
ActionManagerService.class, eprBuilder.build());
|
65
|
// checking whether given action set already exists
|
66
|
List<ActionManagerSet> sets = actionManager.ListSets();
|
67
|
boolean foundSet = false;
|
68
|
if (sets!=null) {
|
69
|
for (ActionManagerSet set : sets) {
|
70
|
if (actionSetId.equals(set.getId())) {
|
71
|
foundSet = true;
|
72
|
break;
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
if (!foundSet) {
|
77
|
// creating new IIS action set
|
78
|
ActionManagerSet set = new ActionManagerSet();
|
79
|
set.setId(actionSetId);
|
80
|
set.setName(actionSetId);
|
81
|
set.setImpact(ImpactTypes.ONLY_INSERT);
|
82
|
String createdId = actionManager.createSet(set);
|
83
|
log.warn("created action set with external id: " + createdId + ","
|
84
|
+ "set id/name: " + actionSetId);
|
85
|
} else {
|
86
|
log.warn("set " + actionSetId + " was already created");
|
87
|
}
|
88
|
} else {
|
89
|
log.warn("skipping action set management! Either '" +
|
90
|
PARAM_ACTION_MANAGER_SERVICE_LOCATION + "' parameter or '" +
|
91
|
PARAM_ACTION_SET_ID + "' parameter was not provided!");
|
92
|
}
|
93
|
}
|
94
|
}
|