1 package com.atlassian.jira.event.issue;
2
3 import java.util.HashMap;
4 import java.util.Iterator;
5 import java.util.List;
6
7 import com.atlassian.jira.function.issue.FunctionHelper;
8 import com.atlassian.jira.issue.Issue;
9 import com.atlassian.jira.project.Project;
10 import com.opensymphony.module.propertyset.PropertySet;
11 import com.opensymphony.module.propertyset.PropertySetManager;
12
13 public class NotifiableUpdateManagerImpl implements NotifiableUpdateManager {
14
15 private PropertySet propertySet;
16
17 protected HashMap cachedProjects;
18
19
20
21
22 public PropertySet getProjectNotifiableFields(final Project _project) {
23 PropertySet projectNotifiableFields = null;
24
25 projectNotifiableFields = (PropertySet) getCachedProjects().get(_project.getId());
26
27 if (projectNotifiableFields == null) {
28 projectNotifiableFields = getPropertySet(_project);
29 getCachedProjects().put(_project.getId(), projectNotifiableFields);
30 }
31 return projectNotifiableFields;
32 }
33
34 public String getPropertyEntityName() {
35 return PROPERTY_ENTITYNAME;
36 }
37
38
39
40
41 protected PropertySet getPropertySet(final Project _project) {
42 HashMap ofbizArgs = new HashMap();
43 ofbizArgs.put("delegator.name", "default");
44 ofbizArgs.put("entityName", getPropertyEntityName());
45 ofbizArgs.put("entityId", _project.getId());
46
47 PropertySet ofbizPs = PropertySetManager.getInstance("ofbiz", ofbizArgs);
48 HashMap args = new HashMap();
49 args.put("PropertySet", ofbizPs);
50 args.put("bulkload", Boolean.TRUE);
51 propertySet = PropertySetManager.getInstance("cached", args);
52
53 return propertySet;
54 }
55
56 public void addNotifiableField(final Project _project, final String _fieldName) {
57 getProjectNotifiableFields(_project).setBoolean(_fieldName, true);
58 }
59
60 public void setNotifiableCustomfield(final Project _project, final String _fieldName, final String _customfieldName) {
61 getProjectNotifiableFields(_project).setString(_fieldName, _customfieldName);
62 }
63
64 public void removeNotifiableField(final Project _project, final String _fieldName) {
65 PropertySet ps = getProjectNotifiableFields(_project);
66 if (ps.exists(_fieldName)) {
67 ps.remove(_fieldName);
68 }
69 }
70
71 public void removeNotifiableFields(final Project _project) {
72 PropertySet ps = getProjectNotifiableFields(_project);
73 for (Iterator iter = ps.getKeys().iterator(); iter.hasNext();) {
74 String fieldName = (String) iter.next();
75 ps.remove(fieldName);
76 }
77 }
78
79 public void addNotifiableFields(final Project _project, final List _fieldNames) {
80 PropertySet ps = getProjectNotifiableFields(_project);
81 for (Iterator iter = _fieldNames.iterator(); iter.hasNext();) {
82 String fieldName = (String) iter.next();
83 ps.setBoolean(fieldName, true);
84 }
85 }
86
87
88
89
90 public void refresh() {
91 setCachedProjects(null);
92 }
93
94 protected HashMap getCachedProjects() {
95 if (cachedProjects == null) {
96 cachedProjects = new HashMap();
97 }
98 return cachedProjects;
99 }
100
101 protected void setCachedProjects(HashMap cachedProjects) {
102 this.cachedProjects = cachedProjects;
103 }
104
105 public void updateIssueNotifiable(final Issue _issue) {
106 Project project = _issue.getProjectObject();
107 PropertySet ps = getProjectNotifiableFields(project);
108 if (ps.exists(NOTIFIABLE_CUSTOMFIELDNAME)) {
109 String cfName = ps.getString(NOTIFIABLE_CUSTOMFIELDNAME);
110 FunctionHelper.setIssueNotifiable(_issue, cfName);
111 }
112 }
113
114 }