Move more services out of XML definition.
parent
50e4a68d28
commit
a739bb3e0b
|
@ -21,7 +21,7 @@ import com.wisemapping.exceptions.ClientException;
|
|||
import com.wisemapping.exceptions.OAuthAuthenticationException;
|
||||
import com.wisemapping.exceptions.Severity;
|
||||
import com.wisemapping.exceptions.ValidationException;
|
||||
import com.wisemapping.mail.NotificationService;
|
||||
import com.wisemapping.service.NotificationService;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.rest.model.RestErrors;
|
||||
import com.wisemapping.security.Utils;
|
||||
|
|
|
@ -17,36 +17,44 @@
|
|||
*/
|
||||
|
||||
|
||||
package com.wisemapping.mail;
|
||||
package com.wisemapping.service;
|
||||
|
||||
import com.wisemapping.util.VelocityEngineUtils;
|
||||
import com.wisemapping.util.VelocityEngineWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.mail.javamail.MimeMessagePreparator;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
public final class Mailer {
|
||||
@Service
|
||||
public final class MailerService {
|
||||
|
||||
//~ Instance fields ......................................................................................
|
||||
|
||||
@Autowired
|
||||
private JavaMailSender mailSender;
|
||||
|
||||
@Autowired
|
||||
private VelocityEngineWrapper velocityEngineWrapper;
|
||||
private final String serverFromEmail;
|
||||
private final String supportEmail;
|
||||
private final String errorReporterEmail;
|
||||
|
||||
@Value("${mail.serverSendEmail")
|
||||
private String serverFromEmail;
|
||||
|
||||
@Value("${mail.supportEmail}")
|
||||
private String supportEmail;
|
||||
|
||||
@Value("${mail.errorReporterEmail}")
|
||||
private String errorReporterEmail;
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
public Mailer(@NotNull String siteEmail, @NotNull String supportEmail, @NotNull String errorReporterEmail) {
|
||||
this.serverFromEmail = siteEmail;
|
||||
this.supportEmail = supportEmail;
|
||||
this.errorReporterEmail = errorReporterEmail;
|
||||
}
|
||||
|
||||
public String getServerSenderEmail() {
|
||||
return serverFromEmail;
|
||||
}
|
|
@ -20,7 +20,6 @@ package com.wisemapping.service;
|
|||
|
||||
import com.wisemapping.dao.MindmapManager;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.mail.NotificationService;
|
||||
import com.wisemapping.model.*;
|
||||
import com.wisemapping.security.Utils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.mail;
|
||||
package com.wisemapping.service;
|
||||
|
||||
import com.wisemapping.filter.SupportedUserAgent;
|
||||
import com.wisemapping.model.Collaboration;
|
||||
|
@ -29,10 +29,13 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
@ -42,13 +45,16 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
final public class NotificationService {
|
||||
final private static Logger logger = LogManager.getLogger();
|
||||
@Autowired
|
||||
private ResourceBundleMessageSource messageSource;
|
||||
|
||||
@Autowired
|
||||
private Mailer mailer;
|
||||
private MailerService mailerService;
|
||||
|
||||
@Value("${site.baseurl:http://localhost:8080/}")
|
||||
private String baseUrl;
|
||||
|
||||
public void newCollaboration(@NotNull Collaboration collaboration, @NotNull Mindmap mindmap, @NotNull User user, @Nullable String message) {
|
||||
|
@ -56,7 +62,7 @@ final public class NotificationService {
|
|||
|
||||
try {
|
||||
// Sent collaboration email ...
|
||||
final String formMail = mailer.getServerSenderEmail();
|
||||
final String formMail = mailerService.getServerSenderEmail();
|
||||
|
||||
// Is the user already registered user ?.
|
||||
final String collabEmail = collaboration.getCollaborator().getEmail();
|
||||
|
@ -72,14 +78,14 @@ final public class NotificationService {
|
|||
model.put("baseUrl", getBaseUrl());
|
||||
model.put("senderMail", user.getEmail());
|
||||
model.put("message", message);
|
||||
model.put("doNotReplay", messageSource.getMessage("EMAIL.DO_NOT_REPLAY", new Object[]{mailer.getSupportEmail()}, locale));
|
||||
model.put("doNotReplay", messageSource.getMessage("EMAIL.DO_NOT_REPLAY", new Object[]{mailerService.getSupportEmail()}, locale));
|
||||
|
||||
// To resolve resources on templates ...
|
||||
model.put("noArg", new Object[]{});
|
||||
model.put("messages", messageSource);
|
||||
model.put("locale", locale);
|
||||
|
||||
mailer.sendEmail(formMail, collabEmail, subject, model, "newCollaboration.vm");
|
||||
mailerService.sendEmail(formMail, collabEmail, subject, model, "newCollaboration.vm");
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
}
|
||||
|
@ -125,8 +131,8 @@ final public class NotificationService {
|
|||
model.put("messageTitle", messageTitle);
|
||||
model.put("messageBody", messageBody);
|
||||
model.put("baseUrl", getBaseUrl());
|
||||
model.put("supportEmail", mailer.getSupportEmail());
|
||||
model.put("doNotReplay", messageSource.getMessage("EMAIL.DO_NOT_REPLAY", new Object[]{mailer.getSupportEmail()}, locale));
|
||||
model.put("supportEmail", mailerService.getSupportEmail());
|
||||
model.put("doNotReplay", messageSource.getMessage("EMAIL.DO_NOT_REPLAY", new Object[]{mailerService.getSupportEmail()}, locale));
|
||||
|
||||
// To resolve resources on templates ...
|
||||
model.put("noArg", new Object[]{});
|
||||
|
@ -134,7 +140,7 @@ final public class NotificationService {
|
|||
model.put("locale", locale);
|
||||
|
||||
logger.debug("Email properties->" + model);
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), mailSubject, model, "baseLayout.vm");
|
||||
mailerService.sendEmail(mailerService.getServerSenderEmail(), user.getEmail(), mailSubject, model, "baseLayout.vm");
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
}
|
||||
|
@ -146,15 +152,15 @@ final public class NotificationService {
|
|||
|
||||
}
|
||||
|
||||
public void setMailer(Mailer mailer) {
|
||||
this.mailer = mailer;
|
||||
public void setMailer(MailerService mailerService) {
|
||||
this.mailerService = mailerService;
|
||||
}
|
||||
|
||||
|
||||
public void activateAccount(@NotNull User user) {
|
||||
final Map<String, Object> model = new HashMap<>();
|
||||
model.put("user", user);
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "[WiseMapping] Active account", model, "activationAccountMail.vm");
|
||||
mailerService.sendEmail(mailerService.getServerSenderEmail(), user.getEmail(), "[WiseMapping] Active account", model, "activationAccountMail.vm");
|
||||
}
|
||||
|
||||
public void sendRegistrationEmail(@NotNull User user) {
|
|
@ -15,7 +15,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.wisemapping.mail;
|
||||
package com.wisemapping.service;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.DigestUtils;
|
|
@ -22,7 +22,6 @@ import com.wisemapping.dao.UserManager;
|
|||
import com.wisemapping.exceptions.InvalidMindmapException;
|
||||
import com.wisemapping.exceptions.OAuthAuthenticationException;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.mail.NotificationService;
|
||||
import com.wisemapping.model.*;
|
||||
import com.wisemapping.rest.model.RestResetPasswordAction;
|
||||
import com.wisemapping.rest.model.RestResetPasswordResponse;
|
||||
|
|
|
@ -20,6 +20,8 @@ package com.wisemapping.service.google;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -30,11 +32,17 @@ import com.wisemapping.service.google.http.HttpInvokerException;
|
|||
|
||||
@Service
|
||||
public class GoogleService {
|
||||
@Autowired
|
||||
private HttpInvoker httpInvoker;
|
||||
@Value("${security.oauth2.google.confirmUrl}")
|
||||
private String optinConfirmUrl;
|
||||
@Value("${security.oauth2.google.userinfoUrl}")
|
||||
private String accountBasicDataUrl;
|
||||
@Value("${security.oauth2.google.clientId}")
|
||||
private String clientId;
|
||||
@Value("${security.oauth2.google.clientSecret}")
|
||||
private String clientSecret;
|
||||
@Value("${security.oauth2.google.callbackUrl}")
|
||||
private String callbackUrl;
|
||||
|
||||
public void setHttpInvoker(HttpInvoker httpInvoker) {
|
||||
|
|
|
@ -9,24 +9,6 @@
|
|||
|
||||
<context:property-placeholder location="/WEB-INF/app.properties" ignore-unresolvable="true"/>
|
||||
|
||||
<bean id="mailer" class="com.wisemapping.mail.Mailer">
|
||||
<constructor-arg index="0" value="${mail.serverSendEmail}"/>
|
||||
<constructor-arg index="1" value="${mail.supportEmail}"/>
|
||||
<constructor-arg index="2" value="${mail.errorReporterEmail}"/>
|
||||
|
||||
<property name="mailSender" ref="mailSender"/>
|
||||
<property name="velocityEngineWrapper" ref="velocityEngineWrapper"/>
|
||||
</bean>
|
||||
|
||||
<bean id="googleService" class="com.wisemapping.service.google.GoogleService">
|
||||
<property name="httpInvoker" ref="httpInvoker"/>
|
||||
<property name="optinConfirmUrl" value="${security.oauth2.google.confirmUrl}"/>
|
||||
<property name="accountBasicDataUrl" value="${security.oauth2.google.userinfoUrl}"/>
|
||||
<property name="clientId" value="${security.oauth2.google.clientId}"/>
|
||||
<property name="clientSecret" value="${security.oauth2.google.clientSecret}"/>
|
||||
<property name="callbackUrl" value="${security.oauth2.google.callbackUrl}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
|
||||
<property name="host" value="${mail.smtp.host}"/>
|
||||
<property name="port" value="${mail.smtp.port}"/>
|
||||
|
@ -42,12 +24,6 @@
|
|||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="notificationService" class="com.wisemapping.mail.NotificationService">
|
||||
<property name="baseUrl" value="${site.baseurl:http://localhost:8080/}"/>
|
||||
<property name="mailer" ref="mailer"/>
|
||||
<property name="messageSource" ref="messageSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
|
||||
<property name="defaultEncoding" value="UTF-8"/>
|
||||
<property name="basenames">
|
||||
|
|
Loading…
Reference in New Issue