@@ -50,6 +50,33 @@ foreach (ExportTask task in exportTasks)
5050
5151 // Dalsza obsługa eksportu...
5252 ```
53+ Przyk ład w j ęzyku ```java ```:
54+ [IncrementalInvoiceRetrieveIntegrationTest .java ](https :// github.com/CIRFMF/ksef-client-java/blob/main/demo-web-app/src/integrationTest/java/pl/akmf/ksef/sdk/IncrementalInvoiceRetrieveIntegrationTest.java)
55+
56+
57+ ```java
58+ Map < InvoiceQuerySubjectType , OffsetDateTime > continuationPoints = new HashMap <>();
59+
60+ List < TimeWindows > timeWindows = buildIncrementalWindows (batchCreationStart , batchCreationCompleted );
61+ List < InvoiceQuerySubjectType > subjectTypes = Arrays .stream (InvoiceQuerySubjectType .values ())
62+ .filter (x -> x != InvoiceQuerySubjectType .SUBJECTAUTHORIZED )
63+ .toList ();
64+
65+ List < ExportTask > exportTasks = timeWindows .stream ()
66+ .flatMap (window -> subjectTypes .stream ()
67+ .map (subjectType -> new ExportTask (window .getFrom (), window .getTo (), subjectType )))
68+ .sorted (Comparator .comparing (ExportTask :: getFrom )
69+ .thenComparing (ExportTask :: getSubjectType ))
70+ .toList ();
71+ exportTasks .forEach (task -> {
72+ EncryptionData encryptionData = defaultCryptographyService .getEncryptionData ();
73+ OffsetDateTime effectiveFrom = getEffectiveStartDate (continuationPoints , task .getSubjectType (), task .getFrom ());
74+ String operationReferenceNumber = initiateInvoiceExportAsync (effectiveFrom , task .getTo (),
75+ task .getSubjectType (), accessToken , encryptionData .encryptionInfo ());
76+
77+ // Dalsza obsługa eksportu...
78+ ```
79+
5380
5481### Zalecane wielkości okien
5582
@@ -112,6 +139,25 @@ OperationResponse response = await KsefRateLimitWrapper.ExecuteWithRetryAsync(
112139 cancellationToken : CancellationToken );
113140```
114141
142+ Przyk ład w j ęzyku ```java ```:
143+ [IncrementalInvoiceRetrieveIntegrationTest .java ](https :// github.com/CIRFMF/ksef-client-java/blob/main/demo-web-app/src/integrationTest/java/pl/akmf/ksef/sdk/IncrementalInvoiceRetrieveIntegrationTest.java)
144+
145+
146+ ```java
147+ EncryptionData encryptionData = defaultCryptographyService .getEncryptionData ();
148+ InvoiceExportFilters filters = new InvoiceExportFilters ();
149+ filters .setSubjectType (subjectType );
150+ filters .setDateRange (new InvoiceQueryDateRange (
151+ InvoiceQueryDateType .PERMANENTSTORAGE , windowFrom , windowTo )
152+ );
153+
154+ InvoiceExportRequest request = new InvoiceExportRequest ();
155+ request .setFilters (filters );
156+ request .setEncryption (encryptionInfo );
157+
158+ InitAsyncInvoicesQueryResponse response = ksefClient .initAsyncQueryInvoice (request , accessToken );
159+ ```
160+
115161## Pobieranie i przetwarzanie paczek
116162
117163Po zako ńczeniu eksportu paczka faktur jest dost ępna do pobrania jako zaszyfrowane archiwum ZIP dzielone na cz ęści . Proces pobierania i przetwarzania obejmuje :
@@ -172,6 +218,29 @@ foreach ((string fileName, string content) in unzippedFiles)
172218}
173219```
174220
221+ Przyk ład w j ęzyku ```java ```:
222+ [IncrementalInvoiceRetrieveIntegrationTest .java ](https :// github.com/CIRFMF/ksef-client-java/blob/main/demo-web-app/src/integrationTest/java/pl/akmf/ksef/sdk/IncrementalInvoiceRetrieveIntegrationTest.java)
223+
224+
225+ ```java
226+ List < InvoicePackagePart > parts = invoiceExportStatus .getPackageParts ().getParts ();
227+ byte [] mergedZip = FilesUtil .mergeZipParts (
228+ encryptionData ,
229+ parts ,
230+ part -> ksefClient .downloadPackagePart (part ),
231+ (encryptedPackagePart , key , iv ) -> defaultCryptographyService .decryptBytesWithAes256 (encryptedPackagePart , key , iv )
232+ );
233+ Map < String , String > downloadedFiles = FilesUtil .unzip (mergedZip );
234+
235+ String metadataJson = downloadedFiles .keySet ()
236+ .stream ()
237+ .filter (fileName -> fileName .endsWith (" .json" ))
238+ .findFirst ()
239+ .map (downloadedFiles :: get )
240+ .orElse (null );
241+ InvoicePackageMetadata invoicePackageMetadata = objectMapper .readValue (metadataJson , InvoicePackageMetadata .class );
242+ ```
243+
175244## Obsługa obciętych paczek (IsTruncated)
176245
177246Flaga `IsTruncated = true ` jest ustawiana , gdy podczas budowy paczki osi ągni ęto limity algorytmu (liczba faktur lub rozmiar danych po kompresji ). W takim przypadku w statusie operacji dost ępna jest w ła ściwo ść `LastPermanentStorageDate ` - data ostatniej faktury uj ętej w paczce .
@@ -204,6 +273,22 @@ private static void UpdateContinuationPointIfNeeded(
204273}
205274```
206275
276+ Przyk ład w j ęzyku ```java ```:
277+ [IncrementalInvoiceRetrieveIntegrationTest .java ](https :// github.com/CIRFMF/ksef-client-java/blob/main/demo-web-app/src/integrationTest/java/pl/akmf/ksef/sdk/IncrementalInvoiceRetrieveIntegrationTest.java)
278+
279+
280+ ```java
281+ private void updateContinuationPointIfNeeded (Map < InvoiceQuerySubjectType , OffsetDateTime > continuationPoints ,
282+ InvoiceQuerySubjectType subjectType ,
283+ InvoiceExportPackage invoiceExportPackage ) {
284+ if (Boolean .TRUE .equals (invoiceExportPackage .getIsTruncated ()) && Objects .nonNull (invoiceExportPackage .getLastPermanentStorageDate ())) {
285+ continuationPoints .put (subjectType , invoiceExportPackage .getLastPermanentStorageDate ());
286+ } else {
287+ continuationPoints .remove (subjectType );
288+ }
289+ }
290+ ```
291+
207292## Deduplikacja faktur
208293
209294### Strategia deduplikacji
@@ -223,6 +308,21 @@ hasDuplicates = packageResult.MetadataSummaries
223308 .Any (summary => ! uniqueInvoices .TryAdd (summary .KsefNumber , summary ));
224309```
225310
311+ Przyk ład w j ęzyku ```java ```:
312+ [IncrementalInvoiceRetrieveIntegrationTest .java ](https :// github.com/CIRFMF/ksef-client-java/blob/main/demo-web-app/src/integrationTest/java/pl/akmf/ksef/sdk/IncrementalInvoiceRetrieveIntegrationTest.java)
313+
314+
315+ ```java
316+ hasDuplicates .set (packageProcessingResult .getInvoiceMetadataList ()
317+ .stream ()
318+ .anyMatch (summary -> uniqueInvoices .containsKey (summary .getKsefNumber ())));
319+
320+ packageProcessingResult .getInvoiceMetadataList ()
321+ .stream ()
322+ .distinct ()
323+ .forEach (summary -> uniqueInvoices .put (summary .getKsefNumber (), summary ));
324+ ```
325+
226326## Powiązane dokumenty
227327
228328- [Limity API ](.. / limity / limity - api .md )
0 commit comments