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