001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.uif.util;
017
018 import java.util.Map;
019
020 import org.apache.log4j.Logger;
021 import org.kuali.rice.core.api.lifecycle.Lifecycle;
022 import org.kuali.rice.krad.datadictionary.DataDictionary;
023 import org.kuali.rice.krad.datadictionary.DataDictionaryException;
024 import org.kuali.rice.krad.uif.UifConstants.ViewType;
025 import org.kuali.rice.krad.uif.service.ViewService;
026 import org.kuali.rice.krad.uif.service.ViewTypeService;
027 import org.kuali.rice.krad.uif.view.View;
028
029 /**
030 * Simple view service implementation for supporting framework level UIF unit tests.
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 public class TestViewService implements ViewService, Lifecycle {
035
036 private static final Logger LOG = Logger.getLogger(TestViewService.class);
037
038 private boolean running;
039 private DataDictionary dataDictionary;
040
041 /**
042 * @return the dataDictionary
043 */
044 public DataDictionary getDataDictionary() {
045 return this.dataDictionary;
046 }
047
048 /**
049 * @param dataDictionary the dataDictionary to set
050 */
051 public void setDataDictionary(DataDictionary dataDictionary) {
052 this.dataDictionary = dataDictionary;
053 }
054
055 /**
056 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
057 */
058 @Override
059 public void start() {
060 try {
061 dataDictionary.parseDataDictionaryConfigurationFiles(false);
062 } catch (DataDictionaryException e) {
063 LOG.error("Error initializing data dictionary", e);
064 }
065 running = true;
066 }
067
068 /**
069 * @see org.springframework.context.Lifecycle#stop()
070 */
071 @Override
072 public void stop() {
073 running = false;
074 }
075
076 /**
077 * @see org.springframework.context.Lifecycle#isRunning()
078 */
079 @Override
080 public boolean isStarted() {
081 return running;
082 }
083
084 /**
085 * @see org.kuali.rice.krad.uif.service.ViewService#getViewById(java.lang.String)
086 */
087 @Override
088 public View getViewById(String viewId) {
089 return dataDictionary.getViewById(viewId);
090 }
091
092 /**
093 * @see org.kuali.rice.krad.uif.service.ViewService#getViewByType(org.kuali.rice.krad.uif.UifConstants.ViewType, java.util.Map)
094 */
095 @Override
096 public View getViewByType(ViewType viewType, Map<String, String> parameters) {
097 return dataDictionary.getViewByTypeIndex(viewType, parameters);
098 }
099
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 }