Project

General

Profile

1
package eu.dnetlib.msro.workflows.nodes.info;
2

    
3
import java.util.Date;
4

    
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;
9

    
10
import com.googlecode.sarasvati.Arc;
11
import com.googlecode.sarasvati.NodeToken;
12

    
13
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager;
14
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
15
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
16
import eu.dnetlib.miscutils.datetime.DateUtils;
17
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
18

    
19
public class MDStoreToApiExtraFieldJobNode extends SimpleJobNode {
20

    
21
	private String mdId;
22
	private String datasourceId;
23
	private String datasourceInterface;
24
	private String extraFieldForTotal;
25
	private String extraFieldForDate;
26
	private String extraFieldForMdId;
27

    
28
	@Autowired
29
	private UniqueServiceLocator serviceLocator;
30

    
31
	@Autowired
32
	private LocalDatasourceManager<?, ?> dsManager;
33

    
34
	private static final Log log = LogFactory.getLog(MDStoreToApiExtraFieldJobNode.class);
35

    
36
	@Override
37
	protected String execute(final NodeToken token) throws Exception {
38
		final String xq = "for $x in collection('/db/DRIVER/MDStoreDSResources/MDStoreDSResourceType') " +
39
				"where $x//RESOURCE_IDENTIFIER/@value='" + mdId + "' " +
40
				"return concat($x//NUMBER_OF_RECORDS, ' @=@ ', $x//LAST_STORAGE_DATE)";
41

    
42
		final String s = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xq);
43

    
44
		final String[] arr = s.split(" @=@ ");
45

    
46
		final int size = NumberUtils.toInt(arr[0].trim(), 0);
47
		final Date date = (new DateUtils()).parse(arr[1]);
48

    
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
		}
56

    
57
		return Arc.DEFAULT_ARC;
58
	}
59

    
60
	public String getMdId() {
61
		return mdId;
62
	}
63

    
64
	public void setMdId(final String mdId) {
65
		this.mdId = mdId;
66
	}
67

    
68
	public String getDatasourceId() {
69
		return datasourceId;
70
	}
71

    
72
	public void setDatasourceId(final String datasourceId) {
73
		this.datasourceId = datasourceId;
74
	}
75

    
76
	public String getDatasourceInterface() {
77
		return datasourceInterface;
78
	}
79

    
80
	public void setDatasourceInterface(final String datasourceInterface) {
81
		this.datasourceInterface = datasourceInterface;
82
	}
83

    
84
	public String getExtraFieldForTotal() {
85
		return extraFieldForTotal;
86
	}
87

    
88
	public void setExtraFieldForTotal(final String extraFieldForTotal) {
89
		this.extraFieldForTotal = extraFieldForTotal;
90
	}
91

    
92
	public String getExtraFieldForDate() {
93
		return extraFieldForDate;
94
	}
95

    
96
	public void setExtraFieldForDate(final String extraFieldForDate) {
97
		this.extraFieldForDate = extraFieldForDate;
98
	}
99

    
100
	public String getExtraFieldForMdId() {
101
		return extraFieldForMdId;
102
	}
103

    
104
	public void setExtraFieldForMdId(final String extraFieldForMdId) {
105
		this.extraFieldForMdId = extraFieldForMdId;
106
	}
107

    
108
}
(1-1/4)