-
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.
renamed project and added changes to optimise thymeleaf usage
- Loading branch information
Showing
8 changed files
with
107 additions
and
36 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
19 changes: 11 additions & 8 deletions
19
src/main/java/com/rds/barcodegen/config/ApplicationConfig.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,28 +1,31 @@ | ||
package com.rds.barcodegen.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.thymeleaf.TemplateEngine; | ||
import org.thymeleaf.spring6.SpringTemplateEngine; | ||
import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver; | ||
import org.thymeleaf.templatemode.TemplateMode; | ||
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; | ||
import org.thymeleaf.templateresolver.ITemplateResolver; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class ApplicationConfig { | ||
@Bean | ||
public SpringResourceTemplateResolver templateResolver() { | ||
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); | ||
public ITemplateResolver foTemplateResolver() { | ||
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); | ||
templateResolver.setTemplateMode(TemplateMode.XML); | ||
templateResolver.setPrefix("classpath:/templates/"); | ||
templateResolver.setOrder(1); | ||
templateResolver.setPrefix("/templates/"); | ||
templateResolver.setSuffix(".fo"); | ||
return templateResolver; | ||
} | ||
|
||
@Bean | ||
public TemplateEngine templateProcessorEngine() { | ||
SpringTemplateEngine templateEngine = new SpringTemplateEngine(); | ||
final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); | ||
templateEngine.setEnableSpringELCompiler(true); | ||
templateEngine.setTemplateResolver(templateResolver()); | ||
templateEngine.setTemplateResolver(foTemplateResolver()); | ||
return templateEngine; | ||
} | ||
} |
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,16 @@ | ||
package com.rds.barcodegen.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CustomerInfo { | ||
private String name; | ||
|
||
private String id; | ||
|
||
private String address; | ||
} |
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,16 @@ | ||
package com.rds.barcodegen.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class Item { | ||
private String itemId; | ||
|
||
private double quantity; | ||
|
||
private String itemName; | ||
|
||
private double perUnitPrice; | ||
|
||
private double itemPrice; | ||
} |
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,21 @@ | ||
package com.rds.barcodegen.model; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class OrderDetail { | ||
private CustomerInfo customerInfo; | ||
|
||
private List<Item> items; | ||
|
||
private double reductionPercentage; | ||
|
||
private double totalAmount; | ||
private double totalDiscount; | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/rds/barcodegen/service/impl/BarcodeDocumentServiceImpl.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,31 @@ | ||
package com.rds.barcodegen.service.impl; | ||
|
||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import com.rds.barcodegen.service.AbstractDocumentService; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang.RandomStringUtils; | ||
import org.thymeleaf.TemplateEngine; | ||
import org.thymeleaf.context.Context; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class BarcodeDocumentServiceImpl extends AbstractDocumentService { | ||
private final TemplateEngine templateEngine; | ||
|
||
public void generatePDF(HttpServletRequest request, HttpServletResponse response) { | ||
String data = RandomStringUtils.random(20, 0, 0, true, true, null).toUpperCase(); | ||
Context context = new Context(Locale.getDefault(), Map.of("model", Map.of( | ||
"title", "BarCode Generation Using Apache FOP", | ||
"titleLine1", "and Barcode4J", | ||
"code39Message", data))); | ||
generateDocument(response, templateEngine.process("code39", context)); | ||
} | ||
} |