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.kew.api.WorkflowDocument;
21 import org.kuali.rice.kim.api.identity.Person;
22 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
23 import org.kuali.rice.krad.document.Document;
24 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25 import org.kuali.rice.krad.web.bind.RequestAccessible;
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
39 @RequestAccessible
40 private String command;
41
42 @RequestAccessible
43 private String docId;
44
45 @RequestAccessible
46 private String docTypeName;
47
48 protected Document document;
49
50 public DocumentFormBase() {
51 super();
52
53 instantiateDocument();
54 }
55
56 public String getAnnotation() {
57 return this.annotation;
58 }
59
60 public void setAnnotation(String annotation) {
61 this.annotation = annotation;
62 }
63
64 public Document getDocument() {
65 return this.document;
66 }
67
68 public void setDocument(Document document) {
69 this.document = document;
70 }
71
72 public String getDocTypeName() {
73 if (this.docTypeName == null && !this.getDefaultDocumentTypeName().isEmpty()) {
74 return this.getDefaultDocumentTypeName();
75 }
76 return this.docTypeName;
77 }
78
79 public void setDocTypeName(String docTypeName) {
80 this.docTypeName = docTypeName;
81 }
82
83 public String getCommand() {
84 return this.command;
85 }
86
87 public void setCommand(String command) {
88 this.command = command;
89 }
90
91 public String getDocId() {
92 return this.docId;
93 }
94
95 public void setDocId(String docId) {
96 this.docId = docId;
97 }
98
99 protected String getDefaultDocumentTypeName() {
100 return "";
101 }
102
103 protected void instantiateDocument() {
104 if (document == null && StringUtils.isNotBlank(getDefaultDocumentTypeName())) {
105 Class<? extends Document> documentClass = KRADServiceLocatorWeb.getDataDictionaryService()
106 .getValidDocumentClassByTypeName(getDefaultDocumentTypeName());
107 try {
108 Document newDocument = documentClass.newInstance();
109 setDocument(newDocument);
110 } catch (Exception e) {
111 LOG.error("Unable to instantiate document class " + documentClass + " document type "
112 + getDefaultDocumentTypeName());
113 throw new RuntimeException("Unable to instantiate document class " + documentClass + " document type "
114 + getDefaultDocumentTypeName(),e);
115 }
116 }
117 }
118
119
120
121
122
123
124 public String getDocumentInitiatorNetworkId() {
125 String initiatorNetworkId = "";
126 if (getWorkflowDocument() != null) {
127 String initiatorPrincipalId = getWorkflowDocument().getInitiatorPrincipalId();
128 Person initiator = KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
129 if (initiator != null) {
130 initiatorNetworkId = initiator.getPrincipalName();
131 }
132 }
133
134 return initiatorNetworkId;
135 }
136
137
138
139
140
141
142
143 public String getDocumentCreateDate() {
144 String createDateStr = "";
145 if (getWorkflowDocument() != null && getWorkflowDocument().getDateCreated() != null) {
146 createDateStr = CoreApiServiceLocator.getDateTimeService().toString(
147 getWorkflowDocument().getDateCreated().toDate(), "hh:mm a MM/dd/yyyy");
148 }
149
150 return createDateStr;
151 }
152
153
154
155
156
157
158
159 public WorkflowDocument getWorkflowDocument() {
160 return getDocument().getDocumentHeader().getWorkflowDocument();
161 }
162
163 }