View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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       * This overridden method saves an option for each optionsMap entry, all for the given principalId
72       * 
73       * @see org.kuali.rice.kew.useroptions.UserOptionsService#save(java.lang.String, java.util.Map)
74       */
75      public void save(String principalId, Map<String,String> optionsMap) {
76      	// create a collection of UserOptions and save it
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 }