Revision 50489
Added by Michele Artini about 6 years ago
UpsertHostedByApisJobNode.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.hostedby; |
2 | 2 |
|
3 | 3 |
import java.util.Map.Entry; |
4 |
import javax.annotation.Resource; |
|
5 | 4 |
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
|
|
6 | 9 |
import com.googlecode.sarasvati.Arc; |
7 | 10 |
import com.googlecode.sarasvati.NodeToken; |
8 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc; |
|
9 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService;
|
|
10 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerServiceException;
|
|
11 |
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
|
|
12 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
|
11 |
|
|
12 |
import eu.dnetlib.enabling.datasources.LocalOpenaireDatasourceManager;
|
|
13 |
import eu.dnetlib.enabling.datasources.common.Api;
|
|
14 |
import eu.dnetlib.enabling.datasources.common.ApiParam;
|
|
15 |
import eu.dnetlib.enabling.datasources.common.DsmException;
|
|
13 | 16 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
14 | 17 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 | 18 |
|
18 | 19 |
public class UpsertHostedByApisJobNode extends SimpleJobNode { |
19 | 20 |
|
... | ... | |
21 | 22 |
|
22 | 23 |
private static final String HOSTED_BY_COMPLIANCE = "hostedBy"; |
23 | 24 |
|
24 |
@Resource
|
|
25 |
private UniqueServiceLocator serviceLocator;
|
|
25 |
@Autowired
|
|
26 |
private LocalOpenaireDatasourceManager dsManager;
|
|
26 | 27 |
|
27 | 28 |
private String countersParam; |
28 | 29 |
private String mdId; |
... | ... | |
33 | 34 |
@Override |
34 | 35 |
protected String execute(final NodeToken token) throws Exception { |
35 | 36 |
final HostedByCounters counters = (HostedByCounters) token.getEnv().getTransientAttribute(countersParam); |
36 |
final DatasourceManagerService dsManager = serviceLocator.getService(DatasourceManagerService.class); |
|
37 | 37 |
final String date = DateUtils.now_ISO8601(); |
38 | 38 |
final String namespacePrefix = token.getEnv().getAttribute("namespacePrefix"); |
39 | 39 |
|
40 | 40 |
log.info(counters); |
41 | 41 |
|
42 |
for (Entry<String, Integer> e : counters.getCounters().entrySet()) { |
|
43 |
updateHostedByApi(dsManager, e.getKey(), namespacePrefix, date, e.getValue());
|
|
42 |
for (final Entry<String, Integer> e : counters.getCounters().entrySet()) {
|
|
43 |
updateHostedByApi(e.getKey(), namespacePrefix, date, e.getValue()); |
|
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
return Arc.DEFAULT_ARC; |
47 | 47 |
} |
48 | 48 |
|
49 |
private void updateHostedByApi(final DatasourceManagerService dsManager, |
|
50 |
final String dsId, |
|
49 |
private void updateHostedByApi(final String dsId, |
|
51 | 50 |
final String namepsacePrefix, |
52 | 51 |
final String date, |
53 | 52 |
final int size) { |
54 | 53 |
log.info("Verifying hostedBy api in ds: " + dsId); |
55 | 54 |
try { |
56 |
final DatasourceDesc ds = dsManager.getDatasource(dsId); |
|
57 | 55 |
|
58 |
for (IfaceDesc iface : ds.getInterfaces()) { |
|
59 |
if (HOSTED_BY_COMPLIANCE.equals(iface.getCompliance())) { |
|
60 |
return; |
|
61 |
} |
|
56 |
for (final Api<ApiParam> iface : dsManager.getApis(dsId)) { |
|
57 |
if (HOSTED_BY_COMPLIANCE.equals(iface.getCompatibility())) { return; } |
|
62 | 58 |
} |
63 | 59 |
|
64 |
final IfaceDesc iface = new IfaceDesc(); |
|
65 |
iface.setId("api_________::" + dsId + "::hostedBy"); |
|
66 |
iface.setTypology(ds.getDatasourceClass()); |
|
67 |
iface.setCompliance(HOSTED_BY_COMPLIANCE); |
|
68 |
iface.setAccessProtocol("UNKNOWN"); |
|
69 |
iface.setContentDescription("metadata"); |
|
70 |
iface.setBaseUrl(""); |
|
71 |
iface.setActive(false); |
|
72 |
iface.setRemovable(true); |
|
73 |
dsManager.addInterface(dsId, iface); |
|
74 |
} catch (DatasourceManagerServiceException e) { |
|
60 |
final Api<ApiParam> api = new Api<>(); |
|
61 |
api.setDatasource(dsId); |
|
62 |
api.setId("api_________::" + dsId + "::hostedBy"); |
|
63 |
api.setTypology(dsManager.getDs(dsId).getTypology()); |
|
64 |
api.setCompatibility(HOSTED_BY_COMPLIANCE); |
|
65 |
api.setProtocol("UNKNOWN"); |
|
66 |
api.setContentdescription("metadata"); |
|
67 |
api.setBaseurl(""); |
|
68 |
api.setActive(false); |
|
69 |
api.setRemovable(true); |
|
70 |
dsManager.addApi(api); |
|
71 |
} catch (final DsmException e) { |
|
75 | 72 |
log.warn("Error setting hostedBy api of ds: " + dsId, e); |
76 | 73 |
} |
77 | 74 |
} |
Also available in: Unified diff
merged branch dsm into trunk