1
2
3
4
5
6
7
8
9
10
11
12
13
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
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 }