Coverage Report - org.kuali.rice.kns.service.impl.NoteServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NoteServiceImpl
0%
0/48
0%
0/12
1.467
 
 1  
 /*
 2  
  * Copyright 2007 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.kns.service.impl;
 17  
 
 18  
 import java.text.MessageFormat;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.kew.exception.WorkflowException;
 25  
 import org.kuali.rice.kim.bo.Person;
 26  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 27  
 import org.kuali.rice.kim.service.PersonService;
 28  
 import org.kuali.rice.kns.bo.AdHocRoutePerson;
 29  
 import org.kuali.rice.kns.bo.AdHocRouteRecipient;
 30  
 import org.kuali.rice.kns.bo.Note;
 31  
 import org.kuali.rice.kns.bo.PersistableBusinessObject;
 32  
 import org.kuali.rice.kns.dao.NoteDao;
 33  
 import org.kuali.rice.kns.document.Document;
 34  
 import org.kuali.rice.kns.service.KualiConfigurationService;
 35  
 import org.kuali.rice.kns.service.NoteService;
 36  
 import org.kuali.rice.kns.util.GlobalVariables;
 37  
 import org.kuali.rice.kns.util.KNSConstants;
 38  
 import org.kuali.rice.kns.util.ObjectUtils;
 39  
 import org.kuali.rice.kns.util.RiceKeyConstants;
 40  
 import org.kuali.rice.kns.util.KNSConstants.NoteTypeEnum;
 41  
 import org.kuali.rice.kns.workflow.service.WorkflowDocumentService;
 42  
 import org.springframework.transaction.annotation.Transactional;
 43  
 
 44  
 /**
 45  
  * This class is the service implementation for the Note structure.
 46  
  * 
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  */
 49  
 @Transactional
 50  
 public class NoteServiceImpl implements NoteService {
 51  
     // set up logging
 52  0
     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NoteServiceImpl.class);
 53  
 
 54  
     private NoteDao noteDao;
 55  
     private PersonService personService;
 56  
     private WorkflowDocumentService workflowDocumentService;
 57  
     private KualiConfigurationService kualiConfigurationService;
 58  
 
 59  
     /**
 60  
      * Default constructor
 61  
      */
 62  
     public NoteServiceImpl() {
 63  0
         super();
 64  0
     }
 65  
 
 66  
     /**
 67  
      * @see org.kuali.rice.kns.service.NoteService#saveNoteValueList(java.util.List)
 68  
      */
 69  
     public void saveNoteList(List notes) {
 70  0
         if (notes != null) {
 71  0
             for (Iterator iter = notes.iterator(); iter.hasNext();) {
 72  0
                 noteDao.save((Note) iter.next());
 73  
             }
 74  
         }
 75  0
     }
 76  
 
 77  
     /**
 78  
      * Saves a Note to the DB.
 79  
      * 
 80  
      * @param Note The accounting Note object to save - can be any object that extends Note (i.e. Source and Target lines).
 81  
      */
 82  
     public Note save(Note note) throws Exception {
 83  0
         noteDao.save(note);
 84  0
         return note;
 85  
     }
 86  
 
 87  
     /**
 88  
      * Retrieves a Note by its associated object id.
 89  
      * 
 90  
      * @see org.kuali.rice.kns.service.NoteService#getByRemoteObjectId(java.lang.String)
 91  
      */
 92  
     public ArrayList getByRemoteObjectId(String remoteObjectId) {
 93  
 
 94  0
         return noteDao.findByremoteObjectId(remoteObjectId);
 95  
     }
 96  
     
 97  
     /**
 98  
      * Retrieves a Note by note identifier.
 99  
      * 
 100  
      * @see org.kuali.rice.kns.service.NoteService#getNoteByNoteId(java.lang.Long)
 101  
      */
 102  
     public Note getNoteByNoteId(Long noteId) {
 103  0
                 return noteDao.getNoteByNoteId(noteId);
 104  
         }
 105  
 
 106  
     /**
 107  
      * Deletes a Note from the DB.
 108  
      * 
 109  
      * @param Note The Note object to delete.
 110  
      */
 111  
     public void deleteNote(Note note) throws Exception {
 112  0
         noteDao.deleteNote(note);
 113  0
     }
 114  
 
 115  
     // needed for Spring injection
 116  
     /**
 117  
      * Sets the data access object
 118  
      * 
 119  
      * @param d
 120  
      */
 121  
     public void setNoteDao(NoteDao d) {
 122  0
         this.noteDao = d;
 123  0
     }
 124  
 
 125  
     /**
 126  
      * Retrieves a data access object
 127  
      */
 128  
     public NoteDao getNoteDao() {
 129  0
         return noteDao;
 130  
     }
 131  
 
 132  
     public Note createNote(Note note, PersistableBusinessObject bo) throws Exception {
 133  
         // TODO: Why is a deep copy being done?  Nowhere that this is called uses the given note argument
 134  
         // again after calling this method.
 135  0
         Note tmpNote = (Note) ObjectUtils.deepCopy(note);
 136  0
         Person kualiUser = GlobalVariables.getUserSession().getPerson();
 137  0
         tmpNote.setRemoteObjectIdentifier(bo.getObjectId());
 138  0
         tmpNote.setAuthorUniversalIdentifier(kualiUser.getPrincipalId());
 139  0
         return tmpNote;
 140  
     }
 141  
 
 142  
     /**
 143  
      * This method gets the property name for the note
 144  
      * 
 145  
      * @param note
 146  
      * @return note property text
 147  
      */
 148  
     public String extractNoteProperty(Note note) {
 149  0
         String propertyName = null;
 150  0
         for (NoteTypeEnum nte : NoteTypeEnum.values()) {
 151  0
             if (StringUtils.equals(nte.getCode(), note.getNoteTypeCode())) {
 152  0
                 propertyName = nte.getPath();
 153  
             }
 154  
         }
 155  0
         return propertyName;
 156  
     }
 157  
 
 158  
     /**
 159  
      * @see org.kuali.rice.kns.service.NoteService#sendNoteNotification(org.kuali.rice.kns.document.Document, org.kuali.rice.kns.bo.Note,
 160  
      *      org.kuali.rice.kim.bo.Person)
 161  
      */
 162  
     public void sendNoteRouteNotification(Document document, Note note, Person sender) throws WorkflowException {
 163  0
         AdHocRouteRecipient routeRecipient = note.getAdHocRouteRecipient();
 164  
 
 165  
         // build notification request
 166  0
         Person requestedUser = this.getPersonService().getPersonByPrincipalName(routeRecipient.getId());
 167  0
         String senderName = sender.getFirstName() + " " + sender.getLastName();
 168  0
         String requestedName = requestedUser.getFirstName() + " " + requestedUser.getLastName();
 169  
         
 170  0
         String notificationText = kualiConfigurationService.getPropertyString(RiceKeyConstants.MESSAGE_NOTE_NOTIFICATION_ANNOTATION);
 171  0
         if (StringUtils.isBlank(notificationText)) {
 172  0
             throw new RuntimeException("No annotation message found for note notification. Message needs added to application resources with key:" + RiceKeyConstants.MESSAGE_NOTE_NOTIFICATION_ANNOTATION);
 173  
         }
 174  0
         notificationText = MessageFormat.format(notificationText, new Object[] { senderName, requestedName, note.getNoteText() });
 175  
 
 176  0
         List<AdHocRouteRecipient> routeRecipients = new ArrayList<AdHocRouteRecipient>();
 177  0
         routeRecipients.add(routeRecipient);
 178  
 
 179  0
         workflowDocumentService.sendWorkflowNotification(document.getDocumentHeader().getWorkflowDocument(), notificationText, routeRecipients, KNSConstants.NOTE_WORKFLOW_NOTIFICATION_REQUEST_LABEL);
 180  
 
 181  
         // clear recipient allowing an notification to be sent to another person
 182  0
         note.setAdHocRouteRecipient(new AdHocRoutePerson());
 183  0
     }
 184  
 
 185  
     /**
 186  
      * @param personService the personService to set
 187  
      */
 188  
     public void setPersonService(PersonService personService) {
 189  0
         this.personService = personService;
 190  0
     }
 191  
 
 192  
     /**
 193  
      * @param workflowDocumentService the workflowDocumentService to set
 194  
      */
 195  
     public void setWorkflowDocumentService(WorkflowDocumentService workflowDocumentService) {
 196  0
         this.workflowDocumentService = workflowDocumentService;
 197  0
     }
 198  
 
 199  
     /**
 200  
      * @param kualiConfigurationService the kualiConfigurationService to set
 201  
      */
 202  
     public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
 203  0
         this.kualiConfigurationService = kualiConfigurationService;
 204  0
     }
 205  
     
 206  
     protected PersonService getPersonService() {
 207  0
         if ( personService == null ) {
 208  0
             personService = KIMServiceLocator.getPersonService();
 209  
         }
 210  0
         return personService;
 211  
     }
 212  
 }