Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ViewDictionaryServiceImpl |
|
| 3.125;3.125 |
1 | /* | |
2 | * Copyright 2011 The Kuali Foundation Licensed under the Educational Community | |
3 | * License, Version 1.0 (the "License"); you may not use this file except in | |
4 | * compliance with the License. You may obtain a copy of the License at | |
5 | * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law | |
6 | * or agreed to in writing, software distributed under the License is | |
7 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
8 | * KIND, either express or implied. See the License for the specific language | |
9 | * governing permissions and limitations under the License. | |
10 | */ | |
11 | package org.kuali.rice.krad.uif.service.impl; | |
12 | ||
13 | import java.util.List; | |
14 | ||
15 | import org.apache.commons.lang.StringUtils; | |
16 | import org.kuali.rice.krad.datadictionary.DataDictionary; | |
17 | import org.kuali.rice.krad.inquiry.Inquirable; | |
18 | import org.kuali.rice.krad.service.DataDictionaryService; | |
19 | import org.kuali.rice.krad.uif.UifConstants; | |
20 | import org.kuali.rice.krad.uif.container.InquiryView; | |
21 | import org.kuali.rice.krad.uif.container.LookupView; | |
22 | import org.kuali.rice.krad.uif.container.MaintenanceView; | |
23 | import org.kuali.rice.krad.uif.container.View; | |
24 | import org.kuali.rice.krad.uif.service.ViewDictionaryService; | |
25 | ||
26 | /** | |
27 | * Implementation of <code>ViewDictionaryService</code> | |
28 | * | |
29 | * <p> | |
30 | * Pulls view entries from the data dictionary to implement the various query | |
31 | * methods | |
32 | * </p> | |
33 | * | |
34 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
35 | */ | |
36 | 0 | public class ViewDictionaryServiceImpl implements ViewDictionaryService { |
37 | ||
38 | private DataDictionaryService dataDictionaryService; | |
39 | ||
40 | /** | |
41 | * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#getInquirable(java.lang.Class, | |
42 | * java.lang.String) | |
43 | */ | |
44 | public Inquirable getInquirable(Class<?> dataObjectClass, String viewName) { | |
45 | 0 | List<View> inquiryViews = getDataDictionary().getViewsForType(UifConstants.ViewType.INQUIRY); |
46 | ||
47 | 0 | Inquirable inquirable = null; |
48 | 0 | for (View view : inquiryViews) { |
49 | 0 | InquiryView inquiryView = (InquiryView) view; |
50 | ||
51 | 0 | if (StringUtils.equals(inquiryView.getDataObjectClassName().getName(), dataObjectClass.getName())) { |
52 | 0 | if (StringUtils.equals(inquiryView.getViewName(), viewName) || (StringUtils.isBlank(viewName) && |
53 | StringUtils.equals(inquiryView.getViewName(), UifConstants.DEFAULT_VIEW_NAME))) { | |
54 | 0 | inquirable = (Inquirable) inquiryView.getViewHelperService(); |
55 | 0 | break; |
56 | } | |
57 | } | |
58 | 0 | } |
59 | ||
60 | 0 | return inquirable; |
61 | } | |
62 | ||
63 | /** | |
64 | * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#isInquirable(java.lang.Class) | |
65 | */ | |
66 | public boolean isInquirable(Class<?> dataObjectClass) { | |
67 | 0 | boolean inquirable = false; |
68 | ||
69 | 0 | List<View> inquiryViews = getDataDictionary().getViewsForType(UifConstants.ViewType.INQUIRY); |
70 | 0 | for (View view : inquiryViews) { |
71 | 0 | InquiryView inquiryView = (InquiryView) view; |
72 | ||
73 | 0 | if (StringUtils.equals(inquiryView.getDataObjectClassName().getName(), dataObjectClass.getName())) { |
74 | 0 | inquirable = true; |
75 | 0 | break; |
76 | } | |
77 | 0 | } |
78 | ||
79 | 0 | return inquirable; |
80 | } | |
81 | ||
82 | /** | |
83 | * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#isLookupable(java.lang.Class) | |
84 | */ | |
85 | public boolean isLookupable(Class<?> dataObjectClass) { | |
86 | 0 | boolean lookupable = false; |
87 | ||
88 | 0 | List<View> lookupViews = getDataDictionary().getViewsForType(UifConstants.ViewType.LOOKUP); |
89 | 0 | for (View view : lookupViews) { |
90 | 0 | LookupView lookupView = (LookupView) view; |
91 | ||
92 | 0 | if (StringUtils.equals(lookupView.getDataObjectClassName().getName(), dataObjectClass.getName())) { |
93 | 0 | lookupable = true; |
94 | 0 | break; |
95 | } | |
96 | 0 | } |
97 | ||
98 | 0 | return lookupable; |
99 | } | |
100 | ||
101 | /** | |
102 | * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#isMaintainable(java.lang.Class) | |
103 | */ | |
104 | public boolean isMaintainable(Class<?> dataObjectClass) { | |
105 | 0 | boolean maintainable = false; |
106 | ||
107 | 0 | List<View> maintenanceViews = getDataDictionary().getViewsForType(UifConstants.ViewType.MAINTENANCE); |
108 | 0 | for (View view : maintenanceViews) { |
109 | 0 | MaintenanceView maintenanceView = (MaintenanceView) view; |
110 | ||
111 | 0 | if (StringUtils.equals(maintenanceView.getDataObjectClassName().getName(), dataObjectClass.getName())) { |
112 | 0 | maintainable = true; |
113 | 0 | break; |
114 | } | |
115 | 0 | } |
116 | ||
117 | 0 | return maintainable; |
118 | } | |
119 | ||
120 | /** | |
121 | * @see org.kuali.rice.krad.uif.service.impl.ViewDictionaryService#getResultSetLimitForLookup(java.lang.Class) | |
122 | */ | |
123 | @Override | |
124 | public Integer getResultSetLimitForLookup(Class<?> dataObjectClass) { | |
125 | 0 | LookupView lookupView = null; |
126 | ||
127 | 0 | List<View> lookupViews = getDataDictionary().getViewsForType(UifConstants.ViewType.LOOKUP); |
128 | 0 | for (View view : lookupViews) { |
129 | 0 | LookupView lView = (LookupView) view; |
130 | ||
131 | 0 | if (StringUtils.equals(lView.getDataObjectClassName().getName(), dataObjectClass.getName())) { |
132 | // if we already found a lookup view, only override if this is the default | |
133 | 0 | if (lookupView != null) { |
134 | 0 | if (StringUtils.equals(lView.getViewName(), UifConstants.DEFAULT_VIEW_NAME)) { |
135 | 0 | lookupView = lView; |
136 | } | |
137 | } else { | |
138 | 0 | lookupView = lView; |
139 | } | |
140 | } | |
141 | 0 | } |
142 | ||
143 | 0 | if (lookupView != null) { |
144 | 0 | return lookupView.getResultSetLimit(); |
145 | } | |
146 | ||
147 | 0 | return null; |
148 | } | |
149 | ||
150 | protected DataDictionary getDataDictionary() { | |
151 | 0 | return getDataDictionaryService().getDataDictionary(); |
152 | } | |
153 | ||
154 | protected DataDictionaryService getDataDictionaryService() { | |
155 | 0 | return this.dataDictionaryService; |
156 | } | |
157 | ||
158 | public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { | |
159 | 0 | this.dataDictionaryService = dataDictionaryService; |
160 | 0 | } |
161 | } |