Coverage Report - org.kuali.rice.kew.impl.note.NoteServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NoteServiceImpl
0%
0/50
0%
0/30
5
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.impl.note;
 17  
 
 18  
 import java.sql.Timestamp;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collections;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 25  
 import org.kuali.rice.kew.api.note.Note;
 26  
 import org.kuali.rice.kew.api.note.NoteService;
 27  
 import org.kuali.rice.kew.notes.dao.NoteDAO;
 28  
 
 29  
 /**
 30  
  * TODO 
 31  
  * 
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  *
 34  
  */
 35  0
 public class NoteServiceImpl implements NoteService {
 36  
 
 37  
         private NoteDAO noteDao;
 38  
         
 39  
         @Override
 40  
         public List<Note> getNotes(String documentId) {
 41  0
                 if (StringUtils.isBlank(documentId)) {
 42  0
                         throw new RiceIllegalArgumentException("documentId was null or blank");
 43  
                 }
 44  0
                 List<org.kuali.rice.kew.notes.Note> noteBos = getNoteDao().getNotesByDocumentId(documentId);
 45  0
                 if (noteBos == null) {
 46  0
                         return Collections.emptyList();
 47  
                 }
 48  0
                 List<Note> notes = new ArrayList<Note>();
 49  0
                 for (org.kuali.rice.kew.notes.Note noteBo : noteBos) {
 50  0
                         notes.add(org.kuali.rice.kew.notes.Note.to(noteBo));
 51  
                 }
 52  0
                 return Collections.unmodifiableList(notes);
 53  
         }
 54  
 
 55  
         @Override
 56  
         public Note getNote(String noteId) {
 57  0
                 if (StringUtils.isBlank(noteId)) {
 58  0
                         throw new RiceIllegalArgumentException("noteId was null or blank");
 59  
                 }
 60  0
                 org.kuali.rice.kew.notes.Note noteBo = getNoteDao().getNoteByNoteId(noteId);
 61  0
                 return org.kuali.rice.kew.notes.Note.to(noteBo);
 62  
         }
 63  
 
 64  
         @Override
 65  
         public Note createNote(Note note) {
 66  0
                 if (note == null) {
 67  0
                         throw new RiceIllegalArgumentException("note was null");
 68  
                 }
 69  0
                 if (note.getId() != null) {
 70  0
                         throw new RiceIllegalArgumentException("Attempted to create a note that already has an id assigned, id must be null upon creation");
 71  
                 }
 72  0
                 if (note.getVersionNumber() != null) {
 73  0
                         throw new RiceIllegalArgumentException("Attempted to create a note that already has a version number assigned, version number must be null upon creation");
 74  
                 }
 75  0
                 org.kuali.rice.kew.notes.Note noteBo = org.kuali.rice.kew.notes.Note.from(note);
 76  0
                 if (noteBo.getNoteCreateDate() == null) {
 77  0
                         noteBo.setNoteCreateDate(new Timestamp(System.currentTimeMillis()));
 78  
                 }
 79  0
                 getNoteDao().saveNote(noteBo);
 80  0
                 return org.kuali.rice.kew.notes.Note.to(noteBo);
 81  
         }
 82  
 
 83  
         @Override
 84  
         public Note updateNote(Note note) {
 85  0
                 if (note == null) {
 86  0
                         throw new RiceIllegalArgumentException("note was null");
 87  
                 }
 88  0
                 if (note.getId() == null) {
 89  0
                         throw new RiceIllegalArgumentException("Attempted to update a note without an id, id must be present when updating");
 90  
                 }
 91  0
                 if (note.getVersionNumber() == null) {
 92  0
                         throw new RiceIllegalArgumentException("Attempted to update a note without a version number, version number must be present when updating");
 93  
                 }
 94  0
                 if (note.getCreateDate() == null) {
 95  0
                         throw new RiceIllegalArgumentException("Attempted to update a note without a create date, note must have a create date");
 96  
                 }
 97  0
                 Note existingNoteBo = getNote(note.getId());
 98  0
                 if (existingNoteBo == null) {
 99  0
                         throw new RiceIllegalArgumentException("Attempted to udpate a note with an id for a not that does not exist: " + note.getId());
 100  
                 }
 101  0
                 org.kuali.rice.kew.notes.Note noteBo = org.kuali.rice.kew.notes.Note.from(note);
 102  0
                 getNoteDao().saveNote(noteBo);
 103  0
                 return org.kuali.rice.kew.notes.Note.to(noteBo);
 104  
         }
 105  
 
 106  
         @Override
 107  
         public Note deleteNote(String noteId) {
 108  0
                 if (StringUtils.isBlank(noteId)) {
 109  0
                         throw new RiceIllegalArgumentException("noteId was null or blank");
 110  
                 }
 111  0
                 org.kuali.rice.kew.notes.Note noteBo = getNoteDao().getNoteByNoteId(noteId);
 112  0
                 if (noteBo == null) {
 113  0
                         throw new RiceIllegalArgumentException("A note does not exist for the given note id: " + noteId);
 114  
                 }
 115  0
                 Note deletedNote = org.kuali.rice.kew.notes.Note.to(noteBo);
 116  0
                 getNoteDao().deleteNote(noteBo);
 117  0
                 return deletedNote;
 118  
         }
 119  
         
 120  
         public void setNoteDao(NoteDAO noteDao) {
 121  0
                 this.noteDao = noteDao;
 122  0
         }
 123  
         
 124  
         public NoteDAO getNoteDao() {
 125  0
                 return noteDao;
 126  
         }
 127  
 
 128  
 }