Skip to content

Commit 97bbd1f

Browse files
committed
Fix some PMD problems and suppress the rest and add it to issues
1 parent 8e53a43 commit 97bbd1f

File tree

10 files changed

+36
-16
lines changed

10 files changed

+36
-16
lines changed

bzst-dip-java-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@
550550
</rulesets>
551551
<!-- All code is auto-generated -->
552552
<excludes>
553-
<exclude>**/**</exclude>
553+
<exclude>software/xdev/bzst/dip/client/generated/**</exclude>
554554
</excludes>
555555
</configuration>
556556
<dependencies>

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/model/configuration/TaxNumberValidator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public final class TaxNumberValidator
4545
*/
4646
public static final int IDNR_CHECKSUM_LENGTH = 1;
4747

48+
private static final Pattern TAX_NUMBER_DIGITS_CHECK_PATTERN = Pattern.compile("^[1-9][0-9]{10}$");
49+
private static final Pattern ID_NUMBER_DIGITS_CHECK_PATTERN = Pattern.compile("^[1-9][0-9]{9}$");
4850
private static final Pattern PATTERN_3_DIGITS_SEQUENCE = Pattern.compile("(.)\\1\\1");
4951
public static final int SIZE_FOR_TRIPLETS_ALLOWED = 8;
5052
public static final int SIZE_FOR_DOUBLET_ALLOWED = 9;
@@ -74,7 +76,7 @@ public static void validateTaxNumber(final String taxNumber)
7476
}
7577

7678
// digits only, no leading zero
77-
if(!taxNumber.matches("^[1-9][0-9]{10}$"))
79+
if(!TAX_NUMBER_DIGITS_CHECK_PATTERN.matcher(taxNumber).matches())
7880
{
7981
throw new TaxNumberException(taxNumber);
8082
}
@@ -99,11 +101,10 @@ public static void validateTaxNumber(final String taxNumber)
99101
*/
100102
private static boolean doValidateIdNr(final String taxNumber)
101103
{
102-
103104
Objects.requireNonNull(taxNumber);
104105

105106
// 10-digits, no leading zero.
106-
if(!taxNumber.matches("^[1-9][0-9]{9}$"))
107+
if(!ID_NUMBER_DIGITS_CHECK_PATTERN.matcher(taxNumber).matches())
107108
{
108109
return false;
109110
}

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/model/message/cesop/BzstCesopPaymentDataBody.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public PaymentDataBodyType toXmlType() throws DatatypeConfigurationException
7272
return paymentDataBodyType;
7373
}
7474

75+
@SuppressWarnings("PMD.ReplaceJavaUtilCalendar")
7576
private List<ReportedPayeeType> convertToReportedPayeesType() throws DatatypeConfigurationException
7677
{
7778
final List<ReportedPayeeType> reportedPayeeTypes = new ArrayList<>();

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/model/message/dac7/BzstDipCountryCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ public enum BzstDipCountryCode
12821282
*/
12831283
XX;
12841284

1285+
@SuppressWarnings("PMD.NPathComplexity")
12851286
public CountryCodeType toXmlType()
12861287
{
12871288
return switch(this)

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/model/message/dac7/BzstDipSingleTransferResult.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package software.xdev.bzst.dip.client.model.message.dac7;
1717

1818
import java.util.Arrays;
19+
import java.util.Map;
20+
import java.util.function.Function;
21+
import java.util.stream.Collectors;
1922

2023

2124
public record BzstDipSingleTransferResult(String transferNumber, int httpStatusCode)
@@ -30,6 +33,10 @@ public enum StatusCodeMeaning
3033
INTERNER_FEHLER(500),
3134
UNDEFINIERT(-1);
3235

36+
private static final Map<Integer, StatusCodeMeaning> CODE_TO_MEANING =
37+
Arrays.stream(StatusCodeMeaning.values())
38+
.collect(Collectors.toMap(s -> s.httpStatusCode, Function.identity()));
39+
3340
private final int httpStatusCode;
3441

3542
StatusCodeMeaning(final int httpStatusCode)
@@ -39,9 +46,7 @@ public enum StatusCodeMeaning
3946

4047
public static StatusCodeMeaning getMeaningFromStatusCode(final int httpStatusCode)
4148
{
42-
return Arrays.stream(StatusCodeMeaning.values()).filter(
43-
meaning -> meaning.httpStatusCode == httpStatusCode
44-
).findFirst().orElseGet(() -> UNDEFINIERT);
49+
return CODE_TO_MEANING.getOrDefault(httpStatusCode, UNDEFINIERT);
4550
}
4651
}
4752

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/signing/XmlSigner.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ public XmlSigner(final SigningProvider certAndKeyProvider)
8282
*
8383
* @return the signed xml document as string
8484
*/
85+
@SuppressWarnings("checkstyle:MagicNumber")
8586
public String signXMLDocument(final String unsignedXmlString)
8687
{
87-
try(final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
88-
final ByteArrayInputStream unsignedXmlByteArrayInputStream =
89-
new ByteArrayInputStream(unsignedXmlString.getBytes(StandardCharsets.UTF_8)))
88+
final byte[] unsignedXmlStringBytes = unsignedXmlString.getBytes(StandardCharsets.UTF_8);
89+
try(final ByteArrayInputStream unsignedXmlByteArrayInputStream =
90+
new ByteArrayInputStream(unsignedXmlStringBytes);
91+
// Output needs at least the size of input + ~3000bytes overhead
92+
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(
93+
unsignedXmlStringBytes.length + 4096))
9094
{
9195
final DocumentBuilderFactory dbf = DocumentBuilderFactoryNoExternalEntities.newInstance();
9296
dbf.setNamespaceAware(true);

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/webclient/BearerTokenRequester.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public String getAccessTokenWithBearerPrefix()
9393
return BEARER_STRING + this.getAccessToken();
9494
}
9595

96+
@SuppressWarnings("PMD.ReplaceJavaUtilDate")
9697
private String createRequestToken()
9798
{
9899
LOGGER.debug("Creating jwt token...");

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/xmldocument/ReportableSellerCreator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
public class ReportableSellerCreator
5151
{
5252
private static final Logger LOGGER = LoggerFactory.getLogger(ReportableSellerCreator.class);
53+
5354
public static final String NULL_STRING = "NULL";
55+
private static final DateTimeFormatter BIRTH_DATE_DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd");
56+
5457
private final BzstDipConfiguration configuration;
5558

5659
public ReportableSellerCreator(final BzstDipConfiguration configuration)
@@ -219,7 +222,7 @@ private static ReportableSellerType.Identity createIdentity(
219222
createNamePerson(firstName, lastName),
220223
addressFixType,
221224
legalAddressTypeEnumType,
222-
LocalDate.parse(birthDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
225+
LocalDate.parse(birthDate, BIRTH_DATE_DTF)
223226
)
224227
);
225228
}

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/xmldocument/XMLDocumentBodyCreator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private Object createData(
133133
return dataType;
134134
}
135135

136-
@SuppressWarnings("PMD.UnusedFormalParameter") // TODO Needs to be resolved!
136+
@SuppressWarnings("PMD.UnusedFormalParameter")
137137
private Object createData(
138138
final PaymentDataBodyType paymentDataBodyType) throws DatatypeConfigurationException
139139
{
@@ -258,6 +258,7 @@ protected static AddressType createAddress(
258258
return addressType;
259259
}
260260

261+
@SuppressWarnings("PMD.ReplaceJavaUtilCalendar")
261262
private software.xdev.bzst.dip.client.xmldocument.model.cesop.MessageSpecType createMessageSpecCesop()
262263
throws DatatypeConfigurationException
263264
{

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/xmldocument/XMLDocumentCreator.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,21 @@ public class XMLDocumentCreator
8989
* </p>
9090
*/
9191
private static final String DPI_XML_XSD = "DPIXML_v1.0.xsd";
92+
private static final DateTimeFormatter XML_GREG_CAL_DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
93+
9294
private final BzstDipConfiguration configuration;
9395

9496
public XMLDocumentCreator(final BzstDipConfiguration configuration)
9597
{
9698
this.configuration = configuration;
9799
}
98100

101+
@SuppressWarnings("checkstyle:MagicNumber")
99102
public String buildXMLDocument(
100103
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
101104
final CorrectablePlatformOperatorType correctablePlatformOperatorType)
102105
{
103-
try(final StringWriter sw = new StringWriter())
106+
try(final StringWriter sw = new StringWriter(4096))
104107
{
105108
final Marshaller jaxbMarshaller = createMarshaller();
106109
final DipType dipType = this.buildRootElement(
@@ -121,10 +124,11 @@ public String buildXMLDocument(
121124
}
122125
}
123126

127+
@SuppressWarnings("checkstyle:MagicNumber")
124128
public String buildXMLDocument(
125129
final PaymentDataBodyType paymentDataBodyType)
126130
{
127-
try(final StringWriter sw = new StringWriter())
131+
try(final StringWriter sw = new StringWriter(4096))
128132
{
129133
final Marshaller jaxbMarshaller = createMarshaller();
130134
final DipType dipType = this.buildRootElement(
@@ -263,8 +267,7 @@ public static XMLGregorianCalendar parseLocalDateToXMLGregorianCalendarDateTime(
263267
{
264268
try
265269
{
266-
return DatatypeFactory.newInstance().newXMLGregorianCalendar(
267-
localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")));
270+
return DatatypeFactory.newInstance().newXMLGregorianCalendar(localDateTime.format(XML_GREG_CAL_DTF));
268271
}
269272
catch(final DatatypeConfigurationException e)
270273
{

0 commit comments

Comments
 (0)