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
99 if(optionValue.length() <= 2000)
100 {
101 UserOptions option = findByOptionId(optionId, principalId);
102 if (option == null) {
103 option = new UserOptions();
104 option.setWorkflowId(principalId);
105 }
106 option.setOptionId(optionId);
107 option.setOptionVal(optionValue);
108 getUserOptionsDAO().save(option);
109 }
110 }
111
112 public UserOptionsDAO getUserOptionsDAO() {
113 return userOptionsDAO;
114 }
115
116 public void setUserOptionsDAO(UserOptionsDAO optionsDAO) {
117 userOptionsDAO = optionsDAO;
118 }
119
120 @Override
121 public List<UserOptions> retrieveEmailPreferenceUserOptions(String emailSetting) {
122 return this.getUserOptionsDAO().findEmailUserOptionsByType(emailSetting);
123 }
124 }