001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kew.useroptions; 017 018 import java.util.ArrayList; 019 import java.util.Collection; 020 import java.util.List; 021 import java.util.Map; 022 import java.util.Properties; 023 import java.util.Map.Entry; 024 025 import org.kuali.rice.kew.useroptions.dao.ReloadActionListDAO; 026 import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO; 027 import org.kuali.rice.kew.api.KewApiConstants; 028 import org.springframework.transaction.annotation.Transactional; 029 030 @Transactional 031 public class UserOptionsServiceImpl implements UserOptionsService { 032 033 private UserOptionsDAO userOptionsDAO; 034 private ReloadActionListDAO reloadActionListDAO; 035 036 private static final Properties defaultProperties = new Properties(); 037 038 static { 039 defaultProperties.setProperty(KewApiConstants.EMAIL_RMNDR_KEY, KewApiConstants.EMAIL_RMNDR_WEEK_VAL); 040 } 041 042 private Long getNewOptionIdForActionList() { 043 return getUserOptionsDAO().getNewOptionIdForActionList(); 044 } 045 046 public List<UserOptions> findByUserQualified(String principalId, String likeString) { 047 if ((principalId == null)) { 048 return new ArrayList<UserOptions>(0); 049 } 050 return this.getUserOptionsDAO().findByUserQualified(principalId, likeString); 051 } 052 053 public UserOptions findByOptionId(String optionId, String principalId) { 054 if (optionId == null || "".equals(optionId) || principalId == null || "".equals(principalId)) { 055 return null; 056 } 057 return this.getUserOptionsDAO().findByOptionId(optionId, principalId); 058 } 059 060 public Collection<UserOptions> findByOptionValue(String optionId, String optionValue){ 061 return this.getUserOptionsDAO().findByOptionValue(optionId, optionValue); 062 } 063 064 public Collection<UserOptions> findByWorkflowUser(String principalId) { 065 return this.getUserOptionsDAO().findByWorkflowUser(principalId); 066 } 067 068 public void save(UserOptions userOptions) { 069 this.getUserOptionsDAO().save(userOptions); 070 } 071 072 /** 073 * This overridden method saves an option for each optionsMap entry, all for the given principalId 074 * 075 * @see org.kuali.rice.kew.useroptions.UserOptionsService#save(java.lang.String, java.util.Map) 076 */ 077 public void save(String principalId, Map<String,String> optionsMap) { 078 // create a collection of UserOptions and save it 079 if (optionsMap != null && optionsMap.size() > 0) { 080 List<UserOptions> toSave = new ArrayList<UserOptions>(); 081 for (Entry<String, String> entry : optionsMap.entrySet()) { 082 UserOptions option = findByOptionId(entry.getKey(), principalId); 083 if (option == null) { 084 option = new UserOptions(); 085 option.setWorkflowId(principalId); 086 } 087 option.setOptionId(entry.getKey()); 088 option.setOptionVal(entry.getValue()); 089 toSave.add(option); 090 } 091 getUserOptionsDAO().save(toSave); 092 } 093 } 094 095 public void deleteUserOptions(UserOptions userOptions) { 096 this.getUserOptionsDAO().deleteUserOptions(userOptions); 097 } 098 099 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 @Override 138 public List<UserOptions> retrieveEmailPreferenceUserOptions(String emailSetting) { 139 return this.getUserOptionsDAO().findEmailUserOptionsByType(emailSetting); 140 } 141 }