001/**
002 * Copyright 2005-2015 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        LOG.info("KIMConfigurer:getPrimarySpringFiles: getRunMode => " + getRunMode());
053        List<String> springFileLocations = new ArrayList<String>();
054        if (RunMode.THIN == getRunMode()) {
055            springFileLocations.add(getDefaultConfigPackagePath() + "KimThinSpringBeans.xml");
056        } else if (RunMode.REMOTE == getRunMode()) {
057            springFileLocations.add(getDefaultConfigPackagePath() + "KimRemoteSpringBeans.xml");
058        } else if (RunMode.EMBEDDED == getRunMode()) {
059            springFileLocations.add(getDefaultConfigPackagePath() + "KimEmbeddedSpringBeans.xml");
060        } else if (RunMode.LOCAL == getRunMode()) {
061            springFileLocations.add(getDefaultConfigPackagePath() + "KimLocalSpringBeans.xml");
062        }
063        return springFileLocations;
064    }
065
066    @Override
067    public void addAdditonalToConfig() {
068        configureDataSource();
069    }
070
071    private void configureDataSource() {
072        if (getDataSource() != null) {
073            ConfigContext.getCurrentContextConfig().putObject(KIM_DATASOURCE_OBJ, getDataSource());
074        }
075    }
076
077    public DataSource getDataSource() {
078        return dataSource;
079    }
080
081    public void setDataSource(DataSource dataSource) {
082        this.dataSource = dataSource;
083    }
084
085    @Override
086    public boolean hasWebInterface() {
087        return true;
088    }
089
090    @Override
091    protected WebModuleConfiguration loadWebModule() {
092        WebModuleConfiguration configuration = super.loadWebModule();
093        configuration.setWebSpringFiles(Arrays.asList(KIM_UI_SPRING_BEANS_PATH));
094        return configuration;
095    }
096}