Skip to content

Commit

Permalink
[BRMO-225] BRK2 GDS2 ophalen proces
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins committed Nov 24, 2022
1 parent 6a228f5 commit 75c3804
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import static nl.b3p.brmo.persistence.staging.AutomatischProces.ProcessingStatus.WAITING;

/**
* Directory scanner for BRK berichten in xml formaat.
* Directory scanner for BRK 2 berichten in xml formaat.
*
* @author Mark Prins
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
import nl.b3p.brmo.loader.BrmoFramework;
import nl.b3p.brmo.loader.entity.Brk2Bericht;
import nl.b3p.brmo.loader.entity.BrkBericht;
import nl.b3p.brmo.loader.util.BrmoDuplicaatLaadprocesException;
import nl.b3p.brmo.loader.util.BrmoException;
import nl.b3p.brmo.loader.util.BrmoLeegBestandException;
import nl.b3p.brmo.loader.xml.Brk2SnapshotXMLReader;
import nl.b3p.brmo.loader.xml.BrkSnapshotXMLReader;
import nl.b3p.brmo.persistence.staging.AutomatischProces;
import static nl.b3p.brmo.persistence.staging.AutomatischProces.LOG_NEWLINE;
Expand Down Expand Up @@ -81,7 +83,6 @@
import org.stripesstuff.stripersist.Stripersist;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;

Expand Down Expand Up @@ -181,7 +182,7 @@ public void execute(ProgressUpdateListener listener) {
}

// datum tijd parsen/instellen
GregorianCalendar vanaf = null;
GregorianCalendar vanaf;
GregorianCalendar tot = getDatumTijd(ClobElement.nullSafeGet(this.config.getConfig().get("totdatum")));
String sVanaf = ClobElement.nullSafeGet(this.config.getConfig().get("vanafdatum"));
if (tot != null && ("-1".equals(sVanaf) | "-2".equals(sVanaf) | "-3".equals(sVanaf))) {
Expand All @@ -191,7 +192,7 @@ public void execute(ProgressUpdateListener listener) {
}

List<AfgifteType> afgiftes = new ArrayList<>();
BestandenlijstOpvragenResponse response = null;
BestandenlijstOpvragenResponse response;
int hoogsteKlantAfgifteNummer = -1;

Gds2AfgifteServiceV20170401 gds2 = initGDS2();
Expand Down Expand Up @@ -345,11 +346,7 @@ public void execute(ProgressUpdateListener listener) {
}

//bereken of einde van periode bereikt is
if (currentMoment.before(tot) && loopNum < loopMax) {
morePeriods2Process = true;
} else {
morePeriods2Process = false;
}
morePeriods2Process = currentMoment.before(tot) && loopNum < loopMax;
}

verzoek.setAfgifteSelectieCriteria(criteria);
Expand Down Expand Up @@ -436,12 +433,15 @@ public void execute(ProgressUpdateListener listener) {

final String soort = this.config.getConfig().getOrDefault("gds2_br_soort", new ClobElement("brk")).getValue();
switch (soort) {
case "brk2":
verwerkAfgiftes(afgiftes, getCertificaatBaseURL(response.getAntwoord()), soort);
break;
case "brk":
verwerkAfgiftes(afgiftes, getCertificaatBaseURL(response.getAntwoord()));
verwerkAfgiftes(afgiftes, getCertificaatBaseURL(response.getAntwoord()), soort);
break;
case "bag":
// bag heeft geen contractnummer
verwerkAfgiftes(afgiftes, getAnoniemBaseURL(response.getAntwoord()));
verwerkAfgiftes(afgiftes, getAnoniemBaseURL(response.getAntwoord()), soort);
break;
default:
throw new BrmoException("Onbekende basisregistratie soort: " + soort);
Expand All @@ -456,6 +456,7 @@ public void execute(ProgressUpdateListener listener) {
if (e.getCause() != null) {
m += ", oorzaak: " + ExceptionUtils.getRootCauseMessage(e);
}
l.addLog(m);
l.exception(e);
} finally {
if (Stripersist.getEntityManager().getTransaction().getRollbackOnly()) {
Expand All @@ -474,7 +475,7 @@ private String getLaadprocesBestandsnaam(AfgifteType a) {
return a.getBestand().getBestandsnaam() + " (" + a.getAfgifteID() + ")";
}

private boolean isAfgifteAlGeladen(AfgifteType a, String url) {
private boolean isAfgifteAlGeladen(AfgifteType a) {
try {
Stripersist.getEntityManager().createQuery("select 1 from LaadProces lp where lp.bestand_naam = :n")
.setParameter("n", getLaadprocesBestandsnaam(a))
Expand All @@ -493,14 +494,16 @@ private boolean isAfgifteAlGeladen(AfgifteType a, String url) {
* @param a de afgifte uit het soap verzoek
* @param url te downloaden bestand
* @throws Exception if any
* @see #laadAfgifte(AfgifteType, String)
* @see #laadAfgifte(AfgifteType, String, String)
* @deprecated BAG wordt niet meer via GDS2 aangeboden
*/
@Deprecated
private void laadBagAfgifte(AfgifteType a, String url) throws Exception {
String msg = "Downloaden " + url;
l.updateStatus(msg);
l.addLog(msg);

InputStream input = null;
InputStream input;
int attempt = 0;
while (true) {
try {
Expand Down Expand Up @@ -591,7 +594,7 @@ private void laadBagAfgifte(AfgifteType a, String url) throws Exception {
brmo.closeBrmoFramework();
}

private Bericht laadAfgifte(AfgifteType a, String url) throws Exception {
private Bericht laadAfgifte(AfgifteType a, String url, String brkSoort) throws Exception {
EntityManager em = Stripersist.getEntityManager();
String msg = "Downloaden " + url;
l.updateStatus(msg);
Expand Down Expand Up @@ -641,7 +644,7 @@ private Bericht laadAfgifte(AfgifteType a, String url) throws Exception {
break;
}
}
lp.setSoort("brk");
lp.setSoort(brkSoort);
lp.setStatus(LaadProces.STATUS.STAGING_OK);
lp.setStatus_datum(new Date());
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
Expand All @@ -651,7 +654,7 @@ private Bericht laadAfgifte(AfgifteType a, String url) throws Exception {
Bericht b = new Bericht();
b.setLaadprocesid(lp);
b.setDatum(lp.getBestand_datum());
b.setSoort("brk");
b.setSoort(brkSoort);
b.setStatus_datum(new Date());

ZipInputStream zip = new ZipInputStream(new ByteArrayInputStream(bos.toByteArray()));
Expand All @@ -674,22 +677,37 @@ private Bericht laadAfgifte(AfgifteType a, String url) throws Exception {
log.debug("Dump xml bericht naar: " + fName);
IOUtils.write(b.getBr_orgineel_xml(), new FileWriter(fName, StandardCharsets.UTF_8));
}

try {
BrkSnapshotXMLReader reader = new BrkSnapshotXMLReader(new ByteArrayInputStream(b.getBr_orgineel_xml().getBytes(StandardCharsets.UTF_8)));
BrkBericht bericht = reader.next();
String brXML;
Date brDatum;
Integer brVolgordeNummer;
String brObjectRef;
if (BrmoFramework.BR_BRK.equals(brkSoort)) {
BrkSnapshotXMLReader reader = new BrkSnapshotXMLReader(new ByteArrayInputStream(b.getBr_orgineel_xml().getBytes(StandardCharsets.UTF_8)));
BrkBericht parsedBericht = reader.next();
brXML = parsedBericht.getBrXml();
brDatum = parsedBericht.getDatum();
brVolgordeNummer = parsedBericht.getVolgordeNummer();
brObjectRef = parsedBericht.getObjectRef();
} else {
Brk2SnapshotXMLReader reader2 = new Brk2SnapshotXMLReader(new ByteArrayInputStream(b.getBr_orgineel_xml().getBytes(StandardCharsets.UTF_8)));
Brk2Bericht parsedBericht = reader2.next();
brXML = parsedBericht.getBrXml();
brDatum = parsedBericht.getDatum();
brVolgordeNummer = parsedBericht.getVolgordeNummer();
brObjectRef = parsedBericht.getObjectRef();
}

if (bericht.getDatum() != null) {
b.setDatum(bericht.getDatum());
if (null != brDatum) {
b.setDatum(brDatum);
}
b.setBr_xml(bericht.getBrXml());
b.setVolgordenummer(bericht.getVolgordeNummer());
b.setBr_xml(brXML);
b.setVolgordenummer(brVolgordeNummer);

//Als objectRef niet opgehaald kan worden,dan kan het
//bericht niet verwerkt worden.
String objectRef = bericht.getObjectRef();
if (objectRef != null && !objectRef.isEmpty()) {
b.setObject_ref(bericht.getObjectRef());
if (null != brObjectRef && !brObjectRef.isBlank()) {
b.setObject_ref(brObjectRef);
b.setStatus(Bericht.STATUS.STAGING_OK);
b.setOpmerking("Klaar voor verwerking.");
} else {
Expand All @@ -700,7 +718,7 @@ private Bericht laadAfgifte(AfgifteType a, String url) throws Exception {
b.setStatus(Bericht.STATUS.STAGING_NOK);
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
b.setOpmerking("Fout bij parsen BRK bericht: " + sw.toString());
b.setOpmerking("Fout bij parsen BRK bericht: " + sw);
}
try {
em.persist(lp);
Expand Down Expand Up @@ -787,26 +805,25 @@ public static boolean doorsturenBericht(AutomatischProces proces, ProgressUpdate
* @param afgiftes lijst afgiftes
* @throws Exception if any
*/
private void verwerkAfgiftes(List<AfgifteType> afgiftes, BaseURLType baseUrl) throws Exception {
private void verwerkAfgiftes(List<AfgifteType> afgiftes, BaseURLType baseUrl, final String soort) throws Exception {
int filterAlVerwerkt = 0;
int aantalGeladen = 0;
int aantalDoorgestuurd = 0;
int progress = 0;
List<Long> geladenBerichtIds = new ArrayList();
List<Long> geladenBerichtIds = new ArrayList<>();
String doorsturenUrl = ClobElement.nullSafeGet(this.config.getConfig().get("delivery_endpoint"));
final String soort = this.config.getConfig().getOrDefault("gds2_br_soort", new ClobElement("brk")).getValue();

for (AfgifteType a : afgiftes) {
String url = getAfgifteURL(a, baseUrl);

if (url != null) {
if (isAfgifteAlGeladen(a, url)) {
if (null != url && !url.isBlank()) {
if (isAfgifteAlGeladen(a)) {
filterAlVerwerkt++;
} else if (soort.equalsIgnoreCase("bag")) {
} else if (soort.equalsIgnoreCase(BrmoFramework.BR_BAG)) {
laadBagAfgifte(a, url);
aantalGeladen++;
} else {
Bericht b = laadAfgifte(a, url);
Bericht b = laadAfgifte(a, url, soort);
if (b != null && doorsturenUrl != null) {
geladenBerichtIds.add(b.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
<tr><td>Hoogste klantafgiftenummer:</td><td><c:out value="${actionBean.config['hoogste_afgiftenummer']}"/></td></tr>
<tr>
<td>Bericht soort:</td>
<td><stripes:select name="config['gds2_br_soort']" value="brk">
<td><stripes:select name="config['gds2_br_soort']" value="brk2">
<stripes:option value="brk2">BRK 2</stripes:option>
<stripes:option value="brk">BRK</stripes:option>
<stripes:option value="bag">BAG</stripes:option>
</stripes:select>
Expand Down
12 changes: 6 additions & 6 deletions brmo-service/src/main/webapp/WEB-INF/jsp/bestand/form.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
<td>
<stripes:select name="basisregistratie">
<stripes:option/>
<stripes:option value="bag">bag</stripes:option>
<stripes:option value="brk2">brk 2</stripes:option>
<stripes:option value="brk">brk</stripes:option>
<stripes:option value="nhr">nhr</stripes:option>
<stripes:option value="gbav">gbav</stripes:option>
<stripes:option value="woz">woz</stripes:option>
<stripes:option value="bag">BAG</stripes:option>
<stripes:option value="brk2">BRK 2</stripes:option>
<stripes:option value="brk">BRK</stripes:option>
<stripes:option value="nhr">nHR</stripes:option>
<stripes:option value="gbav">GBAV</stripes:option>
<stripes:option value="woz">WOZ</stripes:option>
</stripes:select>
</td>
</tr>
Expand Down

0 comments on commit 75c3804

Please sign in to comment.