001 /** 002 * Copyright 2011 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016 package org.kuali.common.impex.spring; 017 018 import java.io.File; 019 import java.util.List; 020 021 import org.kuali.common.impex.schema.DumpSchemaService; 022 import org.kuali.common.impex.schema.execute.DumpSchemaExecutable; 023 import org.kuali.common.impex.schema.execute.DumpSchemaRequest; 024 import org.kuali.common.impex.util.DumpConstants; 025 import org.kuali.common.util.spring.SpringUtils; 026 import org.springframework.beans.factory.annotation.Autowired; 027 import org.springframework.context.annotation.Bean; 028 import org.springframework.context.annotation.Configuration; 029 import org.springframework.context.annotation.Import; 030 import org.springframework.core.env.Environment; 031 032 @Configuration 033 @Import({ ExportServicesConfig.class }) 034 public class DumpSchemaConfig { 035 036 private static final String FILE_KEY = "impex.dump.schema.file"; 037 private static final String INCLUDES_KEY = "impex.dump.schema.includes"; 038 private static final String EXCLUDES_KEY = "impex.dump.schema.excludes"; 039 private static final String SKIP_KEY = "impex.dump.schema.skip"; 040 private static final String RELATIVE_DIR_KEY = "impex.dump.schema.dir.relative"; 041 private static final String LOG_EXCLUDES_KEY = "impex.dump.schema.log.excludes"; 042 043 @Autowired 044 Environment env; 045 046 @Autowired 047 ExportServicesConfig exportServicesConfig; 048 049 @Bean 050 public DumpSchemaExecutable dumpSchemaExecutable() { 051 052 DumpSchemaService service = exportServicesConfig.exportDumpSchemaService(); 053 054 // Extract some context from the environment 055 File outputFile = SpringUtils.getFile(env, FILE_KEY); 056 File relativeDir = SpringUtils.getFile(env, RELATIVE_DIR_KEY, outputFile); 057 boolean skip = SpringUtils.getBoolean(env, SKIP_KEY, false); 058 List<String> includes = SpringUtils.getNoneSensitiveListFromCSV(env, INCLUDES_KEY, DumpConstants.DEFAULT_REGEX_INCLUDE); 059 List<String> excludes = SpringUtils.getNoneSensitiveListFromCSV(env, EXCLUDES_KEY, DumpConstants.DEFAULT_REGEX_EXCLUDE); 060 boolean logExcludedSchemaObjects = SpringUtils.getBoolean(env, LOG_EXCLUDES_KEY, false); 061 062 // Setup the request 063 DumpSchemaRequest request = new DumpSchemaRequest(); 064 request.setOutputFile(outputFile); 065 request.setExcludes(excludes); 066 request.setIncludes(includes); 067 request.setLogExcludedSchemaObjects(logExcludedSchemaObjects); 068 request.setRelativeDir(relativeDir); 069 070 // Setup the executable 071 return new DumpSchemaExecutable(service, skip, request); 072 } 073 074 }