1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreApiServiceLocator;
20 import org.kuali.rice.core.api.util.RiceConstants;
21 import org.kuali.rice.kew.api.WorkflowDocument;
22 import org.kuali.rice.kim.api.identity.Person;
23 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24 import org.kuali.rice.krad.document.Document;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26
27
28
29
30
31
32 public class DocumentFormBase extends UifFormBase {
33 private static final long serialVersionUID = 2190268505427404480L;
34
35 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentFormBase.class);
36
37 private String annotation = "";
38 private String command;
39
40 private String docId;
41 private String docTypeName;
42
43 protected Document document;
44
45 public DocumentFormBase() {
46 super();
47
48 instantiateDocument();
49 }
50
51 public String getAnnotation() {
52 return this.annotation;
53 }
54
55 public void setAnnotation(String annotation) {
56 this.annotation = annotation;
57 }
58
59 public Document getDocument() {
60 return this.document;
61 }
62
63 public void setDocument(Document document) {
64 this.document = document;
65 }
66
67 public String getDocTypeName() {
68 if(this.docTypeName == null && !this.getDefaultDocumentTypeName().isEmpty())
69 {
70 return this.getDefaultDocumentTypeName();
71 }
72 return this.docTypeName;
73 }
74
75 public void setDocTypeName(String docTypeName) {
76 this.docTypeName = docTypeName;
77 }
78
79 public String getCommand() {
80 return this.command;
81 }
82
83 public void setCommand(String command) {
84 this.command = command;
85 }
86
87 public String getDocId() {
88 return this.docId;
89 }
90
91 public void setDocId(String docId) {
92 this.docId = docId;
93 }
94
95 protected String getDefaultDocumentTypeName() {
96 return "";
97 }
98
99 protected void instantiateDocument() {
100 if (document == null && StringUtils.isNotBlank(getDefaultDocumentTypeName())) {
101 Class<? extends Document> documentClass = KRADServiceLocatorWeb.getDataDictionaryService()
102 .getDocumentClassByTypeName(getDefaultDocumentTypeName());
103 try {
104 Document newDocument = documentClass.newInstance();
105 setDocument(newDocument);
106 } catch (Exception e) {
107 LOG.error("Unable to instantiate document class " + documentClass.getName() + " document type "
108 + getDefaultDocumentTypeName());
109 throw new RuntimeException(e);
110 }
111 }
112 }
113
114
115
116
117
118
119 public String getDocumentInitiatorNetworkId() {
120 String initiatorNetworkId = "";
121 if (getWorkflowDocument() != null) {
122 String initiatorPrincipalId = getWorkflowDocument().getInitiatorPrincipalId();
123 Person initiator = KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
124 if (initiator != null) {
125 initiatorNetworkId = initiator.getPrincipalName();
126 }
127 }
128
129 return initiatorNetworkId;
130 }
131
132
133
134
135
136
137
138 public String getDocumentCreateDate() {
139 String createDateStr = "";
140 if (getWorkflowDocument() != null && getWorkflowDocument().getDateCreated() != null) {
141 createDateStr = CoreApiServiceLocator.getDateTimeService().toString(
142 getWorkflowDocument().getDateCreated().toDate(), "hh:mm a "+ RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE);
143 }
144
145 return createDateStr;
146 }
147
148
149
150
151
152
153
154 public WorkflowDocument getWorkflowDocument() {
155 return getDocument().getDocumentHeader().getWorkflowDocument();
156 }
157
158 }