1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18 import java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.krad.bo.Note;
22 import org.kuali.rice.krad.bo.PersistableBusinessObject;
23 import org.kuali.rice.krad.dao.NoteDao;
24 import org.kuali.rice.krad.service.AttachmentService;
25 import org.kuali.rice.krad.service.NoteService;
26 import org.kuali.rice.krad.util.ObjectUtils;
27 import org.springframework.transaction.annotation.Transactional;
28
29
30
31
32
33
34 @Transactional
35 public class NoteServiceImpl implements NoteService {
36
37 private NoteDao noteDao;
38
39 private AttachmentService attachmentService;
40
41 public NoteServiceImpl() {
42 super();
43 }
44
45
46
47
48 public void saveNoteList(List<Note> notes) {
49 if (notes != null) {
50 for (Note note : notes) {
51 if (StringUtils.isBlank(note.getRemoteObjectIdentifier())) {
52 throw new IllegalStateException("The remote object identifier must be established on a Note before it can be saved. The following note in the given list had a null or empty remote object identifier: " + note);
53 }
54 save(note);
55 }
56 }
57 }
58
59
60
61
62 public Note save(Note note) {
63 validateNoteNotNull(note);
64 if (StringUtils.isBlank(note.getRemoteObjectIdentifier())) {
65 throw new IllegalStateException("The remote object identifier must be established on a Note before it can be saved. Given note had a null or empty remote object identifier.");
66 }
67 noteDao.save(note);
68
69 if (note.getAttachment() != null) {
70 attachmentService.moveAttachmentWherePending(note);
71 }
72 return note;
73 }
74
75
76
77
78 public List<Note> getByRemoteObjectId(String remoteObjectId) {
79 if (StringUtils.isBlank(remoteObjectId)) {
80 throw new IllegalArgumentException("The remoteObjectId must not be null or blank.");
81 }
82 return noteDao.findByremoteObjectId(remoteObjectId);
83 }
84
85
86
87
88 public Note getNoteByNoteId(Long noteId) {
89 if (noteId == null) {
90 throw new IllegalArgumentException("The noteId must not be null.");
91 }
92 return noteDao.getNoteByNoteId(noteId);
93 }
94
95
96
97
98 public void deleteNote(Note note) {
99 validateNoteNotNull(note);
100 noteDao.deleteNote(note);
101 }
102
103
104
105
106
107
108 public Note createNote(Note noteToCopy, PersistableBusinessObject bo, String authorPrincipalId) {
109 validateNoteNotNull(noteToCopy);
110 if (bo == null) {
111 throw new IllegalArgumentException("The bo must not be null.");
112 }
113 if (StringUtils.isBlank(authorPrincipalId)) {
114 throw new IllegalArgumentException("The authorPrincipalId must not be null.");
115 }
116
117
118 Note tmpNote = (Note) ObjectUtils.deepCopy(noteToCopy);
119 tmpNote.setRemoteObjectIdentifier(bo.getObjectId());
120 tmpNote.setAuthorUniversalIdentifier(authorPrincipalId);
121 return tmpNote;
122 }
123
124
125
126
127
128
129 public void setNoteDao(NoteDao d) {
130 this.noteDao = d;
131 }
132
133
134
135
136 protected NoteDao getNoteDao() {
137 return noteDao;
138 }
139
140 public void setAttachmentService(AttachmentService attachmentService) {
141 this.attachmentService = attachmentService;
142 }
143
144 protected AttachmentService getAttachmentService() {
145 return this.attachmentService;
146 }
147
148 private void validateNoteNotNull(Note note) {
149 if (note == null) {
150 throw new IllegalArgumentException("Note must not be null.");
151 }
152 }
153
154 }