1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.form;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Properties;
24
25 import javax.servlet.http.HttpServletRequest;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.struts.action.ActionErrors;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.struts.upload.FormFile;
31 import org.kuali.rice.core.api.CoreApiServiceLocator;
32 import org.kuali.rice.core.api.util.RiceKeyConstants;
33 import org.kuali.rice.core.web.format.NoOpStringFormatter;
34 import org.kuali.rice.core.web.format.TimestampAMPMFormatter;
35 import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
36 import org.kuali.rice.kew.api.KewApiServiceLocator;
37 import org.kuali.rice.kew.api.WorkflowDocument;
38 import org.kuali.rice.kew.api.action.ActionRequest;
39 import org.kuali.rice.kew.api.document.DocumentStatus;
40 import org.kuali.rice.kew.api.exception.WorkflowException;
41 import org.kuali.rice.kim.api.KimConstants;
42 import org.kuali.rice.kim.api.identity.Person;
43 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
44 import org.kuali.rice.kns.datadictionary.HeaderNavigation;
45 import org.kuali.rice.kns.datadictionary.KNSDocumentEntry;
46 import org.kuali.rice.kns.util.WebUtils;
47 import org.kuali.rice.kns.web.derivedvaluesetter.DerivedValuesSetter;
48 import org.kuali.rice.kns.web.ui.HeaderField;
49 import org.kuali.rice.krad.bo.AdHocRoutePerson;
50 import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
51 import org.kuali.rice.krad.bo.Note;
52 import org.kuali.rice.krad.datadictionary.DataDictionary;
53 import org.kuali.rice.krad.document.Document;
54 import org.kuali.rice.krad.service.KRADServiceLocator;
55 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
56 import org.kuali.rice.krad.service.ModuleService;
57 import org.kuali.rice.krad.service.SessionDocumentService;
58 import org.kuali.rice.krad.util.GlobalVariables;
59 import org.kuali.rice.krad.util.KRADConstants;
60 import org.kuali.rice.krad.util.MessageMap;
61 import org.kuali.rice.krad.util.ObjectUtils;
62 import org.kuali.rice.krad.util.UrlFactory;
63 import org.springframework.util.AutoPopulatingList;
64
65
66
67
68
69 public abstract class KualiDocumentFormBase extends KualiForm implements Serializable {
70 private static final long serialVersionUID = 916061016201941821L;
71
72 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiDocumentFormBase.class);
73
74 private Document document;
75 private String annotation = "";
76 private String command;
77
78 private String docId;
79 private String docTypeName;
80
81 private List<String> additionalScriptFiles;
82
83 private AdHocRoutePerson newAdHocRoutePerson;
84 private AdHocRouteWorkgroup newAdHocRouteWorkgroup;
85
86 private Note newNote;
87
88
89 private List boNotes;
90
91 protected FormFile attachmentFile = new BlankFormFile();
92
93 protected Map editingMode;
94 protected Map documentActions;
95 protected boolean suppressAllButtons;
96
97 protected Map adHocActionRequestCodes;
98 private boolean returnToActionList;
99
100
101 private String formKey;
102 private String docNum;
103
104 private List<ActionRequest> actionRequests;
105 private List<String> selectedActionRequests;
106 private String superUserAnnotation;
107
108
109
110
111
112 private MessageMap errorMapFromPreviousRequest;
113
114
115
116
117 @Override
118 public void addRequiredNonEditableProperties(){
119 super.addRequiredNonEditableProperties();
120 registerRequiredNonEditableProperty(KRADConstants.DOCUMENT_TYPE_NAME);
121 registerRequiredNonEditableProperty(KRADConstants.FORM_KEY);
122 registerRequiredNonEditableProperty(KRADConstants.NEW_NOTE_NOTE_TYPE_CODE);
123 }
124
125
126
127
128 public String getDocNum() {
129 return this.docNum;
130 }
131
132
133
134
135
136 public void setDocNum(String docNum) {
137 this.docNum = docNum;
138 }
139
140
141
142
143 @SuppressWarnings("unchecked")
144 public KualiDocumentFormBase() {
145 super();
146
147 instantiateDocument();
148 newNote = new Note();
149 this.editingMode = new HashMap();
150
151 this.additionalScriptFiles = new AutoPopulatingList<String>(String.class);
152
153
154 newAdHocRoutePerson = new AdHocRoutePerson();
155
156
157 newAdHocRouteWorkgroup = new AdHocRouteWorkgroup();
158
159
160 setFormatterType("document.documentHeader.note.finDocNotePostedDttmStamp", TimestampAMPMFormatter.class);
161 setFormatterType("document.documentHeader.note.attachment.finDocNotePostedDttmStamp", TimestampAMPMFormatter.class);
162
163
164 setFormatterType("document.documentHeader.boNote.notePostedTimestamp",TimestampAMPMFormatter.class);
165 setFormatterType("document.documentBusinessObject.boNote.notePostedTimestamp",TimestampAMPMFormatter.class);
166
167 setFormatterType("editingMode", NoOpStringFormatter.class);
168 setFormatterType("editableAccounts", NoOpStringFormatter.class);
169
170 setDocumentActions(new HashMap());
171 suppressAllButtons = false;
172
173 initializeHeaderNavigationTabs();
174 }
175
176
177
178
179 @Override
180 public void populate(HttpServletRequest request) {
181 super.populate(request);
182
183 WorkflowDocument workflowDocument = null;
184
185 if (hasDocumentId()) {
186
187
188 try {
189 SessionDocumentService sessionDocumentService = KRADServiceLocatorWeb.getSessionDocumentService();
190 workflowDocument = sessionDocumentService.getDocumentFromSession( GlobalVariables.getUserSession(), getDocument().getDocumentNumber());
191 if ( workflowDocument == null)
192 {
193
194
195 Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(KRADConstants.SYSTEM_USER);
196 workflowDocument = KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(getDocument().getDocumentNumber(), person);
197 sessionDocumentService.addDocumentToUserSession(GlobalVariables.getUserSession(), workflowDocument);
198 if (workflowDocument == null)
199 {
200 throw new WorkflowException("Unable to retrieve workflow document # " + getDocument().getDocumentNumber() + " from workflow document service createWorkflowDocument");
201 }
202 else
203 {
204 LOG.debug("Retrieved workflow Document ID: " + workflowDocument.getDocumentId());
205 }
206 }
207
208 getDocument().getDocumentHeader().setWorkflowDocument(workflowDocument);
209 } catch (WorkflowException e) {
210 LOG.warn("Error while instantiating workflowDoc", e);
211 throw new RuntimeException("error populating documentHeader.workflowDocument", e);
212 }
213 }
214 if (workflowDocument != null) {
215
216 populateHeaderFields(workflowDocument);
217 }
218 }
219
220 protected String getPersonInquiryUrlLink(Person user, String linkBody) {
221 StringBuffer urlBuffer = new StringBuffer();
222
223 if(user != null && StringUtils.isNotEmpty(linkBody) ) {
224 ModuleService moduleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(Person.class);
225 Map<String, String[]> parameters = new HashMap<String, String[]>();
226 parameters.put(KimConstants.AttributeConstants.PRINCIPAL_ID, new String[] { user.getPrincipalId() });
227 String inquiryUrl = moduleService.getExternalizableBusinessObjectInquiryUrl(Person.class, parameters);
228 if(!StringUtils.equals(KimConstants.EntityTypes.SYSTEM, user.getEntityTypeCode())){
229 urlBuffer.append("<a href='");
230 urlBuffer.append(inquiryUrl);
231 urlBuffer.append("' ");
232 urlBuffer.append("target='_blank'");
233 urlBuffer.append("title='Person Inquiry'>");
234 urlBuffer.append(linkBody);
235 urlBuffer.append("</a>");
236 } else{
237 urlBuffer.append(linkBody);
238 }
239 }
240
241 return urlBuffer.toString();
242 }
243
244 protected String getDocumentHandlerUrl(String documentId) {
245 Properties parameters = new Properties();
246 parameters.put(KRADConstants.PARAMETER_DOC_ID, documentId);
247 parameters.put(KRADConstants.PARAMETER_COMMAND, KRADConstants.METHOD_DISPLAY_DOC_SEARCH_VIEW);
248 return UrlFactory.parameterizeUrl(
249 KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
250 KRADConstants.WORKFLOW_URL_KEY) + "/" + KRADConstants.DOC_HANDLER_ACTION, parameters);
251 }
252
253 protected String buildHtmlLink(String url, String linkBody) {
254 StringBuffer urlBuffer = new StringBuffer();
255
256 if(StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(linkBody) ) {
257 urlBuffer.append("<a href='").append(url).append("'>").append(linkBody).append("</a>");
258 }
259
260 return urlBuffer.toString();
261 }
262
263
264
265
266
267
268
269 public void populateHeaderFields(WorkflowDocument workflowDocument) {
270 getDocInfo().clear();
271 getDocInfo().addAll(getStandardHeaderFields(workflowDocument));
272 }
273
274
275
276
277
278
279
280
281
282 protected List<HeaderField> getStandardHeaderFields(WorkflowDocument workflowDocument) {
283 List<HeaderField> headerFields = new ArrayList<HeaderField>();
284 setNumColumns(2);
285
286 HeaderField docTemplateNumber = null;
287 if ((ObjectUtils.isNotNull(getDocument())) && (ObjectUtils.isNotNull(getDocument().getDocumentHeader())) && (StringUtils.isNotBlank(getDocument().getDocumentHeader().getDocumentTemplateNumber()))) {
288 String templateDocumentNumber = getDocument().getDocumentHeader().getDocumentTemplateNumber();
289 docTemplateNumber = new HeaderField(KRADConstants.DocumentFormHeaderFieldIds.DOCUMENT_TEMPLATE_NUMBER, "DataDictionary.DocumentHeader.attributes.documentTemplateNumber",
290 templateDocumentNumber, buildHtmlLink(getDocumentHandlerUrl(templateDocumentNumber), templateDocumentNumber));
291 }
292
293 HeaderField docNumber = new HeaderField("DataDictionary.DocumentHeader.attributes.documentNumber", workflowDocument != null? getDocument().getDocumentNumber() : null);
294 docNumber.setId(KRADConstants.DocumentFormHeaderFieldIds.DOCUMENT_NUMBER);
295 HeaderField docStatus = new HeaderField("DataDictionary.AttributeReferenceDummy.attributes.workflowDocumentStatus", workflowDocument != null? workflowDocument.getStatus().getLabel() : null);
296 docStatus.setId(KRADConstants.DocumentFormHeaderFieldIds.DOCUMENT_WORKFLOW_STATUS);
297 String initiatorNetworkId = null;
298 Person user = null;
299 if (workflowDocument != null) {
300 if (getInitiator() == null) {
301 LOG.warn("User Not Found while attempting to build inquiry link for document header fields");
302 } else {
303 user = getInitiator();
304 initiatorNetworkId = getInitiator().getPrincipalName();
305 }
306 }
307 String inquiryUrl = getPersonInquiryUrlLink(user, workflowDocument != null? initiatorNetworkId:null);
308
309 HeaderField docInitiator = new HeaderField(KRADConstants.DocumentFormHeaderFieldIds.DOCUMENT_INITIATOR, "DataDictionary.AttributeReferenceDummy.attributes.initiatorNetworkId",
310 workflowDocument != null? initiatorNetworkId : null, workflowDocument != null? inquiryUrl : null);
311
312 String createDateStr = null;
313 if(workflowDocument != null && workflowDocument.getDateCreated() != null) {
314 createDateStr = CoreApiServiceLocator.getDateTimeService().toString(workflowDocument.getDateCreated().toDate(), "hh:mm a MM/dd/yyyy");
315 }
316
317 HeaderField docCreateDate = new HeaderField("DataDictionary.AttributeReferenceDummy.attributes.createDate", createDateStr);
318 docCreateDate.setId(KRADConstants.DocumentFormHeaderFieldIds.DOCUMENT_CREATE_DATE);
319 if (ObjectUtils.isNotNull(docTemplateNumber)) {
320 setNumColumns(3);
321 }
322
323 headerFields.add(docNumber);
324 headerFields.add(docStatus);
325 if (ObjectUtils.isNotNull(docTemplateNumber)) {
326 headerFields.add(docTemplateNumber);
327 }
328 headerFields.add(docInitiator);
329 headerFields.add(docCreateDate);
330 if (ObjectUtils.isNotNull(docTemplateNumber)) {
331
332 headerFields.add(HeaderField.EMPTY_FIELD);
333 }
334 return headerFields;
335 }
336
337
338
339
340
341 @Override
342 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
343
344 setAnnotation(StringUtils.stripToNull(getAnnotation()));
345 int diff = StringUtils.defaultString(getAnnotation()).length() - KRADConstants.DOCUMENT_ANNOTATION_MAX_LENGTH;
346 if (diff > 0) {
347 GlobalVariables.getMessageMap().putError("annotation", RiceKeyConstants.ERROR_DOCUMENT_ANNOTATION_MAX_LENGTH_EXCEEDED, new String[] { Integer.toString(KRADConstants.DOCUMENT_ANNOTATION_MAX_LENGTH), Integer.toString(diff) });
348 }
349 return super.validate(mapping, request);
350 }
351
352
353
354
355 final public boolean isFormDocumentInitialized() {
356 boolean initialized = false;
357
358 if (document != null) {
359 if (document.getDocumentHeader() != null) {
360 initialized = document.getDocumentHeader().hasWorkflowDocument();
361 }
362 }
363
364 return initialized;
365 }
366
367
368
369
370
371
372 @SuppressWarnings("unchecked")
373 public Map getEditingMode() {
374 return editingMode;
375 }
376
377
378
379
380 @SuppressWarnings("unchecked")
381 public void setEditingMode(Map editingMode) {
382 this.editingMode = editingMode;
383 }
384
385
386
387
388 @SuppressWarnings("unchecked")
389 public Map getDocumentActions() {
390 return this.documentActions;
391 }
392
393
394
395
396 @SuppressWarnings("unchecked")
397 public void setDocumentActions(Map documentActions) {
398 this.documentActions = documentActions;
399 }
400
401
402
403
404
405
406 @SuppressWarnings("unchecked")
407 public void setAdHocActionRequestCodes(Map adHocActionRequestCodes) {
408 this.adHocActionRequestCodes = adHocActionRequestCodes;
409 }
410
411
412
413
414 @SuppressWarnings("unchecked")
415 public Map getAdHocActionRequestCodes() {
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432 return adHocActionRequestCodes;
433 }
434
435
436
437
438
439 public List<AdHocRoutePerson> getAdHocRoutePersons() {
440 return document.getAdHocRoutePersons();
441 }
442
443
444
445
446
447 public FormFile getAttachmentFile() {
448 return attachmentFile;
449 }
450
451
452
453
454 public void setAttachmentFile(FormFile attachmentFile) {
455 this.attachmentFile = attachmentFile;
456 }
457
458
459
460
461
462
463
464 public void setAdHocRoutePersons(List<AdHocRoutePerson> adHocRouteRecipients) {
465 document.setAdHocRoutePersons(adHocRouteRecipients);
466 }
467
468
469
470
471
472
473 public List<AdHocRouteWorkgroup> getAdHocRouteWorkgroups() {
474 return document.getAdHocRouteWorkgroups();
475 }
476
477
478
479
480
481
482 public void setAdHocRouteWorkgroups(List<AdHocRouteWorkgroup> adHocRouteWorkgroups) {
483 document.setAdHocRouteWorkgroups(adHocRouteWorkgroups);
484 }
485
486
487
488
489
490
491
492 public AdHocRoutePerson getAdHocRoutePerson(int index) {
493 while (getAdHocRoutePersons().size() <= index) {
494 getAdHocRoutePersons().add(new AdHocRoutePerson());
495 }
496 return getAdHocRoutePersons().get(index);
497 }
498
499
500
501
502
503
504
505 public AdHocRouteWorkgroup getAdHocRouteWorkgroup(int index) {
506 while (getAdHocRouteWorkgroups().size() <= index) {
507 getAdHocRouteWorkgroups().add(new AdHocRouteWorkgroup());
508 }
509 return getAdHocRouteWorkgroups().get(index);
510 }
511
512
513
514
515 public AdHocRoutePerson getNewAdHocRoutePerson() {
516 return newAdHocRoutePerson;
517 }
518
519
520
521
522
523
524 public void setNewAdHocRoutePerson(AdHocRoutePerson newAdHocRoutePerson) {
525 this.newAdHocRoutePerson = newAdHocRoutePerson;
526 }
527
528
529
530
531 public AdHocRouteWorkgroup getNewAdHocRouteWorkgroup() {
532 return newAdHocRouteWorkgroup;
533 }
534
535
536
537
538
539
540 public void setNewAdHocRouteWorkgroup(AdHocRouteWorkgroup newAdHocRouteWorkgroup) {
541 this.newAdHocRouteWorkgroup = newAdHocRouteWorkgroup;
542 }
543
544
545
546
547 public Document getDocument() {
548 return document;
549 }
550
551
552
553
554 public void setDocument(Document document) {
555 this.document = document;
556 if(document != null && StringUtils.isNotEmpty(document.getDocumentNumber())) {
557 populateHeaderFields(document.getDocumentHeader().getWorkflowDocument());
558 }
559 }
560
561
562
563
564 public WorkflowDocument getWorkflowDocument() {
565 return getDocument().getDocumentHeader().getWorkflowDocument();
566 }
567
568
569
570
571
572 public boolean isHasWorkflowDocument() {
573 if ( getDocument() == null || getDocument().getDocumentHeader() == null ) {
574 return false;
575 }
576 return getDocument().getDocumentHeader().hasWorkflowDocument();
577 }
578
579
580
581
582 public boolean isUserDocumentInitiator() {
583 if (getWorkflowDocument() != null) {
584 return getWorkflowDocument().getInitiatorPrincipalId().equalsIgnoreCase(
585 GlobalVariables.getUserSession().getPrincipalId());
586 }
587 return false;
588 }
589
590 public Person getInitiator() {
591 String initiatorPrincipalId = getWorkflowDocument().getInitiatorPrincipalId();
592 return KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
593 }
594
595
596
597
598 public boolean isDocumentEnRoute() {
599 return getWorkflowDocument().isEnroute();
600 }
601
602
603
604
605 public void setAnnotation(String annotation) {
606 this.annotation = annotation;
607 }
608
609
610
611
612 public String getAnnotation() {
613 return annotation;
614 }
615
616
617
618
619 public String getCommand() {
620 return command;
621 }
622
623
624
625
626
627
628 public void setCommand(String command) {
629 this.command = command;
630 }
631
632
633
634
635 public String getDocId() {
636 return docId;
637 }
638
639
640
641
642
643
644 public void setDocId(String docId) {
645 this.docId = docId;
646 }
647
648
649
650
651
652
653 public String getDocTypeName() {
654 return docTypeName;
655 }
656
657
658
659
660
661
662 public void setDocTypeName(String docTypeName) {
663 this.docTypeName = docTypeName;
664 }
665
666
667
668
669
670
671 public String getInitiatorNetworkId() {
672 return this.getWorkflowDocument().getInitiatorPrincipalId();
673 }
674
675
676
677
678
679
680 public final boolean isSuppressAllButtons() {
681 return suppressAllButtons;
682 }
683
684
685
686
687
688
689 public final void setSuppressAllButtons(boolean suppressAllButtons) {
690 this.suppressAllButtons = suppressAllButtons;
691 }
692
693
694
695
696
697 public boolean hasDocumentId() {
698 boolean hasDocId = false;
699
700 Document d = getDocument();
701 if (d != null) {
702 String docHeaderId = d.getDocumentNumber();
703
704 hasDocId = StringUtils.isNotBlank(docHeaderId);
705 }
706
707 return hasDocId;
708 }
709
710
711
712
713
714
715
716 public void setReturnToActionList(boolean returnToActionList) {
717 this.returnToActionList = returnToActionList;
718 }
719
720 public boolean isReturnToActionList() {
721 return returnToActionList;
722 }
723
724 public List<String> getAdditionalScriptFiles() {
725 return additionalScriptFiles;
726 }
727
728 public void setAdditionalScriptFiles(List<String> additionalScriptFiles) {
729 this.additionalScriptFiles = additionalScriptFiles;
730 }
731
732 public void setAdditionalScriptFile( int index, String scriptFile ) {
733 additionalScriptFiles.set( index, scriptFile );
734 }
735
736 public String getAdditionalScriptFile( int index ) {
737 return additionalScriptFiles.get( index );
738 }
739
740 public Note getNewNote() {
741 return newNote;
742 }
743
744 public void setNewNote(Note newNote) {
745 this.newNote = newNote;
746 }
747
748
749
750
751
752 @SuppressWarnings("unchecked")
753 public List getBoNotes() {
754 return boNotes;
755 }
756
757
758
759
760
761 @SuppressWarnings("unchecked")
762 public void setBoNotes(List boNotes) {
763 this.boNotes = boNotes;
764 }
765
766 public String getFormKey() {
767 return this.formKey;
768 }
769
770 public void setFormKey(String formKey) {
771 this.formKey = formKey;
772 }
773
774
775
776
777
778
779 @Override
780 public void reset(ActionMapping mapping, HttpServletRequest request) {
781 super.reset(mapping, request);
782 this.setMethodToCall(null);
783 this.setRefreshCaller(null);
784 this.setAnchor(null);
785 this.setCurrentTabIndex(0);
786 this.setSelectedActionRequests(new ArrayList<String>());
787 }
788
789
790
791
792
793
794
795 @Override
796 protected void customInitMaxUploadSizes() {
797 super.customInitMaxUploadSizes();
798 addMaxUploadSize(CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KRADConstants.KNS_NAMESPACE, KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, KRADConstants.ATTACHMENT_MAX_FILE_SIZE_PARM_NM));
799 }
800
801
802
803
804
805
806
807
808
809 @Override
810 public boolean shouldPropertyBePopulatedInForm(String requestParameterName, HttpServletRequest request) {
811 for ( String prefix : KRADConstants.ALWAYS_VALID_PARAMETER_PREFIXES ) {
812 if (requestParameterName.startsWith(prefix)) {
813 return true;
814 }
815 }
816
817 if (StringUtils.equalsIgnoreCase(getMethodToCall(), KRADConstants.DOC_HANDLER_METHOD)) {
818 return true;
819 }
820 if (WebUtils.isDocumentSession(getDocument(), this)) {
821 return isPropertyEditable(requestParameterName) || isPropertyNonEditableButRequired(requestParameterName);
822 }
823 return true;
824 }
825
826
827
828
829
830
831 @Override
832 public boolean shouldMethodToCallParameterBeUsed(
833 String methodToCallParameterName,
834 String methodToCallParameterValue, HttpServletRequest request) {
835 if (StringUtils.equals(methodToCallParameterName, KRADConstants.DISPATCH_REQUEST_PARAMETER) &&
836 StringUtils.equals(methodToCallParameterValue, KRADConstants.DOC_HANDLER_METHOD)) {
837 return true;
838 }
839 return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName,
840 methodToCallParameterValue, request);
841 }
842
843 public MessageMap getMessageMapFromPreviousRequest() {
844 return this.errorMapFromPreviousRequest;
845 }
846
847 public void setMessageMapFromPreviousRequest(MessageMap errorMapFromPreviousRequest) {
848 this.errorMapFromPreviousRequest = errorMapFromPreviousRequest;
849 }
850
851 @Override
852 public void setDerivedValuesOnForm(HttpServletRequest request) {
853 super.setDerivedValuesOnForm(request);
854
855 String docTypeName = getDocTypeName();
856 if (StringUtils.isNotBlank(docTypeName)) {
857 DataDictionary dataDictionary = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary();
858
859 Class<? extends DerivedValuesSetter> derivedValuesSetterClass = null;
860 KNSDocumentEntry documentEntry = (KNSDocumentEntry) dataDictionary.getDocumentEntry(docTypeName);
861 derivedValuesSetterClass = (documentEntry).getDerivedValuesSetterClass();
862
863 if (derivedValuesSetterClass != null) {
864 DerivedValuesSetter derivedValuesSetter = null;
865 try {
866 derivedValuesSetter = derivedValuesSetterClass.newInstance();
867 }
868
869 catch (Exception e) {
870 LOG.error("Unable to instantiate class " + derivedValuesSetterClass.getName(), e);
871 throw new RuntimeException("Unable to instantiate class " + derivedValuesSetterClass.getName(), e);
872 }
873 derivedValuesSetter.setDerivedValues(this, request);
874 }
875 }
876 }
877
878 protected String getDefaultDocumentTypeName() {
879 return "";
880 }
881
882
883 protected void instantiateDocument() {
884 if (document == null && StringUtils.isNotBlank(getDefaultDocumentTypeName())) {
885 Class<? extends Document> documentClass = getDocumentClass();
886 try {
887 Document document = documentClass.newInstance();
888 setDocument(document);
889 } catch (Exception e) {
890 LOG.error("Unable to instantiate document class " + documentClass.getName() + " document type " + getDefaultDocumentTypeName());
891 throw new RuntimeException(e);
892 }
893 }
894 }
895
896
897 private Class<? extends Document> getDocumentClass() {
898 return KRADServiceLocatorWeb.getDataDictionaryService().getDocumentClassByTypeName(getDefaultDocumentTypeName());
899 }
900
901
902 protected void initializeHeaderNavigationTabs() {
903 if (StringUtils.isNotBlank(getDefaultDocumentTypeName())) {
904 final KNSDocumentEntry docEntry = (KNSDocumentEntry) KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDocumentEntry(getDocumentClass().getName());
905 final List<HeaderNavigation> navList = docEntry.getHeaderNavigationList();
906 final HeaderNavigation[] list = new HeaderNavigation[navList.size()];
907 super.setHeaderNavigationTabs(navList.toArray(list));
908 }
909 }
910
911 public List<ActionRequest> getActionRequests() {
912 return actionRequests;
913 }
914
915 public void setActionRequests(List<ActionRequest> actionRequests) {
916 this.actionRequests = actionRequests;
917 }
918
919 public List<String> getSelectedActionRequests() {
920 return selectedActionRequests;
921 }
922
923 public void setSelectedActionRequests(List<String> selectedActionRequests) {
924 this.selectedActionRequests = selectedActionRequests;
925 }
926
927 public String getSuperUserAnnotation() {
928 return superUserAnnotation;
929 }
930
931 public void setSuperUserAnnotation(String superUserAnnotation) {
932 this.superUserAnnotation = superUserAnnotation;
933 }
934
935 public boolean isSuperUserAuthorized() {
936 return KewApiServiceLocator.getDocumentTypeService().isSuperUserForDocumentTypeName(GlobalVariables.getUserSession().getPrincipalId(), this.getDocTypeName());
937 }
938
939 public boolean isStateAllowsSuperUserAction() {
940 if(this.getDocument().getDocumentHeader().hasWorkflowDocument()) {
941 DocumentStatus status = this.getDocument().getDocumentHeader().getWorkflowDocument().getStatus();
942 return !(StringUtils.equals(status.getCode(), DocumentStatus.PROCESSED.getCode()) ||
943 StringUtils.equals(status.getCode(), DocumentStatus.DISAPPROVED.getCode()) ||
944 StringUtils.equals(status.getCode(), DocumentStatus.FINAL.getCode()));
945 } else {
946 return false;
947 }
948 }
949
950 public boolean isSuperUserDocument() {
951 if(this.getDocument().getDocumentHeader().hasWorkflowDocument()) {
952 DocumentStatus status = this.getDocument().getDocumentHeader().getWorkflowDocument().getStatus();
953 return !(StringUtils.equals(status.getCode(), DocumentStatus.INITIATED.getCode()) || StringUtils.equals(status.getCode(), DocumentStatus.SAVED.getCode()));
954 } else {
955 return false;
956 }
957 }
958 }