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.model.spring;
17  
18  import org.kuali.common.impex.model.Schema;
19  import org.kuali.common.impex.model.compare.SchemaCompareExecutable;
20  import org.kuali.common.impex.model.compare.service.SchemaCompareService;
21  import org.kuali.common.impex.model.compare.service.impl.SchemaCompareServiceImpl;
22  import org.kuali.common.util.spring.SpringUtils;
23  import org.springframework.beans.factory.annotation.Autowired;
24  import org.springframework.context.annotation.Bean;
25  import org.springframework.context.annotation.Configuration;
26  import org.springframework.core.env.Environment;
27  
28  @Configuration
29  public abstract class SchemaCompareConfig {
30  
31      protected static final String SCHEMA_1_DEFAULT_LABEL = "schema1";
32      protected static final String SCHEMA_2_DEFAULT_LABEL = "schema2";
33  
34      protected static final String SCHEMA_1_LABEL_KEY = "impex.compare.schema1.label";
35      protected static final String SCHEMA_2_LABEL_KEY = "impex.compare.schema2.label";
36  
37      /**
38       * Property key for a boolean setting whether or not the executable should run
39       */
40      protected static final String EXECUTION_SKIP_KEY = "impex.compare.skip";
41  
42      @Autowired
43      protected Environment env;
44  
45      @Bean
46      public SchemaCompareService compareService() {
47          Schema schema1 = schema1();
48          schema1.setName(schema1Label());
49  
50          Schema schema2 = schema2();
51          schema2.setName(schema2Label());
52  
53          return new SchemaCompareServiceImpl();
54      }
55  
56      public abstract Schema schema1();
57  
58      public abstract Schema schema2();
59  
60      public String schema1Label() {
61          return SpringUtils.getProperty(env, SCHEMA_1_LABEL_KEY, SCHEMA_1_DEFAULT_LABEL);
62      }
63  
64      public String schema2Label() {
65          return SpringUtils.getProperty(env, SCHEMA_2_LABEL_KEY, SCHEMA_2_DEFAULT_LABEL);
66      }
67  
68      @Bean(initMethod = "execute")
69      public SchemaCompareExecutable exportSchemaExecutable() {
70          SchemaCompareExecutable result = new SchemaCompareExecutable(skipExecution());
71          result.setCompareService(compareService());
72          result.setSchema1(schema1());
73          result.setSchema2(schema2());
74  
75          return result;
76      }
77  
78      @Bean
79      public Boolean skipExecution() {
80          return SpringUtils.getBoolean(env, EXECUTION_SKIP_KEY, SchemaCompareExecutable.DEFAULT_EXECUTION_SKIP);
81      }
82  
83  }