Project

General

Profile

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

    
3
import java.util.List;
4

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

    
9
import com.google.common.base.Splitter;
10
import com.googlecode.sarasvati.Arc;
11
import com.googlecode.sarasvati.NodeToken;
12

    
13
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
14

    
15
public class ResetCountersJobNode extends SimpleJobNode {
16

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

    
19
	private String attributesCSV;
20

    
21
	@Override
22
	protected String execute(final NodeToken token) throws Exception {
23

    
24
		if (StringUtils.isNotBlank(getAttributesCSV())) {
25

    
26
			log.info("got wf attributes CSV: " + getAttributesCSV());
27

    
28
			final Splitter splitter = Splitter.on(",").trimResults().omitEmptyStrings();
29
			final List<String> wfAttrs = splitter.splitToList(getAttributesCSV());
30

    
31
			for (final String attr : wfAttrs) {
32
				resetWorkflowParam(token, attr);
33
			}
34

    
35
		} else {
36
			log.info("attribute list is empty, nothing to do here.");
37
		}
38

    
39
		return Arc.DEFAULT_ARC;
40
	}
41

    
42
	private void resetWorkflowParam(final NodeToken token, final String attribute) {
43
		final String count = token.getFullEnv().getAttribute(attribute);
44
		if (StringUtils.isNotBlank(count)) {
45
			log.info(String.format("found loop counter '%s', value '%s'", attribute, count));
46
			token.getFullEnv().setAttribute(attribute, 0);
47

    
48
			log.info(String.format("set '%s', to 0", attribute));
49
		} else {
50
			log.info("loop counter was not found in workflow env, nothing to do here.");
51
		}
52
	}
53

    
54
	public String getAttributesCSV() {
55
		return attributesCSV;
56
	}
57

    
58
	public void setAttributesCSV(final String attributesCSV) {
59
		this.attributesCSV = attributesCSV;
60
	}
61

    
62
}
(14-14/15)