1
|
package eu.dnetlib.msro.workflows.nodes.index;
|
2
|
|
3
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
4
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
5
|
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
|
6
|
import eu.dnetlib.msro.workflows.procs.Env;
|
7
|
import eu.dnetlib.msro.workflows.procs.Token;
|
8
|
import eu.dnetlib.rmi.enabling.ISLookUpDocumentNotFoundException;
|
9
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
10
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
11
|
import eu.dnetlib.rmi.manager.MSROException;
|
12
|
import eu.dnetlib.rmi.provision.IndexService;
|
13
|
import org.apache.commons.lang3.StringUtils;
|
14
|
import org.apache.commons.logging.Log;
|
15
|
import org.apache.commons.logging.LogFactory;
|
16
|
|
17
|
import static java.lang.String.format;
|
18
|
|
19
|
public class FinalizeIndexJobNode extends BlackboardJobNode {
|
20
|
|
21
|
private static final Log log = LogFactory.getLog(FinalizeIndexJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM
|
22
|
|
23
|
@Override
|
24
|
protected String obtainServiceId(final Env env) {
|
25
|
return getServiceLocator().getServiceId(IndexService.class);
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception {
|
30
|
final String indexDsId = getEnvParam(token.getEnv(), "index_id");
|
31
|
|
32
|
log.info("preparing blackboard job DELETE_BY_QUERY index: " + indexDsId);
|
33
|
|
34
|
final String backendId = getBackendId(indexDsId);
|
35
|
if (StringUtils.isBlank(backendId)) { throw new MSROException("empty index backend Id"); }
|
36
|
|
37
|
job.setAction("DELETE_BY_QUERY");
|
38
|
job.getParameters().put("id", indexDsId);
|
39
|
job.getParameters().put("backend_Id", backendId);
|
40
|
job.getParameters().put("query", buildQuery(getEnvParam(token.getEnv(), "index.feed.timestamp")));
|
41
|
}
|
42
|
|
43
|
private String buildQuery(final String version) {
|
44
|
final String query =
|
45
|
String.format("__dsversion:{* TO %s}", DateUtils.getParsedDateField(version));
|
46
|
|
47
|
log.info("delete by query: " + query);
|
48
|
|
49
|
return query;
|
50
|
}
|
51
|
|
52
|
private String getEnvParam(final Env env, final String name) throws MSROException {
|
53
|
final String value = env.getAttribute(name, String.class);
|
54
|
|
55
|
if (StringUtils
|
56
|
.isBlank(value)) { throw new MSROException(format("unable to finalize index feeding, cannot find property '%s' in the workflow env.", name)); }
|
57
|
|
58
|
return value;
|
59
|
}
|
60
|
|
61
|
public String getBackendId(final String indexDsId) throws ISLookUpDocumentNotFoundException, ISLookUpException {
|
62
|
return getServiceLocator().getService(ISLookUpService.class).getResourceProfileByQuery(
|
63
|
"//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='" + indexDsId + "']//BACKEND/text()");
|
64
|
}
|
65
|
|
66
|
}
|