Project

General

Profile

1
package eu.dnetlib.msro.workflows.hadoop;
2

    
3
import javax.annotation.Resource;
4

    
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7

    
8
import com.googlecode.sarasvati.Arc;
9
import com.googlecode.sarasvati.NodeToken;
10

    
11
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
12
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
13
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
14
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode;
15

    
16
public class IndexDSUpdateJobNode extends AsyncJobNode {
17

    
18
	private static final Log log = LogFactory.getLog(IndexDSUpdateJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM
19

    
20
	public final static String N_RECORDS_PARAM = "blackboard:param:index.status code: 0";
21

    
22
	@Resource
23
	private UniqueServiceLocator serviceLocator;
24

    
25
	@Override
26
	public String execute(final NodeToken token) throws Exception {
27

    
28
		final String dsId = token.getEnv().getAttribute("index_id");
29
		final String version = token.getEnv().getAttribute("index.feed.timestamp");
30

    
31
		try {
32
			final int count = Integer.parseInt(token.getEnv().getAttribute(N_RECORDS_PARAM));
33
			log.info("updating indexDS: " + dsId + " version: " + version + " record count: " + count);
34
			updateIndexDS(dsId, version, count);
35
		} catch (NumberFormatException e) {
36
			log.warn("unable to find index feeding details in the workflow env, skippind DS update");
37
		}
38

    
39
		return Arc.DEFAULT_ARC;
40
	}
41

    
42
	/**
43
	 * method updates the given indexDataStructureId INDEX_SIZE, INDEX_LAST_UPDATE
44
	 * 
45
	 * @param dsId
46
	 * @param size
47
	 * @return true if the update was performed successfully, false otherwise
48
	 * @throws ISRegistryException
49
	 */
50
	private boolean updateIndexDS(final String dsId, final String version, final long count) throws ISRegistryException {
51

    
52
		final String xquery = "for $x in collection('')/RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + dsId + "']"
53
				+ " return update value $x//INDEX_SIZE with " + String.valueOf(count) + ","
54
				+ "for $x in collection('')/RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + dsId + "']"
55
				+ " return update value $x//INDEX_LAST_UPDATE with '" + version + "' ";
56

    
57
		log.debug("\n\n updating indexDataStructure: " + xquery + "\n\n");
58

    
59
		return serviceLocator.getService(ISRegistryService.class).executeXUpdate(xquery);
60
	}
61

    
62
}
(4-4/10)