Skip to content

Commit fb0186a

Browse files
committed
Added methods for sending the payment data body to BZST
1 parent 4c48aeb commit fb0186a

File tree

3 files changed

+176
-11
lines changed

3 files changed

+176
-11
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
import java.io.IOException;
1919
import java.util.List;
2020

21+
import javax.xml.datatype.DatatypeConfigurationException;
22+
2123
import org.slf4j.Logger;
2224
import org.slf4j.LoggerFactory;
2325

2426
import com.opencsv.exceptions.CsvValidationException;
2527

2628
import software.xdev.bzst.dip.client.exception.HttpStatusCodeNotExceptedException;
2729
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfiguration;
30+
import software.xdev.bzst.dip.client.model.message.cesop.BzstCesopPaymentDataBody;
2831
import software.xdev.bzst.dip.client.model.message.dac7.BzstDipCompleteResult;
2932
import software.xdev.bzst.dip.client.model.message.dac7.BzstDipMessage;
3033
import software.xdev.bzst.dip.client.model.message.dac7.BzstDipRequestStatusResult;
@@ -37,6 +40,7 @@
3740
import software.xdev.bzst.dip.client.xmldocument.XMLDocumentCreator;
3841
import software.xdev.bzst.dip.client.xmldocument.model.CorrectablePlatformOperatorType;
3942
import software.xdev.bzst.dip.client.xmldocument.model.CorrectableReportableSellerType;
43+
import software.xdev.bzst.dip.client.xmldocument.model.cesop.PaymentDataBodyType;
4044

4145

4246
/**
@@ -136,6 +140,12 @@ public BzstDipCompleteResult sendDipAndQueryResult(final BzstDipMessage message)
136140
return this.sendDipAndQueryResult(message.toXmlType(this.configuration));
137141
}
138142

143+
public BzstDipCompleteResult sendDipAndQueryResult(final BzstCesopPaymentDataBody message)
144+
throws HttpStatusCodeNotExceptedException, InterruptedException, IOException, DatatypeConfigurationException
145+
{
146+
return this.sendDipAndQueryResult(message.toXmlType());
147+
}
148+
139149
/**
140150
* Sends the message and queries a result.
141151
* <p>
@@ -213,6 +223,24 @@ public BzstDipCompleteResult sendDipAndQueryResult(
213223
}
214224
}
215225

226+
public BzstDipCompleteResult sendDipAndQueryResult(
227+
final PaymentDataBodyType paymentDataBodyType
228+
)
229+
throws HttpStatusCodeNotExceptedException, InterruptedException, IOException
230+
{
231+
try(final WebClient client = new WebClient(this.configuration))
232+
{
233+
final BzstDipSendingResult sendingResult =
234+
this.sendDipOnlyInternal(paymentDataBodyType, client);
235+
236+
Thread.sleep(this.configuration.getQueryResultConfiguration().delayBeforeCheckingResults().toMillis());
237+
238+
final BzstDipRequestStatusResult requestStatusResult = this.queryDipResultWithRetry(client, sendingResult);
239+
240+
return BzstDipCompleteResult.fromResult(sendingResult, requestStatusResult);
241+
}
242+
}
243+
216244
/**
217245
* Queries for a DIP result. We recommend using the
218246
* {@link #sendDipAndQueryResult(BzstDipMessage)} counterpart and
@@ -254,6 +282,31 @@ private BzstDipSendingResult sendDipOnlyInternal(
254282
return new BzstDipSendingResult(dataTransferNumber);
255283
}
256284

285+
private BzstDipSendingResult sendDipOnlyInternal(
286+
final PaymentDataBodyType paymentDataBodyType,
287+
final WebClient client
288+
) throws HttpStatusCodeNotExceptedException
289+
{
290+
final XMLDocumentCreator xmlDocumentCreator = new XMLDocumentCreator(this.configuration);
291+
final String signedXML =
292+
SigningUtil.signXMLDocument(
293+
xmlDocumentCreator.buildXMLDocument(
294+
paymentDataBodyType
295+
),
296+
this.configuration);
297+
LOGGER.debug("Created following XML-Document:\n{}", signedXML);
298+
299+
LOGGER.debug("XML data will now be uploaded...");
300+
final String dataTransferNumber = client.getDataTransferNumber();
301+
LOGGER.debug("Data transfer number: {}", dataTransferNumber);
302+
303+
client.uploadMassData(dataTransferNumber, signedXML);
304+
305+
client.closeSubmission(dataTransferNumber);
306+
307+
return new BzstDipSendingResult(dataTransferNumber);
308+
}
309+
257310
private BzstDipRequestStatusResult queryDipResultWithRetry(
258311
final WebClient webClient,
259312
final BzstDipSendingResult sendingResult)

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

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515
*/
1616
package software.xdev.bzst.dip.client.xmldocument;
1717

18+
import java.math.BigDecimal;
1819
import java.time.LocalDate;
1920
import java.time.LocalDateTime;
21+
import java.util.GregorianCalendar;
2022
import java.util.List;
2123
import java.util.UUID;
2224

25+
import javax.xml.datatype.DatatypeConfigurationException;
26+
import javax.xml.datatype.DatatypeFactory;
27+
import javax.xml.datatype.XMLGregorianCalendar;
28+
2329
import org.slf4j.Logger;
2430
import org.slf4j.LoggerFactory;
2531

@@ -44,6 +50,11 @@
4450
import software.xdev.bzst.dip.client.xmldocument.model.ObjectFactory;
4551
import software.xdev.bzst.dip.client.xmldocument.model.TINType;
4652
import software.xdev.bzst.dip.client.xmldocument.model.cesop.CESOP;
53+
import software.xdev.bzst.dip.client.xmldocument.model.cesop.MSCountryCodeType;
54+
import software.xdev.bzst.dip.client.xmldocument.model.cesop.MessageTypeIndicType;
55+
import software.xdev.bzst.dip.client.xmldocument.model.cesop.MessageTypeType;
56+
import software.xdev.bzst.dip.client.xmldocument.model.cesop.PaymentDataBodyType;
57+
import software.xdev.bzst.dip.client.xmldocument.model.cesop.ReportingPeriodType;
4758

4859

4960
public class XMLDocumentBodyCreator
@@ -58,25 +69,44 @@ public XMLDocumentBodyCreator(final BzstDipConfiguration configuration)
5869

5970
public DipBodyType createBody(
6071
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
61-
final CorrectablePlatformOperatorType platformOperatorType)
72+
final CorrectablePlatformOperatorType platformOperatorType) throws DatatypeConfigurationException
6273
{
6374
final DipBodyType dipBodyType = new DipBodyType();
6475
dipBodyType.getConsignmentItem()
6576
.add(this.createConsignmentItem(correctableReportableSellerTypes, platformOperatorType));
6677
return dipBodyType;
6778
}
6879

80+
public DipBodyType createBody(
81+
final PaymentDataBodyType paymentDataBodyType) throws DatatypeConfigurationException
82+
{
83+
final DipBodyType dipBodyType = new DipBodyType();
84+
dipBodyType.getConsignmentItem()
85+
.add(this.createConsignmentItem(paymentDataBodyType));
86+
return dipBodyType;
87+
}
88+
6989
private ConsignmentItemType createConsignmentItem(
7090
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
7191
final CorrectablePlatformOperatorType platformOperatorType
72-
)
92+
) throws DatatypeConfigurationException
7393
{
7494
final ConsignmentItemType consignmentItem = new ConsignmentItemType();
7595
consignmentItem.setData(this.createData(correctableReportableSellerTypes, platformOperatorType));
7696

7797
return consignmentItem;
7898
}
7999

100+
private ConsignmentItemType createConsignmentItem(
101+
final PaymentDataBodyType paymentDataBodyType
102+
) throws DatatypeConfigurationException
103+
{
104+
final ConsignmentItemType consignmentItem = new ConsignmentItemType();
105+
consignmentItem.setData(this.createData(paymentDataBodyType));
106+
107+
return consignmentItem;
108+
}
109+
80110
private Object createData(
81111
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
82112
final CorrectablePlatformOperatorType platformOperatorType)
@@ -93,11 +123,28 @@ private Object createData(
93123
dpioecd.setVersion("1.0");
94124
dataType.setDpioecd(dpioecd);
95125
}
96-
else if(this.configuration.getApplicationCode().equals(BzstDipConfiguration.SupportedApplicationCode.CESOP))
126+
else
127+
{
128+
throw new IllegalArgumentException(
129+
"Unsupported application code: " + this.configuration.getApplicationCode()
130+
);
131+
}
132+
133+
return dataType;
134+
}
135+
136+
private Object createData(
137+
final PaymentDataBodyType paymentDataBodyType) throws DatatypeConfigurationException
138+
{
139+
LOGGER.debug("Creating data...");
140+
141+
final DataType dataType = new DataType();
142+
143+
if(this.configuration.getApplicationCode().equals(BzstDipConfiguration.SupportedApplicationCode.CESOP))
97144
{
98145
final CESOP cesop = new CESOP();
99146
cesop.setMessageSpec(this.createMessageSpecCesop());
100-
// TODO
147+
cesop.setVersion(new BigDecimal("1.0"));
101148
dataType.setCesop(cesop);
102149
}
103150
else
@@ -136,8 +183,6 @@ private DPIBodyType createDPIBody(
136183
return dpiBodyType;
137184
}
138185

139-
140-
141186
private static DocSpecType createPlatformDocSpec(final BzstDipConfiguration configuration)
142187
{
143188
final BzstDipOecdDocType docTypeIndic = configuration.getDocType();
@@ -198,8 +243,6 @@ public static CorrectablePlatformOperatorType createPlatformOperatorFromConfigur
198243
return correctablePlatformOperatorType;
199244
}
200245

201-
202-
203246
protected static AddressType createAddress(
204247
final AddressFixType address,
205248
final OECDLegalAddressTypeEnumType legalAddressTypeEnumType)
@@ -215,10 +258,32 @@ protected static AddressType createAddress(
215258
}
216259

217260
private software.xdev.bzst.dip.client.xmldocument.model.cesop.MessageSpecType createMessageSpecCesop()
261+
throws DatatypeConfigurationException
218262
{
219263
LOGGER.debug("Creating messageSpec...");
220264

221-
// TODO
265+
final software.xdev.bzst.dip.client.xmldocument.model.cesop.MessageSpecType messageSpecType =
266+
new software.xdev.bzst.dip.client.xmldocument.model.cesop.MessageSpecType();
267+
268+
messageSpecType.setTransmittingCountry(MSCountryCodeType.fromValue(this.configuration.getTransmittingCountry()
269+
.name()));
270+
messageSpecType.setMessageType(MessageTypeType.fromValue(this.configuration.getMessageType().value()));
271+
messageSpecType.setMessageTypeIndic(MessageTypeIndicType.fromValue(this.configuration.getMessageTypeIndic()
272+
.name()));
273+
messageSpecType.setMessageRefId(this.configuration.getMessageRefId());
274+
275+
final ReportingPeriodType reportingPeriodType = new ReportingPeriodType();
276+
reportingPeriodType.setQuarter(this.configuration.getReportingPeriodCesopQuarter());
277+
reportingPeriodType.setYear(this.configuration.getReportingPeriodCesopYear());
278+
messageSpecType.setReportingPeriod(reportingPeriodType);
279+
280+
final GregorianCalendar gregorianCalendar = GregorianCalendar.from(this.configuration.getTimestamp());
281+
final XMLGregorianCalendar xmlGregorianCalendar =
282+
DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
283+
284+
messageSpecType.setTimestamp(xmlGregorianCalendar);
285+
286+
return messageSpecType;
222287
}
223288

224289
private MessageSpecType createMessageSpecDac7()

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import software.xdev.bzst.dip.client.xmldocument.model.CorrectablePlatformOperatorType;
4747
import software.xdev.bzst.dip.client.xmldocument.model.CorrectableReportableSellerType;
4848
import software.xdev.bzst.dip.client.xmldocument.model.DipType;
49+
import software.xdev.bzst.dip.client.xmldocument.model.cesop.PaymentDataBodyType;
4950

5051

5152
public class XMLDocumentCreator
@@ -114,7 +115,30 @@ public String buildXMLDocument(
114115

115116
return xmlString;
116117
}
117-
catch(final IOException | JAXBException e)
118+
catch(final IOException | JAXBException | DatatypeConfigurationException e)
119+
{
120+
throw new RuntimeException("Something wrong happened while building the xml document.", e);
121+
}
122+
}
123+
124+
public String buildXMLDocument(
125+
final PaymentDataBodyType paymentDataBodyType)
126+
{
127+
try(final StringWriter sw = new StringWriter())
128+
{
129+
final Marshaller jaxbMarshaller = createMarshaller();
130+
final DipType dipType = this.buildRootElement(
131+
paymentDataBodyType
132+
);
133+
134+
jaxbMarshaller.marshal(dipType, sw);
135+
final String xmlString = sw.toString();
136+
137+
this.validateXMLDocument(xmlString);
138+
139+
return xmlString;
140+
}
141+
catch(final IOException | JAXBException | DatatypeConfigurationException e)
118142
{
119143
throw new RuntimeException("Something wrong happened while building the xml document.", e);
120144
}
@@ -143,7 +167,7 @@ private static Marshaller createMarshaller()
143167
public DipType buildRootElement(
144168
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
145169
final CorrectablePlatformOperatorType correctablePlatformOperatorType
146-
)
170+
) throws DatatypeConfigurationException
147171
{
148172
final DipType dipType = new DipType();
149173

@@ -164,6 +188,29 @@ public DipType buildRootElement(
164188
return dipType;
165189
}
166190

191+
public DipType buildRootElement(
192+
final PaymentDataBodyType paymentDataBodyType
193+
) throws DatatypeConfigurationException
194+
{
195+
final DipType dipType = new DipType();
196+
197+
final XMLDocumentHeaderCreator xmlDocumentHeaderCreator = new XMLDocumentHeaderCreator(this.configuration);
198+
199+
dipType.setHeader(
200+
xmlDocumentHeaderCreator.createHeader(
201+
this.configuration.getEnvironment().toEnvironmentType()
202+
)
203+
);
204+
205+
final XMLDocumentBodyCreator xmlDocumentBodyCreator = new XMLDocumentBodyCreator(this.configuration);
206+
dipType.setBody(
207+
xmlDocumentBodyCreator.createBody(paymentDataBodyType)
208+
);
209+
dipType.setVersion("1.0");
210+
211+
return dipType;
212+
}
213+
167214
private void validateXMLDocument(final String xmlString)
168215
{
169216
LOGGER.debug("Starting to validate xml...");

0 commit comments

Comments
 (0)