initial commit

This commit is contained in:
2021-10-03 17:07:01 +02:00
commit 456332f24e
246 changed files with 24590 additions and 0 deletions
Executable
+26
View File
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.bstly.we</groupId>
<artifactId>webstly-main</artifactId>
<version>${revision}</version>
</parent>
<name>email</name>
<artifactId>webstly-email</artifactId>
<dependencies>
<dependency>
<groupId>de.bstly.we</groupId>
<artifactId>webstly-core</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,43 @@
/**
*
*/
package de.bstly.we.email.businesslogic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailMessage;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
/**
* @author _bastler@bstly.de
*
*/
@Component
public class EmailManager {
@Autowired
private JavaMailSender javaMailSender;
public MailMessage sendText(String to, String from, String subject, String text) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setTo(to);
message.setSubject(subject);
message.setText(text);
javaMailSender.send(message);
return message;
}
public MailMessage sendBcc(String[] bcc, String from, String subject, String text) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setBcc(bcc);
message.setSubject(subject);
message.setText(text);
javaMailSender.send(message);
return message;
}
}
@@ -0,0 +1,102 @@
/**
*
*/
package de.bstly.we.email.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailMessage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.beust.jcommander.internal.Lists;
import de.bstly.we.businesslogic.PermissionManager;
import de.bstly.we.businesslogic.Permissions;
import de.bstly.we.businesslogic.UserManager;
import de.bstly.we.businesslogic.UserProfileFieldManager;
import de.bstly.we.businesslogic.UserProfileFields;
import de.bstly.we.controller.BaseController;
import de.bstly.we.email.businesslogic.EmailManager;
import de.bstly.we.email.controller.model.UserMailModel;
import de.bstly.we.model.Permission;
import de.bstly.we.model.User;
import de.bstly.we.model.UserProfileField;
/**
* @author _bastler@bstly.de
*
*/
@RestController
@RequestMapping("/email")
public class EmailController extends BaseController {
@Autowired
private EmailManager emailManager;
@Autowired
private UserManager userManager;
@Autowired
private PermissionManager permissionManager;
@Autowired
private UserProfileFieldManager userProfileFieldManager;
/**
*
* @param to
* @return
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@PostMapping("/test")
public MailMessage sendTest(@RequestBody String to) {
return emailManager.sendText(to, "no-reply@we.bstly.de", "Test Email",
"Test from we.bstly");
}
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/list")
public List<UserMailModel> getUserMailList() {
List<UserMailModel> result = Lists.newArrayList();
for (Permission permission : permissionManager.getNotExpiresByName(Permissions.MAIL)) {
User user = userManager.get(permission.getTarget());
if (user == null) {
continue;
}
String email = userManager.getBstlyEmail(user.getUsername());
UserProfileField primaryEmailUserProfileField = userProfileFieldManager
.get(user.getId(), UserProfileFields.PROFILE_FIELD_EMAIL_PRIMARY);
if (primaryEmailUserProfileField != null
&& "true".equals(primaryEmailUserProfileField.getValue())) {
UserProfileField emailUserProfileField = userProfileFieldManager.get(user.getId(),
UserProfileFields.PROFILE_FIELD_EMAIL);
if (emailUserProfileField != null
&& StringUtils.hasText(emailUserProfileField.getValue())) {
email = emailUserProfileField.getValue();
}
}
UserMailModel userMailModel = new UserMailModel(user.getUsername(), email);
UserProfileField localeUserProfileField = userProfileFieldManager.get(user.getId(),
UserProfileFields.PROFILE_FIELD_LOCALE);
if (localeUserProfileField != null
&& StringUtils.hasText(localeUserProfileField.getValue())) {
userMailModel.setLocale(localeUserProfileField.getValue());
}
result.add(userMailModel);
}
return result;
}
}
@@ -0,0 +1,68 @@
/**
*
*/
package de.bstly.we.email.controller.model;
/**
* @author _bastler@bstly.de
*
*/
public class UserMailModel {
private String username;
private String email;
private String locale;
/**
* @param username
* @param email
*/
public UserMailModel(String username, String email) {
super();
this.username = username;
this.email = email;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the locale
*/
public String getLocale() {
return locale;
}
/**
* @param locale the locale to set
*/
public void setLocale(String locale) {
this.locale = locale;
}
}