1 |
27548
|
michele.ar
|
package eu.dnetlib.msro.workflows.nodes.collect;
|
2 |
|
|
|
3 |
|
|
import java.text.SimpleDateFormat;
|
4 |
|
|
import java.util.Date;
|
5 |
41550
|
michele.ar
|
import java.util.HashMap;
|
6 |
27548
|
michele.ar
|
import java.util.Map;
|
7 |
41550
|
michele.ar
|
|
8 |
27548
|
michele.ar
|
import javax.annotation.Resource;
|
9 |
|
|
|
10 |
41550
|
michele.ar
|
import org.apache.commons.logging.Log;
|
11 |
|
|
import org.apache.commons.logging.LogFactory;
|
12 |
|
|
|
13 |
41783
|
michele.ar
|
import eu.dnetlib.msro.logging.DnetLogger;
|
14 |
40094
|
michele.ar
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
15 |
27548
|
michele.ar
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
16 |
40099
|
michele.ar
|
import eu.dnetlib.msro.workflows.procs.Env;
|
17 |
41620
|
michele.ar
|
import eu.dnetlib.msro.workflows.procs.ProcessAware;
|
18 |
|
|
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
|
19 |
27548
|
michele.ar
|
|
20 |
41620
|
michele.ar
|
public class FindDateRangeForIncrementalHarvestingJobNode extends SimpleJobNode implements ProcessAware {
|
21 |
40094
|
michele.ar
|
|
22 |
|
|
private static final Log log = LogFactory.getLog(FindDateRangeForIncrementalHarvestingJobNode.class);
|
23 |
27548
|
michele.ar
|
private String fromDateParam;
|
24 |
|
|
private String untilDateParam;
|
25 |
41620
|
michele.ar
|
private static final long ONE_DAY = 1000 * 60 * 60 * 24;
|
26 |
|
|
|
27 |
|
|
private WorkflowProcess process;
|
28 |
|
|
|
29 |
27548
|
michele.ar
|
@Resource(name = "msroWorkflowLogger")
|
30 |
|
|
private DnetLogger dnetLogger;
|
31 |
40094
|
michele.ar
|
|
32 |
27548
|
michele.ar
|
@Override
|
33 |
40094
|
michele.ar
|
protected String execute(final Env env) throws Exception {
|
34 |
41550
|
michele.ar
|
final String fromDate = calculateFromDate();
|
35 |
27548
|
michele.ar
|
final String untilDate = null;
|
36 |
40094
|
michele.ar
|
|
37 |
41550
|
michele.ar
|
log.info("Incremental Harv Details - from: " + fromDate + " - until: " + untilDate);
|
38 |
40094
|
michele.ar
|
|
39 |
27548
|
michele.ar
|
if (fromDate != null) {
|
40 |
40094
|
michele.ar
|
env.setAttribute(getFromDateParam(), fromDate);
|
41 |
27548
|
michele.ar
|
}
|
42 |
40094
|
michele.ar
|
|
43 |
41550
|
michele.ar
|
// if (untilDate != null) {
|
44 |
|
|
// env.setAttribute(getUntilDateParam(), untilDate);
|
45 |
|
|
// }
|
46 |
40094
|
michele.ar
|
|
47 |
27548
|
michele.ar
|
return Arc.DEFAULT_ARC;
|
48 |
40094
|
michele.ar
|
}
|
49 |
|
|
|
50 |
41550
|
michele.ar
|
private String calculateFromDate() {
|
51 |
|
|
final long d = findLastSuccessStartDate();
|
52 |
41620
|
michele.ar
|
return (d > 0) ? (new SimpleDateFormat("yyyy-MM-dd")).format(new Date(d - ONE_DAY)) : null;
|
53 |
27548
|
michele.ar
|
}
|
54 |
|
|
|
55 |
41550
|
michele.ar
|
private long findLastSuccessStartDate() {
|
56 |
41620
|
michele.ar
|
final long res = -1;
|
57 |
40094
|
michele.ar
|
|
58 |
41550
|
michele.ar
|
// TODO find the right condition to obtain the list of the previous executions
|
59 |
|
|
|
60 |
|
|
final Map<String, Object> query = new HashMap<String, Object>();
|
61 |
|
|
query.put("", "");
|
62 |
|
|
|
63 |
41620
|
michele.ar
|
/*
|
64 |
|
|
* final Iterator<Map<String, String>> iter = this.dnetLogger.find(query); while (iter.hasNext()) { final Map<String, String> map =
|
65 |
|
|
* iter.next(); if ("true".equalsIgnoreCase(map.get(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY))) { final long curr =
|
66 |
|
|
* NumberUtils.toLong(map.get(WorkflowsConstants.SYSTEM_START_DATE), -1); if (curr > res) { res = curr; } } }
|
67 |
|
|
*/
|
68 |
27548
|
michele.ar
|
return res;
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
public String getFromDateParam() {
|
72 |
41550
|
michele.ar
|
return this.fromDateParam;
|
73 |
27548
|
michele.ar
|
}
|
74 |
40094
|
michele.ar
|
|
75 |
41550
|
michele.ar
|
public void setFromDateParam(final String fromDateParam) {
|
76 |
27548
|
michele.ar
|
this.fromDateParam = fromDateParam;
|
77 |
|
|
}
|
78 |
40094
|
michele.ar
|
|
79 |
27548
|
michele.ar
|
public String getUntilDateParam() {
|
80 |
41550
|
michele.ar
|
return this.untilDateParam;
|
81 |
27548
|
michele.ar
|
}
|
82 |
40094
|
michele.ar
|
|
83 |
41550
|
michele.ar
|
public void setUntilDateParam(final String untilDateParam) {
|
84 |
27548
|
michele.ar
|
this.untilDateParam = untilDateParam;
|
85 |
|
|
}
|
86 |
40094
|
michele.ar
|
|
87 |
41620
|
michele.ar
|
public WorkflowProcess getProcess() {
|
88 |
|
|
return this.process;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
@Override
|
92 |
|
|
public void setProcess(final WorkflowProcess process) {
|
93 |
|
|
this.process = process;
|
94 |
|
|
}
|
95 |
|
|
|
96 |
27548
|
michele.ar
|
}
|