Skip to content

Commit 2a8f039

Browse files
Merge branch 'develop' into openapi-client
2 parents 1ab3201 + 614107c commit 2a8f039

File tree

13 files changed

+753
-63
lines changed

13 files changed

+753
-63
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static BzstDipConfiguration createConfiguration()
115115
{
116116
return new BzstDipConfigurationBuilder()
117117
.setClientId("abcd1234-ab12-ab12-ab12-abcdef123456")
118-
.setTaxID("123")
118+
.setTaxID("86095742719")
119119
.setTaxNumber("123")
120120
.setCertificateKeystoreInputStream(() -> ClassLoader.getSystemClassLoader()
121121
.getResourceAsStream("DemoKeystore.jks"))

bzst-dip-java-client-demo/src/main/java/software/xdev/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static BzstDipConfiguration createConfiguration()
5050
{
5151
return new BzstDipConfigurationBuilder()
5252
.setClientId("abcd1234-ab12-ab12-ab12-abcdef123456")
53-
.setTaxID("123")
53+
.setTaxID("86095742719")
5454
.setTaxNumber("123")
5555
.setCertificateKeystoreInputStream(() -> ClassLoader.getSystemClassLoader()
5656
.getResourceAsStream("DemoKeystore.jks"))

bzst-dip-java-client/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@
147147
<version>5.10.2</version>
148148
<scope>test</scope>
149149
</dependency>
150+
<dependency>
151+
<groupId>org.junit.jupiter</groupId>
152+
<artifactId>junit-jupiter-params</artifactId>
153+
<version>5.10.2</version>
154+
<scope>test</scope>
155+
</dependency>
150156
<dependency>
151157
<groupId>org.apache.logging.log4j</groupId>
152158
<artifactId>log4j-slf4j2-impl</artifactId>

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/BzstDipClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public BzstDipSendingResult sendDipOnly(final BzstDipMessage message)
9393
*/
9494
public BzstDipSendingResult sendDipOnly(final String csvData)
9595
{
96-
return this.sendDipOnly(ReportableSellerCsvFileParser.parseCsvData(csvData, this.configuration));
96+
return this.sendDipOnly(new ReportableSellerCsvFileParser(this.configuration).parseCsvData(csvData));
9797
}
9898

9999
/**
@@ -163,7 +163,7 @@ public BzstDipCompleteResult sendDipAndQueryResult(final BzstDipMessage message)
163163
public BzstDipCompleteResult sendDipAndQueryResult(final String csvData)
164164
throws InterruptedException, IOException
165165
{
166-
return this.sendDipAndQueryResult(ReportableSellerCsvFileParser.parseCsvData(csvData, this.configuration));
166+
return this.sendDipAndQueryResult(new ReportableSellerCsvFileParser(this.configuration).parseCsvData(csvData));
167167
}
168168

169169
/**
@@ -268,7 +268,10 @@ private BzstDipRequestStatusResult queryDipResultWithRetry(
268268
{
269269
if(retryCounter != 0)
270270
{
271-
Thread.sleep(this.configuration.getQueryResultConfiguration().delayInBetweenResultChecks().toMillis());
271+
final long delayInMilliseconds =
272+
this.configuration.getQueryResultConfiguration().delayInBetweenResultChecks().toMillis();
273+
LOGGER.debug("Waiting {}ms for next query...", delayInMilliseconds);
274+
Thread.sleep(delayInMilliseconds);
272275
}
273276
requestStatusResult = this.webClient.readAndConfirmDataTransferNumbers();
274277
retryCounter++;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.bzst.dip.client.exception;
17+
18+
/**
19+
* Is used for exceptions that occur during configuration with the
20+
* {@link software.xdev.bzst.dip.client.model.configuration.BzstDipConfigurationBuilder} or something similar.
21+
*/
22+
public class TaxNumberException extends ConfigurationException
23+
{
24+
public TaxNumberException(final String taxNumber)
25+
{
26+
super("The taxnumber (Steueridentifikationsnummer) is not valid!");
27+
}
28+
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public class BzstDipConfiguration
9393
* <p>
9494
* E.g. for the year 2023 this would be {@code LocalDate.of(2023,12,31)}
9595
* </p>
96+
* <p>
97+
* Date must be in the past or current date.<br>
98+
* See
99+
* <a href="https://www.bzst.de/SharedDocs/Downloads/DE/Digitale_Plattformbetreiber/kommunikationshandbuch_dac7_dpi.pdf?__blob=publicationFile&v=9">
100+
* Kommunikationshandbuch Meldepflichten digitaler Plattformbetreiber (Section 2.2)
101+
* </a>
102+
* <i>"Eine Lieferung von Daten zu in der Zukunft liegenden Meldejahren ist nicht möglich, d.h. das
103+
* Kalenderjahr in ReportingPeriod muss kleiner gleich dem aktuellen Kalenderjahr sein.</i>
104+
* </p>
96105
*/
97106
private final LocalDate reportingPeriod;
98107

@@ -108,8 +117,8 @@ public class BzstDipConfiguration
108117

109118

110119
/**
111-
* Must get set if {@link #docType} is {@link BzstDipOecdDocType#OECD_0}.<br/> The id references the xml document
112-
* which is supposed to be overwritten.
120+
* Must get set if {@link #docType} is {@link BzstDipOecdDocType#OECD_0}.<br/>
121+
* The id references the xml document which is supposed to be overwritten.
113122
*/
114123
private final String platformOperatorDocRefId;
115124
/**

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.time.LocalDate;
2121
import java.util.function.Supplier;
2222

23-
import software.xdev.bzst.dip.client.exception.ConfigurationException;
2423
import software.xdev.bzst.dip.client.exception.PropertyNotSetException;
2524
import software.xdev.bzst.dip.client.model.message.BzstDipAddressFix;
2625

@@ -364,25 +363,10 @@ public BzstDipConfiguration buildAndValidate()
364363
PropertiesSupplier.PROPERTY_NAME_PLATFORM_OPERATOR_PLATFORM),
365364
this.getSetPropertyOrReadFromFileAddress(this.platformOperatorAddress)
366365
);
367-
this.validateConfiguration(configuration);
366+
BzstDipConfigurationValidator.validateConfiguration(configuration);
368367
return configuration;
369368
}
370369

371-
private void validateConfiguration(final BzstDipConfiguration configuration)
372-
{
373-
if(
374-
configuration.getDocType().isNewTransmission()
375-
&& (configuration.getPlatformOperatorDocRefId() == null
376-
|| configuration.getPlatformOperatorDocRefId().isBlank())
377-
)
378-
{
379-
throw new ConfigurationException(
380-
PropertiesSupplier.PROPERTY_NAME_PLATFORM_OPERATOR_DOC_REF_ID,
381-
"When sending a new transmission (OECD_0) a DocRefId must be set!"
382-
);
383-
}
384-
}
385-
386370
private Supplier<InputStream> getInputStreamSupplier(
387371
final Supplier<InputStream> builderProperty,
388372
final String propertyNameInFile)
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.bzst.dip.client.model.configuration;
17+
18+
import java.time.Duration;
19+
import java.time.LocalDate;
20+
21+
import software.xdev.bzst.dip.client.exception.ConfigurationException;
22+
23+
24+
public class BzstDipConfigurationValidator
25+
{
26+
public static void validateConfiguration(final BzstDipConfiguration configuration)
27+
{
28+
checkForNullOrBlank(
29+
PropertiesSupplier.PROPERTY_NAME_CERTIFICATE_KEYSTORE_PASSWORD,
30+
configuration.getCertificateKeystorePassword());
31+
checkForNullOrBlank(
32+
PropertiesSupplier.PROPERTY_NAME_CLIENT_ID, configuration.getClientId());
33+
checkForNullOrBlank(
34+
PropertiesSupplier.PROPERTY_NAME_TAX_ID, configuration.getTaxID());
35+
TaxNumberValidator.validateTaxNumber(configuration.getTaxID());
36+
checkForNullOrBlank(
37+
PropertiesSupplier.PROPERTY_NAME_TAX_NUMBER, configuration.getTaxNumber());
38+
checkForNullOrBlank(
39+
PropertiesSupplier.PROPERTY_NAME_REALM_ENVIRONMENT_BASE_URL, configuration.getRealmEnvironmentBaseUrl());
40+
checkForNull(PropertiesSupplier.PROPERTY_NAME_ENVIRONMENT, configuration.getEnvironment());
41+
checkForNull(PropertiesSupplier.PROPERTY_NAME_MESSAGE_TYPE_INDIC, configuration.getMessageTypeIndic());
42+
checkForNull(PropertiesSupplier.PROPERTY_NAME_DOC_TYPE_INDIC, configuration.getDocType());
43+
checkForNull("certificate keystore input", configuration.getCertificateKeystoreInputStream());
44+
checkForNullOrBlank(
45+
PropertiesSupplier.PROPERTY_NAME_PLATFORM_OPERATOR_ORGANIZATION,
46+
configuration.getPlatformOperatorOrganizationName());
47+
checkForNullOrBlank(
48+
PropertiesSupplier.PROPERTY_NAME_PLATFORM_OPERATOR_PLATFORM,
49+
configuration.getPlatformOperatorPlatformName());
50+
checkForNull("platform address", configuration.getPlatformOperatorAddress());
51+
52+
checkForNullOrFuture(
53+
PropertiesSupplier.PROPERTY_NAME_REPORTING_PERIOD, configuration.getReportingPeriod());
54+
if(
55+
configuration.getDocType().isNewTransmission()
56+
&& (configuration.getPlatformOperatorDocRefId() == null
57+
|| configuration.getPlatformOperatorDocRefId().isBlank())
58+
)
59+
{
60+
throw new ConfigurationException(
61+
PropertiesSupplier.PROPERTY_NAME_PLATFORM_OPERATOR_DOC_REF_ID,
62+
"When sending a new transmission (OECD_0) a DocRefId must be set!"
63+
);
64+
}
65+
if(configuration.getDocType().isCorrectionOrDeletion()
66+
&& (configuration.getPlatformOperatorCorrDocRefId() == null
67+
|| configuration.getPlatformOperatorCorrDocRefId().isBlank())
68+
)
69+
{
70+
throw new ConfigurationException(
71+
PropertiesSupplier.PROPERTY_NAME_PLATFORM_OPERATOR_CORR_DOC_REF_ID,
72+
"When sending a correction or deletion (OECD_2 or OECD_3) a CorrDocRefId must be set!"
73+
);
74+
}
75+
final BzstDipQueryResultConfiguration queryResultConfiguration =
76+
checkForNull("query result configuration", configuration.getQueryResultConfiguration());
77+
checkForNullOrNegative(
78+
PropertiesSupplier.PROPERTY_NAME_DELAY_BEFORE_CHECKING_RESULTS_IN_MS,
79+
queryResultConfiguration.delayBeforeCheckingResults());
80+
checkForNullOrNegative(
81+
PropertiesSupplier.PROPERTY_NAME_DELAY_IN_BETWEEN_RESULT_CHECKS_IN_MS,
82+
queryResultConfiguration.delayInBetweenResultChecks());
83+
checkForNullOrNegative(
84+
PropertiesSupplier.PROPERTY_NAME_RETRY_QUERY_RESULTS_AMOUNT,
85+
queryResultConfiguration.retryQueryResultsAmount());
86+
}
87+
88+
private static <T> T checkForNull(final String propertyName, final T value)
89+
{
90+
if(value == null)
91+
{
92+
throw new ConfigurationException(
93+
propertyName,
94+
"Configuration value \"%s\" must not be null.".formatted(propertyName));
95+
}
96+
return value;
97+
}
98+
99+
private static void checkForNullOrBlank(final String propertyName, final String value)
100+
{
101+
if(value == null || value.isBlank())
102+
{
103+
throw new ConfigurationException(
104+
propertyName,
105+
"Configuration value \"%s\" must not be null or blank.".formatted(propertyName));
106+
}
107+
}
108+
109+
private static void checkForNullOrNegative(final String propertyName, final Duration value)
110+
{
111+
if(value == null || value.isNegative())
112+
{
113+
throw new ConfigurationException(
114+
propertyName,
115+
"Configuration value \"%s\" must not be null or negative.".formatted(propertyName));
116+
}
117+
}
118+
119+
private static void checkForNullOrNegative(final String propertyName, final Integer value)
120+
{
121+
if(value == null || value < 0)
122+
{
123+
throw new ConfigurationException(
124+
propertyName,
125+
"Configuration value \"%s\" must not be null or negative.".formatted(propertyName));
126+
}
127+
}
128+
129+
private static void checkForNullOrFuture(final String propertyName, final LocalDate value)
130+
{
131+
if(value == null || value.isAfter(LocalDate.now()))
132+
{
133+
throw new ConfigurationException(
134+
propertyName,
135+
"Configuration value \"%s\" must not be null or in the future.".formatted(propertyName));
136+
}
137+
}
138+
}

0 commit comments

Comments
 (0)