-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8d8b53
commit 17e3fb5
Showing
19 changed files
with
229 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 0 additions & 89 deletions
89
src/main/java/org/folio/print/server/resources/BatchCreationResource.java
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/main/java/org/folio/print/server/service/BatchCreationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.folio.print.server.service; | ||
|
||
import io.vertx.ext.web.RoutingContext; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.pdfbox.util.Hex; | ||
import org.folio.okapi.common.XOkapiHeaders; | ||
import org.folio.print.server.data.PrintEntry; | ||
import org.folio.print.server.data.PrintEntryType; | ||
import org.folio.print.server.storage.PrintStorage; | ||
|
||
public class BatchCreationService { | ||
private static final Logger LOGGER = LogManager.getLogger(BatchCreationService.class); | ||
private static final int MAX_COUNT_IN_BATCH = 1000; | ||
|
||
private BatchCreationService() { | ||
} | ||
|
||
/** | ||
* Process batch creation request. | ||
* @param ctx Batch creation request context | ||
*/ | ||
public static void process(RoutingContext ctx) { | ||
String tenant = ctx.request().getHeader(XOkapiHeaders.TENANT); | ||
LOGGER.debug("process:: tenant " + tenant); | ||
PrintStorage printStorage = new PrintStorage(ctx.vertx(), tenant); | ||
LocalDateTime localDateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT); | ||
|
||
printStorage.getEntriesByQuery("type=\"SINGLE\" and created > " + localDateTime | ||
+ " sortby sortingField created", 0, MAX_COUNT_IN_BATCH) | ||
.onSuccess(l -> processListAndSaveResult(l, printStorage)) | ||
.onFailure(e -> LOGGER.error("Failed to create print batch", e)); | ||
ctx.response().setStatusCode(204); | ||
ctx.response().end(); | ||
} | ||
|
||
private static void processListAndSaveResult(List<PrintEntry> entries, PrintStorage storage) { | ||
if (!entries.isEmpty()) { | ||
byte[] merged = PdfService.combinePdfFiles(entries); | ||
PrintEntry batch = new PrintEntry(); | ||
batch.setId(UUID.randomUUID()); | ||
batch.setCreated(ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC)); | ||
batch.setType(PrintEntryType.BATCH); | ||
batch.setContent(Hex.getString(merged)); | ||
storage.createEntry(batch); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.