1 |
29397
|
claudio.at
|
package eu.dnetlib.msro.openaireplus.workflows.nodes;
|
2 |
|
|
|
3 |
45641
|
claudio.at
|
import java.text.SimpleDateFormat;
|
4 |
|
|
import java.util.Date;
|
5 |
29397
|
claudio.at
|
|
6 |
|
|
import com.googlecode.sarasvati.Arc;
|
7 |
|
|
import com.googlecode.sarasvati.NodeToken;
|
8 |
45641
|
claudio.at
|
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 |
29397
|
claudio.at
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
15 |
45641
|
claudio.at
|
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 |
29397
|
claudio.at
|
|
20 |
45641
|
claudio.at
|
public class PrepareLodParamJobNode extends SimpleJobNode {
|
21 |
29397
|
claudio.at
|
|
22 |
|
|
/**
|
23 |
|
|
* logger.
|
24 |
|
|
*/
|
25 |
45641
|
claudio.at
|
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 |
29397
|
claudio.at
|
|
30 |
45641
|
claudio.at
|
@Value("${dnet.openaire.lod.jsonrels}")
|
31 |
|
|
private String lodJsonRels;
|
32 |
29578
|
claudio.at
|
|
33 |
45641
|
claudio.at
|
@Value("${dnet.openaire.lod.wfId}")
|
34 |
|
|
private String lodWfId;
|
35 |
29397
|
claudio.at
|
|
36 |
45641
|
claudio.at
|
@Value("${dnet.openaire.lod.default.date}")
|
37 |
|
|
private String defaultLodDate;
|
38 |
29397
|
claudio.at
|
|
39 |
45641
|
claudio.at
|
@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 |
29397
|
claudio.at
|
@Override
|
48 |
|
|
protected String execute(final NodeToken token) throws Exception {
|
49 |
|
|
|
50 |
45641
|
claudio.at
|
log.info("prepare LOD update job");
|
51 |
29397
|
claudio.at
|
|
52 |
45641
|
claudio.at
|
token.getEnv().setAttribute("lod_jsonRels", lodJsonRels);
|
53 |
|
|
token.getEnv().setAttribute("lod_lastExecutionDate", getFormattedDate());
|
54 |
29397
|
claudio.at
|
|
55 |
45641
|
claudio.at
|
return Arc.DEFAULT_ARC;
|
56 |
|
|
}
|
57 |
29397
|
claudio.at
|
|
58 |
45641
|
claudio.at
|
/**
|
59 |
|
|
* Queries the MSRO logger to find the last time the LOD update workflow was successfully executed.
|
60 |
|
|
* @return
|
61 |
|
|
* 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 |
29397
|
claudio.at
|
|
70 |
45641
|
claudio.at
|
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 |
29397
|
claudio.at
|
}
|
79 |
|
|
|
80 |
45641
|
claudio.at
|
private MongoCollection<DBObject> getLoggerDao() {
|
81 |
|
|
return mongoDao.getDb().getCollection(dnetLogger.getName(), DBObject.class);
|
82 |
29578
|
claudio.at
|
}
|
83 |
|
|
|
84 |
29397
|
claudio.at
|
}
|