1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.uif.service.impl; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.kuali.rice.kew.exception.WorkflowException; |
22 | |
import org.kuali.rice.krad.document.Document; |
23 | |
import org.kuali.rice.krad.service.DocumentDictionaryService; |
24 | |
import org.kuali.rice.krad.service.DocumentService; |
25 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
26 | |
import org.kuali.rice.krad.uif.UifConstants; |
27 | |
import org.kuali.rice.krad.uif.UifConstants.ViewType; |
28 | |
import org.kuali.rice.krad.uif.UifParameters; |
29 | |
import org.kuali.rice.krad.uif.container.MaintenanceView; |
30 | |
import org.kuali.rice.krad.uif.container.View; |
31 | |
import org.kuali.rice.krad.uif.service.ViewTypeService; |
32 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class MaintenanceViewTypeServiceImpl implements ViewTypeService { |
45 | |
private DocumentService documentService; |
46 | |
private DocumentDictionaryService documentDictionaryService; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public String getViewTypeName() { |
52 | 0 | return ViewType.MAINTENANCE; |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public Map<String, String> getParametersFromView(View view) { |
59 | 0 | Map<String, String> parameters = new HashMap<String, String>(); |
60 | |
|
61 | 0 | MaintenanceView maintenanceView = (MaintenanceView) view; |
62 | |
|
63 | 0 | parameters.put(UifParameters.VIEW_NAME, maintenanceView.getViewName()); |
64 | 0 | parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, maintenanceView.getDataObjectClassName() |
65 | |
.getName()); |
66 | |
|
67 | 0 | return parameters; |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
@Override |
77 | |
public Map<String, String> getParametersFromRequest(Map<String, String> requestParameters) { |
78 | 0 | Map<String, String> parameters = new HashMap<String, String>(); |
79 | |
|
80 | 0 | if (requestParameters.containsKey(UifParameters.VIEW_NAME)) { |
81 | 0 | parameters.put(UifParameters.VIEW_NAME, requestParameters.get(UifParameters.VIEW_NAME)); |
82 | |
} |
83 | |
else { |
84 | 0 | parameters.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME); |
85 | |
} |
86 | |
|
87 | 0 | if (requestParameters.containsKey(UifParameters.DATA_OBJECT_CLASS_NAME)) { |
88 | 0 | parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, |
89 | |
requestParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME)); |
90 | |
} |
91 | 0 | else if (requestParameters.containsKey(KRADPropertyConstants.DOC_ID)) { |
92 | 0 | String documentNumber = requestParameters.get(KRADPropertyConstants.DOC_ID); |
93 | |
|
94 | 0 | boolean objectClassFound = false; |
95 | |
try { |
96 | |
|
97 | 0 | Document document = documentService.getByDocumentHeaderId(documentNumber); |
98 | 0 | if (document != null) { |
99 | 0 | String docTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(); |
100 | 0 | Class<?> objectClassName = getDocumentDictionaryService().getMaintenanceDataObjectClass(docTypeName); |
101 | 0 | if (objectClassName != null) { |
102 | 0 | objectClassFound = true; |
103 | 0 | parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, objectClassName.getName()); |
104 | |
} |
105 | |
} |
106 | |
|
107 | 0 | if (!objectClassFound) { |
108 | 0 | throw new RuntimeException("Could not determine object class for maintenance document with id: " |
109 | |
+ documentNumber); |
110 | |
} |
111 | |
} |
112 | 0 | catch (WorkflowException e) { |
113 | 0 | throw new RuntimeException("Encountered workflow exception while retrieving document with id: " |
114 | |
+ documentNumber, e); |
115 | 0 | } |
116 | |
} |
117 | |
|
118 | 0 | return parameters; |
119 | |
} |
120 | |
|
121 | |
protected DocumentService getDocumentService() { |
122 | 0 | if (documentService == null) { |
123 | 0 | this.documentService = KRADServiceLocatorWeb.getDocumentService(); |
124 | |
} |
125 | 0 | return this.documentService; |
126 | |
} |
127 | |
|
128 | |
public void setDocumentService(DocumentService documentService) { |
129 | 0 | this.documentService = documentService; |
130 | 0 | } |
131 | |
|
132 | |
public DocumentDictionaryService getDocumentDictionaryService() { |
133 | 0 | if (documentDictionaryService == null) { |
134 | 0 | this.documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService(); |
135 | |
} |
136 | 0 | return documentDictionaryService; |
137 | |
} |
138 | |
|
139 | |
public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) { |
140 | 0 | this.documentDictionaryService = documentDictionaryService; |
141 | 0 | } |
142 | |
} |