Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dennysfredericci/3665e4dab7961952b3a586d7fa0393d0 to your computer and use it in GitHub Desktop.
Save dennysfredericci/3665e4dab7961952b3a586d7fa0393d0 to your computer and use it in GitHub Desktop.
package be.schaubroeck.golf.liquibase.corrections;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class LiquibaseGeneratorForFormulierOnderdeel {
public static void main(String[] args) throws IOException {
// template.txt content example
//<changeSet id="201903121604_dfr_add_formulier_onderdeel_aards_${COUNTER}" author="dfr">
// <preConditions onFail="MARK_RAN">
// <sqlCheck expectedResult="0">
// SELECT COUNT(1) FROM golf_formulier_onderdeel_aard WHERE aard = '${AARD}';
// </sqlCheck>
// </preConditions>
// <insert tableName="golf_formulier_onderdeel_aard">
// <column name="id" valueComputed="(SELECT COALESCE(MAX(id) + 1, 1) FROM (SELECT * FROM golf_formulier_onderdeel_aard) dt)"/>
// <column name="aard" value="${AARD}"/>
// <column name="naam" value="${DESC}"/>
// <column name="volg_nummer" valueNumeric="${VOG}"/>
// <column name="version" valueNumeric="0"/>
// </insert>
//</changeSet>
final String template = FileUtils.readFileToString(new File("C:\\ambiente-de-trabalho\\temp\\workaround\\template.txt"));
// source.txt content example
//300;EFFECT_BIODIVERSITEIT_VW_VRAAG;Aantasting kenmerken SBZ
//2500;EFFECT_OMGEVING_VW_FORM;Effect op de omgeving
//1630;FO2019_ACTIE_OVERZICHT_BS_FORM;ACTIES EN OVERZICHT
//1631;FO2019_ACTIE_OVERZICHT_BS_VAST;Acties en overzicht
//744;FO2019_BESLISSING_FORM;Beslissing
final BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\ambiente-de-trabalho\\temp\\workaround\\source.txt"));
Integer i = 1;
String line = bufferedReader.readLine();
while(line != null) {
String[] formulierOnderdeelArray = line.split(";");
Map<String,String> map = new HashMap<>();
map.put("AARD", formulierOnderdeelArray[1]);
map.put("DESC", formulierOnderdeelArray[2]);
map.put("VOG", formulierOnderdeelArray[0]);
map.put("COUNTER", i.toString()); i++;
StrSubstitutor sub = new StrSubstitutor(map);
String result = sub.replace(template);
System.out.println(result);
line = bufferedReader.readLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment