1
|
package eu.dnetlib.msro.worker.nodes.repobye;
|
2
|
|
3
|
import org.apache.commons.logging.Log;
|
4
|
import org.apache.commons.logging.LogFactory;
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
|
7
|
import com.googlecode.sarasvati.Arc;
|
8
|
import com.googlecode.sarasvati.NodeToken;
|
9
|
|
10
|
import eu.dnetlib.enabling.datastructures.Datasource;
|
11
|
import eu.dnetlib.enabling.datastructures.MetaWorkflow;
|
12
|
import eu.dnetlib.enabling.is.client.InformationServiceClient;
|
13
|
import eu.dnetlib.msro.worker.WorkflowConstants;
|
14
|
import eu.dnetlib.msro.worker.nodes.SimpleJobNode;
|
15
|
import eu.dnetlib.rmi.objects.datasources.IfaceDesc;
|
16
|
import eu.dnetlib.rmi.soap.InformationService;
|
17
|
|
18
|
public class DeleteMetaWfJobNode extends SimpleJobNode {
|
19
|
|
20
|
private String metaWfId;
|
21
|
|
22
|
@Autowired
|
23
|
private InformationService informationService;
|
24
|
|
25
|
@Autowired
|
26
|
private InformationServiceClient isClient;
|
27
|
|
28
|
private static final Log log = LogFactory.getLog(DeleteMetaWfJobNode.class);
|
29
|
|
30
|
@Override
|
31
|
protected String execute(final NodeToken token) throws Exception {
|
32
|
final MetaWorkflow metaWf = isClient.getResourceByCode(metaWfId, MetaWorkflow.class);
|
33
|
|
34
|
final String dsId = metaWf.getDatasourceId();
|
35
|
final String dsName = metaWf.getDatasourceName();
|
36
|
final String ifaceId = metaWf.getDatasourceInterfaceId();
|
37
|
|
38
|
log.info("Removing a MetaWf of dataprovider: " + metaWf.getDatasourceId());
|
39
|
token.getEnv().setAttribute(WorkflowConstants.DATAPROVIDER_ID, dsId);
|
40
|
token.getEnv().setAttribute(WorkflowConstants.DATAPROVIDER_NAME, dsName);
|
41
|
token.getEnv().setAttribute(WorkflowConstants.DATAPROVIDER_INTERFACE, metaWf.getDatasourceInterfaceId());
|
42
|
|
43
|
isClient.deleteResourceByCode(metaWfId, MetaWorkflow.class);
|
44
|
|
45
|
verifyDatasource(dsId, ifaceId);
|
46
|
|
47
|
return Arc.DEFAULT_ARC;
|
48
|
}
|
49
|
|
50
|
private void verifyDatasource(final String dsId, final String ifaceId) throws Exception {
|
51
|
|
52
|
final String sql = String.format(
|
53
|
"select id from resource_properties where name = 'metaWf::ifaceId' and value = '%s'", ifaceId);
|
54
|
|
55
|
final boolean active = !informationService.searchSql(sql).isEmpty();
|
56
|
|
57
|
updateIfaceActivationStatus(dsId, ifaceId, active);
|
58
|
}
|
59
|
|
60
|
protected void updateIfaceActivationStatus(final String dsId, final String ifaceId, final boolean active) throws Exception {
|
61
|
final Datasource ds = isClient.getResourceByCode(dsId, Datasource.class);
|
62
|
for (IfaceDesc iface : ds.getInterfaces()) {
|
63
|
if (iface.getId().equals(ifaceId)) {
|
64
|
iface.setActive(active);
|
65
|
isClient.updateResource(ds);
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
|
70
|
public String getMetaWfId() {
|
71
|
return metaWfId;
|
72
|
}
|
73
|
|
74
|
public void setMetaWfId(final String metaWfId) {
|
75
|
this.metaWfId = metaWfId;
|
76
|
}
|
77
|
|
78
|
}
|