1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes;
|
2
|
|
3
|
import java.text.SimpleDateFormat;
|
4
|
import java.util.Date;
|
5
|
|
6
|
import com.googlecode.sarasvati.Arc;
|
7
|
import com.googlecode.sarasvati.NodeToken;
|
8
|
import com.mongodb.DBObject;
|
9
|
import com.mongodb.client.MongoCollection;
|
10
|
import com.mongodb.client.model.Filters;
|
11
|
import com.mongodb.client.model.Sorts;
|
12
|
import eu.dnetlib.common.logging.DnetLogger;
|
13
|
import eu.dnetlib.common.logging.dao.DnetLoggerMongoDao;
|
14
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
15
|
import org.apache.commons.logging.Log;
|
16
|
import org.apache.commons.logging.LogFactory;
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
import org.springframework.beans.factory.annotation.Value;
|
19
|
|
20
|
public class PrepareLodParamJobNode extends SimpleJobNode {
|
21
|
|
22
|
/**
|
23
|
* logger.
|
24
|
*/
|
25
|
private static final Log log = LogFactory.getLog(PrepareLodParamJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM
|
26
|
private static final String SYSTEM_PROFILE_ID = "system:profileId";
|
27
|
private static final String LOG_DATE = "log:date";
|
28
|
private static final String IS_COMPLETED_SUCCESSFULLY = "system:isCompletedSuccessfully";
|
29
|
|
30
|
@Value("${dnet.openaire.lod.jsonrels}")
|
31
|
private String lodJsonRels;
|
32
|
|
33
|
@Value("${dnet.openaire.lod.wfId}")
|
34
|
private String lodWfId;
|
35
|
|
36
|
@Value("${dnet.openaire.lod.default.date}")
|
37
|
private String defaultLodDate;
|
38
|
|
39
|
@Autowired
|
40
|
private DnetLogger dnetLogger;
|
41
|
|
42
|
@Autowired
|
43
|
private DnetLoggerMongoDao mongoDao;
|
44
|
|
45
|
private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
|
46
|
|
47
|
@Override
|
48
|
protected String execute(final NodeToken token) throws Exception {
|
49
|
|
50
|
log.info("prepare LOD update job");
|
51
|
|
52
|
token.getEnv().setAttribute("lod_jsonRels", lodJsonRels);
|
53
|
token.getEnv().setAttribute("lod_lastExecutionDate", getFormattedDate());
|
54
|
|
55
|
return Arc.DEFAULT_ARC;
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Queries the MSRO logger to find the last time the LOD update workflow was successfully executed.
|
60
|
*
|
61
|
* @return the formatted date
|
62
|
*/
|
63
|
private String getFormattedDate() {
|
64
|
final DBObject dbo = getLoggerDao()
|
65
|
.find(Filters.and(Filters.eq(SYSTEM_PROFILE_ID, lodWfId), Filters.eq(IS_COMPLETED_SUCCESSFULLY, "true")))
|
66
|
.sort(Sorts.descending(LOG_DATE))
|
67
|
.limit(1)
|
68
|
.first();
|
69
|
|
70
|
if (dbo == null || !dbo.containsField(LOG_DATE)) {
|
71
|
log.warn(String.format("Cannot find log entry for LOD update workflow, using default date: '%s'", defaultLodDate));
|
72
|
return defaultLodDate;
|
73
|
}
|
74
|
|
75
|
final String lastExecutionDate = dateFormat.format(new Date((Long) dbo.get(LOG_DATE)));
|
76
|
log.debug(String.format("Last LOD execution date: '%s'", lastExecutionDate));
|
77
|
return lastExecutionDate;
|
78
|
}
|
79
|
|
80
|
private MongoCollection<DBObject> getLoggerDao() {
|
81
|
return mongoDao.getDb().getCollection(dnetLogger.getName(), DBObject.class);
|
82
|
}
|
83
|
|
84
|
}
|