Переглянути джерело

do not throw exception when optional template is not found

tags/v0.1.8
Jonathan Cobb 5 роки тому
джерело
коміт
fd7144c9b5
3 змінених файлів з 23 додано та 4 видалено
  1. +21
    -2
      bubble-server/src/main/java/bubble/cloud/auth/AuthenticationDriver.java
  2. +1
    -1
      bubble-web
  3. +1
    -1
      utils/cobbzilla-wizard

+ 21
- 2
bubble-server/src/main/java/bubble/cloud/auth/AuthenticationDriver.java Переглянути файл

@@ -14,17 +14,23 @@ import bubble.server.BubbleConfiguration;
import bubble.service.account.StandardAccountMessageService;
import com.github.jknack.handlebars.Handlebars;
import org.apache.commons.collections4.map.SingletonMap;
import org.apache.commons.lang3.ArrayUtils;
import org.cobbzilla.util.handlebars.HandlebarsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static org.cobbzilla.util.daemon.ZillaRuntime.die;
import static org.cobbzilla.util.io.FileUtil.basename;
import static org.cobbzilla.util.io.StreamUtil.stream2string;

public interface AuthenticationDriver extends CloudServiceDriver {

Logger log = LoggerFactory.getLogger(AuthenticationDriver.class);

String CTX_LOCALE = "locale";

default BubbleConfiguration getConfiguration() { return die("getConfiguration: not implemented!"); }
@@ -107,13 +113,13 @@ public interface AuthenticationDriver extends CloudServiceDriver {
} catch (Exception e) {
final String defaultLocale = configuration.getDefaultLocale();
if (locale.equals(defaultLocale)) {
return die("loadTemplate: no default template found: "+path);
return handleTemplateNotFound(templateName, path);
}
final String defaultPath = localePath(defaultLocale, templatePath, handlebars) + "/" + templateName;
try {
return stream2string(defaultPath);
} catch (Exception e2) {
return die("loadTemplate: no default template found: "+defaultPath);
return handleTemplateNotFound(templateName, path);
}
}
}
@@ -126,4 +132,17 @@ public interface AuthenticationDriver extends CloudServiceDriver {
k -> HandlebarsUtil.apply(hbs, templatePath, new SingletonMap<>(CTX_LOCALE, locale), '[', ']'));
}

String HTML_MESSAGE_HBS = "htmlMessage.hbs";
String[] OPTIONAL_TEMPLATES = {HTML_MESSAGE_HBS};
static String[] getOptionalTemplates() { return OPTIONAL_TEMPLATES; }

static String handleTemplateNotFound(String templateName, String path) {
if (ArrayUtils.contains(getOptionalTemplates(), basename(templateName))) {
log.warn("loadTemplate: no (optional) default template found: "+path);
return null;
} else {
return die("loadTemplate: no default template found: " + path);
}
}

}

+ 1
- 1
bubble-web

@@ -1 +1 @@
Subproject commit 6278ddb7067c668ceb676a9289e99fe734bdce89
Subproject commit eb9d244107c7949075d6767be10b85d26bf3b4e9

+ 1
- 1
utils/cobbzilla-wizard

@@ -1 +1 @@
Subproject commit 577bcd1f18224f11dcc467be725b9ca786e6aa37
Subproject commit dc43c3c657d55db2058a924cb345672383e50f14

Завантаження…
Відмінити
Зберегти