1 | |
package liquibase.precondition.core; |
2 | |
|
3 | |
import liquibase.exception.ValidationErrors; |
4 | |
import liquibase.exception.Warnings; |
5 | |
import liquibase.precondition.Precondition; |
6 | |
import liquibase.database.Database; |
7 | |
import liquibase.changelog.DatabaseChangeLog; |
8 | |
import liquibase.changelog.ChangeSet; |
9 | |
import liquibase.changelog.ChangeLogParameters; |
10 | |
import liquibase.exception.PreconditionFailedException; |
11 | |
import liquibase.exception.PreconditionErrorException; |
12 | |
|
13 | 8 | public class ChangeLogPropertyDefinedPrecondition implements Precondition { |
14 | |
|
15 | |
private String property; |
16 | |
private String value; |
17 | |
|
18 | |
public String getName() { |
19 | 8 | return "changeLogPropertyDefined"; |
20 | |
} |
21 | |
|
22 | |
public String getProperty() { |
23 | 0 | return property; |
24 | |
} |
25 | |
|
26 | |
public void setProperty(String property) { |
27 | 0 | this.property = property; |
28 | 0 | } |
29 | |
|
30 | |
public String getValue() { |
31 | 0 | return value; |
32 | |
} |
33 | |
|
34 | |
public void setValue(String value) { |
35 | 0 | this.value = value; |
36 | 0 | } |
37 | |
|
38 | |
public Warnings warn(Database database) { |
39 | 0 | return new Warnings(); |
40 | |
} |
41 | |
|
42 | |
public ValidationErrors validate(Database database) { |
43 | 0 | return new ValidationErrors(); |
44 | |
} |
45 | |
|
46 | |
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) |
47 | |
throws PreconditionFailedException, PreconditionErrorException { |
48 | 0 | ChangeLogParameters changeLogParameters = changeLog.getChangeLogParameters(); |
49 | 0 | if (changeLogParameters == null) { |
50 | 0 | throw new PreconditionFailedException("No Changelog properties were set", changeLog, this); |
51 | |
} |
52 | 0 | Object propertyValue = changeLogParameters.getValue(property); |
53 | 0 | if (propertyValue == null) { |
54 | 0 | throw new PreconditionFailedException("Changelog property '" + property + "' was not set", changeLog, this); |
55 | |
} |
56 | 0 | if (value != null && !propertyValue.toString().equals(value)) { |
57 | 0 | throw new PreconditionFailedException("Expected changelog property '" + property + "' to have a value of '" |
58 | |
+ value + "'. Got '" + propertyValue + "'", changeLog, this); |
59 | |
} |
60 | 0 | } |
61 | |
} |