com.liquibase.ext.parser.ChangeLogErrorHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-commercial-mongodb Show documentation
Show all versions of liquibase-commercial-mongodb Show documentation
Liquibase Commercial Extension for MongoDB
The newest version!
package com.liquibase.ext.parser;
import com.liquibase.ext.change.MongoshChange;
import com.liquibase.ext.change.MongoshFileChange;
import liquibase.Scope;
import liquibase.change.Change;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.exception.ChangeLogParseException;
import liquibase.util.StringUtil;
import java.util.ResourceBundle;
class ChangeLogErrorHandler {
private static final ResourceBundle mongoshBundle = ResourceBundle.getBundle("liquibase/i18n/liquibase-mongosh");
private static final String CHANGELOG_ATTRIBUTE_IS_MISSING = mongoshBundle.getString("changelog.attribute.is.missing");
private static final String CHANGELOG_ATTRIBUTE_IS_NOT_CORRECT = mongoshBundle.getString("changelog.runwith.attribute.is.not.correct");
private ChangeLogErrorHandler() {
}
public static DatabaseChangeLog parse(DatabaseChangeLog databaseChangeLog, String physicalChangeLogLocation, String missingAttribute) throws ChangeLogParseException {
if(Scope.getCurrentScope().has("modifyChangeSets")) {
//it's inner changeSet in modifyChangeSets flow, runWith will be added later on
return databaseChangeLog;
}
for (ChangeSet changeSet : databaseChangeLog.getChangeSets()) {
for (Change change : changeSet.getChanges()) {
if (change instanceof MongoshChange || change instanceof MongoshFileChange) {
if (StringUtil.isEmpty(changeSet.getRunWith()) ) {
throw new ChangeLogParseException(String.format(CHANGELOG_ATTRIBUTE_IS_MISSING, physicalChangeLogLocation, changeSet.getAuthor(), changeSet.getId(), missingAttribute));
} else if (!changeSet.getRunWith().equalsIgnoreCase("mongosh")) {
throw new ChangeLogParseException(String.format(CHANGELOG_ATTRIBUTE_IS_NOT_CORRECT, physicalChangeLogLocation, changeSet.getAuthor(), changeSet.getId(), getChangelogSpecificElementSyntax(changeSet.getRunWith(), missingAttribute), missingAttribute));
}
}
}
}
return databaseChangeLog;
}
private static String getChangelogSpecificElementSyntax(String actualAttribute, String missingAttribute) {
return missingAttribute.replace("mongosh", actualAttribute);
}
}