Skip to content

Commit

Permalink
Gebruik de br_origineel_xml om de bestandsnaam van verwijderberichten…
Browse files Browse the repository at this point in the history
… te herstellen
  • Loading branch information
mprins committed Nov 5, 2019
1 parent 00bf83d commit 64caad5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,48 @@ public void init(InputStream input, StagingProxy staging) throws IOException{
}

public void check(){
// ga per afgifte langs of het bericht in de staging zit
for (Afgifte afgifte : afgiftes) {
afgiftes.forEach((afgifte) -> {
check(afgifte);
}
});
}


/**
* afgifte controle.
*
* @param afgifte de te controleren afgifte
*/
private void check(Afgifte afgifte){
try {
LaadProces lp = staging.getLaadProcesByRestoredFilename(afgifte.getBestandsnaam());

// kijk of afgifte bestaat in staging
if(lp != null){
// zo ja, haal status op en schrijf naar afgifte
if (lp != null) {
afgifte.setFoundInStaging(true);
processFoundLaadprocess(afgifte, lp);
}else{

// zo nee, herstel bestandsnamen, en kijk of het dan bestaat
// zo ja, haal status op en schrijf naar afgifte
// zo nee, schrijf status weg naar afgifte
}
} catch (SQLException ex) {
log.error("Error querying staging for laadproces for afgifte: " + afgifte.toString(), ex);
}

}

/**
* zoek de status van alle bijbehorende berichten op en leg die vast in de
* afgifte.
*
* @param afgifte de te controleren afgifte
* @param lp het laadproces waar de berichten bij zoeken
* @throws SQLException if any
*/
private void processFoundLaadprocess(Afgifte afgifte, LaadProces lp) throws SQLException{
List<Bericht> berichten = staging.getBerichtByLaadProces(lp);
Map<Bericht.STATUS, Integer> counts = afgifte.getStatussen();
for (Bericht bericht : berichten) {
berichten.stream().map((bericht) -> {
if(!counts.containsKey(bericht.getStatus())){
counts.put(bericht.getStatus(), 0);
}
counts.put(bericht.getStatus() ,counts.get(bericht.getStatus()) +1 );
}
return bericht;
}).forEachOrdered((bericht) -> {
counts.put(bericht.getStatus(), counts.get(bericht.getStatus()) + 1);
});
}

public File getResults(String input, String f) throws FileNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public Date getDatum() {

public String getRestoredFileName(Date bestanddatum, Integer volgordenummer){
try {
SimpleDateFormat output = new SimpleDateFormat("yyyyMMdd");
final SimpleDateFormat output = new SimpleDateFormat("yyyyMMdd");

String prefix = "BKE-MUTBX01";
String kadGemCode;
Expand All @@ -115,12 +115,19 @@ public String getRestoredFileName(Date bestanddatum, Integer volgordenummer){
String appartementsrechtVolgnummer;

String basePath = "/KadastraalObjectSnapshot/*[local-name()= 'Perceel' or local-name()='Appartementsrecht']/kadastraleAanduiding/";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(getBrXml())));
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(this.getBrXml())));

// in geval van een verwijderbericht is de "wordt" leeg, db_xml <empty/>
if (this.getBrXml().contains("<empty/>") && StringUtils.isNotBlank(this.getBrOrgineelXml())) {
// dan proberen om de db_origineel_xml te gebruiken.
basePath = "/Mutatie/kadastraalObject/AanduidingKadastraalObject/kadastraleAanduiding/";
doc = builder.parse(new InputSource(new StringReader(this.getBrOrgineelXml())));
}

XPathExpression expr = xpath.compile(basePath + "AKRKadastraleGemeenteCode/waarde/text()");
kadGemCode = expr.evaluate(doc);

Expand All @@ -132,11 +139,16 @@ public String getRestoredFileName(Date bestanddatum, Integer volgordenummer){

expr = xpath.compile(basePath + "appartementsrechtVolgnummer/text()");
appartementsrechtVolgnummer = expr.evaluate(doc);
if (!StringUtils.isEmpty(appartementsrechtVolgnummer)) {
if (StringUtils.isNotBlank(appartementsrechtVolgnummer)) {
appartementsrechtVolgnummer = "A" + appartementsrechtVolgnummer;
}

String filename = prefix + "-" + kadGemCode + sectie + perceelnummer + appartementsrechtVolgnummer + "-" + brkdatum + "-" + volgordenummer.toString() + ".zip";

String aanduiding = kadGemCode + sectie + perceelnummer + appartementsrechtVolgnummer;
log.debug("gevonden aanduiding voor herstelde bestandsnaam: " + aanduiding);
String filename = "bestandsnaam kon niet worden hersteld";
if (StringUtils.isNotBlank(aanduiding)) {
filename = prefix + "-" + aanduiding + "-" + brkdatum + "-" + volgordenummer.toString() + ".zip";
}
return filename;
} catch (ParserConfigurationException | XPathExpressionException | SAXException | IOException ex) {
log.error("Cannot create filename from xml: ", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class AdvancedFunctionsActionBean implements ActionBean, ProgressUpdateLi
private final String NHR_FIX_TYPERING = "Fix 'typering' en 'clazz' van nHR persoon";
private final String NHR_ARCHIVING = "Opschonen en archiveren van nHR berichten met status RSGB_OK, ouder dan 3 maanden";
private final String NHR_REMOVAL = "Verwijderen van nHR berichten met status ARCHIVE";
private final String BRK_HERSTEL_BESTANDSNAAM = "Bepaal de herstelde bestandsnaam van BRK laadprocessen";
private final String BRK_HERSTEL_BESTANDSNAAM = "Vul de 'herstelde bestandsnaam' van BRK laadprocessen";

private final boolean repairFirst = false;

Expand Down Expand Up @@ -221,7 +221,8 @@ public void populateAdvancedFunctionProcesses() {
new AdvancedFunctionProcess("Verwijderen van BAG berichten met status ARCHIVE", BrmoFramework.BR_BAG, Bericht.STATUS.ARCHIVE.toString()),
new AdvancedFunctionProcess(NHR_REMOVAL, BrmoFramework.BR_NHR, Bericht.STATUS.ARCHIVE.toString()),
new AdvancedFunctionProcess(BRK_VERWIJDEREN_NOGMAALS_UITVOEREN, BrmoFramework.BR_BRK, Bericht.STATUS.RSGB_OK.toString()),
new AdvancedFunctionProcess(NHR_FIX_TYPERING, BrmoFramework.BR_NHR, null), new AdvancedFunctionProcess(BRK_HERSTEL_BESTANDSNAAM, BrmoFramework.BR_BRK, "0")
new AdvancedFunctionProcess(NHR_FIX_TYPERING, BrmoFramework.BR_NHR, null),
new AdvancedFunctionProcess(BRK_HERSTEL_BESTANDSNAAM, BrmoFramework.BR_BRK, "0")
});
}

Expand Down Expand Up @@ -928,11 +929,11 @@ public Exception handle(ResultSet rs) throws SQLException {
while (rs.next()) {
try {
final Bericht bericht = processor.toBean(rs, Bericht.class);
// throws class cast exception want bericht is een instance van nl.b3p.brmo.loader.entity.Bericht
// String bestandsnaamHersteld = ((BrkBericht) bericht).getRestoredFileName(bericht.getDatum(), bericht.getVolgordeNummer());
final String bestandsnaamHersteld = (new BrkBericht(bericht.getBrXml()).getRestoredFileName(bericht.getDatum(), bericht.getVolgordeNummer()));
LOG.trace(String.format(
"Bijwerken bestand_naam_hersteld voor laadproces %d met waarde %s op basis van bericht %d",
final BrkBericht brkBericht = new BrkBericht(bericht.getBrXml());
brkBericht.setBrOrgineelXml(bericht.getBrOrgineelXml());
final String bestandsnaamHersteld = brkBericht.getRestoredFileName(bericht.getDatum(), bericht.getVolgordeNummer());
LOG.debug(String.format(
"Bijwerken bestand_naam_hersteld voor laadproces %d met waarde '%s' op basis van bericht %d",
bericht.getLaadProcesId(),
bestandsnaamHersteld,
bericht.getId())
Expand Down

0 comments on commit 64caad5

Please sign in to comment.