001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.service.impl;
017:
018: import java.text.MessageFormat;
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.apache.commons.lang.StringUtils;
024: import org.kuali.RiceKeyConstants;
025: import org.kuali.RiceConstants.NoteTypeEnum;
026: import org.kuali.core.bo.AdHocRoutePerson;
027: import org.kuali.core.bo.AdHocRouteRecipient;
028: import org.kuali.core.bo.Note;
029: import org.kuali.core.bo.PersistableBusinessObject;
030: import org.kuali.core.bo.user.UniversalUser;
031: import org.kuali.core.dao.NoteDao;
032: import org.kuali.core.document.Document;
033: import org.kuali.core.exceptions.UserNotFoundException;
034: import org.kuali.core.service.KualiConfigurationService;
035: import org.kuali.core.service.NoteService;
036: import org.kuali.core.service.UniversalUserService;
037: import org.kuali.core.util.GlobalVariables;
038: import org.kuali.core.util.ObjectUtils;
039: import org.kuali.core.workflow.service.WorkflowDocumentService;
040: import org.springframework.transaction.annotation.Transactional;
041:
042: import edu.iu.uis.eden.EdenConstants;
043: import edu.iu.uis.eden.exception.WorkflowException;
044:
045: /**
046: * This class is the service implementation for the Note structure.
047: *
048: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
049: */
050: @Transactional
051: public class NoteServiceImpl implements NoteService {
052: // set up logging
053: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
054: .getLogger(NoteServiceImpl.class);
055:
056: private NoteDao noteDao;
057: private UniversalUserService universalUserService;
058: private WorkflowDocumentService workflowDocumentService;
059: private KualiConfigurationService kualiConfigurationService;
060:
061: /**
062: * Default constructor
063: */
064: public NoteServiceImpl() {
065: super ();
066: }
067:
068: /**
069: * @see org.kuali.core.service.NoteService#saveNoteValueList(java.util.List)
070: */
071: public void saveNoteList(List notes) {
072: if (notes != null) {
073: for (Iterator iter = notes.iterator(); iter.hasNext();) {
074: noteDao.save((Note) iter.next());
075: }
076: }
077: }
078:
079: /**
080: * Saves a Note to the DB.
081: *
082: * @param Note The accounting Note object to save - can be any object that extends Note (i.e. Source and Target lines).
083: */
084: public Note save(Note note) throws Exception {
085: noteDao.save(note);
086: return note;
087: }
088:
089: /**
090: * Retrieves a Note by its associated object id.
091: *
092: * @see org.kuali.core.service.NoteService#getByRemoteObjectId(java.lang.String)
093: */
094: public ArrayList getByRemoteObjectId(String remoteObjectId) {
095:
096: return noteDao.findByremoteObjectId(remoteObjectId);
097: }
098:
099: /**
100: * Deletes a Note from the DB.
101: *
102: * @param Note The Note object to delete.
103: */
104: public void deleteNote(Note note) throws Exception {
105: noteDao.deleteNote(note);
106: }
107:
108: // needed for Spring injection
109: /**
110: * Sets the data access object
111: *
112: * @param d
113: */
114: public void setNoteDao(NoteDao d) {
115: this .noteDao = d;
116: }
117:
118: /**
119: * Retrieves a data access object
120: */
121: public NoteDao getNoteDao() {
122: return noteDao;
123: }
124:
125: public Note createNote(Note note, PersistableBusinessObject bo)
126: throws Exception {
127: Note tmpNote = (Note) ObjectUtils.deepCopy(note);
128: UniversalUser kualiUser = GlobalVariables.getUserSession()
129: .getUniversalUser();
130: tmpNote.setRemoteObjectIdentifier(bo.getObjectId());
131: tmpNote.setAuthorUniversalIdentifier(kualiUser
132: .getPersonUniversalIdentifier());
133: return tmpNote;
134: }
135:
136: /**
137: * This method gets the property name for the note
138: *
139: * @param note
140: * @return note property text
141: */
142: public String extractNoteProperty(Note note) {
143: String propertyName = null;
144: for (NoteTypeEnum nte : NoteTypeEnum.values()) {
145: if (StringUtils.equals(nte.getCode(), note
146: .getNoteTypeCode())) {
147: propertyName = nte.getPath();
148: }
149: }
150: return propertyName;
151: }
152:
153: /**
154: * @see org.kuali.core.service.NoteService#sendNoteNotification(org.kuali.core.document.Document, org.kuali.core.bo.Note,
155: * org.kuali.core.bo.user.UniversalUser)
156: */
157: public void sendNoteRouteNotification(Document document, Note note,
158: UniversalUser sender) throws UserNotFoundException,
159: WorkflowException {
160: AdHocRouteRecipient routeRecipient = note
161: .getAdHocRouteRecipient();
162:
163: // build notification request
164: UniversalUser requestedUser = universalUserService
165: .getUniversalUserByAuthenticationUserId(routeRecipient
166: .getId());
167: String senderName = sender.getPersonFirstName() + " "
168: + sender.getPersonLastName();
169: String requestedName = requestedUser.getPersonFirstName() + " "
170: + requestedUser.getPersonLastName();
171:
172: String notificationText = kualiConfigurationService
173: .getPropertyString(RiceKeyConstants.MESSAGE_NOTE_NOTIFICATION_ANNOTATION);
174: if (StringUtils.isBlank(notificationText)) {
175: throw new RuntimeException(
176: "No annotation message found for note notification. Message needs added to application resources with key:"
177: + RiceKeyConstants.MESSAGE_NOTE_NOTIFICATION_ANNOTATION);
178: }
179: notificationText = MessageFormat.format(notificationText,
180: new Object[] { senderName, requestedName,
181: note.getNoteText() });
182:
183: List<AdHocRouteRecipient> routeRecipients = new ArrayList<AdHocRouteRecipient>();
184: routeRecipients.add(routeRecipient);
185:
186: workflowDocumentService.sendWorkflowNotification(document
187: .getDocumentHeader().getWorkflowDocument(),
188: notificationText, routeRecipients);
189:
190: // clear recipient allowing an notification to be sent to another person
191: note.setAdHocRouteRecipient(new AdHocRoutePerson());
192: }
193:
194: /**
195: * @param universalUserService the universalUserService to set
196: */
197: public void setUniversalUserService(
198: UniversalUserService universalUserService) {
199: this .universalUserService = universalUserService;
200: }
201:
202: /**
203: * @param workflowDocumentService the workflowDocumentService to set
204: */
205: public void setWorkflowDocumentService(
206: WorkflowDocumentService workflowDocumentService) {
207: this .workflowDocumentService = workflowDocumentService;
208: }
209:
210: /**
211: * @param kualiConfigurationService the kualiConfigurationService to set
212: */
213: public void setKualiConfigurationService(
214: KualiConfigurationService kualiConfigurationService) {
215: this.kualiConfigurationService = kualiConfigurationService;
216: }
217: }
|