1
|
package eu.dnetlib.msro.workflows.nodes;
|
2
|
|
3
|
import javax.annotation.Resource;
|
4
|
|
5
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
6
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
7
|
import eu.dnetlib.msro.workflows.procs.Env;
|
8
|
import eu.dnetlib.rmi.enabling.ISRegistryException;
|
9
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
|
13
|
public class IndexDSUpdateJobNode extends SimpleJobNode {
|
14
|
|
15
|
public final static String N_RECORDS_PARAM = "blackboard:param:index.status code: 0";
|
16
|
private static final Log log = LogFactory.getLog(IndexDSUpdateJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM
|
17
|
@Resource
|
18
|
private UniqueServiceLocator serviceLocator;
|
19
|
|
20
|
@Override
|
21
|
public String execute(final Env env) throws Exception {
|
22
|
|
23
|
final String dsId = env.getAttribute("index_id", String.class);
|
24
|
final String version = env.getAttribute("index.feed.timestamp", String.class);
|
25
|
|
26
|
try {
|
27
|
final int count = Integer.parseInt(env.getAttribute(N_RECORDS_PARAM, String.class));
|
28
|
log.info("updating indexDS: " + dsId + " version: " + version + " record count: " + count);
|
29
|
updateIndexDS(dsId, version, count);
|
30
|
} catch (NumberFormatException e) {
|
31
|
log.warn("unable to find index feeding details in the workflow env, skippind DS update");
|
32
|
}
|
33
|
|
34
|
return Arc.DEFAULT_ARC;
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* method updates the given indexDataStructureId INDEX_SIZE, INDEX_LAST_UPDATE
|
39
|
*
|
40
|
* @param dsId
|
41
|
* @param version
|
42
|
* @param count
|
43
|
* @return true if the update was performed successfully, false otherwise
|
44
|
* @throws ISRegistryException
|
45
|
*/
|
46
|
private boolean updateIndexDS(final String dsId, final String version, final long count) throws ISRegistryException {
|
47
|
|
48
|
final String xquery = "for $x in collection('')/RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + dsId + "']"
|
49
|
+ " return update value $x//INDEX_SIZE with " + String.valueOf(count) + ","
|
50
|
+ "for $x in collection('')/RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + dsId + "']"
|
51
|
+ " return update value $x//INDEX_LAST_UPDATE with '" + version + "' ";
|
52
|
|
53
|
log.debug("\n\n updating indexDataStructure: " + xquery + "\n\n");
|
54
|
|
55
|
return serviceLocator.getService(ISRegistryService.class).executeXUpdate(xquery);
|
56
|
}
|
57
|
|
58
|
}
|