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.kew.useroptions.dao.UserOptionsDAO;
26 import org.kuali.rice.kew.api.KewApiConstants;
27 import org.springframework.transaction.annotation.Transactional;
28
29 @Transactional
30 public class UserOptionsServiceImpl implements UserOptionsService {
31
32 private UserOptionsDAO userOptionsDAO;
33
34 private static final Properties defaultProperties = new Properties();
35
36 static {
37 defaultProperties.setProperty(KewApiConstants.EMAIL_RMNDR_KEY, KewApiConstants.EMAIL_RMNDR_WEEK_VAL);
38 }
39
40 private Long getNewOptionIdForActionList() {
41 return getUserOptionsDAO().getNewOptionIdForActionList();
42 }
43
44 public List<UserOptions> findByUserQualified(String principalId, String likeString) {
45 if ((principalId == null)) {
46 return new ArrayList<UserOptions>(0);
47 }
48 return this.getUserOptionsDAO().findByUserQualified(principalId, likeString);
49 }
50
51 public UserOptions findByOptionId(String optionId, String principalId) {
52 if (optionId == null || "".equals(optionId) || principalId == null || "".equals(principalId)) {
53 return null;
54 }
55 return this.getUserOptionsDAO().findByOptionId(optionId, principalId);
56 }
57
58 public Collection<UserOptions> findByOptionValue(String optionId, String optionValue){
59 return this.getUserOptionsDAO().findByOptionValue(optionId, optionValue);
60 }
61
62 public Collection<UserOptions> findByWorkflowUser(String principalId) {
63 return this.getUserOptionsDAO().findByWorkflowUser(principalId);
64 }
65
66 public void save(UserOptions userOptions) {
67 this.getUserOptionsDAO().save(userOptions);
68 }
69
70
71
72
73
74
75 public void save(String principalId, Map<String,String> optionsMap) {
76
77 if (optionsMap != null && optionsMap.size() > 0) {
78 List<UserOptions> toSave = new ArrayList<UserOptions>();
79 for (Entry<String, String> entry : optionsMap.entrySet()) {
80 UserOptions option = findByOptionId(entry.getKey(), principalId);
81 if (option == null) {
82 option = new UserOptions();
83 option.setWorkflowId(principalId);
84 }
85 option.setOptionId(entry.getKey());
86 option.setOptionVal(entry.getValue());
87 toSave.add(option);
88 }
89 getUserOptionsDAO().save(toSave);
90 }
91 }
92
93 public void deleteUserOptions(UserOptions userOptions) {
94 this.getUserOptionsDAO().deleteUserOptions(userOptions);
95 }
96
97 public void save(String principalId, String optionId, String optionValue) {
98 UserOptions option = findByOptionId(optionId, principalId);
99 if (option == null) {
100 option = new UserOptions();
101 option.setWorkflowId(principalId);
102 }
103 option.setOptionId(optionId);
104 option.setOptionVal(optionValue);
105 getUserOptionsDAO().save(option);
106 }
107
108 public UserOptionsDAO getUserOptionsDAO() {
109 return userOptionsDAO;
110 }
111
112 public void setUserOptionsDAO(UserOptionsDAO optionsDAO) {
113 userOptionsDAO = optionsDAO;
114 }
115
116 @Override
117 public List<UserOptions> retrieveEmailPreferenceUserOptions(String emailSetting) {
118 return this.getUserOptionsDAO().findEmailUserOptionsByType(emailSetting);
119 }
120 }