Revision 50488
Added by Michele Artini about 6 years ago
MDStoreToApiExtraFieldJobNode.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.workflows.nodes.info; |
2 | 2 |
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.Map; |
|
3 |
import java.util.Date; |
|
5 | 4 |
|
6 |
import javax.annotation.Resource; |
|
5 |
import org.apache.commons.lang.math.NumberUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 | 9 |
|
8 |
import org.dom4j.Document; |
|
9 |
import org.dom4j.Node; |
|
10 |
import org.dom4j.io.SAXReader; |
|
11 |
|
|
12 |
import com.google.common.collect.Maps; |
|
13 | 10 |
import com.googlecode.sarasvati.Arc; |
14 | 11 |
import com.googlecode.sarasvati.NodeToken; |
15 | 12 |
|
16 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService;
|
|
13 |
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager;
|
|
17 | 14 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
18 | 15 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
16 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
19 | 17 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
20 | 18 |
|
21 | 19 |
public class MDStoreToApiExtraFieldJobNode extends SimpleJobNode { |
... | ... | |
27 | 25 |
private String extraFieldForDate; |
28 | 26 |
private String extraFieldForMdId; |
29 | 27 |
|
30 |
@Resource
|
|
28 |
@Autowired
|
|
31 | 29 |
private UniqueServiceLocator serviceLocator; |
32 | 30 |
|
31 |
@Autowired |
|
32 |
private LocalDatasourceManager<?, ?> dsManager; |
|
33 |
|
|
34 |
private static final Log log = LogFactory.getLog(MDStoreToApiExtraFieldJobNode.class); |
|
35 |
|
|
33 | 36 |
@Override |
34 | 37 |
protected String execute(final NodeToken token) throws Exception { |
35 | 38 |
final String xq = "for $x in collection('/db/DRIVER/MDStoreDSResources/MDStoreDSResourceType') " + |
... | ... | |
40 | 43 |
|
41 | 44 |
final String[] arr = s.split(" @=@ "); |
42 | 45 |
|
43 |
final Map<String, String> map = getCurrentExtraFields(datasourceId, datasourceInterface); |
|
44 |
map.put(extraFieldForTotal, arr[0].trim()); |
|
45 |
map.put(extraFieldForDate, arr[1].trim()); |
|
46 |
map.put(extraFieldForMdId, mdId); |
|
46 |
final int size = NumberUtils.toInt(arr[0].trim(), 0); |
|
47 |
final Date date = (new DateUtils()).parse(arr[1]); |
|
47 | 48 |
|
48 |
serviceLocator.getService(DatasourceManagerService.class).bulkUpdateApiExtraFields(datasourceId, datasourceInterface, map); |
|
49 |
if (extraFieldForTotal.equals("last_collection_total")) { |
|
50 |
dsManager.setLastCollectionInfo(datasourceId, datasourceInterface, mdId, size, date); |
|
51 |
} else if (extraFieldForTotal.equals("last_aggregation_total")) { |
|
52 |
dsManager.setLastAggregationInfo(datasourceId, datasourceInterface, mdId, size, date); |
|
53 |
} else { |
|
54 |
log.warn("Invalid field for total: " + extraFieldForTotal); |
|
55 |
} |
|
49 | 56 |
|
50 | 57 |
return Arc.DEFAULT_ARC; |
51 | 58 |
} |
52 | 59 |
|
53 |
private Map<String, String> getCurrentExtraFields(final String repoId, final String ifaceId) throws Exception { |
|
54 |
final Map<String, String> res = Maps.newHashMap(); |
|
55 |
|
|
56 |
final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId); |
|
57 |
|
|
58 |
final SAXReader reader = new SAXReader(); |
|
59 |
final Document doc = reader.read(new StringReader(profile)); |
|
60 |
|
|
61 |
final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']"); |
|
62 |
if (ifcNode != null) { |
|
63 |
for (Object o : ifcNode.selectNodes("./INTERFACE_EXTRA_FIELD")) { |
|
64 |
res.put(((Node) o).valueOf("@name"), ((Node) o).getText()); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
return res; |
|
69 |
} |
|
70 |
|
|
71 | 60 |
public String getMdId() { |
72 | 61 |
return mdId; |
73 | 62 |
} |
Also available in: Unified diff
merged branch dsm into trunk