Revision 31774
Added by Michele Artini over 9 years ago
modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/datacite/PatchHostedBy.java | ||
---|---|---|
35 | 35 |
public String evaluate(final String record) { |
36 | 36 |
try { |
37 | 37 |
final Document doc = reader.read(new StringReader(record)); |
38 |
final HostedByEntry ds = findHostedBy(doc);
|
|
39 |
if (ds != null) {
|
|
40 |
final Element node = (Element) doc.selectSingleNode("//*[local-name()='hostedBy']");
|
|
41 |
if (node != null) {
|
|
38 |
final Element node = (Element) doc.selectSingleNode("//*[local-name()='hostedBy']");
|
|
39 |
if (node != null) {
|
|
40 |
final HostedByEntry ds = findHostedBy(doc);
|
|
41 |
if (ds != null) {
|
|
42 | 42 |
node.addAttribute("id", ds.getId()); |
43 | 43 |
node.addAttribute("name", ds.getName()); |
44 | 44 |
counters.increaseCounter(ds.getId()); |
45 | 45 |
} |
46 | 46 |
return doc.asXML(); |
47 |
} else if (log.isDebugEnabled()) { |
|
48 |
log.debug(" -- Missing hostedBy --"); |
|
47 | 49 |
} |
48 | 50 |
} catch(Throwable e) { |
49 | 51 |
log.error("Error adding hosted by to " + record); |
... | ... | |
55 | 57 |
for(Object o : doc.selectNodes("//*[local-name()='header']/*[local-name()='setSpec']")) { |
56 | 58 |
final String set = ((Element) o).getText().trim(); |
57 | 59 |
if (setSpecHostedByMap.containsKey(set)) { |
58 |
if (log.isDebugEnabled()) {
|
|
59 |
log.debug(set + " -> " + setSpecHostedByMap.get(set));
|
|
60 |
if (log.isInfoEnabled()) {
|
|
61 |
log.info(set + " -> " + setSpecHostedByMap.get(set));
|
|
60 | 62 |
} |
61 | 63 |
return setSpecHostedByMap.get(set); |
62 | 64 |
} else if (log.isDebugEnabled()) { |
modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/datacite/ValidateDataciteHostedByReposJobNode.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.datacite; |
2 | 2 |
|
3 |
import java.util.Map.Entry; |
|
4 |
|
|
5 |
import org.apache.commons.lang.StringUtils; |
|
3 | 6 |
import org.apache.commons.logging.Log; |
4 | 7 |
import org.apache.commons.logging.LogFactory; |
8 |
import org.springframework.beans.factory.annotation.Required; |
|
5 | 9 |
|
6 | 10 |
import com.googlecode.sarasvati.Arc; |
7 | 11 |
import com.googlecode.sarasvati.NodeToken; |
8 | 12 |
|
13 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc; |
|
14 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService; |
|
15 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerServiceException; |
|
16 |
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc; |
|
17 |
import eu.dnetlib.enabling.tools.ServiceLocator; |
|
18 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
9 | 19 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
10 | 20 |
|
11 | 21 |
public class ValidateDataciteHostedByReposJobNode extends SimpleJobNode { |
12 |
private String countersParam; |
|
13 |
|
|
14 | 22 |
private static final Log log = LogFactory.getLog(ValidateDataciteHostedByReposJobNode.class); |
15 | 23 |
|
24 |
private static final String HOSTED_BY_COMPLIANCE = "hostedBy"; |
|
25 |
|
|
26 |
private ServiceLocator<DatasourceManagerService> datasourceManagerLocator; |
|
27 |
|
|
28 |
private String countersParam; |
|
29 |
private String mdId; |
|
30 |
private String extraFieldsForTotal; |
|
31 |
private String extraFieldForDate; |
|
32 |
private String extraFieldForMdId; |
|
33 |
|
|
16 | 34 |
@Override |
17 | 35 |
protected String execute(NodeToken token) throws Exception { |
18 | 36 |
final DataciteHostedByCounters counters = (DataciteHostedByCounters) token.getEnv().getTransientAttribute(countersParam); |
37 |
final DatasourceManagerService dsManager = datasourceManagerLocator.getService(); |
|
38 |
final String date = DateUtils.now_ISO8601(); |
|
19 | 39 |
|
20 | 40 |
log.info(counters); |
21 | 41 |
|
22 |
//TODO |
|
23 |
log.info("TODO: I should assign a new API to the following ds: " + counters.getCounters().keySet()); |
|
24 |
|
|
42 |
for(Entry<String, Integer> e : counters.getCounters().entrySet()) { |
|
43 |
updateHostedByApi(dsManager, e.getKey(), date, e.getValue()); |
|
44 |
} |
|
45 |
|
|
25 | 46 |
return Arc.DEFAULT_ARC; |
26 | 47 |
} |
27 | 48 |
|
49 |
private void updateHostedByApi(final DatasourceManagerService dsManager, final String dsId, final String date, final int size) { |
|
50 |
log.info("Verifying hostedBy api in ds: " + dsId); |
|
51 |
try { |
|
52 |
final DatasourceDesc ds = dsManager.getDatasource(dsId); |
|
53 |
|
|
54 |
for (IfaceDesc iface : ds.getInterfaces()) { |
|
55 |
if (HOSTED_BY_COMPLIANCE.equals(iface.getCompliance())) { |
|
56 |
if (StringUtils.isNotBlank(extraFieldForDate)) { |
|
57 |
dsManager.updateExtraField(dsId, iface.getId(), extraFieldForDate, date, false); |
|
58 |
} |
|
59 |
if (StringUtils.isNotBlank(extraFieldsForTotal)) { |
|
60 |
dsManager.updateExtraField(dsId, iface.getId(), extraFieldsForTotal, Integer.toString(size), false); |
|
61 |
} |
|
62 |
if (StringUtils.isNotBlank(mdId) && StringUtils.isNotBlank(extraFieldForMdId)) { |
|
63 |
dsManager.updateExtraField(dsId, iface.getId(), extraFieldForMdId, mdId, false); |
|
64 |
} |
|
65 |
return; |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
final IfaceDesc iface = new IfaceDesc(); |
|
70 |
iface.setId("api_________::" + dsId + "::hostedBy"); |
|
71 |
iface.setTypology(ds.getTypology()); |
|
72 |
iface.setCompliance(HOSTED_BY_COMPLIANCE); |
|
73 |
iface.setAccessProtocol("UNKNOWN"); |
|
74 |
iface.setContentDescription("metadata"); |
|
75 |
iface.setBaseUrl(""); |
|
76 |
iface.setActive(false); |
|
77 |
iface.setRemovable(true); |
|
78 |
if (StringUtils.isNotBlank(extraFieldForDate)) { |
|
79 |
iface.getExtraFields().put(extraFieldForDate, date); |
|
80 |
} |
|
81 |
if (StringUtils.isNotBlank(extraFieldsForTotal)) { |
|
82 |
iface.getExtraFields().put(extraFieldsForTotal, Integer.toString(size)); |
|
83 |
} |
|
84 |
if (StringUtils.isNotBlank(mdId) && StringUtils.isNotBlank(extraFieldForMdId)) { |
|
85 |
iface.getExtraFields().put(extraFieldForMdId, mdId); |
|
86 |
} |
|
87 |
dsManager.addInterface(dsId, iface); |
|
88 |
} catch (DatasourceManagerServiceException e) { |
|
89 |
log.warn("Error setting hostedBy api of ds: " + dsId, e); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
public ServiceLocator<DatasourceManagerService> getDatasourceManagerLocator() { |
|
94 |
return datasourceManagerLocator; |
|
95 |
} |
|
96 |
|
|
97 |
@Required |
|
98 |
public void setDatasourceManagerLocator(ServiceLocator<DatasourceManagerService> datasourceManagerLocator) { |
|
99 |
this.datasourceManagerLocator = datasourceManagerLocator; |
|
100 |
} |
|
101 |
|
|
102 |
public String getMdId() { |
|
103 |
return mdId; |
|
104 |
} |
|
105 |
|
|
106 |
public void setMdId(String mdId) { |
|
107 |
this.mdId = mdId; |
|
108 |
} |
|
109 |
|
|
110 |
public String getExtraFieldsForTotal() { |
|
111 |
return extraFieldsForTotal; |
|
112 |
} |
|
113 |
|
|
114 |
public void setExtraFieldsForTotal(String extraFieldsForTotal) { |
|
115 |
this.extraFieldsForTotal = extraFieldsForTotal; |
|
116 |
} |
|
117 |
|
|
118 |
public String getExtraFieldForDate() { |
|
119 |
return extraFieldForDate; |
|
120 |
} |
|
121 |
|
|
122 |
public void setExtraFieldForDate(String extraFieldForDate) { |
|
123 |
this.extraFieldForDate = extraFieldForDate; |
|
124 |
} |
|
125 |
|
|
126 |
public String getExtraFieldForMdId() { |
|
127 |
return extraFieldForMdId; |
|
128 |
} |
|
129 |
|
|
130 |
public void setExtraFieldForMdId(String extraFieldForMdId) { |
|
131 |
this.extraFieldForMdId = extraFieldForMdId; |
|
132 |
} |
|
133 |
|
|
28 | 134 |
public String getCountersParam() { |
29 | 135 |
return countersParam; |
30 | 136 |
} |
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/msro/openaireplus/workflows/repo-hi/datacite/transform.wf.st | ||
---|---|---|
88 | 88 |
<NODE name="validateHostedByRepos" type="ValidateDataciteHostedByRepos"> |
89 | 89 |
<DESCRIPTION>Validate hostedBy Repos</DESCRIPTION> |
90 | 90 |
<PARAMETERS> |
91 |
<PARAM required="true" type="string" name="countersParam" managedBy="system">hostedByCounters</PARAM> |
|
91 |
<PARAM required="true" type="string" name="countersParam" managedBy="system">hostedByCounters</PARAM> |
|
92 |
<PARAM required="true" type="string" name="mdId" managedBy="system">$params.("tran_id")$</PARAM> |
|
93 |
<PARAM required="true" type="string" name="extraFieldsForTotal" managedBy="system">datacite::last_aggregation_total</PARAM> |
|
94 |
<PARAM required="true" type="string" name="extraFieldForDate" managedBy="system">datacite::last_aggregation_date</PARAM> |
|
95 |
<PARAM required="true" type="string" name="extraFieldForMdId" managedBy="system">datacite::last_aggregation_mdId</PARAM> |
|
92 | 96 |
</PARAMETERS> |
93 | 97 |
<ARCS> |
94 | 98 |
<ARC to="success"/> |
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/msro/openaireplus/workflows/applicationContext-msro-openaire-nodes.xml | ||
---|---|---|
219 | 219 |
p:resultSetClientFactory-ref="resultSetClientFactory"/> |
220 | 220 |
|
221 | 221 |
<bean id="wfNodeValidateDataciteHostedByRepos" class="eu.dnetlib.msro.openaireplus.workflows.nodes.datacite.ValidateDataciteHostedByReposJobNode" |
222 |
p:datasourceManagerLocator-ref="openaireDatasourceManagerServiceLocator" |
|
222 | 223 |
scope="prototype" /> |
223 | 224 |
|
224 | 225 |
</beans> |
Also available in: Unified diff
Node to add hostedBy apis