Skip to content

Commit

Permalink
CTPL-278 - Generate descriptive pdf download filename and include it …
Browse files Browse the repository at this point in the history
…in shelf copy of callslip. Also update Java, Springboot and folio API versions
  • Loading branch information
scott-yeadon committed Jan 24, 2025
1 parent cb95f15 commit 63a10e6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM nla-registry-quay-quay.apps.dev-containers.nla.gov.au/nla/ubi8-openjdk-17:latest
FROM nla-registry-quay-quay.apps.dev-containers.nla.gov.au/nla/ubi8-openjdk-21:latest
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} /app/app.jar
ENTRYPOINT ["bash", "-c", "java ${JAVA_OPTS} -DfolioConfigMap=\"{ FOLIO_OKAPI_URL: '$FOLIO_OKAPI_URL', FOLIO_TENANT: '$FOLIO_TENANT', FOLIO_USERNAME: '$FOLIO_USERNAME', FOLIO_PASSWORD: '$FOLIO_PASSWORD' }\" -jar /app/app.jar"]
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nlaBuild steps: this,
applicationName: "folio-pickslip-viewer",
jdk: 'JDK 17',
jdk: 'JDK 21',
deployToDev: false,
devHostname: "spade",
deployToNexus: true,
Expand Down
16 changes: 4 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.1</version>
<version>3.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>au.gov.nla</groupId>
<artifactId>folio-pickslip-viewer</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>folio-pickslip-viewer</name>
<description>FOLIO pickslip / request queue viewer</description>
<properties>
<java.version>17</java.version>
<java.version>21</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
Expand Down Expand Up @@ -62,10 +62,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -83,10 +79,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-authorization-server</artifactId>
</dependency>
<!--dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency-->

<dependency>
<groupId>org.webjars</groupId>
Expand Down Expand Up @@ -122,7 +114,7 @@
<dependency>
<groupId>au.gov.nla</groupId>
<artifactId>folio-api</artifactId>
<version>1.0.21-RELEASE</version>
<version>1.0.23-RELEASE</version>
</dependency>

<dependency>
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/au/gov/nla/pickslip/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import java.io.IOException;
import java.security.Principal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -51,15 +53,19 @@ public class HomeController {
@Autowired
RequestEditService requestEditService;

private static final DateTimeFormatter CS_DOWNLOAD_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");

@GetMapping("/export/{id}")
public void export(@PathVariable String id, HttpServletResponse response) throws IOException {

ServletOutputStream sos = response.getOutputStream();
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=print.pdf");

PickslipQueues.Pickslip pickslip = pickslipQueues.getPickslipByRequestId(id);
String filename = "cs-" + pickslip.item().barcode() + "-" + CS_DOWNLOAD_DATE_FORMATTER.format(
LocalDateTime.now()) + ".pdf";
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename);

pdfResponderService.generate(sos, Collections.singletonList(pickslip));
pdfResponderService.generate(sos, Collections.singletonList(pickslip), filename);
response.flushBuffer();
}

Expand Down Expand Up @@ -104,8 +110,10 @@ public void bulkExport(
HttpServletResponse response)
throws IOException {

String filename = "csbulk-" + CS_DOWNLOAD_DATE_FORMATTER.format(LocalDateTime.now()) + ".pdf";

ServletOutputStream sos = response.getOutputStream();
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=print.pdf");
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename);

var uptoPickslip = this.pickslipQueues.getPickslipByRequestId(upToId);
var stackPickslips =
Expand Down Expand Up @@ -147,7 +155,7 @@ public void bulkExport(
.callNumber())))
.toList();

pdfResponderService.generate(sos, sorted);
pdfResponderService.generate(sos, sorted, filename);
response.flushBuffer();
}

Expand Down Expand Up @@ -204,7 +212,7 @@ private List<StackLocations.Location> filterStackLocations(String[] stackCodes)
}
}
}
return (stackList != null && stackList.size() > 0) ? stackList : stackLocations.getStacks();
return (stackList != null && !stackList.isEmpty()) ? stackList : stackLocations.getStacks();
}

@GetMapping("/request/{requestId}/edit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PdfResponderService {

@Autowired UnicodeFontMap unicodeFontMap;

private Logger log = LoggerFactory.getLogger(this.getClass());
private final Logger log = LoggerFactory.getLogger(this.getClass());

private ITextRenderer renderer;

Expand Down Expand Up @@ -68,7 +68,7 @@ public static String generateCode128BarcodeImage(String barcodeText, int width,

Code128Writer barcodeWriter = new Code128Writer();

Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.MARGIN, 4);

Expand All @@ -80,7 +80,7 @@ public static String generateCode128BarcodeImage(String barcodeText, int width,
return Base64.getEncoder().encodeToString(bos.toByteArray());
}

public synchronized void generate(OutputStream os, List<PickslipQueues.Pickslip> pickslipList) {
public synchronized void generate(OutputStream os, List<PickslipQueues.Pickslip> pickslipList, String filename) {

Context ctx = new Context(LocaleContextHolder.getLocale());

Expand Down Expand Up @@ -114,6 +114,7 @@ public synchronized void generate(OutputStream os, List<PickslipQueues.Pickslip>

ctx.setVariable("instance", instances.get(pickslip.instance().id()));
ctx.setVariable("pickslip", pickslip);
ctx.setVariable("printFilename", filename);
ctx.setVariable("unicodeFontMap", unicodeFontMap);

String htmlContent = this.templateEngine.process("pdf/print_pdf", ctx);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/templates/pdf/print_pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
<div class="access-info">
<table>
<tr> <td class="label-left">Access conditions:</td> <td class="heavy-font" th:text="${#strings.abbreviate(instance.accessConditions,100)} ?: '-'"/> </tr>
<tr> <td class="label-left">Terms of use:</td> <td class="heavy-font" th:text="${#strings.abbreviate(instance.termsOfUse,100)} ?: '-'"/> </tr>
<tr> <td class="label-left">Terms of use:</td> <td class="heavy-font" th:text="${#strings.abbreviate(instance.termsOfUse,40)} ?: '-'"/> </tr>
<tr> <td class="label-left">Ref:</td> <td class="heavy-font" th:text="${#strings.abbreviate(printFilename,100)} ?: '-'"/> </tr>
</table>
</div>
</div>
Expand Down

0 comments on commit 63a10e6

Please sign in to comment.