View Javadoc

1   /**
2    * Copyright 2005-2011 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.ReloadActionListDAO;
26  import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO;
27  import org.kuali.rice.kew.api.KewApiConstants;
28  import org.springframework.transaction.annotation.Transactional;
29  
30  @Transactional
31  public class UserOptionsServiceImpl implements UserOptionsService {
32  
33      private UserOptionsDAO userOptionsDAO;
34      private ReloadActionListDAO reloadActionListDAO;
35  
36      private static final Properties defaultProperties = new Properties();
37  
38      static {
39          defaultProperties.setProperty(KewApiConstants.EMAIL_RMNDR_KEY, KewApiConstants.EMAIL_RMNDR_WEEK_VAL);
40      }
41  
42      private Long getNewOptionIdForActionList() {
43  		return getUserOptionsDAO().getNewOptionIdForActionList();
44  	}
45  
46      public List<UserOptions> findByUserQualified(String principalId, String likeString) {
47          if ((principalId == null)) {
48              return new ArrayList<UserOptions>(0);
49          }
50          return this.getUserOptionsDAO().findByUserQualified(principalId, likeString);
51      }
52  
53      public UserOptions findByOptionId(String optionId, String principalId) {
54          if (optionId == null || "".equals(optionId) || principalId == null || "".equals(principalId)) {
55              return null;
56          }
57          return this.getUserOptionsDAO().findByOptionId(optionId, principalId);
58      }
59  
60      public Collection<UserOptions> findByOptionValue(String optionId, String optionValue){
61          return this.getUserOptionsDAO().findByOptionValue(optionId, optionValue);
62      }
63  
64      public Collection<UserOptions> findByWorkflowUser(String principalId) {
65          return this.getUserOptionsDAO().findByWorkflowUser(principalId);
66      }
67  
68      public void save(UserOptions userOptions) {
69          this.getUserOptionsDAO().save(userOptions);
70      }
71      
72      /**
73       * This overridden method saves an option for each optionsMap entry, all for the given principalId
74       * 
75       * @see org.kuali.rice.kew.useroptions.UserOptionsService#save(java.lang.String, java.util.Map)
76       */
77      public void save(String principalId, Map<String,String> optionsMap) {
78      	// create a collection of UserOptions and save it
79      	if (optionsMap != null && optionsMap.size() > 0) {
80      		List<UserOptions> toSave = new ArrayList<UserOptions>();
81      		for (Entry<String, String> entry : optionsMap.entrySet()) {
82      			UserOptions option = findByOptionId(entry.getKey(), principalId);
83      			if (option == null) {
84      				option = new UserOptions();
85      				option.setWorkflowId(principalId);
86      			}
87      			option.setOptionId(entry.getKey());
88      			option.setOptionVal(entry.getValue());
89      			toSave.add(option);
90      		}
91  			getUserOptionsDAO().save(toSave);
92      	}
93      }
94      
95      public void deleteUserOptions(UserOptions userOptions) {
96          this.getUserOptionsDAO().deleteUserOptions(userOptions);
97      }
98  
99      public void save(String principalId, String optionId, String optionValue) {
100         UserOptions option = findByOptionId(optionId, principalId);
101         if (option == null) {
102             option = new UserOptions();
103             option.setWorkflowId(principalId);
104         }
105         option.setOptionId(optionId);
106         option.setOptionVal(optionValue);
107         getUserOptionsDAO().save(option);
108     }
109 
110     public boolean refreshActionList(String principalId) {
111     	return getReloadActionListDAO().checkAndResetReloadActionListFlag(principalId);
112     }
113 
114     public void saveRefreshUserOption(String principalId) {
115     	getReloadActionListDAO().setReloadActionListFlag(principalId);
116     }
117 
118     public UserOptionsDAO getUserOptionsDAO() {
119         return userOptionsDAO;
120     }
121 
122     public void setUserOptionsDAO(UserOptionsDAO optionsDAO) {
123         userOptionsDAO = optionsDAO;
124     }
125     
126     /**
127 	 * @return the reloadActionListDAO
128 	 */
129 	public ReloadActionListDAO getReloadActionListDAO() {
130 		return this.reloadActionListDAO;
131 	}
132 	
133 	public void setReloadActionListDAO(ReloadActionListDAO rald) {
134 		this.reloadActionListDAO = rald;
135 	}
136 
137 }