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.List;
19  import java.util.Map;
20  
21  import org.apache.log4j.Logger;
22  import org.kuali.rice.krad.service.DataDictionaryService;
23  import org.kuali.rice.krad.uif.UifConstants;
24  import org.kuali.rice.krad.uif.UifConstants.ViewType;
25  import org.kuali.rice.krad.uif.service.ViewService;
26  import org.kuali.rice.krad.uif.service.ViewTypeService;
27  import org.kuali.rice.krad.uif.view.View;
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  public class ViewServiceImpl implements ViewService {
41      private static final Logger LOG = Logger.getLogger(ViewServiceImpl.class);
42  
43      private DataDictionaryService dataDictionaryService;
44  
45      
46      private List<ViewTypeService> viewTypeServices;
47  
48      
49  
50  
51      public View getViewById(final String viewId) {
52          if (LOG.isDebugEnabled()) {
53              LOG.debug("retrieving view instance for id: " + viewId);
54          }
55          
56          return dataDictionaryService.getViewById(viewId);
57      }
58  
59      
60  
61  
62  
63  
64  
65  
66  
67      public View getViewByType(ViewType viewType, Map<String, String> parameters) {
68          ViewTypeService typeService = getViewTypeService(viewType);
69          if (typeService == null) {
70              throw new RuntimeException("Unable to find view type service for view type name: " + viewType);
71          }
72  
73          Map<String, String> typeParameters = typeService.getParametersFromRequest(parameters);
74  
75          View view = dataDictionaryService.getViewByTypeIndex(viewType, typeParameters);
76          if (view == null) {
77              LOG.warn("View not found for type: " + viewType);
78          }
79  
80          return view;
81      }
82  
83      
84  
85  
86  
87      public String getViewIdForViewType(ViewType viewType, Map<String, String> parameters) {
88          ViewTypeService typeService = getViewTypeService(viewType);
89          if (typeService == null) {
90              throw new RuntimeException("Unable to find view type service for view type name: " + viewType);
91          }
92  
93          Map<String, String> typeParameters = typeService.getParametersFromRequest(parameters);
94  
95          return dataDictionaryService.getViewIdByTypeIndex(viewType, typeParameters);
96      }
97  
98      public ViewTypeService getViewTypeService(UifConstants.ViewType viewType) {
99          if (viewTypeServices != null) {
100             for (ViewTypeService typeService : viewTypeServices) {
101                 if (viewType.equals(typeService.getViewTypeName())) {
102                     return typeService;
103                 }
104             }
105         }
106 
107         return null;
108     }
109 
110     public List<ViewTypeService> getViewTypeServices() {
111         return this.viewTypeServices;
112     }
113 
114     public void setViewTypeServices(List<ViewTypeService> viewTypeServices) {
115         this.viewTypeServices = viewTypeServices;
116     }
117 
118     protected DataDictionaryService getDataDictionaryService() {
119         return this.dataDictionaryService;
120     }
121 
122     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
123         this.dataDictionaryService = dataDictionaryService;
124     }
125 
126 }