Skip to content

Commit

Permalink
chore: adjust external resource handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Eberl committed Dec 3, 2021
1 parent 2704a8c commit 3e5396d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import de.caritas.cob.mailservice.api.exception.ExchangeMailServiceException;
import de.caritas.cob.mailservice.api.mailtemplate.TemplateImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
Expand Down Expand Up @@ -138,8 +140,7 @@ private void addEmailAttachmentsIfNecessary(List<TemplateImage> templateImages,
for (TemplateImage templateImage : templateImages) {
try {
var inputStream =
useCustomResourcesPath ? getClass().getResourceAsStream(
customResourcePath + CUSTOM_TEMPLATE_IMAGE_DIR + templateImage.getFilename())
useCustomResourcesPath ? buildStreamForExternalPath(templateImage.getFilename())
: getClass()
.getResourceAsStream(TEMPLATE_IMAGE_DIR + templateImage.getFilename());
msg.getAttachments().addFileAttachment(templateImage.getFilename(), inputStream);
Expand All @@ -158,6 +159,11 @@ private void addEmailAttachmentsIfNecessary(List<TemplateImage> templateImages,
}
}

private FileInputStream buildStreamForExternalPath(String templateName)
throws FileNotFoundException {
return new FileInputStream(customResourcePath + CUSTOM_TEMPLATE_IMAGE_DIR + templateName);
}

private void setMailRecipients(String recipients, EmailMessage msg)
throws ExchangeMailServiceException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import de.caritas.cob.mailservice.api.exception.TemplateDescriptionServiceException;
import de.caritas.cob.mailservice.api.mailtemplate.TemplateDescription;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -66,8 +68,7 @@ private TemplateDescription loadTemplateDescription(String templateName)
private String loadTemplateDescriptionFile(String templateName)
throws TemplateDescriptionServiceException {
try {
var inputStream = useCustomResourcesPath ? TemplateDescriptionService.class
.getResourceAsStream(customResourcePath + templateName.toLowerCase() + TEMPLATE_EXTENSION)
var inputStream = useCustomResourcesPath ? buildStreamForExternalPath(templateName)
: TemplateDescriptionService.class.getResourceAsStream(getTemplateFilename(templateName));
assert inputStream != null;
final List<String> fileLines = IOUtils
Expand All @@ -80,6 +81,12 @@ private String loadTemplateDescriptionFile(String templateName)
}
}

private FileInputStream buildStreamForExternalPath(String templateName)
throws FileNotFoundException {
return new FileInputStream(
customResourcePath + templateName.toLowerCase() + TEMPLATE_EXTENSION);
}

/**
* Get the filename and filepath for the template description file
*
Expand Down

0 comments on commit 3e5396d

Please sign in to comment.