mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-08 18:07:39 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user