View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.common.impex.spring;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.kuali.common.impex.schema.execute.ProjectSchemaExportExecutable;
23  import org.kuali.common.impex.util.DumpConstants;
24  import org.kuali.common.util.Project;
25  import org.kuali.common.util.ProjectUtils;
26  import org.kuali.common.util.StringFilter;
27  import org.kuali.common.util.spring.SpringUtils;
28  import org.springframework.beans.factory.annotation.Autowired;
29  import org.springframework.context.annotation.Bean;
30  import org.springframework.context.annotation.Configuration;
31  import org.springframework.core.env.Environment;
32  
33  /**
34   * This class supports exporting a schema with multiple output modules
35   */
36  @Configuration
37  public class ProjectSchemaExportConfig {
38  
39  	public static final String PROJECTS_KEY = "impex.export.schema.projects";
40  	public static final String STAGING_DIR_KEY = "impex.export.schema.stagingDir";
41  
42  	@Autowired
43  	Environment env;
44  
45  	@Bean
46  	public List<ProjectSchemaExportExecutable> projectSchemaExportExecutables() {
47  
48  		File stagingDir = SpringUtils.getFile(env, STAGING_DIR_KEY);
49  		List<String> gavs = SpringUtils.getListFromCSV(env, PROJECTS_KEY);
50  
51  		List<ProjectSchemaExportExecutable> executables = new ArrayList<ProjectSchemaExportExecutable>();
52  		for (String gav : gavs) {
53  			ProjectSchemaExportExecutable exec = getProjectSchemaExportExecutable(gav, stagingDir);
54  			executables.add(exec);
55  		}
56  		return executables;
57  	}
58  
59  	protected ProjectSchemaExportExecutable getProjectSchemaExportExecutable(String gav, File stagingDir) {
60  		Project project = ProjectUtils.loadProject(gav);
61  		StringFilter nameFilter = getNameFilter(project);
62  		File basedir = SpringUtils.getFile(env, "project.basedir");
63  
64  		ProjectSchemaExportExecutable exec = new ProjectSchemaExportExecutable();
65  		exec.setProject(project);
66  		exec.setStagingDir(stagingDir);
67  		exec.setNameFilter(nameFilter);
68  		exec.setBasedir(basedir);
69  		return exec;
70  	}
71  
72  	protected StringFilter getNameFilter(Project project) {
73  		String includesKey = "impex.export.schema." + project.getArtifactId() + ".includes";
74  		String excludesKey = "impex.export.schema." + project.getArtifactId() + ".excludes";
75  		List<String> includes = SpringUtils.getListFromCSV(env, includesKey, DumpConstants.DEFAULT_REGEX_INCLUDE);
76  		List<String> excludes = SpringUtils.getListFromCSV(env, excludesKey, DumpConstants.DEFAULT_REGEX_EXCLUDE);
77  		return StringFilter.getInstance(includes, excludes);
78  	}
79  
80  }