generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add methods for printing all pending * pending jobs code without pagination * pending jobs code with pagination * process pending with save via sftp * fix tests * async changes * added postman json * choose tranaction point * async processing changes * unit tests and retry fix * use saxon for xlst 2 compatibility * define default transaction manager with primary * define default transaction manager with primary --------- Co-authored-by: Sabah u Din Irfan <sabah.irfan@gmail.com> Co-authored-by: Cade Faulkner <147704481+CadeFaulkner@users.noreply.github.com>
- Loading branch information
1 parent
37bcbbd
commit e5aa7e8
Showing
15 changed files
with
419 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "47e7c899-66b9-485a-bf81-13002887dbc6", | ||
"name": "Opal Print Service", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
"_exporter_id": "1068308" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "generate-pdf", | ||
"request": { | ||
"method": "POST", | ||
"header": [ | ||
{ | ||
"key": "Content-Type", | ||
"value": "application/json", | ||
"type": "text" | ||
} | ||
], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>John Doe</name><accountNumber>123456789</accountNumber><balance>501.55</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n}\n" | ||
}, | ||
"url": { | ||
"raw": "http://localhost:4550/api/print/generate-pdf", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "4550", | ||
"path": [ | ||
"api", | ||
"print", | ||
"generate-pdf" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "enqueue-print-jobs", | ||
"request": { | ||
"method": "POST", | ||
"header": [ | ||
{ | ||
"key": "Content-Type", | ||
"value": "application/json", | ||
"type": "text" | ||
} | ||
], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "[\n {\n \"xmlData\": \"This one should fail\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Bob Brown</name><accountNumber>112233445</accountNumber><balance>250.00</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Alice Green</name><accountNumber>556677889</accountNumber><balance>799.99</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Charlie Black</name><accountNumber>223344556</accountNumber><balance>1240.50</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Emma White</name><accountNumber>667788990</accountNumber><balance>645.25</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Liam Grey</name><accountNumber>334455667</accountNumber><balance>320.75</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Olivia Brown</name><accountNumber>445566778</accountNumber><balance>510.65</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Noah Blue</name><accountNumber>223344556</accountNumber><balance>985.20</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Ava Red</name><accountNumber>778899001</accountNumber><balance>450.10</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>William Green</name><accountNumber>112233445</accountNumber><balance>702.95</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Sophia Violet</name><accountNumber>667788990</accountNumber><balance>250.50</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>James Yellow</name><accountNumber>334455667</accountNumber><balance>890.30</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Isabella Orange</name><accountNumber>445566778</accountNumber><balance>395.75</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Benjamin Pink</name><accountNumber>223344556</accountNumber><balance>980.00</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Mia Purple</name><accountNumber>778899001</accountNumber><balance>215.80</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Lucas Grey</name><accountNumber>112233445</accountNumber><balance>467.35</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Amelia White</name><accountNumber>667788990</accountNumber><balance>730.15</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Henry Black</name><accountNumber>334455667</accountNumber><balance>1005.25</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n },\n {\n \"xmlData\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><fine><name>Emily Brown</name><accountNumber>445566778</accountNumber><balance>589.45</balance></fine>\",\n \"docType\": \"TEST_PDF_definition_id\",\n \"docVersion\": \"test_version_1\"\n }\n]\n\n\n" | ||
}, | ||
"url": { | ||
"raw": "http://localhost:4550/api/print/enqueue-print-jobs", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "4550", | ||
"path": [ | ||
"api", | ||
"print", | ||
"enqueue-print-jobs" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "process-pending-jobs", | ||
"request": { | ||
"method": "POST", | ||
"header": [ | ||
{ | ||
"key": "Content-Type", | ||
"value": "application/json", | ||
"type": "text" | ||
} | ||
], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"info\": {\n \"general\": {\n \"version\": \"00_1\",\n \"docref\": \"AAA\"\n }\n },\n \"data\": {\n \"job\": {\n \"division\": \"MinimalDivision\",\n \"accountnumber\": \"000001\",\n \"casenumber\": \"CASE-00001\",\n \"dob\": \"1990-01-01\",\n \"defendantname\": \"John Doe\",\n \"sex\": \"Male\",\n \"amountoutstanding\": \"£100.00\",\n \"defendantindefault\": \"No\",\n \"dateproduced\": \"2024-04-09\",\n \"dateoforder\": \"2024-03-01\",\n \"defendantaddress\": {\n \"street\": \"123 Minimal St\",\n \"city\": \"Minimal City\",\n \"postalCode\": \"M1234\"\n },\n \"jobcentreaddress\": {\n \"name\": \"Minimal Job Centre\",\n \"address\": {\n \"street\": \"456 Minimal St\",\n \"city\": \"Job Centre City\",\n \"postalCode\": \"JC123\"\n }\n }\n }\n }\n}\n" | ||
}, | ||
"url": { | ||
"raw": "http://localhost:4550/api/print/process-pending-jobs", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "4550", | ||
"path": [ | ||
"api", | ||
"print", | ||
"process-pending-jobs" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} |
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,10 @@ | ||
package uk.gov.hmcts.opal.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
|
||
@Configuration | ||
@EnableAsync | ||
public class AsyncConfig { | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/uk/gov/hmcts/opal/config/PrintTransactionManagerConfig.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,18 @@ | ||
package uk.gov.hmcts.opal.config; | ||
|
||
import jakarta.persistence.EntityManagerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
|
||
@Configuration | ||
public class PrintTransactionManagerConfig { | ||
|
||
@Bean(name = "printTransactionManager") | ||
public JpaTransactionManager printTransactionManager(EntityManagerFactory entityManagerFactory) { | ||
JpaTransactionManager transactionManager = new JpaTransactionManager(); | ||
transactionManager.setEntityManagerFactory(entityManagerFactory); | ||
return transactionManager; | ||
} | ||
|
||
} |
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
3 changes: 2 additions & 1 deletion
3
src/main/java/uk/gov/hmcts/opal/repository/print/PrintDefinitionRepository.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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package uk.gov.hmcts.opal.repository.print; | ||
|
||
import jakarta.transaction.Transactional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import uk.gov.hmcts.opal.entity.print.PrintDefinition; | ||
|
||
|
||
@Repository | ||
public interface PrintDefinitionRepository extends JpaRepository<PrintDefinition, Long> { | ||
|
||
@Transactional | ||
PrintDefinition findByDocTypeAndTemplateId(String docType, String templateId); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/uk/gov/hmcts/opal/repository/print/PrintJobRepository.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 |
---|---|---|
@@ -1,8 +1,24 @@ | ||
package uk.gov.hmcts.opal.repository.print; | ||
|
||
import jakarta.persistence.LockModeType; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Lock; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
import uk.gov.hmcts.opal.entity.print.PrintJob; | ||
import uk.gov.hmcts.opal.entity.print.PrintStatus; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Repository | ||
public interface PrintJobRepository extends JpaRepository<PrintJob, Long> { | ||
|
||
@Lock(LockModeType.PESSIMISTIC_WRITE) | ||
@Query("SELECT p FROM PrintJob p WHERE p.status = :status AND p.createdAt <= :cutoffDate") | ||
public Page<PrintJob> findPendingJobsForUpdate(@Param("status") PrintStatus status, | ||
@Param("cutoffDate") LocalDateTime cutoffDate, | ||
Pageable pageable); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/uk/gov/hmcts/opal/service/print/AsyncPrintJobProcessor.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,24 @@ | ||
package uk.gov.hmcts.opal.service.print; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Service | ||
public class AsyncPrintJobProcessor { | ||
|
||
private final PrintService printService; | ||
|
||
@Autowired | ||
public AsyncPrintJobProcessor(PrintService printService) { | ||
this.printService = printService; | ||
} | ||
|
||
@Async | ||
public void processPendingJobsAsync(LocalDateTime cutoffDate) { | ||
printService.processPendingJobs(cutoffDate); | ||
} | ||
|
||
} |
Oops, something went wrong.