- Start working on a I18n tutorial mindmap.
This commit is contained in:
@@ -21,6 +21,7 @@ package com.wisemapping.mail;
|
||||
import com.wisemapping.model.Collaboration;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -137,16 +138,17 @@ final public class NotificationService {
|
||||
}
|
||||
|
||||
public void sendRegistrationEmail(@NotNull User user) {
|
||||
try {
|
||||
final Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("user", user);
|
||||
final String activationUrl = "http://wisemapping.com/c/activation?code=" + user.getActivationCode();
|
||||
model.put("emailcheck", activationUrl);
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
|
||||
"confirmationMail.vm");
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
}
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
// try {
|
||||
// final Map<String, Object> model = new HashMap<String, Object>();
|
||||
// model.put("user", user);
|
||||
// final String activationUrl = "http://wisemapping.com/c/activation?code=" + user.getActivationCode();
|
||||
// model.put("emailcheck", activationUrl);
|
||||
// mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
|
||||
// "confirmationMail.vm");
|
||||
// } catch (Exception e) {
|
||||
// handleException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
public void reportMindmapEditorError(@NotNull MindMap mindmap, @NotNull User user, @NotNull String userAgent, @Nullable String jsErrorMsg) {
|
||||
@@ -198,11 +200,8 @@ final public class NotificationService {
|
||||
e.printStackTrace(pw);
|
||||
retValue = sw.toString();
|
||||
} finally {
|
||||
try {
|
||||
if (pw != null) pw.close();
|
||||
if (sw != null) sw.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
IOUtils.closeQuietly(pw);
|
||||
IOUtils.closeQuietly(sw);
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
@@ -26,15 +26,16 @@ import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.ui.velocity.VelocityEngineUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.*;
|
||||
|
||||
public class UserServiceImpl
|
||||
implements UserService {
|
||||
@@ -42,6 +43,7 @@ public class UserServiceImpl
|
||||
private MindmapService mindmapService;
|
||||
private NotificationService notificationService;
|
||||
private MessageSource messageSource;
|
||||
private VelocityEngine velocityEngine;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -131,6 +133,7 @@ public class UserServiceImpl
|
||||
final MindMap mindMap = buildWelcomeMindmap(user.getFirstname());
|
||||
mindmapService.addMindmap(mindMap, user);
|
||||
|
||||
|
||||
// Send registration email.
|
||||
if (emailConfirmEnabled) {
|
||||
notificationService.sendRegistrationEmail(user);
|
||||
@@ -142,24 +145,27 @@ public class UserServiceImpl
|
||||
return user;
|
||||
}
|
||||
|
||||
private MindMap buildWelcomeMindmap(@NotNull String firstName) throws WiseMappingException {
|
||||
public MindMap buildWelcomeMindmap(@NotNull String firstName) {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
final Locale locale = LocaleContextHolder.getLocale();
|
||||
MindMap result = new MindMap();
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
|
||||
// @TODO: Remove this once is translated
|
||||
locale = Locale.ENGLISH;
|
||||
MindMap result = new MindMap();
|
||||
final Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("messages", messageSource);
|
||||
model.put("noArgs", new Object[]{});
|
||||
model.put("locale", locale);
|
||||
|
||||
final String mapXml = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/samples/tutorial.vm", model);
|
||||
|
||||
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream resourceAsStream = contextClassLoader.getResourceAsStream("samples/welcome_" + locale.toString() + ".xml");
|
||||
if (resourceAsStream == null) {
|
||||
resourceAsStream = contextClassLoader.getResourceAsStream("samples/welcome_en.xml");
|
||||
}
|
||||
try {
|
||||
final byte[] bytes = IOUtils.toByteArray(resourceAsStream);
|
||||
result.setXml(bytes);
|
||||
result.setXmlStr(mapXml);
|
||||
result.setTitle(messageSource.getMessage("WELCOME", null, locale) + " " + firstName);
|
||||
result.setDescription("");
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new WiseMappingException("Could not be loaded", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -201,4 +207,8 @@ public class UserServiceImpl
|
||||
public void setMessageSource(@NotNull MessageSource messageSource) {
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public void setVelocityEngine(VelocityEngine velocityEngine) {
|
||||
this.velocityEngine = velocityEngine;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user