Coverage Report - org.kuali.rice.kew.useroptions.UserOptionsServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UserOptionsServiceImpl
0%
0/51
0%
0/28
2.154
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.useroptions;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.Date;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 import java.util.Properties;
 25  
 import java.util.Random;
 26  
 import java.util.Map.Entry;
 27  
 
 28  
 import org.apache.commons.lang.StringUtils;
 29  
 import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO;
 30  
 import org.kuali.rice.kew.util.KEWConstants;
 31  
 import org.springframework.transaction.annotation.Transactional;
 32  
 
 33  
 @Transactional
 34  0
 public class UserOptionsServiceImpl implements UserOptionsService {
 35  
 
 36  
     private UserOptionsDAO userOptionsDAO;
 37  0
     private Random random = new Random();
 38  
 
 39  0
     private static final Properties defaultProperties = new Properties();
 40  
 
 41  
     static {
 42  0
         defaultProperties.setProperty(KEWConstants.EMAIL_RMNDR_KEY, KEWConstants.EMAIL_RMNDR_WEEK_VAL);
 43  0
     }
 44  
 
 45  
     private Long getNewOptionIdForActionList() {
 46  0
                 return getUserOptionsDAO().getNewOptionIdForActionList();
 47  
         }
 48  
 
 49  
     public List<UserOptions> findByUserQualified(String principalId, String likeString) {
 50  0
         if ((principalId == null)) {
 51  0
             return new ArrayList<UserOptions>(0);
 52  
         }
 53  0
         return this.getUserOptionsDAO().findByUserQualified(principalId, likeString);
 54  
     }
 55  
 
 56  
     public UserOptions findByOptionId(String optionId, String principalId) {
 57  0
         if (optionId == null || "".equals(optionId) || principalId == null || "".equals(principalId)) {
 58  0
             return null;
 59  
         }
 60  0
         return this.getUserOptionsDAO().findByOptionId(optionId, principalId);
 61  
     }
 62  
 
 63  
     public Collection<UserOptions> findByOptionValue(String optionId, String optionValue){
 64  0
         return this.getUserOptionsDAO().findByOptionValue(optionId, optionValue);
 65  
     }
 66  
 
 67  
     public Collection<UserOptions> findByWorkflowUser(String principalId) {
 68  0
         return this.getUserOptionsDAO().findByWorkflowUser(principalId);
 69  
     }
 70  
 
 71  
     public void save(UserOptions userOptions) {
 72  0
         this.getUserOptionsDAO().save(userOptions);
 73  0
     }
 74  
     
 75  
     /**
 76  
      * This overridden method saves an option for each optionsMap entry, all for the given principalId
 77  
      * 
 78  
      * @see org.kuali.rice.kew.useroptions.UserOptionsService#save(java.lang.String, java.util.Map)
 79  
      */
 80  
     public void save(String principalId, Map<String,String> optionsMap) {
 81  
             // create a collection of UserOptions and save it
 82  0
             if (optionsMap != null && optionsMap.size() > 0) {
 83  0
                     List<UserOptions> toSave = new ArrayList<UserOptions>();
 84  0
                     for (Entry<String, String> entry : optionsMap.entrySet()) {
 85  0
                             UserOptions option = findByOptionId(entry.getKey(), principalId);
 86  0
                             if (option == null) {
 87  0
                                     option = new UserOptions();
 88  0
                                     option.setWorkflowId(principalId);
 89  
                             }
 90  0
                             option.setOptionId(entry.getKey());
 91  0
                             option.setOptionVal(entry.getValue());
 92  0
                             toSave.add(option);
 93  0
                     }
 94  0
                         getUserOptionsDAO().save(toSave);
 95  
             }
 96  0
     }
 97  
     
 98  
     public void deleteUserOptions(UserOptions userOptions) {
 99  0
         this.getUserOptionsDAO().deleteUserOptions(userOptions);
 100  0
     }
 101  
 
 102  
     public void save(String principalId, String optionId, String optionValue) {
 103  0
         UserOptions option = findByOptionId(optionId, principalId);
 104  0
         if (option == null) {
 105  0
             option = new UserOptions();
 106  0
             option.setWorkflowId(principalId);
 107  
         }
 108  0
         option.setOptionId(optionId);
 109  0
         option.setOptionVal(optionValue);
 110  0
         getUserOptionsDAO().save(option);
 111  0
     }
 112  
 
 113  
     public boolean refreshActionList(String principalId) {
 114  0
         List<UserOptions> options = findByUserQualified(principalId, KEWConstants.RELOAD_ACTION_LIST + "%");
 115  0
         boolean refresh = ! options.isEmpty();
 116  0
         if (refresh && StringUtils.isNotEmpty(principalId)) {
 117  0
             getUserOptionsDAO().deleteByUserQualified(principalId, KEWConstants.RELOAD_ACTION_LIST + "%");
 118  
         }
 119  0
         return refresh;
 120  
     }
 121  
 
 122  
     public void saveRefreshUserOption(String principalId) {
 123  0
         if (random.nextInt(10) == 0) { // 10% chance of clearing out other RELOAD_ACTION_LIST entries first
 124  0
             getUserOptionsDAO().deleteByUserQualified(principalId, KEWConstants.RELOAD_ACTION_LIST + "%");
 125  
         }
 126  0
         save(principalId, KEWConstants.RELOAD_ACTION_LIST + new Date().getTime() + getNewOptionIdForActionList(), "true");
 127  0
     }
 128  
 
 129  
     public UserOptionsDAO getUserOptionsDAO() {
 130  0
         return userOptionsDAO;
 131  
     }
 132  
 
 133  
     public void setUserOptionsDAO(UserOptionsDAO optionsDAO) {
 134  0
         userOptionsDAO = optionsDAO;
 135  0
     }
 136  
 
 137  
 }