1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.useroptions;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Properties;
23 import java.util.Map.Entry;
24
25 import org.kuali.rice.core.api.criteria.QueryByCriteria;
26 import org.kuali.rice.kew.api.KewApiConstants;
27 import org.kuali.rice.krad.data.DataObjectService;
28
29 import org.springframework.transaction.annotation.Transactional;
30
31 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
32
33
34
35
36
37
38
39 @Transactional
40 public class UserOptionsServiceImpl implements UserOptionsService {
41
42
43 private DataObjectService dataObjectService;
44
45
46 private static final Properties defaultProperties = new Properties();
47
48
49 static {
50 defaultProperties.setProperty(KewApiConstants.EMAIL_RMNDR_KEY, KewApiConstants.EMAIL_RMNDR_WEEK_VAL);
51 }
52
53
54
55 @Override
56 public Collection<UserOptions> findByWorkflowUser(String principalId) {
57
58 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
59 criteria.setPredicates(equal("workflowId", principalId));
60
61 return dataObjectService.findMatching(UserOptions.class, criteria.build()).getResults();
62 }
63
64
65
66
67 @Override
68 public List<UserOptions> findByUserQualified(String principalId, String likeString) {
69 if ((principalId == null)) {
70 return new ArrayList<UserOptions>(0);
71 }
72 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
73 criteria.setPredicates(and(equal("workflowId", principalId),like("optionId", likeString)));
74 return this.dataObjectService.findMatching(UserOptions.class, criteria.build()).getResults();
75 }
76
77
78
79
80 @Override
81 public UserOptions findByOptionId(String optionId, String principalId) {
82 if (optionId == null || "".equals(optionId) || principalId == null || "".equals(principalId)) {
83 return null;
84 }
85
86 return this.dataObjectService.find(UserOptions.class, new UserOptionsId(principalId, optionId));
87 }
88
89
90
91
92 @Override
93 public void save(UserOptions userOptions) {
94 this.dataObjectService.save(userOptions);
95 }
96
97
98
99
100 @Override
101 public void save(String principalId, Map<String,String> optionsMap) {
102
103
104 if (optionsMap != null && !optionsMap.isEmpty()) {
105 for (Entry<String, String> entry : optionsMap.entrySet()) {
106 UserOptions option = findByOptionId(entry.getKey(), principalId);
107 if (option == null) {
108 option = new UserOptions();
109 option.setWorkflowId(principalId);
110 }
111 option.setOptionId(entry.getKey());
112 option.setOptionVal(entry.getValue());
113 this.save(option);
114 }
115 }
116 }
117
118
119
120
121 @Override
122 public void save(String principalId, String optionId, String optionValue) {
123
124 if(optionValue.length() <= 2000)
125 {
126 UserOptions option = findByOptionId(optionId, principalId);
127 if (option == null) {
128 option = new UserOptions();
129 option.setWorkflowId(principalId);
130 }
131 option.setOptionId(optionId);
132 option.setOptionVal(optionValue);
133 this.save(option);
134 }
135 }
136
137
138
139
140 @Override
141 public void deleteUserOptions(UserOptions userOptions) {
142 this.dataObjectService.delete(userOptions);
143 }
144
145
146
147
148 @Override
149 public List<UserOptions> retrieveEmailPreferenceUserOptions(String emailSetting) {
150
151 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
152 criteria.setPredicates(
153 or(
154 equal("optionId", KewApiConstants.EMAIL_RMNDR_KEY),
155 like("optionId", "%" + KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_SUFFIX)
156 ),
157 equal("optionVal", emailSetting)
158 );
159
160 return this.dataObjectService.findMatching(UserOptions.class, criteria.build()).getResults();
161 }
162
163
164
165
166
167 public DataObjectService getDataObjectService() {
168 return dataObjectService;
169 }
170
171
172
173
174 public void setDataObjectService(DataObjectService dataObjectService) {
175 this.dataObjectService = dataObjectService;
176 }
177 }