Skip to content

Commit

Permalink
fix: PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurt Janssen committed Jan 18, 2024
1 parent b01e94d commit fef011e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ public void setValue(String expression, String value) {
}
}

public void setValueOrRemoveNode(String expression, String value) {
if(value != null) {
setValue(expression, value);
} else {
removeNode(expression);
}
}

public void createNode(String expression, String nodeName) {
var node = xml.createElement(nodeName);
xpath(expression).item(0).appendChild(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,57 +159,40 @@ public MagdaServiceIdentification magdaServiceIdentification() {
@Override
protected void fillIn(MagdaDocument request, MagdaRegistrationInfo magdaRegistrationInfo) {
fillInCommonFields(request, magdaRegistrationInfo);
var dateFormatter = DateTimeFormatter.ISO_LOCAL_DATE;

if(getIncludeBasicData() != null){
request.setValue("//Criteria/Basisgegevens", getIncludeBasicData() ? "1" : "0");
} else {
request.removeNode("//Criteria/Basisgegevens");
}

if(getIncludeJuridicalSituations() != null){
request.setValue("//Criteria/Rechtstoestanden", getIncludeJuridicalSituations() ? "1" : "0");
} else {
request.removeNode("//Criteria/Rechtstoestanden");
}
request.setValueOrRemoveNode("//Criteria/Basisgegevens", getStringValue(getIncludeBasicData()));
request.setValueOrRemoveNode("//Criteria/Rechtstoestanden", getStringValue(getIncludeJuridicalSituations()));

if(getIncludeEstablishments() != null || getIncludeEstablishmentsDetails() != null)
{
if(getIncludeEstablishments() != null){
request.setValue("//Criteria/Vestigingen/Aanduiding", getIncludeEstablishments() ? "1" : "0");
} else {
request.removeNode("//Criteria/Vestigingen/Aanduiding");
}
if(getIncludeEstablishmentsDetails() != null){
request.setValue("//Criteria/Vestigingen/Details", getIncludeEstablishmentsDetails() ? "1" : "0");
} else {
request.removeNode("//Criteria/Vestigingen/Details");
}
request.setValueOrRemoveNode("//Criteria/Vestigingen/Aanduiding", getStringValue(getIncludeEstablishments()));
request.setValueOrRemoveNode("//Criteria/Vestigingen/Details", getStringValue(getIncludeEstablishmentsDetails()));
} else {
request.removeNode("//Criteria/Vestigingen");
}

if(getIncludeDescriptions() != null){
request.setValue("//Criteria/Omschrijvingen/Aanduiding", getIncludeDescriptions() ? "1" : "0");
if(getIncludeDescriptions() != null) {
request.setValueOrRemoveNode("//Criteria/Omschrijvingen/Aanduiding", getStringValue(getIncludeDescriptions()));
} else {
request.removeNode("//Criteria/Omschrijvingen");
}

if(getStartDate() != null || getEndDate() != null)
{
if(getStartDate() != null){
request.setValue("//Criteria/Datums/Periode/Begin", getStartDate().format(dateFormatter));
} else {
request.removeNode("//Criteria/Datums/Periode/Begin");
}
if(getEndDate() != null){
request.setValue("//Criteria/Datums/Periode/Einde", getEndDate().format(dateFormatter));
} else {
request.removeNode("//Criteria/Datums/Periode/Einde");
}
request.setValueOrRemoveNode("//Criteria/Datums/Periode/Begin", getStringValue(getStartDate()));
request.setValueOrRemoveNode("//Criteria/Datums/Periode/Einde", getStringValue(getEndDate()));
} else {
request.removeNode("//Criteria/Datums");
}

}

private String getStringValue(Boolean value) {
return value != null ? value ? "1" : "0" : null;
}

private String getStringValue(LocalDate value) {
return value != null ? value.format(DateTimeFormatter.ISO_LOCAL_DATE) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Basisgegevens>IncludeBasicData</Basisgegevens>
<Rechtstoestanden>IncludeJuridicalSituations</Rechtstoestanden>
<Vestigingen>
<Aanduiding>IncludeEstablishmentsIndication</Aanduiding>
<Aanduiding>IncludeEstablishments</Aanduiding>
<Details>IncludeEstablishmentsDetails</Details>
</Vestigingen>
<Omschrijvingen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@ void setValue_doesNothingIfThereIsNoSuchField() {
""").ignoreWhitespace());
}

@Test
void setValueOrRemoveNode_setsValueIfSpecified() {
var magdaDocument = MagdaDocument.fromString("""
<foo>
<bar>Donald</bar>
<baz>Trump</baz>
</foo>""");

magdaDocument.setValueOrRemoveNode("//foo/bar", "Stormy Daniels");

assertThat(magdaDocument.toString(), isIdenticalTo("""
<foo>
<bar>Stormy Daniels</bar>
<baz>Trump</baz>
</foo>
""").ignoreWhitespace());
}

@Test
void setValueOrRemoveNode_removesNodeIfValueNotSpecified() {
var magdaDocument = MagdaDocument.fromString("""
<foo>
<bar>Donald</bar>
<baz>Trump</baz>
</foo>""");

magdaDocument.setValueOrRemoveNode("//foo/bar", null);

assertThat(magdaDocument.toString(), isIdenticalTo("""
<foo>
<baz>Trump</baz>
</foo>
""").ignoreWhitespace());
}

@Test
void getValue_readsValue() {
var magdaDocument = MagdaDocument.fromString("""
Expand Down

0 comments on commit fef011e

Please sign in to comment.