refactored channel exception to have a unified interface to form the exception message

replaced getOne with findById in order to get optionals and handle those
some places still have the general abstracto run time exception
This commit is contained in:
Sheldan
2020-05-13 12:49:08 +02:00
parent 5755d033eb
commit c429aa882b
52 changed files with 501 additions and 344 deletions

View File

@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Optional;
/**
* Loads the the template from the database to be used by Freemarker. This bean is also used when the templates within
@@ -37,12 +38,8 @@ public class DatabaseTemplateLoader implements TemplateLoader {
@Override
public long getLastModified(Object o) {
Template casted = (Template) o;
Template templateByKey = templateManagementService.getTemplateByKey(casted.getKey());
if(templateByKey != null){
return templateByKey.getLastModified().getEpochSecond();
} else {
return Long.MAX_VALUE;
}
Optional<Template> templateByKey = templateManagementService.getTemplateByKey(casted.getKey());
return templateByKey.map(template -> template.getLastModified().getEpochSecond()).orElse(Long.MAX_VALUE);
}
/**

View File

@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.Optional;
/**
* ManagementService bean used to retrieve the templates by key from the database.
@@ -20,8 +21,8 @@ public class TemplateManagementServiceBean implements TemplateManagementService
private TemplateRepository repository;
@Override
public Template getTemplateByKey(String key) {
return repository.getOne(key);
public Optional<Template> getTemplateByKey(String key) {
return repository.findById(key);
}
@Override