PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/onresolve/jira/groovy/GroovyCondition.java

https://bitbucket.org/sorin/jira-plugin-intellij
Java | 52 lines | 38 code | 8 blank | 6 comment | 3 complexity | 38666fdea52bac222c240a0221d6897e MD5 | raw file
  1. package com.onresolve.jira.groovy;
  2. import com.atlassian.jira.workflow.condition.AbstractJiraCondition;
  3. import com.opensymphony.module.propertyset.PropertySet;
  4. import com.opensymphony.workflow.WorkflowException;
  5. import org.apache.log4j.Category;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. /**
  9. * User: echlinj
  10. * Date: 04-Apr-2008
  11. * Time: 13:25:57
  12. */
  13. public class GroovyCondition extends AbstractJiraCondition {
  14. private static final Category log = Category.getInstance(GroovyCondition.class);
  15. ScriptManager scriptManager;
  16. public GroovyCondition(ScriptManager scriptManager) {
  17. this.scriptManager = scriptManager;
  18. }
  19. @SuppressWarnings("unchecked")
  20. public boolean passesCondition(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
  21. GroovyRunner groovyRunner = new GroovyRunner(scriptManager);
  22. Map bindVars = new HashMap();
  23. // Move args to top level
  24. bindVars.put("args", args);
  25. for (Object o : args.keySet()) {
  26. bindVars.put(o, args.get(o));
  27. }
  28. bindVars.put("issue", transientVars.get("issue"));
  29. bindVars.put("passesCondition", true);
  30. bindVars.put("transientVars", transientVars);
  31. bindVars.put("args", args);
  32. Map ret;
  33. try {
  34. ret = groovyRunner.run((String) args.get("scriptFileName"), bindVars);
  35. assert ret != null;
  36. if (ret.containsKey("passesCondition")) {
  37. return (Boolean) ret.get("passesCondition");
  38. }
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. }
  42. return true;
  43. }
  44. }