| 1 |  |  | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  |  | 
            
  
    | 4 |  |  | 
            
  
    | 5 |  |  | 
            
  
    | 6 |  |  | 
            
  
    | 7 |  |  | 
            
  
    | 8 |  |  | 
            
  
    | 9 |  |  | 
            
  
    | 10 |  |  | 
            
  
    | 11 |  |  | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
            
  
    | 14 |  |  | 
            
  
    | 15 |  |  | 
            
  
    | 16 |  | package org.kuali.rice.kcb.service.impl; | 
            
  
    | 17 |  |  | 
            
  
    | 18 |  | import java.util.Collection; | 
            
  
    | 19 |  | import java.util.HashMap; | 
            
  
    | 20 |  | import java.util.Map; | 
            
  
    | 21 |  |  | 
            
  
    | 22 |  | import org.kuali.rice.core.api.exception.RiceRuntimeException; | 
            
  
    | 23 |  | import org.kuali.rice.kcb.bo.RecipientDelivererConfig; | 
            
  
    | 24 |  | import org.kuali.rice.kcb.bo.RecipientPreference; | 
            
  
    | 25 |  | import org.kuali.rice.kcb.deliverer.MessageDeliverer; | 
            
  
    | 26 |  | import org.kuali.rice.kcb.exception.ErrorList; | 
            
  
    | 27 |  | import org.kuali.rice.kcb.service.RecipientPreferenceService; | 
            
  
    | 28 |  |  | 
            
  
    | 29 |  |  | 
            
  
    | 30 |  |  | 
            
  
    | 31 |  |  | 
            
  
    | 32 |  | @author | 
            
  
    | 33 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 75 (75) | Complexity: 16 | Complexity Density: 0.3 |  | 
  
  
    | 34 |  | public class RecipientPreferenceServiceImpl extends BusinessObjectServiceImpl implements RecipientPreferenceService { | 
            
  
    | 35 |  |  | 
            
  
    | 36 |  | @see | 
            
  
    | 37 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 11 (11) | Complexity: 3 | Complexity Density: 0.43 |  | 
  
  
    | 38 | 0 |  public RecipientPreference getRecipientPreference(String recipientId, String key) {... | 
            
  
    | 39 | 0 | Map<String, String> fields = new HashMap<String, String>(2); | 
            
  
    | 40 | 0 | fields.put(RecipientPreference.RECIPIENT_FIELD, recipientId); | 
            
  
    | 41 | 0 | fields.put(RecipientPreference.PROPERTY_FIELD, key); | 
            
  
    | 42 |  |  | 
            
  
    | 43 | 0 | Collection<RecipientPreference> prefs = dao.findMatching(RecipientPreference.class, fields); | 
            
  
    | 44 | 0 | assert(prefs.size() <= 1); | 
            
  
    | 45 |  |  | 
            
  
    | 46 | 0 | if (prefs.size() > 0) { | 
            
  
    | 47 | 0 | return prefs.iterator().next(); | 
            
  
    | 48 |  | } else { | 
            
  
    | 49 | 0 | return null; | 
            
  
    | 50 |  | } | 
            
  
    | 51 |  | } | 
            
  
    | 52 |  |  | 
            
  
    | 53 |  |  | 
            
  
    | 54 |  | @see | 
            
  
    | 55 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 56 | 0 |  public void deleteRecipientPreference(RecipientPreference pref) {... | 
            
  
    | 57 | 0 | dao.delete(pref); | 
            
  
    | 58 |  | } | 
            
  
    | 59 |  |  | 
            
  
    | 60 |  |  | 
            
  
    | 61 |  | @see | 
            
  
    | 62 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 7 (7) | Complexity: 1 | Complexity Density: 0.14 |  | 
  
  
    | 63 | 0 |  public HashMap<String, String> getRecipientPreferences(String recipientId) {... | 
            
  
    | 64 | 0 | Map<String, String> fields = new HashMap<String, String>(1); | 
            
  
    | 65 | 0 | fields.put(RecipientPreference.RECIPIENT_FIELD, recipientId); | 
            
  
    | 66 | 0 | HashMap<String, String> prefs = new HashMap<String,String>(); | 
            
  
    | 67 | 0 | Collection<RecipientPreference> userPrefs =  dao.findMatching(RecipientPreference.class, fields); | 
            
  
    | 68 | 0 | for (RecipientPreference p: userPrefs) { | 
            
  
    | 69 | 0 | prefs.put(p.getProperty(), p.getValue()); | 
            
  
    | 70 |  | } | 
            
  
    | 71 |  |  | 
            
  
    | 72 | 0 | return prefs; | 
            
  
    | 73 |  | } | 
            
  
    | 74 |  |  | 
            
  
    | 75 |  |  | 
            
  
    | 76 |  | @see | 
            
  
    | 77 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 78 | 0 |  public void saveRecipientPreference(RecipientPreference pref) {... | 
            
  
    | 79 | 0 | dao.save(pref); | 
            
  
    | 80 |  | } | 
            
  
    | 81 |  |  | 
            
  
    | 82 |  |  | 
            
  
    | 83 |  | @see | 
            
  
    | 84 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 17 (17) | Complexity: 2 | Complexity Density: 0.13 |  | 
  
  
    | 85 | 0 |  public void saveRecipientPreferences(String recipientId, HashMap<String, String> prefs, MessageDeliverer deliverer) throws ErrorList {... | 
            
  
    | 86 | 0 | deliverer.validatePreferenceValues(prefs); | 
            
  
    | 87 |  |  | 
            
  
    | 88 | 0 | for (Map.Entry<String, String> entry: prefs.entrySet()) { | 
            
  
    | 89 | 0 | String prop = entry.getKey(); | 
            
  
    | 90 | 0 | String value = entry.getValue(); | 
            
  
    | 91 |  |  | 
            
  
    | 92 |  |  | 
            
  
    | 93 |  |  | 
            
  
    | 94 |  |  | 
            
  
    | 95 | 0 | RecipientPreference currentPreference = getRecipientPreference(recipientId, prop); | 
            
  
    | 96 | 0 | if (currentPreference != null) { | 
            
  
    | 97 | 0 | currentPreference.setRecipientId(recipientId); | 
            
  
    | 98 | 0 | currentPreference.setProperty(prop); | 
            
  
    | 99 | 0 | currentPreference.setValue(value); | 
            
  
    | 100 | 0 | dao.save(currentPreference); | 
            
  
    | 101 |  | } else { | 
            
  
    | 102 | 0 | RecipientPreference recipientPreference = new RecipientPreference(); | 
            
  
    | 103 | 0 | recipientPreference.setRecipientId(recipientId); | 
            
  
    | 104 | 0 | recipientPreference.setProperty(prop); | 
            
  
    | 105 | 0 | recipientPreference.setValue(value); | 
            
  
    | 106 | 0 | dao.save(recipientPreference); | 
            
  
    | 107 |  | } | 
            
  
    | 108 |  | } | 
            
  
    | 109 |  | } | 
            
  
    | 110 |  |  | 
            
  
    | 111 |  |  | 
            
  
    | 112 |  |  | 
            
  
    | 113 |  |  | 
            
  
    | 114 |  | @see | 
            
  
    | 115 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 3 (3) | Complexity: 1 | Complexity Density: 0.33 |  | 
  
  
    | 116 | 0 |  public void removeRecipientDelivererConfigs(String recipientId) {... | 
            
  
    | 117 | 0 | Map<String, String> fields = new HashMap<String, String>(1); | 
            
  
    | 118 | 0 | fields.put(RecipientDelivererConfig.RECIPIENT_ID, recipientId); | 
            
  
    | 119 | 0 | dao.deleteMatching(RecipientDelivererConfig.class, fields); | 
            
  
    | 120 |  | } | 
            
  
    | 121 |  |  | 
            
  
    | 122 |  |  | 
            
  
    | 123 |  | @see | 
            
  
    | 124 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 19 (19) | Complexity: 5 | Complexity Density: 0.38 |  | 
  
  
    | 125 | 0 |  public void saveRecipientDelivererConfig(String recipientId, String delivererName, String[] channels) {... | 
            
  
    | 126 | 0 | if (channels == null || channels.length == 0) return; | 
            
  
    | 127 |  |  | 
            
  
    | 128 |  |  | 
            
  
    | 129 |  |  | 
            
  
    | 130 | 0 | for (String channel: channels) { | 
            
  
    | 131 | 0 | RecipientDelivererConfig config = new RecipientDelivererConfig(); | 
            
  
    | 132 |  |  | 
            
  
    | 133 | 0 | config.setRecipientId(recipientId); | 
            
  
    | 134 | 0 | config.setDelivererName(delivererName); | 
            
  
    | 135 | 0 | config.setChannel(channel); | 
            
  
    | 136 |  |  | 
            
  
    | 137 |  |  | 
            
  
    | 138 | 0 | Collection<RecipientDelivererConfig> deliverers = getDeliverersForRecipientAndChannel(recipientId, channel); | 
            
  
    | 139 | 0 | if (deliverers != null) { | 
            
  
    | 140 | 0 | for (RecipientDelivererConfig deliverer : deliverers) { | 
            
  
    | 141 | 0 | if (deliverer.getDelivererName().equals(delivererName)) { | 
            
  
    | 142 | 0 | throw new RiceRuntimeException("Attempting to save a duplicate Recipient Deliverer Config."); | 
            
  
    | 143 |  | } | 
            
  
    | 144 |  | } | 
            
  
    | 145 |  | } | 
            
  
    | 146 | 0 | dao.save(config); | 
            
  
    | 147 |  | } | 
            
  
    | 148 |  | } | 
            
  
    | 149 |  |  | 
            
  
    | 150 |  |  | 
            
  
    | 151 |  | @see | 
            
  
    | 152 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 3 (3) | Complexity: 1 | Complexity Density: 0.33 |  | 
  
  
    | 153 | 0 |  public Collection<RecipientDelivererConfig> getDeliverersForRecipient(String recipientId) {... | 
            
  
    | 154 | 0 | Map<String, String> fields = new HashMap<String, String>(1); | 
            
  
    | 155 | 0 | fields.put(RecipientDelivererConfig.RECIPIENT_ID, recipientId); | 
            
  
    | 156 | 0 | return dao.findMatching(RecipientDelivererConfig.class, fields); | 
            
  
    | 157 |  | } | 
            
  
    | 158 |  |  | 
            
  
    | 159 |  |  | 
            
  
    | 160 |  | @see | 
            
  
    | 161 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 4 (4) | Complexity: 1 | Complexity Density: 0.25 |  | 
  
  
    | 162 | 0 |  public Collection<RecipientDelivererConfig> getDeliverersForRecipientAndChannel(String recipientId, String channel) {... | 
            
  
    | 163 | 0 | Map<String, String> fields = new HashMap<String, String>(1); | 
            
  
    | 164 | 0 | fields.put(RecipientDelivererConfig.RECIPIENT_ID, recipientId); | 
            
  
    | 165 | 0 | fields.put(RecipientDelivererConfig.CHANNEL, channel); | 
            
  
    | 166 |  |  | 
            
  
    | 167 | 0 | return dao.findMatching(RecipientDelivererConfig.class, fields); | 
            
  
    | 168 |  | } | 
            
  
    | 169 |  | } |