2525import org .slf4j .Logger ;
2626import org .slf4j .LoggerFactory ;
2727
28- import software .xdev .bzst .dip .client .generated .api .MdEinreichenProviderApi ;
28+ import software .xdev .bzst .dip .client .generated .api .MdsProviderV21Api ;
2929import software .xdev .bzst .dip .client .generated .client .ApiClient ;
3030import software .xdev .bzst .dip .client .model .configuration .BzstDipConfiguration ;
3131import software .xdev .bzst .dip .client .model .message .dac7 .BzstDipRequestStatusResult ;
@@ -41,54 +41,59 @@ public class WebClient
4141 private static final Logger LOGGER = LoggerFactory .getLogger (WebClient .class );
4242 public static final int OK_HTTP_STATUS_CODE = 200 ;
4343
44- private final MdEinreichenProviderApi client ;
44+ private final BzstDipConfiguration configuration ;
45+ private final MdsProviderV21Api client ;
4546 private final BearerTokenRequester bearerTokenRequester ;
4647
4748 public WebClient (final BzstDipConfiguration configuration )
4849 {
49- this (configuration , new MdEinreichenProviderApi ());
50- this .client .getApiClient ().setBasePath (configuration .getRealmEnvironmentBaseUrl ());
50+ this (configuration , new ApiClient ());
5151 }
5252
53- public WebClient (final BzstDipConfiguration configuration , final ApiClient apiClient )
53+ public WebClient (
54+ final BzstDipConfiguration configuration ,
55+ final ApiClient apiClient )
5456 {
55- this (configuration , new MdEinreichenProviderApi (apiClient ));
57+ this .configuration = configuration ;
58+ apiClient .setBasePath (configuration .getRealmEnvironmentBaseUrl ());
59+
60+ this .client = new MdsProviderV21Api (apiClient );
61+
62+ this .bearerTokenRequester = new BearerTokenRequester (configuration , new MdsProviderV21Api (apiClient ));
63+ apiClient .setBearerToken (this .bearerTokenRequester ::getAccessToken );
5664 }
5765
5866 public WebClient (
5967 final BzstDipConfiguration configuration ,
60- final MdEinreichenProviderApi mdEinreichenProviderApi )
68+ final MdsProviderV21Api mdsProviderV21Api )
6169 {
62- this .client = mdEinreichenProviderApi ;
63- this .bearerTokenRequester = new BearerTokenRequester (configuration , this .client );
70+ this .configuration = configuration ;
71+ this .client = mdsProviderV21Api ;
72+ this .bearerTokenRequester = new BearerTokenRequester (
73+ configuration ,
74+ new MdsProviderV21Api (mdsProviderV21Api .getApiClient ()));
6475 }
6576
6677 /**
6778 * @return XML as string with data transfer numbers
6879 */
6980 public String getDataTransferNumber ()
7081 {
71- return this .getDataTransferNumber ("DAC7" );
82+ return this .getDataTransferNumber (this . configuration . getApplicationCode () );
7283 }
7384
7485 public String getDataTransferNumber (final String fachverfahren )
7586 {
7687 LOGGER .debug ("Getting data transfer number..." );
77- return this .client .einreichungAnmelden (
78- fachverfahren ,
79- this .bearerTokenRequester .getAccessTokenWithBearerPrefix ()
80- );
88+ return this .client .einreichungAnmelden (fachverfahren );
8189 }
8290
8391 public void uploadMassData (final String dataTransferNumber , final String xmlString )
8492 {
8593 LOGGER .debug ("Uploading the xml data..." );
8694
87- this .client .massendatenEinreichen (
88- dataTransferNumber ,
89- this .bearerTokenRequester .getAccessTokenWithBearerPrefix (),
90- new ByteArrayInputStream (xmlString .getBytes ())
91- );
95+ final InputStream inputStream = new ByteArrayInputStream (xmlString .getBytes (StandardCharsets .UTF_8 ));
96+ this .client .massendatenEinreichen (dataTransferNumber , inputStream );
9297
9398 LOGGER .debug ("Uploaded data successfully!" );
9499 }
@@ -99,10 +104,7 @@ public void uploadMassData(final String dataTransferNumber, final String xmlStri
99104 public void closeSubmission (final String dataTransferNumber )
100105 {
101106 LOGGER .debug ("Closing submission..." );
102- this .client .einreichungBeenden (
103- dataTransferNumber ,
104- this .bearerTokenRequester .getAccessTokenWithBearerPrefix ()
105- );
107+ this .client .einreichungBeenden (dataTransferNumber );
106108 LOGGER .debug ("Closed submission successfully!" );
107109 }
108110
@@ -114,9 +116,7 @@ public void closeSubmission(final String dataTransferNumber)
114116 public List <String > requestResultLogs () throws IOException
115117 {
116118 try (
117- final InputStream inputStream = this .client .alleProtokollnummern (
118- this .bearerTokenRequester .getAccessTokenWithBearerPrefix ()
119- )
119+ final InputStream inputStream = this .client .alleProtokollnummern ()
120120 )
121121 {
122122 final String responseBody = new String (inputStream .readAllBytes (), StandardCharsets .UTF_8 );
@@ -136,9 +136,7 @@ public BzstDipSingleTransferResult requestTransferResult(final String dataTransf
136136 {
137137 try (
138138 final InputStream inputStream = this .client .protokollAbrufen (
139- dataTransferNumber ,
140- this .bearerTokenRequester .getAccessTokenWithBearerPrefix ()
141- )
139+ dataTransferNumber )
142140 )
143141 {
144142 // TODO: Check text
@@ -153,20 +151,14 @@ public BzstDipSingleTransferResult requestTransferResult(final String dataTransf
153151 */
154152 public BzstDipSingleTransferResult confirmTransfer (final String dataTransferNumber )
155153 {
156- this .client .protokollErhalten (
157- dataTransferNumber ,
158- this .bearerTokenRequester .getAccessTokenWithBearerPrefix ()
159- );
154+ this .client .protokollErhalten (dataTransferNumber );
160155 return new BzstDipSingleTransferResult (dataTransferNumber , OK_HTTP_STATUS_CODE );
161156 }
162157
163158 public void abortSubmission (final String dataTransferNumber )
164159 {
165160 LOGGER .error ("Aborting submission..." );
166- this .client .einreichungAbbrechen (
167- dataTransferNumber ,
168- this .bearerTokenRequester .getAccessTokenWithBearerPrefix ()
169- );
161+ this .client .einreichungAbbrechen (dataTransferNumber );
170162 LOGGER .debug ("Aborted successfully." );
171163 }
172164
@@ -207,4 +199,11 @@ private BzstDipSingleTransferResult requestSingleTransferAndConfirm(final String
207199 }
208200 return singleTransferResult ;
209201 }
202+
203+ public void uploadAttachment (final String dataTransferNumber , final InputStream attachment )
204+ {
205+ LOGGER .debug ("Uploading attachment..." );
206+ this .client .anhangEinreichen (dataTransferNumber , attachment );
207+ LOGGER .debug ("Uploaded attachment successfully!" );
208+ }
210209}
0 commit comments