001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.edl.components;
018:
019: import java.sql.Timestamp;
020: import java.text.DateFormat;
021: import java.util.Collections;
022: import java.util.Comparator;
023: import java.util.Date;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import org.apache.commons.fileupload.FileItem;
028: import org.apache.log4j.Logger;
029: import org.w3c.dom.Document;
030: import org.w3c.dom.Element;
031:
032: import edu.iu.uis.eden.EdenConstants;
033: import edu.iu.uis.eden.KEWServiceLocator;
034: import edu.iu.uis.eden.clientapp.WorkflowDocument;
035: import edu.iu.uis.eden.edl.EDLContext;
036: import edu.iu.uis.eden.edl.EDLModelComponent;
037: import edu.iu.uis.eden.edl.EDLXmlUtils;
038: import edu.iu.uis.eden.edl.RequestParser;
039: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
040: import edu.iu.uis.eden.notes.Attachment;
041: import edu.iu.uis.eden.notes.CustomNoteAttribute;
042: import edu.iu.uis.eden.notes.Note;
043: import edu.iu.uis.eden.notes.NoteService;
044: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
045: import edu.iu.uis.eden.routeheader.RouteHeaderService;
046: import edu.iu.uis.eden.user.UserService;
047: import edu.iu.uis.eden.user.WorkflowUser;
048: import edu.iu.uis.eden.user.WorkflowUserId;
049: import edu.iu.uis.eden.util.Utilities;
050:
051: /**
052: * Adds notes support to EDL
053: *
054: * @author shenl
055: * @author rkirkend
056: *
057: */
058: public class NoteConfigComponent implements EDLModelComponent {
059:
060: private static final Logger LOG = Logger
061: .getLogger(NoteConfigComponent.class);
062:
063: public void updateDOM(Document dom, Element configElement,
064: EDLContext edlContext) {
065: NoteForm noteForm = new NoteForm(edlContext.getRequestParser());
066: WorkflowDocument document = (WorkflowDocument) edlContext
067: .getRequestParser().getAttribute(
068: RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY);
069: try {
070: //establish notes depends on a document id being set on noteform or nothing happens
071: if (document != null) {
072: noteForm.setDocId(document.getRouteHeaderId());
073: }
074: establishNotes(noteForm, edlContext, dom);
075: addNotes(dom, noteForm);
076: } catch (Exception e) {
077: throw new WorkflowRuntimeException(
078: "Caught exception processing notes", e);
079: }
080:
081: }
082:
083: public void establishNotes(NoteForm form, EDLContext edlContext,
084: Document dom) throws Exception {
085:
086: form.setCurrentUserName(edlContext.getUserSession()
087: .getWorkflowUser().getDisplayName());
088: form.setCurrentDate(getCurrentDate());
089: String methodToCall = form.getMethodToCall();
090: if (!Utilities.isEmpty(methodToCall)) {
091: if ("save".equalsIgnoreCase(methodToCall)) {
092: this .saveNote(form, edlContext, dom);
093: } else if ("edit".equalsIgnoreCase(methodToCall)) {
094: this .editNote(form);
095: } else if ("add".equalsIgnoreCase(methodToCall)) {
096: this .addNote(form);
097: } else if ("cancel".equalsIgnoreCase(methodToCall)) {
098: this .cancelEdit(form);
099: } else if ("delete".equalsIgnoreCase(methodToCall)) {
100: this .deleteNote(form);
101: } else if ("sort".equalsIgnoreCase(methodToCall)) {
102: this .sortNotes(form);
103: } else if ("deleteAttachment"
104: .equalsIgnoreCase(methodToCall)) {
105: this .deleteAttachment(form);
106: }
107: }
108: retrieveNoteList(form, edlContext);
109:
110: }
111:
112: /**
113: * Method added for notes editing function. Retrieve Note Listing from Route Header and put that in EdocLiteForm.
114: * @param request
115: * @param noteForm
116: * @throws Exception
117: */
118:
119: private void retrieveNoteList(NoteForm form, EDLContext edlContext)
120: throws Exception {
121: if (form.getDocId() != null) {
122: List allNotes = getNoteService().getNotesByRouteHeaderId(
123: form.getDocId());
124: CustomNoteAttribute customNoteAttribute = null;
125: DocumentRouteHeaderValue routeHeader = getRouteHeaderService()
126: .getRouteHeader(form.getDocId());
127: boolean canAddNotes = false;
128: if (routeHeader != null) {
129: customNoteAttribute = routeHeader
130: .getCustomNoteAttribute();
131: if (customNoteAttribute != null) {
132: customNoteAttribute.setUserSession(edlContext
133: .getUserSession());
134: canAddNotes = customNoteAttribute
135: .isAuthorizedToAddNotes();
136: }
137: }
138: Iterator notesIter = allNotes.iterator();
139: while (notesIter.hasNext()) {
140: Note singleNote = (Note) notesIter.next();
141: singleNote.setNoteCreateLongDate(new Long(singleNote
142: .getNoteCreateDate().getTime()));
143: getAuthorData(singleNote);
144: boolean canEditNote = false;
145: if (customNoteAttribute != null) {
146: canEditNote = customNoteAttribute
147: .isAuthorizedToEditNote(singleNote);
148: }
149: singleNote.setAuthorizedToEdit(Boolean
150: .valueOf(canEditNote));
151: if (form.getNoteIdNumber() != null
152: && (form.getNoteIdNumber().intValue() == singleNote
153: .getNoteId().intValue())) {
154: singleNote.setEditingNote(Boolean.TRUE);
155: }
156: }
157: if (form.getSortNotes() != null
158: && form.getSortNotes().booleanValue()) {
159: if (EdenConstants.Sorting.SORT_SEQUENCE_DSC
160: .equalsIgnoreCase(form.getSortOrder())) {
161: form
162: .setSortOrder(EdenConstants.Sorting.SORT_SEQUENCE_ASC);
163: form.setSortNotes(new Boolean(false));
164: } else {
165: form
166: .setSortOrder(EdenConstants.Sorting.SORT_SEQUENCE_DSC);
167: form.setSortNotes(new Boolean(false));
168: }
169: } else {
170: form.setSortOrder(form.getSortOrder());
171: }
172: form.setNoteList(sortNotes(allNotes, form.getSortOrder()));
173: form.setNumberOfNotes(new Integer(allNotes.size()));
174: form.setAuthorizedToAdd(new Boolean(canAddNotes));
175: form.setShowAdd(Boolean.TRUE);
176: if (!canAddNotes) {
177: form.setShowAdd(Boolean.FALSE);
178: } else if (form.getNoteList().size() == 0) {
179: //form.setShowAdd(Boolean.TRUE);
180: }
181: }
182: }
183:
184: public void editNote(NoteForm form) throws Exception {
185: form.setShowEdit("yes");
186: // Note noteToEdit =
187: // getNoteService().getNoteByNoteId(form.getNoteIdNumber());
188: //form.setNote(noteToEdit);
189: form.getNote().setNoteCreateLongDate(
190: new Long(form.getNote().getNoteCreateDate().getTime()));
191: form.getNote().setNoteText(form.getNoteText());
192: //retrieveNoteList(request, form);
193: }
194:
195: public void addNote(NoteForm form) throws Exception {
196: form.setShowEdit("no");
197: form.setNoteIdNumber(null);
198: form.setShowAdd(Boolean.TRUE);
199: //retrieveNoteList(request,form);
200:
201: }
202:
203: public void cancelEdit(NoteForm form) throws Exception {
204: form.setShowEdit("no");
205: form.setNote(new Note());
206: form.setNoteIdNumber(null);
207: //retrieveNoteList(request, form);
208: }
209:
210: public void deleteNote(NoteForm form) throws Exception {
211: Note noteToDelete = getNoteService().getNoteByNoteId(
212: form.getNoteIdNumber());
213: getNoteService().deleteNote(noteToDelete);
214: form.setShowEdit("no");
215: //retrieveNoteList(request, form);
216: form.setNote(new Note());
217: form.setNoteIdNumber(null);
218: }
219:
220: public void sortNotes(NoteForm form) throws Exception {
221: form.setShowEdit("no");
222: }
223:
224: public void deleteAttachment(NoteForm form) throws Exception {
225: Note note = getNoteService().getNoteByNoteId(
226: form.getNoteIdNumber());
227: getNoteService().deleteAttachment(
228: (Attachment) note.getAttachments().remove(0));
229: }
230:
231: public void saveNote(NoteForm form, EDLContext edlContext,
232: Document dom) throws Exception {
233: Note noteToSave = null;
234: if (form.getShowEdit() != null
235: && form.getShowEdit().equals("yes")) {
236: //LOG.debug(form.getNoteIdNumber());
237: noteToSave = getNoteService().getNoteByNoteId(
238: form.getNoteIdNumber());
239: String noteText = form.getNoteText();
240: if (noteText != null) {
241: noteToSave.setNoteText(noteText);
242: }
243: //LOG.debug(noteToSave);
244: //LOG.debug(noteToSave.getNoteCreateDate());
245: //noteToSave.setNoteCreateDate(new Timestamp(noteToSave.getNoteCreateLongDate().longValue()));
246: } else {
247: noteToSave = new Note();
248: noteToSave.setNoteId(null);
249: noteToSave.setRouteHeaderId(form.getDocId());
250: noteToSave.setNoteCreateDate(new Timestamp((new Date())
251: .getTime()));
252: noteToSave.setNoteAuthorWorkflowId(edlContext
253: .getUserSession().getWorkflowUser()
254: .getWorkflowUserId().getWorkflowId());
255: noteToSave.setNoteText(form.getAddText());
256: }
257: CustomNoteAttribute customNoteAttribute = null;
258: DocumentRouteHeaderValue routeHeader = getRouteHeaderService()
259: .getRouteHeader(noteToSave.getRouteHeaderId());
260: boolean canEditNote = false;
261: boolean canAddNotes = false;
262: if (routeHeader != null) {
263: customNoteAttribute = routeHeader.getCustomNoteAttribute();
264: if (customNoteAttribute != null) {
265: customNoteAttribute.setUserSession(edlContext
266: .getUserSession());
267: canAddNotes = customNoteAttribute
268: .isAuthorizedToAddNotes();
269: canEditNote = customNoteAttribute
270: .isAuthorizedToEditNote(noteToSave);
271: }
272: }
273: if ((form.getShowEdit() != null
274: && form.getShowEdit().equals("yes") && canEditNote)
275: || ((form.getShowEdit() == null || !form.getShowEdit()
276: .equals("yes")) && canAddNotes)) {
277: FileItem uploadedFile = (FileItem) form.getFile();
278: if (uploadedFile != null
279: && org.apache.commons.lang.StringUtils
280: .isNotBlank(uploadedFile.getName())) {
281: Attachment attachment = new Attachment();
282: attachment.setAttachedObject(uploadedFile
283: .getInputStream());
284: String internalFileIndicator = uploadedFile.getName();
285: int indexOfSlash = internalFileIndicator
286: .lastIndexOf("/");
287: int indexOfBackSlash = internalFileIndicator
288: .lastIndexOf("\\");
289: if (indexOfSlash >= 0) {
290: internalFileIndicator = internalFileIndicator
291: .substring(indexOfSlash + 1);
292: } else {
293: if (indexOfBackSlash >= 0) {
294: internalFileIndicator = internalFileIndicator
295: .substring(indexOfBackSlash + 1);
296: }
297: }
298: attachment.setFileName(internalFileIndicator);
299: LOG.debug(internalFileIndicator);
300: attachment.setMimeType(uploadedFile.getContentType());
301: attachment.setNote(noteToSave);
302: noteToSave.getAttachments().add(attachment);
303: }
304: if (Utilities.isEmpty(noteToSave.getNoteText())
305: && noteToSave.getAttachments().size() == 0) {
306: if (form.getShowEdit() != null
307: && form.getShowEdit().equals("yes")) {
308: form.setNote(new Note());
309: } else {
310: form.setAddText(null);
311: }
312: form.setShowEdit("no");
313: form.setNoteIdNumber(null);
314: // throw new Exception("Note has empty content");
315: EDLXmlUtils.addGlobalErrorMessage(dom,
316: "Note has empty content");
317: return;
318: }
319: getNoteService().saveNote(noteToSave);
320: }
321: if (form.getShowEdit() != null
322: && form.getShowEdit().equals("yes")) {
323: form.setNote(new Note());
324: } else {
325: form.setAddText(null);
326: }
327: form.setShowEdit("no");
328: form.setNoteIdNumber(null);
329: }
330:
331: public static void addNotes(Document doc, NoteForm form) {
332: Element noteForm = EDLXmlUtils.getOrCreateChildElement(doc
333: .getDocumentElement(), "NoteForm", true);
334: if (form.getShowEdit() != null) {
335: Element showEdit = EDLXmlUtils.getOrCreateChildElement(
336: noteForm, "showEdit", true);
337: showEdit.appendChild(doc.createTextNode(form.getShowEdit()
338: .toLowerCase()));
339: } else {
340: Element showEdit = EDLXmlUtils.getOrCreateChildElement(
341: noteForm, "showEdit", true);
342: showEdit.appendChild(doc.createTextNode("no"));
343: }
344: if (form.getShowAdd() != null) {
345: Element showAdd = EDLXmlUtils.getOrCreateChildElement(
346: noteForm, "showAdd", true);
347: showAdd.appendChild(doc.createTextNode(form.getShowAdd()
348: .toString().toLowerCase()));
349: }
350: if (form.getCurrentUserName() != null) {
351: Element currentUserName = EDLXmlUtils
352: .getOrCreateChildElement(noteForm,
353: "currentUserName", true);
354: currentUserName.appendChild(doc.createTextNode(form
355: .getCurrentUserName()));
356: }
357: if (form.getCurrentDate() != null) {
358: Element currentDate = EDLXmlUtils.getOrCreateChildElement(
359: noteForm, "currentDate", true);
360: currentDate.appendChild(doc.createTextNode(form
361: .getCurrentDate()));
362: }
363: if (form.getNoteIdNumber() != null) {
364: Element noteIdNumber = EDLXmlUtils.getOrCreateChildElement(
365: noteForm, "noteIdNumber", true);
366: noteIdNumber.appendChild(doc.createTextNode(form
367: .getNoteIdNumber().toString()));
368: }
369: if (form.getDocId() != null) {
370: Element docId = EDLXmlUtils.getOrCreateChildElement(
371: noteForm, "docId", true);
372: docId.appendChild(doc.createTextNode((form.getDocId()
373: .toString())));
374: }
375: if (form.getSortNotes() != null) {
376: Element sortNotes = EDLXmlUtils.getOrCreateChildElement(
377: noteForm, "sortNotes", true);
378: sortNotes.appendChild(doc.createTextNode(form
379: .getSortNotes().toString().toLowerCase()));
380: }
381: if (form.getSortOrder() != null) {
382: Element sortOrder = EDLXmlUtils.getOrCreateChildElement(
383: noteForm, "sortOrder", true);
384: sortOrder.appendChild(doc.createTextNode(form
385: .getSortOrder().toUpperCase()));
386: }
387: if (form.getNumberOfNotes() != null) {
388: Element numberOfNotes = EDLXmlUtils
389: .getOrCreateChildElement(noteForm, "numberOfNotes",
390: true);
391: numberOfNotes.appendChild(doc.createTextNode(form
392: .getNumberOfNotes().toString()));
393: }
394: if (form.getAuthorizedToAdd() != null) {
395: Element authorizedToAdd = EDLXmlUtils
396: .getOrCreateChildElement(noteForm,
397: "authorizedToAdd", true);
398: authorizedToAdd.appendChild(doc.createTextNode(form
399: .getAuthorizedToAdd().toString().toLowerCase()));
400: }
401: if (form.getNumberOfNotes().intValue() > 0) {
402: Element notes = EDLXmlUtils.getOrCreateChildElement(
403: noteForm, "Notes", true);
404: for (Iterator i = form.getNoteList().iterator(); i
405: .hasNext();) {
406: Note noteObj = (Note) i.next();
407: Element note = notes.getOwnerDocument().createElement(
408: "Note");
409: notes.appendChild(note);
410: // Element note = Util.getOrCreateChildElement(notes, "Note",
411: // true);
412: if (noteObj.getNoteId() != null) {
413: Element noteId = EDLXmlUtils
414: .getOrCreateChildElement(note, "noteId",
415: true);
416: noteId.appendChild(doc.createTextNode(noteObj
417: .getNoteId().toString()));
418: }
419: if (noteObj.getFormattedCreateDate() != null) {
420: Element formattedCreateDate = EDLXmlUtils
421: .getOrCreateChildElement(note,
422: "formattedCreateDate", true);
423: formattedCreateDate.appendChild(doc
424: .createTextNode(noteObj
425: .getFormattedCreateDate()));
426: }
427: if (noteObj.getFormattedCreateTime() != null) {
428: Element formattedCreateTime = EDLXmlUtils
429: .getOrCreateChildElement(note,
430: "formattedCreateTime", true);
431: formattedCreateTime.appendChild(doc
432: .createTextNode(noteObj
433: .getFormattedCreateTime()));
434: }
435: if (noteObj.getNoteAuthorFullName() != null) {
436: Element noteAuthorFullName = EDLXmlUtils
437: .getOrCreateChildElement(note,
438: "noteAuthorFullName", true);
439: noteAuthorFullName.appendChild(doc
440: .createTextNode(noteObj
441: .getNoteAuthorFullName()));
442: }
443: if (noteObj.getNoteText() != null) {
444: Element noteText = EDLXmlUtils
445: .getOrCreateChildElement(note, "noteText",
446: true);
447: noteText.appendChild(doc.createTextNode(noteObj
448: .getNoteText()));
449: }
450: if (noteObj.getEditingNote() != null) {
451: Element editingNote = EDLXmlUtils
452: .getOrCreateChildElement(note,
453: "editingNote", true);
454: editingNote.appendChild(doc.createTextNode(noteObj
455: .getEditingNote().toString()));
456: }
457: if (noteObj.getAuthorizedToEdit() != null) {
458: Element authorizedToEdit = EDLXmlUtils
459: .getOrCreateChildElement(note,
460: "authorizedToEdit", true);
461: authorizedToEdit.appendChild(doc
462: .createTextNode(noteObj
463: .getAuthorizedToEdit().toString()));
464: }
465: if (!noteObj.getAttachments().isEmpty()) {
466: Element attachments = EDLXmlUtils
467: .getOrCreateChildElement(note,
468: "attachments", true);
469: for (Iterator j = noteObj.getAttachments()
470: .iterator(); j.hasNext();) {
471: Attachment attachmentObj = (Attachment) j
472: .next();
473: Element attachment = EDLXmlUtils
474: .getOrCreateChildElement(attachments,
475: "attachment", true);
476: Element attachmentId = EDLXmlUtils
477: .getOrCreateChildElement(attachment,
478: "attachmentId", true);
479: attachmentId.appendChild(doc
480: .createTextNode(attachmentObj
481: .getAttachmentId().toString()));
482: Element fileName = EDLXmlUtils
483: .getOrCreateChildElement(attachment,
484: "fileName", true);
485: fileName.appendChild(doc
486: .createTextNode(attachmentObj
487: .getFileName()));
488: }
489: }
490: }
491: }
492:
493: }
494:
495: private static class NoteForm {
496: private String showEdit;
497: private Boolean showAdd;
498: private Long noteIdNumber;
499: private Integer numberOfNotes = new Integer(0);
500: private String sortOrder = "DESCENDING";
501: private Boolean sortNotes;
502: private String currentUserName;
503: private String currentDate;
504: private Boolean authorizedToAdd;
505: private List noteList;
506: private String addText;
507: private Long idInEdit;
508: private Note note;
509: private String noteText;
510: private Long docId;
511: private String methodToCall;
512: private FileItem file;
513:
514: public NoteForm(RequestParser requestParser) {
515:
516: showEdit = requestParser.getParameterValue("showEdit");
517: if (!Utilities.isEmpty(requestParser
518: .getParameterValue("showAdd"))) {
519: showAdd = Boolean.valueOf(requestParser
520: .getParameterValue("showAdd"));
521: }
522: if (!Utilities.isEmpty(requestParser
523: .getParameterValue("noteIdNumber"))) {
524: noteIdNumber = Long.valueOf(requestParser
525: .getParameterValue("noteIdNumber"));
526: }
527: methodToCall = requestParser
528: .getParameterValue("methodToCall");
529: sortOrder = "DESCENDING";
530: if (!Utilities.isEmpty(requestParser
531: .getParameterValue("sortNotes"))) {
532: sortNotes = Boolean.valueOf(requestParser
533: .getParameterValue("sortNotes"));
534: }
535: addText = requestParser.getParameterValue("addText");
536: noteText = requestParser.getParameterValue("noteText");
537: if (!Utilities.isEmpty(requestParser
538: .getParameterValue("idInEdit"))) {
539: idInEdit = Long.valueOf(requestParser
540: .getParameterValue("idInEdit"));
541: }
542: if (noteIdNumber != null) {
543: note = KEWServiceLocator.getNoteService()
544: .getNoteByNoteId(noteIdNumber);
545: }
546: if (requestParser.getUploadList() != null
547: && !requestParser.getUploadList().isEmpty()) {
548: file = (FileItem) requestParser.getUploadList().get(0);
549: }
550: }
551:
552: public String getAddText() {
553: return addText;
554: }
555:
556: public void setAddText(String addText) {
557: this .addText = addText;
558: }
559:
560: public Boolean getAuthorizedToAdd() {
561: return authorizedToAdd;
562: }
563:
564: public void setAuthorizedToAdd(Boolean authorizedToAdd) {
565: this .authorizedToAdd = authorizedToAdd;
566: }
567:
568: public String getCurrentDate() {
569: return currentDate;
570: }
571:
572: public void setCurrentDate(String currentDate) {
573: this .currentDate = currentDate;
574: }
575:
576: public String getCurrentUserName() {
577: return currentUserName;
578: }
579:
580: public void setCurrentUserName(String currentUserName) {
581: this .currentUserName = currentUserName;
582: }
583:
584: public Long getIdInEdit() {
585: return idInEdit;
586: }
587:
588: public void setIdInEdit(Long idInEdit) {
589: this .idInEdit = idInEdit;
590: }
591:
592: public Note getNote() {
593: return note;
594: }
595:
596: public void setNote(Note note) {
597: this .note = note;
598: }
599:
600: public Long getNoteIdNumber() {
601: return noteIdNumber;
602: }
603:
604: public void setNoteIdNumber(Long noteIdNumber) {
605: this .noteIdNumber = noteIdNumber;
606: }
607:
608: public List getNoteList() {
609: return noteList;
610: }
611:
612: public void setNoteList(List noteList) {
613: this .noteList = noteList;
614: }
615:
616: public String getNoteText() {
617: return noteText;
618: }
619:
620: public void setNoteText(String noteText) {
621: this .noteText = noteText;
622: }
623:
624: public Integer getNumberOfNotes() {
625: return numberOfNotes;
626: }
627:
628: public void setNumberOfNotes(Integer numberOfNotes) {
629: this .numberOfNotes = numberOfNotes;
630: }
631:
632: public Boolean getShowAdd() {
633: return showAdd;
634: }
635:
636: public void setShowAdd(Boolean showAdd) {
637: this .showAdd = showAdd;
638: }
639:
640: public String getShowEdit() {
641: return showEdit;
642: }
643:
644: public void setShowEdit(String showEdit) {
645: this .showEdit = showEdit;
646: }
647:
648: public Boolean getSortNotes() {
649: return sortNotes;
650: }
651:
652: public void setSortNotes(Boolean sortNotes) {
653: this .sortNotes = sortNotes;
654: }
655:
656: public String getSortOrder() {
657: return sortOrder;
658: }
659:
660: public void setSortOrder(String sortOrder) {
661: this .sortOrder = sortOrder;
662: }
663:
664: public Long getDocId() {
665: return docId;
666: }
667:
668: public void setDocId(Long docId) {
669: this .docId = docId;
670: }
671:
672: public String getMethodToCall() {
673: return methodToCall;
674: }
675:
676: public void setMethodToCall(String methodToCall) {
677: this .methodToCall = methodToCall;
678: }
679:
680: public FileItem getFile() {
681: return file;
682: }
683:
684: public void setFile(FileItem file) {
685: this .file = file;
686: }
687: }
688:
689: /**
690: * Method added for notes editing function. Called by retrieveNoteList method
691: * @param allNotes
692: * @param sortOrder
693: * @return
694: */
695:
696: private List sortNotes(List allNotes, String sortOrder) {
697: final int returnCode = EdenConstants.Sorting.SORT_SEQUENCE_DSC
698: .equalsIgnoreCase(sortOrder) ? -1 : 1;
699:
700: try {
701: Collections.sort(allNotes, new Comparator() {
702: public int compare(Object o1, Object o2) {
703: Timestamp date1 = ((Note) o1).getNoteCreateDate();
704: Timestamp date2 = ((Note) o2).getNoteCreateDate();
705:
706: if (date1.before(date2)) {
707: return returnCode * -1;
708: } else if (date1.after(date2)) {
709: return returnCode;
710: } else {
711: return 0;
712: }
713: }
714: });
715: } catch (Throwable e) {
716: LOG.error(e.getMessage(), e);
717: }
718: return allNotes;
719: }
720:
721: /**
722: * Method added for notes editing function. Called by retrieveNoteList method
723: * @param note
724: * @throws Exception
725: */
726:
727: private void getAuthorData(Note note) throws Exception {
728: WorkflowUser workflowUser = null;
729: String id = "";
730: if (note != null && note.getNoteAuthorWorkflowId() != null
731: && !"".equalsIgnoreCase(note.getNoteAuthorWorkflowId())) {
732: workflowUser = getUserService().getWorkflowUser(
733: new WorkflowUserId(note.getNoteAuthorWorkflowId()));
734: id = note.getNoteAuthorWorkflowId();
735: }
736: if (workflowUser != null) {
737: note.setNoteAuthorFullName(workflowUser.getDisplayName());
738: note.setNoteAuthorEmailAddress(workflowUser
739: .getEmailAddress());
740: note.setNoteAuthorNetworkId(workflowUser
741: .getAuthenticationUserId().getAuthenticationId());
742: } else {
743: note.setNoteAuthorFullName(id + " (Name not Available)");
744: note.setNoteAuthorEmailAddress("Not Available");
745: note.setNoteAuthorNetworkId("Not Available");
746: }
747: }
748:
749: public String getCurrentDate() {
750: Date currentDate = new Date();
751: DateFormat dateFormat = EdenConstants.getDefaultDateFormat();
752: return dateFormat.format(currentDate);
753: }
754:
755: /**
756: * Method added for notes editing function.
757: * @return
758: */
759: private NoteService getNoteService() {
760: return (NoteService) KEWServiceLocator
761: .getService(KEWServiceLocator.NOTE_SERVICE);
762: }
763:
764: /**
765: * Method added for notes editing function.
766: * @return
767: */
768: private UserService getUserService() {
769: return (UserService) KEWServiceLocator
770: .getService(KEWServiceLocator.USER_SERVICE);
771: }
772:
773: /**
774: * Method added for notes editing function.
775: * @return
776: */
777: private RouteHeaderService getRouteHeaderService() {
778: return (RouteHeaderService) KEWServiceLocator
779: .getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
780: }
781: }
|