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.api.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.util.ViewModelUtils; |
30 | |
import org.kuali.rice.krad.uif.service.ViewTypeService; |
31 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
32 | |
import org.springframework.beans.PropertyValues; |
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 ViewType getViewTypeName() { |
52 | 0 | return ViewType.MAINTENANCE; |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public Map<String, String> getParametersFromViewConfiguration(PropertyValues propertyValues) { |
59 | 0 | Map<String, String> parameters = new HashMap<String, String>(); |
60 | |
|
61 | 0 | String viewName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.VIEW_NAME); |
62 | 0 | String dataObjectClassName = ViewModelUtils.getStringValFromPVs(propertyValues, |
63 | |
UifParameters.DATA_OBJECT_CLASS_NAME); |
64 | |
|
65 | 0 | parameters.put(UifParameters.VIEW_NAME, viewName); |
66 | 0 | parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName); |
67 | |
|
68 | 0 | return parameters; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@Override |
78 | |
public Map<String, String> getParametersFromRequest(Map<String, String> requestParameters) { |
79 | 0 | Map<String, String> parameters = new HashMap<String, String>(); |
80 | |
|
81 | 0 | if (requestParameters.containsKey(UifParameters.VIEW_NAME)) { |
82 | 0 | parameters.put(UifParameters.VIEW_NAME, requestParameters.get(UifParameters.VIEW_NAME)); |
83 | |
} |
84 | |
else { |
85 | 0 | parameters.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME); |
86 | |
} |
87 | |
|
88 | 0 | if (requestParameters.containsKey(UifParameters.DATA_OBJECT_CLASS_NAME)) { |
89 | 0 | parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, |
90 | |
requestParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME)); |
91 | |
} |
92 | 0 | else if (requestParameters.containsKey(KRADPropertyConstants.DOC_ID)) { |
93 | 0 | String documentNumber = requestParameters.get(KRADPropertyConstants.DOC_ID); |
94 | |
|
95 | 0 | boolean objectClassFound = false; |
96 | |
try { |
97 | |
|
98 | 0 | Document document = documentService.getByDocumentHeaderId(documentNumber); |
99 | 0 | if (document != null) { |
100 | 0 | String docTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(); |
101 | 0 | Class<?> objectClassName = getDocumentDictionaryService().getMaintenanceDataObjectClass(docTypeName); |
102 | 0 | if (objectClassName != null) { |
103 | 0 | objectClassFound = true; |
104 | 0 | parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, objectClassName.getName()); |
105 | |
} |
106 | |
} |
107 | |
|
108 | 0 | if (!objectClassFound) { |
109 | 0 | throw new RuntimeException("Could not determine object class for maintenance document with id: " |
110 | |
+ documentNumber); |
111 | |
} |
112 | |
} |
113 | 0 | catch (WorkflowException e) { |
114 | 0 | throw new RuntimeException("Encountered workflow exception while retrieving document with id: " |
115 | |
+ documentNumber, e); |
116 | 0 | } |
117 | |
} |
118 | |
|
119 | 0 | return parameters; |
120 | |
} |
121 | |
|
122 | |
protected DocumentService getDocumentService() { |
123 | 0 | if (documentService == null) { |
124 | 0 | this.documentService = KRADServiceLocatorWeb.getDocumentService(); |
125 | |
} |
126 | 0 | return this.documentService; |
127 | |
} |
128 | |
|
129 | |
public void setDocumentService(DocumentService documentService) { |
130 | 0 | this.documentService = documentService; |
131 | 0 | } |
132 | |
|
133 | |
public DocumentDictionaryService getDocumentDictionaryService() { |
134 | 0 | if (documentDictionaryService == null) { |
135 | 0 | this.documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService(); |
136 | |
} |
137 | 0 | return documentDictionaryService; |
138 | |
} |
139 | |
|
140 | |
public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) { |
141 | 0 | this.documentDictionaryService = documentDictionaryService; |
142 | 0 | } |
143 | |
} |