BrmoFramework.java

  1. package nl.b3p.brmo.loader;

  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.math.BigInteger;
  7. import java.sql.Connection;
  8. import java.sql.SQLException;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.zip.ZipEntry;
  12. import java.util.zip.ZipInputStream;
  13. import javax.sql.DataSource;
  14. import javax.xml.bind.JAXBException;
  15. import nl.b3p.brmo.loader.checks.AfgifteChecker;
  16. import nl.b3p.brmo.loader.entity.Bericht;
  17. import nl.b3p.brmo.loader.entity.LaadProces;
  18. import nl.b3p.brmo.loader.updates.UpdateProcess;
  19. import nl.b3p.brmo.loader.util.BrmoDuplicaatLaadprocesException;
  20. import nl.b3p.brmo.loader.util.BrmoException;
  21. import nl.b3p.brmo.loader.util.BrmoLeegBestandException;
  22. import nl.b3p.brmo.loader.util.TopNLRsgbTransformer;
  23. import nl.b3p.jdbc.util.converter.GeometryJdbcConverter;
  24. import nl.b3p.jdbc.util.converter.GeometryJdbcConverterFactory;
  25. import nl.b3p.topnl.TopNLType;
  26. import org.apache.commons.dbutils.DbUtils;
  27. import org.apache.commons.dbutils.QueryRunner;
  28. import org.apache.commons.dbutils.handlers.ScalarHandler;
  29. import org.apache.commons.io.input.CloseShieldInputStream;
  30. import org.apache.commons.io.input.CountingInputStream;
  31. import org.apache.commons.logging.Log;
  32. import org.apache.commons.logging.LogFactory;

  33. /**
  34.  * BRMO framework.
  35.  *
  36.  * @author Matthijs Laan
  37.  */
  38. public class BrmoFramework {

  39.   private static final Log log = LogFactory.getLog(BrmoFramework.class);

  40.   public static final String BR_BRK2 = "brk2";
  41.   public static final String BR_NHR = "nhr";
  42.   public static final String BR_TOPNL = "topnl";
  43.   public static final String BR_BRP = "brp";
  44.   public static final String BR_GBAV = "gbav";
  45.   public static final String BR_WOZ = "woz";

  46.   public static final String XSL_BRK2 = "/xsl/brk2-snapshot-to-rsgb-xml.xsl";
  47.   public static final String XSL_NHR = "/xsl/nhr-to-rsgb-xml-3.0.xsl";
  48.   public static final String XSL_BRP = "/xsl/brp-to-rsgb-xml.xsl";
  49.   public static final String XSL_GBAV = "/xsl/gbav-to-rsgb-xml.xsl";
  50.   public static final String XSL_WOZ = "/xsl/woz-to-rsgb.xsl";

  51.   public static final String LAADPROCES_TABEL = "laadproces";
  52.   public static final String BERICHT_TABLE = "bericht";
  53.   public static final String JOB_TABLE = "job";
  54.   public static final String BRMO_METADATA_TABEL = "brmo_metadata";

  55.   private StagingProxy stagingProxy = null;
  56.   private final DataSource dataSourceRsgb;
  57.   private final DataSource dataSourceRsgbBrk;
  58.   private DataSource dataSourceRsgbBgt = null;
  59.   private final DataSource dataSourceStaging;
  60.   private DataSource dataSourceTopNL = null;
  61.   private boolean enablePipeline = false;
  62.   private Integer pipelineCapacity;
  63.   private boolean renewConnectionAfterCommit = false;
  64.   private boolean orderBerichten = true;
  65.   private String errorState = null;

  66.   public BrmoFramework(
  67.       DataSource dataSourceStaging, DataSource dataSourceRsgb, DataSource dataSourceRsgbBrk)
  68.       throws BrmoException {
  69.     if (dataSourceStaging != null) {
  70.       try {
  71.         stagingProxy = new StagingProxy(dataSourceStaging);
  72.       } catch (SQLException ex) {
  73.         throw new BrmoException(ex);
  74.       }
  75.     }
  76.     this.dataSourceStaging = dataSourceStaging;
  77.     this.dataSourceRsgb = dataSourceRsgb;
  78.     this.dataSourceRsgbBrk = dataSourceRsgbBrk;
  79.   }

  80.   public BrmoFramework(
  81.       DataSource dataSourceStaging,
  82.       DataSource dataSourceRsgb,
  83.       DataSource dataSourceRsgbBgt,
  84.       DataSource dataSourceTopNL,
  85.       DataSource dataSourceRsgbBrk)
  86.       throws BrmoException {
  87.     if (dataSourceStaging != null) {
  88.       try {
  89.         stagingProxy = new StagingProxy(dataSourceStaging);
  90.       } catch (SQLException ex) {
  91.         throw new BrmoException(ex);
  92.       }
  93.     }
  94.     this.dataSourceRsgb = dataSourceRsgb;
  95.     this.dataSourceRsgbBgt = dataSourceRsgbBgt;
  96.     this.dataSourceStaging = dataSourceStaging;
  97.     this.dataSourceTopNL = dataSourceTopNL;
  98.     this.dataSourceRsgbBrk = dataSourceRsgbBrk;
  99.   }

  100.   public void setDataSourceRsgbBgt(DataSource dataSourceRsgbBgt) {
  101.     this.dataSourceRsgbBgt = dataSourceRsgbBgt;
  102.   }

  103.   public void setDataSourceTopNL(DataSource dataSourceTopNL) {
  104.     this.dataSourceTopNL = dataSourceTopNL;
  105.   }

  106.   public String getStagingVersion() {
  107.     try {
  108.       return getVersion(dataSourceStaging);
  109.     } catch (SQLException ex) {
  110.       log.error("Versienummer kon niet uit de STAGING database worden gelezen.", ex);
  111.       return "";
  112.     }
  113.   }

  114.   public String getRsgbVersion() {
  115.     try {
  116.       return getVersion(dataSourceRsgb);
  117.     } catch (SQLException ex) {
  118.       log.error("Versienummer kon niet uit de RSGB database worden gelezen.", ex);
  119.       return "";
  120.     }
  121.   }

  122.   public String getRsgbBgtVersion() {
  123.     try {
  124.       return getVersion(dataSourceRsgbBgt);
  125.     } catch (SQLException ex) {
  126.       log.error("Versienummer kon niet uit de RSGBBGT database worden gelezen.", ex);
  127.       return "";
  128.     }
  129.   }

  130.   public String getRsgbBrkVersion() {
  131.     try {
  132.       return getVersion(dataSourceRsgbBrk);
  133.     } catch (SQLException ex) {
  134.       log.error("Versienummer kon niet uit de RSGB BRK database worden gelezen.", ex);
  135.       return "";
  136.     }
  137.   }

  138.   private String getVersion(DataSource dataSource) throws SQLException {
  139.     String sql =
  140.         "SELECT waarde FROM " + BrmoFramework.BRMO_METADATA_TABEL + " WHERE naam = 'brmoversie'";
  141.     final Connection c = dataSource.getConnection();
  142.     GeometryJdbcConverter geomToJdbc = GeometryJdbcConverterFactory.getGeometryJdbcConverter(c);
  143.     String o = new QueryRunner(geomToJdbc.isPmdKnownBroken()).query(c, sql, new ScalarHandler<>());
  144.     DbUtils.closeQuietly(c);
  145.     return o;
  146.   }

  147.   public void setEnablePipeline(boolean enablePipeline) {
  148.     this.enablePipeline = enablePipeline;
  149.   }

  150.   public void setRenewConnectionAfterCommit(boolean renewConnectionAfterCommit) {
  151.     this.renewConnectionAfterCommit = renewConnectionAfterCommit;
  152.   }

  153.   public void setTransformPipelineCapacity(int pipelineCapacity) {
  154.     this.pipelineCapacity = pipelineCapacity;
  155.   }

  156.   public void setBatchCapacity(int batchCapacity) {
  157.     if (stagingProxy != null) {
  158.       stagingProxy.setBatchCapacity(batchCapacity);
  159.     }
  160.   }

  161.   public void setLimitStandBerichtenToTransform(Integer limitStandBerichtenToTransform) {
  162.     if (stagingProxy != null) {
  163.       stagingProxy.setLimitStandBerichtenToTransform(limitStandBerichtenToTransform);
  164.     }
  165.   }

  166.   /**
  167.    * stel bericht sortering van berichten in.
  168.    *
  169.    * @param orderBerichten {@code false} voor stand, {@code true} voor mutaties
  170.    */
  171.   public void setOrderBerichten(boolean orderBerichten) {
  172.     this.orderBerichten = orderBerichten;
  173.   }

  174.   public boolean isOrderBerichten() {
  175.     return this.orderBerichten;
  176.   }

  177.   public void setErrorState(String errorState) {
  178.     this.errorState = errorState;
  179.   }

  180.   public void closeBrmoFramework() {
  181.     if (stagingProxy != null) {
  182.       stagingProxy.closeStagingProxy();
  183.     }
  184.     // rsgbProxy is thread and will be closed in thread
  185.   }

  186.   public Thread toRsgb() throws BrmoException {
  187.     return toRsgb((ProgressUpdateListener) null);
  188.   }

  189.   public Thread toRsgb(ProgressUpdateListener listener) throws BrmoException {
  190.     return toRsgb(Bericht.STATUS.STAGING_OK, listener);
  191.   }

  192.   public Thread toRsgb(Bericht.STATUS status, ProgressUpdateListener listener)
  193.       throws BrmoException {
  194.     RsgbProxy rsgbProxy =
  195.         new RsgbProxy(dataSourceRsgb, dataSourceRsgbBrk, stagingProxy, status, listener);
  196.     rsgbProxy.setEnablePipeline(enablePipeline);
  197.     if (pipelineCapacity != null) {
  198.       rsgbProxy.setPipelineCapacity(pipelineCapacity);
  199.     }
  200.     rsgbProxy.setRenewConnectionAfterCommit(renewConnectionAfterCommit);
  201.     rsgbProxy.setOrderBerichten(orderBerichten);
  202.     rsgbProxy.setErrorState(errorState);
  203.     Thread t = new Thread(rsgbProxy);
  204.     t.start();
  205.     return t;
  206.   }

  207.   /**
  208.    * @param mode geeft aan wat ids zijn (laadprocessen of berichten)
  209.    * @param ids array van ids
  210.    * @param listener voortgangs listener
  211.    * @return running transformatie thread
  212.    * @throws BrmoException if any
  213.    */
  214.   public Thread toRsgb(
  215.       RsgbProxy.BerichtSelectMode mode, long[] ids, ProgressUpdateListener listener)
  216.       throws BrmoException {
  217.     String soort = "";
  218.     if (mode == RsgbProxy.BerichtSelectMode.BY_LAADPROCES) {
  219.       try {
  220.         soort = stagingProxy.getLaadProcesById(ids[0]).getSoort();
  221.       } catch (SQLException ex) {
  222.         throw new BrmoException(ex);
  223.       }
  224.     }

  225.     Runnable worker;
  226.     if (TopNLType.isTopNLType(soort)) {
  227.       try {
  228.         worker = new TopNLRsgbTransformer(dataSourceTopNL, stagingProxy, ids, listener);
  229.       } catch (JAXBException | SQLException ex) {
  230.         throw new BrmoException("Probleem met TopNL parser initialiseren: ", ex);
  231.       }
  232.     } else {
  233.       worker = new RsgbProxy(dataSourceRsgb, dataSourceRsgbBrk, stagingProxy, mode, ids, listener);
  234.       ((RsgbProxy) worker).setEnablePipeline(enablePipeline);
  235.       if (pipelineCapacity != null) {
  236.         ((RsgbProxy) worker).setPipelineCapacity(pipelineCapacity);
  237.       }
  238.       ((RsgbProxy) worker).setRenewConnectionAfterCommit(renewConnectionAfterCommit);
  239.       ((RsgbProxy) worker).setOrderBerichten(orderBerichten);
  240.       ((RsgbProxy) worker).setErrorState(errorState);
  241.     }
  242.     Thread t = new Thread(worker);
  243.     t.start();
  244.     return t;
  245.   }

  246.   public Thread toRsgb(UpdateProcess updateProcess, ProgressUpdateListener listener)
  247.       throws BrmoException {
  248.     RsgbProxy rsgbProxy =
  249.         new RsgbProxy(dataSourceRsgb, dataSourceRsgbBrk, stagingProxy, updateProcess, listener);
  250.     rsgbProxy.setEnablePipeline(enablePipeline);
  251.     if (pipelineCapacity != null) {
  252.       rsgbProxy.setPipelineCapacity(pipelineCapacity);
  253.     }
  254.     rsgbProxy.setRenewConnectionAfterCommit(renewConnectionAfterCommit);
  255.     rsgbProxy.setOrderBerichten(orderBerichten);
  256.     rsgbProxy.setErrorState(errorState);
  257.     Thread t = new Thread(rsgbProxy);
  258.     t.start();
  259.     return t;
  260.   }

  261.   public void delete(Long id) throws BrmoException {
  262.     if (id != null) {
  263.       try {
  264.         stagingProxy.deleteByLaadProcesId(id);
  265.       } catch (SQLException ex) {
  266.         throw new BrmoException(ex);
  267.       }
  268.     }
  269.   }

  270.   public List<LaadProces> listLaadProcessen() throws BrmoException {
  271.     try {
  272.       return stagingProxy.getLaadProcessen();
  273.     } catch (SQLException ex) {
  274.       throw new BrmoException(ex);
  275.     }
  276.   }

  277.   public List<Bericht> listBerichten() throws BrmoException {
  278.     try {
  279.       return stagingProxy.getBerichten();
  280.     } catch (SQLException ex) {
  281.       throw new BrmoException(ex);
  282.     }
  283.   }

  284.   /**
  285.    * @param type basis registratie type
  286.    * @param fileName bestand
  287.    * @throws BrmoException als er een fout optreed tijdens verwerking
  288.    * @deprecated gebruik van de variant met automatischProces ID heeft de voorkeur
  289.    * @see #loadFromFile(java.lang.String, java.lang.String, java.lang.Long)
  290.    */
  291.   @Deprecated
  292.   public void loadFromFile(String type, String fileName) throws BrmoException {
  293.     loadFromFile(type, fileName, null);
  294.   }

  295.   /**
  296.    * @see #loadFromFile(java.lang.String, java.lang.String,
  297.    *     nl.b3p.brmo.loader.ProgressUpdateListener, Long)
  298.    * @param type basis registratie type
  299.    * @param fileName bestand
  300.    * @param automatischProces id van automatisch proces dat deze functie aanroept
  301.    * @throws BrmoException als er een fout optreed tijdens verwerking
  302.    */
  303.   public void loadFromFile(String type, String fileName, Long automatischProces)
  304.       throws BrmoException {
  305.     try {
  306.       loadFromFile(type, fileName, null, automatischProces);
  307.     } catch (Exception e) {
  308.       if (e instanceof BrmoException) {
  309.         throw (BrmoException) e;
  310.       } else {
  311.         throw new BrmoException("Fout bij loaden basisregistratie gegevens", e);
  312.       }
  313.     }
  314.   }

  315.   /**
  316.    * laden van BR data uit een bestand. <br>
  317.    * NB na gebruik zelf de database verbinding sluiten / opruimen met {@link #closeBrmoFramework()}.
  318.    *
  319.    * @param type basis registratie type
  320.    * @param fileName bestand
  321.    * @param listener voortgangsmonitor
  322.    * @param automatischProces id van automatisch proces dat deze functie aanroept
  323.    * @throws BrmoException als er een fout optreed tijdens verwerking
  324.    */
  325.   public void loadFromFile(
  326.       String type, String fileName, final ProgressUpdateListener listener, Long automatischProces)
  327.       throws BrmoException {
  328.     try {
  329.       if (fileName.toLowerCase().endsWith(".zip")) {
  330.         log.info("Openen ZIP bestand " + fileName);
  331.         ZipInputStream zip = null;
  332.         try {
  333.           File f = new File(fileName);
  334.           if (listener != null) {
  335.             listener.total(f.length());
  336.           }
  337.           CountingInputStream zipCis =
  338.               new CountingInputStream(new FileInputStream(f)) {
  339.                 @Override
  340.                 protected synchronized void afterRead(int n) throws IOException {
  341.                   super.afterRead(n);
  342.                   if (listener != null) {
  343.                     listener.progress(getByteCount());
  344.                   }
  345.                 }
  346.               };
  347.           zip = new ZipInputStream(zipCis);
  348.           ZipEntry entry = zip.getNextEntry();
  349.           while (entry != null) {
  350.             if (!entry.getName().toLowerCase().endsWith(".xml")) {
  351.               log.warn("Overslaan zip entry geen XML: " + entry.getName());
  352.             } else {
  353.               log.info("Lezen XML bestand uit zip: " + entry.getName());
  354.               stagingProxy.loadBr(
  355.                   CloseShieldInputStream.wrap(zip),
  356.                   type,
  357.                   fileName + "/" + entry.getName(),
  358.                   null,
  359.                   null,
  360.                   automatischProces);
  361.             }
  362.             entry = zip.getNextEntry();
  363.           }
  364.         } finally {
  365.           if (zip != null) {
  366.             zip.close();
  367.           }
  368.         }
  369.         log.info("Klaar met ZIP bestand " + fileName);
  370.       } else {
  371.         File f = new File(fileName);
  372.         if (listener != null) {
  373.           listener.total(f.length());
  374.         }

  375.         try (FileInputStream fis = new FileInputStream(fileName)) {
  376.           stagingProxy.loadBr(fis, type, fileName, null, listener, automatischProces);
  377.         }
  378.       }
  379.     } catch (Exception e) {
  380.       if (e instanceof BrmoException) {
  381.         throw (BrmoException) e;
  382.       } else {
  383.         throw new BrmoException("Fout bij loaden basisregistratie gegevens", e);
  384.       }
  385.     }
  386.   }

  387.   /**
  388.    * laden van BR data uit een stream.
  389.    *
  390.    * @param type type registratie, bijv. {@value BrmoFramework#BR_BRK2}
  391.    * @param stream datastream
  392.    * @param fileName te gebruiken bestandsnaam om laadproces te identificeren
  393.    * @throws BrmoException als er een algemene fout optreed
  394.    * @throws BrmoDuplicaatLaadprocesException als het "bestand" {@code fileName} al geladen is
  395.    * @throws BrmoLeegBestandException als het "bestand" {@code fileName} leeg is
  396.    * @deprecated probeer de variant met automatischProces argument te gebruiken
  397.    * @see #loadFromStream(String, InputStream, String, Long)
  398.    */
  399.   @Deprecated
  400.   public void loadFromStream(String type, InputStream stream, String fileName)
  401.       throws BrmoException, BrmoDuplicaatLaadprocesException, BrmoLeegBestandException {
  402.     this.loadFromStream(type, stream, fileName, (Long) null);
  403.   }

  404.   /**
  405.    * laden van BR data uit een stream.
  406.    *
  407.    * @param type type registratie, bijv. {@value BrmoFramework#BR_BRK2}
  408.    * @param stream datastream
  409.    * @param fileName te gebruiken bestandsnaam om laadproces te identificeren
  410.    * @param automatischProces id van automatisch proces dat deze functie aanroept
  411.    * @throws BrmoException als er een algemene fout optreed
  412.    * @throws BrmoDuplicaatLaadprocesException als het "bestand" {@code fileName} al geladen is
  413.    * @throws BrmoLeegBestandException als het "bestand" {@code fileName} leeg is
  414.    */
  415.   public void loadFromStream(
  416.       String type, InputStream stream, String fileName, Long automatischProces)
  417.       throws BrmoException, BrmoDuplicaatLaadprocesException, BrmoLeegBestandException {
  418.     try {
  419.       stagingProxy.loadBr(stream, type, fileName, null, null, automatischProces);
  420.     } catch (Exception e) {
  421.       if (e instanceof BrmoDuplicaatLaadprocesException) {
  422.         throw (BrmoDuplicaatLaadprocesException) e;
  423.       }
  424.       if (e instanceof BrmoLeegBestandException) {
  425.         throw (BrmoLeegBestandException) e;
  426.       }
  427.       throw new BrmoException("Fout bij laden " + type + " berichten uit bestand " + fileName, e);
  428.     }
  429.   }

  430.   /**
  431.    * laden van BR data uit een stream.
  432.    *
  433.    * @param type type registratie, bijv. {@value BrmoFramework#BR_BRK2}
  434.    * @param stream datastream
  435.    * @param fileName te gebruiken bestandsnaam om laadproces te identificeren
  436.    * @param d bestandsdatum
  437.    * @throws BrmoException als er een algemene fout optreed
  438.    * @throws BrmoDuplicaatLaadprocesException als het "bestand" {@code fileName} al geladen is
  439.    * @throws BrmoLeegBestandException als het "bestand" {@code fileName} leeg is
  440.    * @deprecated Gebruik {@link #loadFromStream(String, InputStream, String, Date, Long)}
  441.    */
  442.   @Deprecated
  443.   public void loadFromStream(String type, InputStream stream, String fileName, Date d)
  444.       throws BrmoException, BrmoDuplicaatLaadprocesException, BrmoLeegBestandException {
  445.     loadFromStream(type, stream, fileName, d, null);
  446.   }

  447.   /**
  448.    * laden van BR data uit een stream.
  449.    *
  450.    * @param type type registratie, bijv. {@value BrmoFramework#BR_BRK2}
  451.    * @param stream datastream
  452.    * @param fileName te gebruiken bestandsnaam om laadproces te identificeren
  453.    * @param d bestandsdatum
  454.    * @param automatischProces id van automatisch proces dat deze functie aanroept
  455.    * @throws BrmoException als er een algemene fout optreed
  456.    * @throws BrmoDuplicaatLaadprocesException als het "bestand" {@code fileName} al geladen is
  457.    * @throws BrmoLeegBestandException als het "bestand" {@code fileName} leeg is
  458.    */
  459.   public void loadFromStream(
  460.       String type, InputStream stream, String fileName, Date d, Long automatischProces)
  461.       throws BrmoException, BrmoDuplicaatLaadprocesException, BrmoLeegBestandException {
  462.     try {
  463.       stagingProxy.loadBr(stream, type, fileName, d, null, automatischProces);
  464.     } catch (Exception e) {
  465.       if (e instanceof BrmoDuplicaatLaadprocesException) {
  466.         throw (BrmoDuplicaatLaadprocesException) e;
  467.       }
  468.       if (e instanceof BrmoLeegBestandException) {
  469.         throw (BrmoLeegBestandException) e;
  470.       }
  471.       throw new BrmoException("Fout bij laden " + type + " berichten uit bestand " + fileName, e);
  472.     }
  473.   }

  474.   /**
  475.    * laden van BR data uit een stream.
  476.    *
  477.    * @param type type registratie, bijv. {@value BrmoFramework#BR_BRK2}
  478.    * @param stream datastream
  479.    * @param fileName te gebruiken bestandsnaam om laadproces te identificeren
  480.    * @param listener mag {@code null} zijn
  481.    * @param automatischProces id van automatisch proces dat deze functie aanroept
  482.    * @throws BrmoException als er een algemene fout optreed
  483.    * @throws BrmoDuplicaatLaadprocesException als het "bestand" {@code fileName} al geladen is
  484.    * @throws BrmoLeegBestandException als het "bestand" {@code fileName} leeg is
  485.    */
  486.   public void loadFromStream(
  487.       String type,
  488.       InputStream stream,
  489.       String fileName,
  490.       ProgressUpdateListener listener,
  491.       Long automatischProces)
  492.       throws BrmoException, BrmoDuplicaatLaadprocesException, BrmoLeegBestandException {
  493.     try {
  494.       stagingProxy.loadBr(stream, type, fileName, null, listener, automatischProces);
  495.     } catch (Exception e) {
  496.       if (e instanceof BrmoDuplicaatLaadprocesException) {
  497.         throw (BrmoDuplicaatLaadprocesException) e;
  498.       }
  499.       if (e instanceof BrmoLeegBestandException) {
  500.         throw (BrmoLeegBestandException) e;
  501.       }
  502.       throw new BrmoException("Fout bij laden " + type + " berichten uit bestand " + fileName, e);
  503.     }
  504.   }

  505.   public void emptyStagingDb() throws BrmoException {
  506.     try {
  507.       stagingProxy.emptyStagingDb();
  508.     } catch (SQLException ex) {
  509.       throw new BrmoException(ex);
  510.     }
  511.   }

  512.   public Long getLaadProcesIdByFileName(String name) throws BrmoException {
  513.     Long id = null;
  514.     LaadProces lp;
  515.     try {
  516.       lp = stagingProxy.getLaadProcesByFileName(name);
  517.     } catch (SQLException ex) {
  518.       throw new BrmoException(ex);
  519.     }

  520.     if (lp != null) {
  521.       id = lp.getId();
  522.     }

  523.     return id;
  524.   }

  525.   public Bericht getBerichtById(long id) throws BrmoException {
  526.     try {
  527.       return stagingProxy.getBerichtById(id);
  528.     } catch (SQLException ex) {
  529.       throw new BrmoException(ex);
  530.     }
  531.   }

  532.   public LaadProces getLaadProcesById(long id) throws BrmoException {
  533.     try {
  534.       return stagingProxy.getLaadProcesById(id);
  535.     } catch (SQLException ex) {
  536.       throw new BrmoException(ex);
  537.     }
  538.   }

  539.   public List<Bericht> getBerichten(
  540.       int page,
  541.       int start,
  542.       int limit,
  543.       String sort,
  544.       String dir,
  545.       String filterSoort,
  546.       String filterStatus)
  547.       throws BrmoException {

  548.     try {
  549.       return stagingProxy.getBerichten(page, start, limit, sort, dir, filterSoort, filterStatus);
  550.     } catch (SQLException ex) {
  551.       throw new BrmoException(ex);
  552.     }
  553.   }

  554.   public List<LaadProces> getLaadprocessen(
  555.       int page,
  556.       int start,
  557.       int limit,
  558.       String sort,
  559.       String dir,
  560.       String filterSoort,
  561.       String filterStatus)
  562.       throws BrmoException {

  563.     try {
  564.       return stagingProxy.getLaadprocessen(
  565.           page, start, limit, sort, dir, filterSoort, filterStatus);
  566.     } catch (SQLException ex) {
  567.       throw new BrmoException(ex);
  568.     }
  569.   }

  570.   public Long[] getLaadProcessenIds(
  571.       String sort, String dir, String filterSoort, String filterStatus) throws BrmoException {
  572.     try {
  573.       return stagingProxy.getLaadProcessenIds(sort, dir, filterSoort, filterStatus);
  574.     } catch (SQLException ex) {
  575.       throw new BrmoException(ex);
  576.     }
  577.   }

  578.   public long getCountBerichten(String filterSoort, String filterStatus) throws BrmoException {
  579.     try {
  580.       return stagingProxy.getCountBerichten(filterSoort, filterStatus);
  581.     } catch (SQLException ex) {
  582.       throw new BrmoException(ex);
  583.     }
  584.   }

  585.   public long getCountLaadProcessen(String filterSoort, String filterStatus) throws BrmoException {
  586.     try {
  587.       return stagingProxy.getCountLaadProces(filterSoort, filterStatus);
  588.     } catch (SQLException ex) {
  589.       throw new BrmoException(ex);
  590.     }
  591.   }

  592.   public long getCountJob() throws BrmoException {
  593.     try {
  594.       return stagingProxy.getCountJob();
  595.     } catch (SQLException ex) {
  596.       throw new BrmoException(ex);
  597.     }
  598.   }

  599.   /**
  600.    * update laadproces (GDS2 afgifte) metadata.
  601.    *
  602.    * @param lpId laadproces id
  603.    * @param klantafgiftenummer klantafgiftenummer
  604.    * @param contractafgiftenummer contractafgiftenummer
  605.    * @param artikelnummer artikelnummer
  606.    * @param contractnummer contractnummer
  607.    * @param afgifteid afgifteid
  608.    * @param afgiftereferentie afgiftereferentie
  609.    * @param bestandsreferentie bestandsreferentie
  610.    * @param beschikbaar_tot beschikbaar_tot
  611.    * @throws BrmoException if any
  612.    */
  613.   public void updateLaadProcesMeta(
  614.       Long lpId,
  615.       BigInteger klantafgiftenummer,
  616.       BigInteger contractafgiftenummer,
  617.       String artikelnummer,
  618.       String contractnummer,
  619.       String afgifteid,
  620.       String afgiftereferentie,
  621.       String bestandsreferentie,
  622.       Date beschikbaar_tot)
  623.       throws BrmoException {
  624.     try {
  625.       stagingProxy.updateLaadProcesMeta(
  626.           lpId,
  627.           klantafgiftenummer,
  628.           contractafgiftenummer,
  629.           artikelnummer,
  630.           contractnummer,
  631.           afgifteid,
  632.           afgiftereferentie,
  633.           bestandsreferentie,
  634.           beschikbaar_tot);
  635.     } catch (SQLException ex) {
  636.       throw new BrmoException(ex);
  637.     }
  638.   }

  639.   public File checkAfgiftelijst(String bestandsnaam, String output) throws IOException {
  640.     File f = new File(bestandsnaam);
  641.     return checkAfgiftelijst(bestandsnaam, new FileInputStream(f), new File(output));
  642.   }

  643.   public File checkAfgiftelijst(String bestandsnaam, InputStream is, File output)
  644.       throws IOException {
  645.     AfgifteChecker checker = new AfgifteChecker();
  646.     checker.init(is, stagingProxy);
  647.     checker.check();
  648.     return checker.getResults(bestandsnaam, output);
  649.   }
  650. }