SHARE
TWEET

Untitled

a guest Mar 18th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package be.schaubroeck.golf.liquibase.corrections;
  2.  
  3. import org.apache.commons.io.FileUtils;
  4. import org.apache.commons.lang3.text.StrSubstitutor;
  5.  
  6. import java.io.BufferedReader;
  7. import java.io.File;
  8. import java.io.FileReader;
  9. import java.io.IOException;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12.  
  13. public class LiquibaseGeneratorForFormulierOnderdeel {
  14.  
  15.  
  16.     public static void main(String[] args) throws IOException {
  17.  
  18.         // template.txt content example
  19.         //<changeSet id="201903121604_dfr_add_formulier_onderdeel_aards_${COUNTER}" author="dfr">
  20.         //  <preConditions onFail="MARK_RAN">
  21.         //      <sqlCheck expectedResult="0">
  22.         //          SELECT COUNT(1) FROM golf_formulier_onderdeel_aard WHERE aard = '${AARD}';
  23.         //      </sqlCheck>
  24.         //  </preConditions>
  25.         //  <insert tableName="golf_formulier_onderdeel_aard">
  26.         //      <column name="id" valueComputed="(SELECT COALESCE(MAX(id) + 1, 1) FROM (SELECT * FROM golf_formulier_onderdeel_aard) dt)"/>
  27.         //      <column name="aard" value="${AARD}"/>
  28.         //      <column name="naam" value="${DESC}"/>
  29.         //      <column name="volg_nummer" valueNumeric="${VOG}"/>
  30.         //      <column name="version" valueNumeric="0"/>
  31.         //  </insert>
  32.         //</changeSet>      
  33.         final String template = FileUtils.readFileToString(new File("C:\\ambiente-de-trabalho\\temp\\workaround\\template.txt"));
  34.  
  35.         // source.txt content example
  36.         //300;EFFECT_BIODIVERSITEIT_VW_VRAAG;Aantasting kenmerken SBZ
  37.         //2500;EFFECT_OMGEVING_VW_FORM;Effect op de omgeving
  38.         //1630;FO2019_ACTIE_OVERZICHT_BS_FORM;ACTIES EN OVERZICHT
  39.         //1631;FO2019_ACTIE_OVERZICHT_BS_VAST;Acties en overzicht
  40.         //744;FO2019_BESLISSING_FORM;Beslissing
  41.         final BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\ambiente-de-trabalho\\temp\\workaround\\source.txt"));
  42.  
  43.         Integer i = 1;
  44.         String line = bufferedReader.readLine();
  45.         while(line != null) {
  46.             String[] formulierOnderdeelArray = line.split(";");
  47.  
  48.             Map<String,String> map = new HashMap<>();
  49.             map.put("AARD", formulierOnderdeelArray[1]);
  50.             map.put("DESC", formulierOnderdeelArray[2]);
  51.             map.put("VOG", formulierOnderdeelArray[0]);
  52.             map.put("COUNTER", i.toString()); i++;
  53.  
  54.             StrSubstitutor sub = new StrSubstitutor(map);
  55.             String result = sub.replace(template);
  56.  
  57.             System.out.println(result);
  58.             line = bufferedReader.readLine();
  59.         }
  60.  
  61.  
  62.     }
  63.  
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top