Fix invalid parsing of 3PID medium configs

This commit is contained in:
Max Dor
2019-01-11 21:44:51 +01:00
parent 7ec11ba8cf
commit 82a1a3df68
2 changed files with 10 additions and 11 deletions

View File

@@ -20,7 +20,6 @@
package io.kamax.mxisd.config.threepid;
import com.google.gson.JsonObject;
import io.kamax.matrix.ThreePidMedium;
import io.kamax.matrix.json.GsonUtil;
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
@@ -31,18 +30,18 @@ import java.util.Map;
public class ThreePidConfig {
private Map<String, JsonObject> medium = new HashMap<>();
private Map<String, Object> medium = new HashMap<>();
public ThreePidConfig() {
public ThreePidConfig() { // TODO Check if this is still needed
medium.put(ThreePidMedium.Email.getId(), GsonUtil.makeObj(new EmailConfig()));
medium.put(ThreePidMedium.PhoneNumber.getId(), GsonUtil.makeObj(new PhoneConfig()));
}
public Map<String, JsonObject> getMedium() {
public Map<String, Object> getMedium() {
return medium;
}
public void setMedium(Map<String, JsonObject> medium) {
public void setMedium(Map<String, Object> medium) {
this.medium = medium;
}

View File

@@ -63,9 +63,9 @@ public class BuiltInNotificationHandlerSupplier implements NotificationHandlerSu
private void acceptEmail(String handler, Mxisd mxisd) {
if (StringUtils.equals(EmailRawNotificationHandler.ID, handler)) {
JsonObject emailCfgJson = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.Email.getId());
if (Objects.nonNull(emailCfgJson)) {
EmailConfig emailCfg = GsonUtil.get().fromJson(emailCfgJson, EmailConfig.class);
Object o = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.Email.getId());
if (Objects.nonNull(o)) {
EmailConfig emailCfg = GsonUtil.get().fromJson(GsonUtil.makeObj(o), EmailConfig.class);
if (org.apache.commons.lang.StringUtils.isBlank(emailCfg.getGenerator())) {
throw new ConfigurationException("notification.email.generator");
@@ -105,9 +105,9 @@ public class BuiltInNotificationHandlerSupplier implements NotificationHandlerSu
private void acceptPhone(String handler, Mxisd mxisd) {
if (StringUtils.equals(PhoneNotificationHandler.ID, handler)) {
JsonObject cfgJson = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.PhoneNumber.getId());
if (Objects.nonNull(cfgJson)) {
PhoneConfig cfg = GsonUtil.get().fromJson(cfgJson, PhoneConfig.class);
Object o = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.PhoneNumber.getId());
if (Objects.nonNull(o)) {
PhoneConfig cfg = GsonUtil.get().fromJson(GsonUtil.makeObj(o), PhoneConfig.class);
List<PhoneGenerator> generators = StreamSupport
.stream(ServiceLoader.load(PhoneGeneratorSupplier.class).spliterator(), false)