Skip to content

Commit 194e4f8

Browse files
authored
updatePackages (#131)
* update openpdf references * update versions * refactor code for jackson 3 * format code * update java to 21 * update java to 21
1 parent b89bb02 commit 194e4f8

File tree

6 files changed

+84
-82
lines changed

6 files changed

+84
-82
lines changed

.github/workflows/codeql.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: "CodeQL"
32

43
on:
@@ -11,7 +10,7 @@ on:
1110
- cron: '29 3 * * 2'
1211

1312
env:
14-
JAVA_VERSION: '17'
13+
JAVA_VERSION: '21'
1514
PACKAGE_DIRECTORY: 'FunctionApp'
1615

1716
jobs:
@@ -42,7 +41,7 @@ jobs:
4241
with:
4342
languages: ${{ matrix.language }}
4443

45-
# AFAIk, this is unavaoidable, since the CodeQL actions
44+
# AFAIk, this is unavoidable, since the CodeQL actions
4645
# must be run in the same job as build actions.
4746
- name: Setup Java Sdk ${{ env.JAVA_VERSION }}
4847
uses: actions/setup-java@v4

.github/workflows/main_restpdfformfiller(dev).yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
env:
1212
AZURE_FUNCTIONAPP_NAME: restpdfformfiller # set this to your function app name on Azure
1313
PACKAGE_DIRECTORY: 'FunctionApp' # set this to the directory which contains pom.xml file
14-
JAVA_VERSION: '17' # set this to the java version to use
14+
JAVA_VERSION: '21' # set this to the java version to use
1515

1616
jobs:
1717
deploy-and-submit-dependencies:

.github/workflows/maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
env:
1313
PACKAGE_DIRECTORY: 'FunctionApp' # set this to the directory which contains pom.xml file
14-
JAVA_VERSION: '17' # set this to the java version to use
14+
JAVA_VERSION: '21' # set this to the java version to use
1515

1616
jobs:
1717

@@ -32,6 +32,6 @@ jobs:
3232
run: mvn -B package --file ${{ env.PACKAGE_DIRECTORY }}/pom.xml
3333

3434
- name: Upload coverage reports to Codecov
35-
uses: codecov/codecov-action@v3
35+
uses: codecov/codecov-action@v4
3636
env:
3737
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

FunctionApp/pom.xml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,68 +12,67 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<java.version>17</java.version>
16-
<azure.functions.java.library.version>3.1.0</azure.functions.java.library.version>
15+
<java.version>21</java.version>
1716
<functionAppName>RestPdfFormFiller-1654224697708</functionAppName>
1817
</properties>
1918

2019
<dependencies>
2120
<dependency>
2221
<groupId>com.microsoft.azure.functions</groupId>
2322
<artifactId>azure-functions-java-library</artifactId>
24-
<version>${azure.functions.java.library.version}</version>
23+
<version>3.2.2</version>
2524
</dependency>
2625
<dependency>
2726
<groupId>com.microsoft.graph</groupId>
2827
<artifactId>microsoft-graph</artifactId>
29-
<version>6.39.0</version>
28+
<version>6.59.0</version>
3029
</dependency>
3130
<dependency>
3231
<groupId>com.azure</groupId>
3332
<artifactId>azure-identity</artifactId>
34-
<version>1.16.1</version>
33+
<version>1.18.1</version>
3534
</dependency>
3635

3736
<dependency>
3837
<groupId>com.github.librepdf</groupId>
3938
<artifactId>openpdf</artifactId>
40-
<version>2.0.5</version>
39+
<version>3.0.0</version>
4140
</dependency>
4241
<dependency>
4342
<groupId>org.bouncycastle</groupId>
4443
<artifactId>bcutil-jdk18on</artifactId>
45-
<version>1.80</version>
44+
<version>1.83</version>
4645
</dependency>
4746
<dependency>
48-
<groupId>com.fasterxml.jackson.core</groupId>
47+
<groupId>tools.jackson.core</groupId>
4948
<artifactId>jackson-databind</artifactId>
50-
<version>2.19.0</version>
49+
<version>3.0.3</version>
5150
</dependency>
5251
<dependency>
53-
<groupId>com.fasterxml.jackson.dataformat</groupId>
52+
<groupId>tools.jackson.dataformat</groupId>
5453
<artifactId>jackson-dataformat-xml</artifactId>
55-
<version>2.19.0</version>
54+
<version>3.0.3</version>
5655
</dependency>
5756

5857

5958
<!-- Test -->
6059
<dependency>
6160
<groupId>org.junit.jupiter</groupId>
6261
<artifactId>junit-jupiter</artifactId>
63-
<version>5.13.0</version>
62+
<version>6.0.1</version>
6463
<scope>test</scope>
6564
</dependency>
6665

6766
<dependency>
6867
<groupId>org.mockito</groupId>
6968
<artifactId>mockito-core</artifactId>
70-
<version>5.18.0</version>
69+
<version>5.21.0</version>
7170
<scope>test</scope>
7271
</dependency>
7372
<dependency>
7473
<groupId>org.jetbrains</groupId>
7574
<artifactId>annotations</artifactId>
76-
<version>26.0.2</version>
75+
<version>26.0.2-1</version>
7776
<scope>compile</scope>
7877
</dependency>
7978
</dependencies>
@@ -83,16 +82,16 @@
8382
<plugin>
8483
<groupId>org.apache.maven.plugins</groupId>
8584
<artifactId>maven-compiler-plugin</artifactId>
86-
<version>3.11.0</version>
85+
<version>3.14.1</version>
8786
<configuration>
88-
<release>17</release>
87+
<release>21</release>
8988
<encoding>${project.build.sourceEncoding}</encoding>
9089
</configuration>
9190
</plugin>
9291
<plugin>
9392
<groupId>com.microsoft.azure</groupId>
9493
<artifactId>azure-functions-maven-plugin</artifactId>
95-
<version>1.27.0</version>
94+
<version>1.40.0</version>
9695
<configuration>
9796
<!-- function app name -->
9897
<appName>${functionAppName}</appName>
@@ -113,7 +112,7 @@
113112
<runtime>
114113
<!-- runtime os, could be windows, linux or docker-->
115114
<os>windows</os>
116-
<javaVersion>17</javaVersion>
115+
<javaVersion>21</javaVersion>
117116
<!-- for docker function, please set the following parameters -->
118117
<!-- <image>[hub-user/]repo-name[:tag]</image> -->
119118
<!-- <serverId></serverId> -->

FunctionApp/src/main/java/app/djk/RestPdfFormFiller/Pdf/DataFormatter.java

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package app.djk.RestPdfFormFiller.Pdf;
22

33
import app.djk.RestPdfFormFiller.projectExceptions.InvalidXfaFormDataException;
4-
import app.djk.RestPdfFormFiller.projectExceptions.InvalidXfaFormException;
5-
import com.fasterxml.jackson.core.JsonProcessingException;
6-
import com.fasterxml.jackson.databind.JsonNode;
7-
import com.fasterxml.jackson.databind.ObjectMapper;
8-
import com.fasterxml.jackson.databind.node.JsonNodeType;
9-
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
4+
import tools.jackson.databind.JsonNode;
5+
import tools.jackson.databind.ObjectMapper;
6+
import tools.jackson.databind.node.JsonNodeType;
7+
import tools.jackson.dataformat.xml.XmlMapper;
108
import org.jetbrains.annotations.NotNull;
119
import org.w3c.dom.Document;
1210

@@ -19,26 +17,29 @@
1917
import java.io.StringWriter;
2018

2119
public class DataFormatter {
22-
private DataFormatter() { throw new IllegalStateException("Utility class"); }
20+
private DataFormatter() {
21+
throw new IllegalStateException("Utility class");
22+
}
2323

24-
public static String convertXmlToJsonString(String xml) throws JsonProcessingException {
24+
public static String convertXmlToJsonString(String xml) {
2525
return convertXmlToJsonNode(xml).toPrettyString();
2626

2727
}
2828

29-
private static JsonNode convertXmlToJsonNode(String xml) throws JsonProcessingException {
29+
private static JsonNode convertXmlToJsonNode(String xml) {
3030
final var xmlMapper = new XmlMapper();
3131
return xmlMapper.readTree(xml);
3232
}
3333

3434
/**
3535
* Converts a JSON representation of XFA form data to a String XML representation.
3636
* This method wraps the {@link #convertJsonToXml(String)} method.
37+
*
3738
* @param json The JSON data object.
3839
* @return The XML Document representation of the data in <code>json</code>.
3940
* @throws ParserConfigurationException If there's a problem with creating the XML document.
40-
* @throws TransformerException If there's a problem with transforming the XML document into a string.
41-
* @throws InvalidXfaFormDataException If a JSON object is not in the correct format for an XFA form.
41+
* @throws TransformerException If there's a problem with transforming the XML document into a string.
42+
* @throws InvalidXfaFormDataException If a JSON object is not in the correct format for an XFA form.
4243
*/
4344
public static String convertJsonToXmlString(String json) throws ParserConfigurationException, TransformerException {
4445
final var xmlDocument = convertJsonToXml(json);
@@ -57,73 +58,78 @@ public static String convertJsonToXmlString(String json) throws ParserConfigurat
5758
* Converts a JSON representation of XFA form data to its XML form.
5859
* The root XML and data elements are hard-coded because they are constant.
5960
* This method recurses through the remaining JSON elements and creates the XML elements.
61+
*
6062
* @param json The JSON data object.
6163
* @return The XML Document representation of the data in <code>json</code>.
6264
* @throws ParserConfigurationException If there's a problem with creating the XML document.
63-
* @throws InvalidXfaFormDataException If a JSON object is not in the correct format for an XFA form.
65+
* @throws InvalidXfaFormDataException If a JSON object is not in the correct format for an XFA form.
6466
*/
6567
public static Document convertJsonToXml(String json) throws ParserConfigurationException {
6668
final var xmlDocument = (DocumentBuilderFactory.newInstance()).newDocumentBuilder().newDocument();
6769

68-
try {
69-
final var rootJsonNode = (new ObjectMapper()).readTree(json);
70+
final var rootJsonNode = (new ObjectMapper()).readTree(json);
7071

7172

72-
// Creating the root element that an XFA form expects.
73-
// This element name is not expected to be in the JSON data object.
74-
final var rootElement = xmlDocument.createElement("xfa:datasets");
75-
rootElement.setAttribute("xmlns:xfa", "http://www.xfa.org/schema/xfa-data/1.0/");
76-
xmlDocument.appendChild(rootElement);
73+
// Creating the root element that an XFA form expects.
74+
// This element name is not expected to be in the JSON data object.
75+
final var rootElement = xmlDocument.createElement("xfa:datasets");
76+
rootElement.setAttribute("xmlns:xfa", "http://www.xfa.org/schema/xfa-data/1.0/");
77+
xmlDocument.appendChild(rootElement);
7778

78-
// The JSON data object should only have one key, "data".
79-
if (rootJsonNode.getNodeType() != JsonNodeType.OBJECT || rootJsonNode.size() != 1) {
80-
throw new InvalidXfaFormDataException();
81-
}
79+
// The JSON data object should only have one key, "data".
80+
if (rootJsonNode.getNodeType() != JsonNodeType.OBJECT || rootJsonNode.size() != 1) {
81+
throw new InvalidXfaFormDataException();
82+
}
8283

83-
// Hard-coding the data element because the element name that I give the JSON
84-
// object is just "data". The XFA form expects the "xfa:data" element name.
85-
final var dataElement = xmlDocument.createElement("xfa:data");
86-
rootElement.appendChild(dataElement);
84+
// Hard-coding the data element because the element name that I give the JSON
85+
// object is just "data". The XFA form expects the "xfa:data" element name.
86+
final var dataElement = xmlDocument.createElement("xfa:data");
87+
rootElement.appendChild(dataElement);
8788

88-
// The "data" key should always have a JSON object as its value.
89-
final var dataNode = rootJsonNode.get("data");
90-
if (dataNode.getNodeType() != JsonNodeType.OBJECT) {
91-
throw new InvalidXfaFormDataException();
92-
}
89+
// The "data" key should always have a JSON object as its value.
90+
final var dataNode = rootJsonNode.get("data");
91+
if (dataNode.getNodeType() != JsonNodeType.OBJECT) {
92+
throw new InvalidXfaFormDataException();
93+
}
9394

94-
// Recurses through the data node and creates the XML elements.
95-
// This call modifies dataElement, and by extension, xmlDocument.
96-
convertJsonNodeToXmlElement(xmlDocument, dataElement, dataNode);
95+
// Recurses through the data node and creates the XML elements.
96+
// This call modifies dataElement, and by extension, xmlDocument.
97+
convertJsonNodeToXmlElement(xmlDocument, dataElement, dataNode);
9798

98-
return xmlDocument;
99-
} catch(JsonProcessingException ex) {
100-
throw new InvalidXfaFormException();
101-
}
99+
return xmlDocument;
102100
}
103101

104102
/**
105103
* Recursively converts a <code>JsonNode</code> to XML elements.
106104
* This method modifies the <code>element</code> parameter by adding child elements to it.
105+
*
107106
* @param xmlDocument The XML document to which the elements will be added.
108-
* @param element The XML element to which the child elements will be added.
109-
* @param jsonNode The JSON node to be converted. This should be the corresponding JSON value content
110-
* for the <code>element</code> parameter.
107+
* @param element The XML element to which the child elements will be added.
108+
* @param jsonNode The JSON node to be converted. This should be the corresponding JSON value content
109+
* for the <code>element</code> parameter.
111110
*/
112111
private static void convertJsonNodeToXmlElement(
113112
final @NotNull Document xmlDocument,
114113
@NotNull org.w3c.dom.Element element,
115114
@NotNull JsonNode jsonNode) {
116115

117116
switch (jsonNode.getNodeType()) {
118-
case OBJECT -> jsonNode.fields().forEachRemaining(entry -> {
119-
final var childElement = xmlDocument.createElement(entry.getKey());
120-
element.appendChild(childElement);
121-
convertJsonNodeToXmlElement(xmlDocument, childElement, entry.getValue());
122-
});
117+
case OBJECT -> {
118+
for (final String fieldName : jsonNode.propertyNames()) {
119+
final var childElement = xmlDocument.createElement(fieldName);
120+
element.appendChild(childElement);
121+
convertJsonNodeToXmlElement(xmlDocument, childElement, jsonNode.path(fieldName));
122+
}
123+
}
123124
case STRING -> {
124-
final var textNode = xmlDocument.createTextNode(jsonNode.asText());
125+
// Jackson 3 deprecates textValue(); stringValue() is the non-deprecated string accessor.
126+
final var textNode = xmlDocument.createTextNode(jsonNode.stringValue());
125127
element.appendChild(textNode);
126128
}
129+
default -> {
130+
// For now, ignore other node types (numbers, booleans, arrays, null).
131+
// If you need them, add cases and/or schema support.
132+
}
127133
}
128134
}
129135

@@ -139,7 +145,7 @@ private static void convertJsonNodeToXmlElement(
139145
* @param xml The XML data from the form.
140146
* @return A pretty-printed String of a JSON schema object representing the JSON schema version of the form schema.
141147
*/
142-
public static String generateJsonSchema(final String xml) throws JsonProcessingException {
148+
public static String generateJsonSchema(final String xml) {
143149
final var topNode = convertXmlToJsonNode(xml);
144150
return generateJsonSchema(topNode).toPrettyString();
145151
}
@@ -165,12 +171,10 @@ public static String generateJsonSchema(final String xml) throws JsonProcessingE
165171
final var schemaObjectProperties = objectMapper.createObjectNode();
166172
schemaNode.set("properties", schemaObjectProperties);
167173

168-
// recursing on the child nodes and feeding their schemas into the properties schema node
169-
var sourceChildren = sourceNode.fields();
170-
sourceChildren.forEachRemaining(entry -> {
171-
var childSchema = generateJsonSchema(entry.getValue());
172-
schemaObjectProperties.set(entry.getKey(), childSchema);
173-
});
174+
for (final String fieldName : sourceNode.propertyNames()) {
175+
var childSchema = generateJsonSchema(sourceNode.path(fieldName));
176+
schemaObjectProperties.set(fieldName, childSchema);
177+
}
174178
} else {
175179
schemaNode.put("type", "string");
176180
}

FunctionApp/src/main/java/app/djk/RestPdfFormFiller/Pdf/RestPdfApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package app.djk.RestPdfFormFiller.Pdf;
22

33
import app.djk.RestPdfFormFiller.projectExceptions.InvalidXfaFormException;
4-
import com.lowagie.text.pdf.PdfReader;
5-
import com.lowagie.text.pdf.PdfStamper;
6-
import com.lowagie.text.pdf.XfaForm;
4+
import org.openpdf.text.pdf.PdfReader;
5+
import org.openpdf.text.pdf.PdfStamper;
6+
import org.openpdf.text.pdf.XfaForm;
77
import org.xml.sax.SAXException;
88

99
import javax.xml.parsers.ParserConfigurationException;

0 commit comments

Comments
 (0)