1 /**
2 * Copyright 2005-2014 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.uif.util;
17
18 import java.util.Map;
19
20 import org.apache.log4j.Logger;
21 import org.kuali.rice.core.api.lifecycle.Lifecycle;
22 import org.kuali.rice.krad.datadictionary.DataDictionary;
23 import org.kuali.rice.krad.datadictionary.DataDictionaryException;
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 * Simple view service implementation for supporting framework level UIF unit tests.
31 *
32 * @author Kuali Rice Team (rice.collab@kuali.org)
33 */
34 public class TestViewService implements ViewService, Lifecycle {
35
36 private static final Logger LOG = Logger.getLogger(TestViewService.class);
37
38 private boolean running;
39 private DataDictionary dataDictionary;
40
41 /**
42 * @return the dataDictionary
43 */
44 public DataDictionary getDataDictionary() {
45 return this.dataDictionary;
46 }
47
48 /**
49 * @param dataDictionary the dataDictionary to set
50 */
51 public void setDataDictionary(DataDictionary dataDictionary) {
52 this.dataDictionary = dataDictionary;
53 }
54
55 /**
56 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
57 */
58 @Override
59 public void start() {
60 try {
61 dataDictionary.parseDataDictionaryConfigurationFiles(false);
62 } catch (DataDictionaryException e) {
63 LOG.error("Error initializing data dictionary", e);
64 }
65 running = true;
66 }
67
68 /**
69 * @see org.springframework.context.Lifecycle#stop()
70 */
71 @Override
72 public void stop() {
73 running = false;
74 }
75
76 /**
77 * @see org.springframework.context.Lifecycle#isRunning()
78 */
79 @Override
80 public boolean isStarted() {
81 return running;
82 }
83
84 /**
85 * @see org.kuali.rice.krad.uif.service.ViewService#getViewById(java.lang.String)
86 */
87 @Override
88 public View getViewById(String viewId) {
89 return dataDictionary.getViewById(viewId);
90 }
91
92 /**
93 * @see org.kuali.rice.krad.uif.service.ViewService#getViewByType(org.kuali.rice.krad.uif.UifConstants.ViewType, java.util.Map)
94 */
95 @Override
96 public View getViewByType(ViewType viewType, Map<String, String> parameters) {
97 return dataDictionary.getViewByTypeIndex(viewType, parameters);
98 }
99
100 /**
101 * @see org.kuali.rice.krad.uif.service.ViewService#getViewIdForViewType(org.kuali.rice.krad.uif.UifConstants.ViewType, java.util.Map)
102 */
103 @Override
104 public String getViewIdForViewType(ViewType viewType, Map<String, String> parameters) {
105 return dataDictionary.getViewIdByTypeIndex(viewType, parameters);
106 }
107
108 /**
109 * @see org.kuali.rice.krad.uif.service.ViewService#getViewTypeService(org.kuali.rice.krad.uif.UifConstants.ViewType)
110 */
111 @Override
112 public ViewTypeService getViewTypeService(ViewType viewType) {
113 return null;
114 }
115
116 }