001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.kim.config;
017
018import org.kuali.rice.core.api.config.module.RunMode;
019import org.kuali.rice.core.api.config.property.ConfigContext;
020import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
021import org.kuali.rice.core.framework.config.module.WebModuleConfiguration;
022import org.kuali.rice.kim.api.KimApiConstants;
023
024import javax.sql.DataSource;
025import java.util.ArrayList;
026import java.util.Arrays;
027import java.util.List;
028
029/**
030 * This class handles the Spring based KIM configuration that is part of the Rice Configurer that must 
031 * exist in all Rice based systems and clients. 
032 * 
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035public class KIMConfigurer extends ModuleConfigurer {
036    public static final String KIM_DATASOURCE_OBJ = "kim.datasource";
037        private static final String KIM_UI_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kim/impl/config/KimWebSpringBeans.xml";
038    private DataSource dataSource;
039
040    public KIMConfigurer() {
041        super(KimApiConstants.Namespaces.MODULE_NAME);
042        setValidRunModes(Arrays.asList(RunMode.THIN, RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL));
043    }
044
045    @Override
046    protected String getDefaultConfigPackagePath() {
047        return "classpath:org/kuali/rice/kim/impl/config/";
048    }
049
050    @Override
051        public List<String> getPrimarySpringFiles() {
052        List<String> springFileLocations = new ArrayList<String>();
053        if (RunMode.THIN == getRunMode()) {
054            springFileLocations.add(getDefaultConfigPackagePath() + "KimThinSpringBeans.xml");
055        } else if (RunMode.REMOTE == getRunMode()) {
056            springFileLocations.add(getDefaultConfigPackagePath() + "KimRemoteSpringBeans.xml");
057        } else if (RunMode.EMBEDDED == getRunMode()) {
058            springFileLocations.add(getDefaultConfigPackagePath() + "KimEmbeddedSpringBeans.xml");
059        } else if (RunMode.LOCAL == getRunMode()) {
060            springFileLocations.add(getDefaultConfigPackagePath() + "KimLocalSpringBeans.xml");
061        }
062                return springFileLocations;
063        }
064
065    @Override
066    public void addAdditonalToConfig() {
067        configureDataSource();
068    }
069
070    private void configureDataSource() {
071        if (getDataSource() != null) {
072            ConfigContext.getCurrentContextConfig().putObject(KIM_DATASOURCE_OBJ, getDataSource());
073        }
074    }
075
076    public DataSource getDataSource() {
077        return dataSource;
078    }
079
080    public void setDataSource(DataSource dataSource) {
081        this.dataSource = dataSource;
082    }
083    @Override
084    public boolean hasWebInterface() {
085        return true;
086    }
087
088    @Override
089    protected WebModuleConfiguration loadWebModule() {
090        WebModuleConfiguration configuration = super.loadWebModule();
091        configuration.setWebSpringFiles(Arrays.asList(KIM_UI_SPRING_BEANS_PATH));
092        return configuration;
093    }
094}