1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.execute;
17
18 import java.util.Properties;
19
20 import org.apache.commons.lang3.StringUtils;
21 import org.kuali.common.util.Version;
22 import org.kuali.common.util.VersionUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.util.Assert;
26
27 public class SetSourceDbSchemaNameExecutable implements Executable {
28
29 private static final Logger logger = LoggerFactory.getLogger(SetSourceDbSchemaNameExecutable.class);
30
31 String sourceDbSchemaNameKey = "jdbc.source.db.username";
32 String dbBranchQualifierKey = "db.branch.qualifier";
33
34 String baseSourceDbSchemaName;
35 Properties mavenProperties;
36 String version;
37 boolean skip;
38
39 @Override
40 public void execute() {
41
42 if (skip) {
43 logger.info("Skipping execution");
44 return;
45 }
46
47
48 Assert.notNull(mavenProperties, "mavenProperties is null");
49 Assert.hasText(baseSourceDbSchemaName, "baseSourceDbSchemaName is blank");
50
51
52 String existingValue = mavenProperties.getProperty(sourceDbSchemaNameKey);
53 if (!StringUtils.isBlank(existingValue)) {
54 logger.info("Existing value - [{}={}]", sourceDbSchemaNameKey, existingValue);
55 return;
56 }
57
58
59 String qualifier = getQualifier(mavenProperties, dbBranchQualifierKey, version);
60
61
62 String sourceDbSchemaName = baseSourceDbSchemaName + qualifier;
63
64
65 mavenProperties.setProperty(sourceDbSchemaNameKey, sourceDbSchemaName);
66 logger.debug("Set property - [{}={}]", sourceDbSchemaNameKey, sourceDbSchemaName);
67 }
68
69 protected String getQualifier(Properties mavenProperties, String explicitQualifierKey, String version) {
70
71 String qualifier = mavenProperties.getProperty(explicitQualifierKey);
72 if (!StringUtils.isBlank(qualifier)) {
73 return "_" + qualifier;
74 }
75
76
77 Version v = VersionUtils.getVersion(version);
78
79
80 if (StringUtils.isBlank(v.getQualifier())) {
81 return qualifier;
82 }
83
84
85 qualifier = v.getQualifier();
86 qualifier = StringUtils.upperCase(qualifier);
87 qualifier = StringUtils.replace(qualifier, "-", "_");
88 qualifier = StringUtils.replace(qualifier, ".", "_");
89 qualifier = "_" + qualifier;
90 return qualifier;
91 }
92
93 public Properties getMavenProperties() {
94 return mavenProperties;
95 }
96
97 public void setMavenProperties(Properties mavenProperties) {
98 this.mavenProperties = mavenProperties;
99 }
100
101 public String getVersion() {
102 return version;
103 }
104
105 public void setVersion(String version) {
106 this.version = version;
107 }
108
109 public boolean isSkip() {
110 return skip;
111 }
112
113 public void setSkip(boolean skip) {
114 this.skip = skip;
115 }
116
117 public String getBaseSourceDbSchemaName() {
118 return baseSourceDbSchemaName;
119 }
120
121 public void setBaseSourceDbSchemaName(String sourceDbSchemaName) {
122 this.baseSourceDbSchemaName = sourceDbSchemaName;
123 }
124
125 public String getSourceDbSchemaNameKey() {
126 return sourceDbSchemaNameKey;
127 }
128
129 public void setSourceDbSchemaNameKey(String sourceDbSchemaNameKey) {
130 this.sourceDbSchemaNameKey = sourceDbSchemaNameKey;
131 }
132
133 public String getDbBranchQualifierKey() {
134 return dbBranchQualifierKey;
135 }
136
137 public void setDbBranchQualifierKey(String dbBranchQualifierKey) {
138 this.dbBranchQualifierKey = dbBranchQualifierKey;
139 }
140
141 }