/src/main/java/com/onresolve/jira/groovy/GroovyCondition.java
Java | 52 lines | 38 code | 8 blank | 6 comment | 3 complexity | 38666fdea52bac222c240a0221d6897e MD5 | raw file
- package com.onresolve.jira.groovy;
-
- import com.atlassian.jira.workflow.condition.AbstractJiraCondition;
- import com.opensymphony.module.propertyset.PropertySet;
- import com.opensymphony.workflow.WorkflowException;
- import org.apache.log4j.Category;
-
- import java.util.HashMap;
- import java.util.Map;
-
- /**
- * User: echlinj
- * Date: 04-Apr-2008
- * Time: 13:25:57
- */
- public class GroovyCondition extends AbstractJiraCondition {
- private static final Category log = Category.getInstance(GroovyCondition.class);
- ScriptManager scriptManager;
-
- public GroovyCondition(ScriptManager scriptManager) {
- this.scriptManager = scriptManager;
- }
-
- @SuppressWarnings("unchecked")
- public boolean passesCondition(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
- GroovyRunner groovyRunner = new GroovyRunner(scriptManager);
- Map bindVars = new HashMap();
-
- // Move args to top level
- bindVars.put("args", args);
- for (Object o : args.keySet()) {
- bindVars.put(o, args.get(o));
- }
-
- bindVars.put("issue", transientVars.get("issue"));
- bindVars.put("passesCondition", true);
- bindVars.put("transientVars", transientVars);
- bindVars.put("args", args);
-
- Map ret;
- try {
- ret = groovyRunner.run((String) args.get("scriptFileName"), bindVars);
- assert ret != null;
- if (ret.containsKey("passesCondition")) {
- return (Boolean) ret.get("passesCondition");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- }