Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StUF-BG 2.04 / BRP bericht verwerking verbeteringen #588

Merged
merged 32 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8385ac7
voeg een logfile viewer to voor de brmo-stufbg204 module
mprins Dec 27, 2018
fb9e257
herstel debug logging en gebruik een switch ipv if voor mutatiesoort.
mprins Dec 27, 2018
20a0fd5
maak integratie test met tomcat mogelijk
mprins Dec 27, 2018
7310d56
stufbg204 mutatie integratie test
mprins Dec 27, 2018
1eaaaec
verwijder een k uit het SimpleDateFormat masker
mprins Dec 27, 2018
0e1dd9b
gebruik INGESCHREVEN NATUURLIJK PERSOON voor de persoon uit het beric…
mprins Dec 28, 2018
c2ae7df
update javadoc en foutmeldingen
mprins Dec 28, 2018
276f54d
wip
mprins Dec 28, 2018
40c192f
meer -geanonimiseerde- stufbg204 test berichten
mprins Feb 14, 2019
5071968
annoying comment removed and soap envelope added
mtoonen Jun 11, 2019
9c02ae6
process brp berichten: when there is an old bericht, merge the fields
mtoonen Jun 11, 2019
44f6d34
moar tests!
mtoonen Jun 11, 2019
e0ef12a
Tests updated
mtoonen Jun 11, 2019
3b97f35
Don't create comfort data when identifying columns are empty. Save in…
mtoonen Jun 11, 2019
d34d24d
Added new classes
mtoonen Jun 12, 2019
1283ec9
project updated
mtoonen Jun 12, 2019
561a4ab
Update variable names, commented out some failing tests
mtoonen Jun 12, 2019
f9da9eb
Add prefix to brp messages and identif columns
mtoonen Jun 14, 2019
8d12c5f
Added toevoeging
mtoonen Jun 24, 2019
d8bfba7
Added test resources
mtoonen Jul 15, 2019
bd79d43
added integrationtest and implemented merging of brp documents
mtoonen Jul 15, 2019
f390f99
Fixed test, added function for previous bericht
mtoonen Jul 19, 2019
fcd9a51
herstel mutTestZipFile() test
mprins Aug 8, 2019
aa2878b
extra huwelijksmutatie test case + uitleg waarom bepaalde testcases f…
mprins Oct 4, 2019
693ae4b
cleanup testcase
mprins Oct 4, 2019
8a4fabf
ignore alle HuwelijksMutatie tests voor nu...
mprins Oct 4, 2019
dacfc74
update test resources
mprins Nov 14, 2019
cc34362
oplossen van Tomcat datasource unwrapping problemen
mprins Nov 15, 2019
9140157
testcase refactoring
mprins Nov 15, 2019
c734527
fix syntaxfout in xsl
mprins Nov 15, 2019
5675c2e
oracle fixes voor integratie tests
mprins Nov 15, 2019
0afea1a
gebruik jdbc-util 4.1
mprins Nov 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions brmo-loader/src/main/java/nl/b3p/brmo/loader/RsgbBRPTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package nl.b3p.brmo.loader;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.SQLException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import nl.b3p.brmo.loader.entity.Bericht;
import nl.b3p.brmo.loader.util.RsgbTransformer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
*
* @author meine
*/
public class RsgbBRPTransformer extends RsgbTransformer {

private static final Log log = LogFactory.getLog(RsgbBRPTransformer.class);
private StagingProxy staging;

public RsgbBRPTransformer(String pathToXsl, StagingProxy staging) throws TransformerConfigurationException, ParserConfigurationException {
super(pathToXsl);
this.staging = staging;
}

@Override
public String transformToDbXml(Bericht bericht) throws SAXException, IOException, TransformerConfigurationException, TransformerException {
String current = super.transformToDbXml(bericht);
StringBuilder loadLog = new StringBuilder();

try {
Bericht old = staging.getPreviousBericht(bericht, loadLog);

if (old != null) {
Document d = merge(old.getDbXml(), current);
String mergedDBXML = print(d);
bericht.setDbXml(mergedDBXML);
current = mergedDBXML;
}
} catch (SQLException ex) {
log.error("Cannot retrieve old bericht: ", ex);
} catch (Exception ex) {
log.error("Cannot retrieve old bericht: ", ex);
}

// retrieve old bericht
// apply current to old
// return modified dbxml
return current;
}

@Override
public Node transformToDbXmlNode(Bericht bericht) throws SAXException, IOException, TransformerConfigurationException, TransformerException {
Node n = super.transformToDbXmlNode(bericht);

// retrieve old bericht
// apply current to old
// return modified dbxml
return n;
}

protected static Document merge(String oldFile, String newFile) throws Exception {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xpath = xPathFactory.newXPath();
XPathExpression expression = xpath.compile("/root/data");

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document base = docBuilder.parse(new InputSource(new StringReader(oldFile)));

Element old = (Element) expression.evaluate(base, XPathConstants.NODE);
if (old == null) {
throw new IOException(oldFile + ": expression does not evaluate to node");
}

Document merge = docBuilder.parse(new InputSource(new StringReader(newFile)));
Node newNode = (Node) expression.evaluate(merge, XPathConstants.NODE);

/*
(1)Voor elke node in merge, kijk of hij bestaat in base
zo nee, importeer
zo ja, kijk of dit het een na diepste niveau is
zo ja,
ga voor elk childnode na of deze bestaat
zo nee, importeer
zo ja, overschrijf waarde
zo nee, recurse in (1)
*/
merge(base, newNode, old, true/*, merge*/);

return base;
}

private static final String GEEN_WAARDE = "geenWaarde";

private static void merge(Document base, Node newNode, Element old, boolean first/*, Node merge*/) {
while (newNode.hasChildNodes()) {
Node newChild = newNode.getFirstChild();
newNode.removeChild(newChild);
String name = newChild.getNodeName();
NodeList nl = old.getElementsByTagName(name);
if (nl.getLength() == 0) { // Geen oude data gevonden voor huidige node
newChild = base.importNode(newChild, true);
newChild.setTextContent(newChild.getTextContent());
old.appendChild(newChild);
} else {
Element oldItem = (Element) nl.item(0);
if (first) {
merge(base, newChild, oldItem, false);
} else {
String content = newChild.getTextContent();
if (content.equals(GEEN_WAARDE)) {
oldItem.setTextContent("");
} else if(content.equals("")){
//keep old content
}else {
oldItem.setTextContent(sanitizeValue(newChild.getTextContent()));
}
}
}
}
}

private static String sanitizeValue(String val){
if(val.contains(GEEN_WAARDE)){
String newValue = val.replaceAll(GEEN_WAARDE + " ", "");
newValue = newValue.replaceAll(GEEN_WAARDE, "");
return newValue;
}else{
return val;
}
}

protected static String print(Document doc) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StringWriter sw = new StringWriter();
Result result = new StreamResult(sw);
transformer.transform(source, result);
return sw.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ private RsgbTransformer getTransformer(String brType) throws TransformerConfigur
} else if (brType.equals(BrmoFramework.BR_BAG)) {
t = new RsgbTransformer(BrmoFramework.XSL_BAG);
} else if(brType.equals(BrmoFramework.BR_BRP)){
t = new RsgbTransformer(BrmoFramework.XSL_BRP);
t = new RsgbBRPTransformer(BrmoFramework.XSL_BRP, this.stagingProxy);
}else if (brType.equals(BrmoFramework.BR_NHR)) {
t = new RsgbTransformer(BrmoFramework.XSL_NHR);
// } else if (brType.equals(BrmoFramework.BR_BGTLIGHT)) {
Expand Down
88 changes: 86 additions & 2 deletions brmo-loader/src/main/java/nl/b3p/brmo/loader/StagingProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ public void updateBerichtenDbXml(List<Bericht> berichten, RsgbTransformer transf
private PreparedStatement getOldBerichtStatementById;

public Bericht getOldBericht(Bericht nieuwBericht, StringBuilder loadLog) throws SQLException {
return getOldBericht(nieuwBericht.getObjectRef(), loadLog);
}

public Bericht getOldBericht(String objectRef, StringBuilder loadLog) throws SQLException {
Split split = SimonManager.getStopwatch("b3p.staging.bericht.getold").start();

Bericht bericht = null;
Expand All @@ -498,7 +502,7 @@ public Bericht getOldBericht(Bericht nieuwBericht, StringBuilder loadLog) throws
} else {
getOldBerichtStatement.clearParameters();
}
getOldBerichtStatement.setString(1, nieuwBericht.getObjectRef());
getOldBerichtStatement.setString(1, objectRef);

ResultSet rs = getOldBerichtStatement.executeQuery();
List<Bericht> list = h.handle(rs);
Expand Down Expand Up @@ -543,6 +547,86 @@ public Bericht getOldBericht(Bericht nieuwBericht, StringBuilder loadLog) throws
split.stop();
return bericht;
}


private PreparedStatement getPreviousBerichtStatement;

public Bericht getPreviousBericht(Bericht ber, StringBuilder loadLog) throws SQLException {
return getPreviousBericht(ber.getObjectRef(), ber.getDatum(), ber.getId(), loadLog);
}

/**
* Gets the previous method (not the first)
* @param objectRef
* @param datum
* @param currentBerichtId
* @param loadLog
* @return
* @throws SQLException
*/
public Bericht getPreviousBericht(String objectRef, Date datum, Long currentBerichtId, StringBuilder loadLog) throws SQLException {
Split split = SimonManager.getStopwatch("b3p.staging.bericht.getprevious").start();

Bericht bericht = null;
ResultSetHandler<List<Bericht>> h
= new BeanListHandler(Bericht.class, new StagingRowHandler());

if(getPreviousBerichtStatement == null) {
String sql = "SELECT id, object_ref, datum, volgordenummer, soort, status, job_id, status_datum FROM "
+ BrmoFramework.BERICHT_TABLE + " WHERE"
+ " object_ref = ? and datum <= ? and id <> ?"
+ " ORDER BY datum asc, volgordenummer desc";
sql = geomToJdbc.buildPaginationSql(sql, 0, 1);

getPreviousBerichtStatement = getConnection().prepareStatement(sql);
} else {
getPreviousBerichtStatement.clearParameters();
}
getPreviousBerichtStatement.setString(1, objectRef);
getPreviousBerichtStatement.setTimestamp(2, new java.sql.Timestamp(datum.getTime()));
getPreviousBerichtStatement.setLong(3, currentBerichtId);

ResultSet rs = getPreviousBerichtStatement.executeQuery();
List<Bericht> list = h.handle(rs);
rs.close();

if(!list.isEmpty()) {
loadLog.append("Vorig bericht gevonden:\n");
for(Bericht b: list) {
if( bericht == null) {
loadLog.append("Meest recent bericht gevonden: ").append(b).append("\n");
bericht = b;
} else {
loadLog.append("Niet geschikt bericht: ").append(b).append("\n");
}
}
}

if (bericht != null) {
//bericht nu wel vullen met alle kolommen
if (getOldBerichtStatementById == null) {
String sql = "SELECT * FROM "
+ BrmoFramework.BERICHT_TABLE +
" WHERE id = ?";

getOldBerichtStatementById = getConnection().prepareStatement(sql);
} else {
getOldBerichtStatementById.clearParameters();
}
getOldBerichtStatementById.setLong(1, bericht.getId());

ResultSet rs2 = getOldBerichtStatementById.executeQuery();
List<Bericht> list2 = h.handle(rs2);
rs2.close();

if(!list2.isEmpty()) {
bericht = list2.get(0);
}
}

split.stop();
return bericht;
}

/**
* Update (overschrijft) een bericht in job tabel. (object_ref, datum,
Expand Down Expand Up @@ -682,7 +766,7 @@ public void loadBr(InputStream stream, String type, String fileName, Date d, Pro
} else if (TopNLType.isTopNLType(type)) {
brmoXMLReader = new TopNLFileReader(fileName, type);
} else if(type.equals(BrmoFramework.BR_BRP)){
brmoXMLReader = new BRPXMLReader(cis, d);
brmoXMLReader = new BRPXMLReader(cis, d, this);
} else if (type.equals(BrmoFramework.BR_GBAV)) {
brmoXMLReader = new GbavXMLReader(cis);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
public class RsgbTransformer {
private static final Log log = LogFactory.getLog(RsgbTransformer.class);
private final Templates t;
private final DocumentBuilder db;
protected final Templates t;
protected final DocumentBuilder db;

public RsgbTransformer(String pathToXsl)
throws TransformerConfigurationException, ParserConfigurationException {
Expand Down
Loading