forked from DavidShepherdson/jira-suite-utilities
/
AbstractPreserveChangesPostFunction.java
95 lines (77 loc) · 2.96 KB
/
AbstractPreserveChangesPostFunction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.googlecode.jsu.workflow.function;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.WorkflowException;
/**
* Abstract post-function with transparent change tracking.
*
* @author <A href="mailto:abashev at gmail dot com">Alexey Abashev</A>
*/
abstract class AbstractPreserveChangesPostFunction extends AbstractJiraFunctionProvider {
private static final String CHANGE_ITEMS = "changeItems";
protected final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* Mirror for execute method but with holder for changes
*
* @throws WorkflowException
*/
protected abstract void executeFunction(
Map<String, Object> transientVars, Map<String, String> args,
PropertySet ps, IssueChangeHolder holder
) throws WorkflowException;
@SuppressWarnings("unchecked")
public final void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
IssueChangeHolder holder = createChangeHolder(transientVars);
if (log.isDebugEnabled()) {
log.debug(
"Executing function with [transientVars=" +
transientVars +
";args=" +
args +
";ps=" +
ps +
"]"
);
}
try {
executeFunction(transientVars, args, ps, holder);
} finally {
releaseChangeHolder(holder, transientVars);
}
}
/**
* Create new holder with changes from transient vars
*/
@SuppressWarnings("unchecked")
private IssueChangeHolder createChangeHolder(Map<String, Object> transientVars) {
List<ChangeItemBean> changeItems = (List<ChangeItemBean>) transientVars.get(CHANGE_ITEMS);
if (changeItems == null) {
changeItems = new LinkedList<ChangeItemBean>();
}
if (log.isDebugEnabled()) {
log.debug("Create new holder with items - " + changeItems.toString());
}
IssueChangeHolder holder = new DefaultIssueChangeHolder();
holder.setChangeItems(changeItems);
return holder;
}
/**
* Release holder for changes.
*/
@SuppressWarnings("unchecked")
private void releaseChangeHolder(IssueChangeHolder holder, Map<String, Object> transientVars) {
List<ChangeItemBean> items = holder.getChangeItems();
if (log.isDebugEnabled()) {
log.debug("Release holder with items - " + items.toString());
}
transientVars.put(CHANGE_ITEMS, items);
}
}