-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
closes #528 **Changes** - create usertask notification api
- Loading branch information
Showing
40 changed files
with
587 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...a/io/miragon/miranum/platform/example/adapter/in/miranum/UsertaskNotificationAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.miragon.miranum.platform.example.adapter.in.miranum; | ||
|
||
import io.miragon.miranum.platform.example.application.domain.Notification; | ||
import io.miragon.miranum.platform.example.application.port.in.NotificationInPort; | ||
import io.miragon.miranum.platform.tasklist.application.port.out.task.TaskNotificationOutPort; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.camunda.bpm.engine.delegate.DelegateTask; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class UsertaskNotificationAdapter implements TaskNotificationOutPort { | ||
|
||
private final NotificationInPort notificationInPort; | ||
|
||
@Override | ||
public void notifyAssignee(final String assignee, final String eventName, final DelegateTask task) { | ||
// example implementation | ||
notificationInPort.notifyUsers(List.of(assignee), Notification.builder() | ||
.eventName(eventName) | ||
.taskName(task.getName()) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public void notifyCandidateUsers(final List<String> candidateUsers, final String eventName, final DelegateTask task) { | ||
// example implementation | ||
notificationInPort.notifyUsers(candidateUsers, Notification.builder() | ||
.eventName(eventName) | ||
.taskName(task.getName()) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public void notifyCandidateGroups(final List<String> candidateGroups, final String eventName, final DelegateTask task) { | ||
// example implementation | ||
notificationInPort.notifyGroup(candidateGroups, Notification.builder() | ||
.eventName(eventName) | ||
.taskName(task.getName()) | ||
.build()); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...ple/src/main/java/io/miragon/miranum/platform/example/adapter/out/email/EmailAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.miragon.miranum.platform.example.adapter.out.email; | ||
|
||
import io.miragon.miranum.platform.example.application.domain.SendNotification; | ||
import io.miragon.miranum.platform.example.application.port.out.SendNotificationOutPort; | ||
import jakarta.mail.Message; | ||
import jakarta.mail.MessagingException; | ||
import jakarta.mail.internet.InternetAddress; | ||
import jakarta.mail.internet.MimeMessage; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Properties; | ||
|
||
@Slf4j | ||
@Component | ||
public class EmailAdapter implements SendNotificationOutPort { | ||
|
||
private final JavaMailSender mailSender; | ||
|
||
public EmailAdapter() throws jakarta.mail.MessagingException { | ||
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); | ||
|
||
final int timeout = 30000; // 30 seconds | ||
Properties properties = mailSender.getJavaMailProperties(); | ||
properties.put("mail.smtp.connectiontimeout", timeout); | ||
properties.put("mail.smtp.timeout", timeout); | ||
properties.put("mail.smtp.writetimeout", timeout); | ||
|
||
mailSender.testConnection(); | ||
|
||
this.mailSender = mailSender; | ||
} | ||
|
||
|
||
@Override | ||
public void notify(final SendNotification sendNotification) { | ||
try { | ||
final MimeMessage mimeMessage = this.mailSender.createMimeMessage(); | ||
|
||
mimeMessage.setFrom(new InternetAddress("[email protected]")); | ||
mimeMessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(String.join(",", sendNotification.receivers()))); | ||
mimeMessage.setSubject(sendNotification.subject()); | ||
mimeMessage.setText(sendNotification.body()); | ||
|
||
this.mailSender.send(mimeMessage); | ||
} catch (final MessagingException e) { | ||
log.error("Error sending email", e); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ain/java/io/miragon/miranum/platform/example/application/UsertaskNotificationUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.miragon.miranum.platform.example.application; | ||
|
||
import io.miragon.miranum.platform.example.application.domain.Notification; | ||
import io.miragon.miranum.platform.example.application.domain.SendNotification; | ||
import io.miragon.miranum.platform.example.application.port.in.NotificationInPort; | ||
import io.miragon.miranum.platform.example.application.port.out.SendNotificationOutPort; | ||
import io.miragon.miranum.platform.user.application.port.in.UserApi; | ||
import io.miragon.miranum.platform.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UsertaskNotificationUseCase implements NotificationInPort { | ||
|
||
private final SendNotificationOutPort sendNotificationOutPort; | ||
private final UserApi userApi; | ||
|
||
@Override | ||
public void notifyUsers(final List<String> users, final Notification notification) { | ||
// don't send notification for create and complete events | ||
if(notification.getEventName().equalsIgnoreCase("create") || notification.getEventName().equalsIgnoreCase("complete")) { | ||
return; | ||
} | ||
|
||
final List<User> receivers = new ArrayList<>(); | ||
users.forEach(user -> receivers.add(userApi.getUserByUserName(user))); | ||
|
||
sendNotificationOutPort.notify(SendNotification.builder() | ||
.receivers(receivers.stream().map(User::getEmail).toList()) | ||
.subject(notification.getTitle()) | ||
.body(notification.getMessage()) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public void notifyGroup(final List<String> groups, final Notification notification) { | ||
// don't send notification for assignment events | ||
if (notification.getEventName().equalsIgnoreCase("assignment")) { | ||
return; | ||
} | ||
|
||
final List<User> receivers = new ArrayList<>(); | ||
groups.forEach(group -> receivers.addAll(userApi.getUsersByGroup(group))); | ||
|
||
sendNotificationOutPort.notify(SendNotification.builder() | ||
.receivers(receivers.stream().map(User::getEmail).toList()) | ||
.subject(notification.getTitle()) | ||
.body(notification.getMessage()) | ||
.build()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...le/src/main/java/io/miragon/miranum/platform/example/application/domain/Notification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.miragon.miranum.platform.example.application.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class Notification { | ||
|
||
private String eventName; | ||
private String taskName; | ||
|
||
public String getTitle() { | ||
return eventName.equalsIgnoreCase("create") || eventName.equalsIgnoreCase("assignment") ? | ||
String.format("Task %s was assigned to you", taskName) : | ||
String.format("Task %s was completed", taskName); | ||
} | ||
|
||
public String getMessage() { | ||
return eventName.equalsIgnoreCase("create") || eventName.equalsIgnoreCase("assignment") ? | ||
"You have a new Task": | ||
"Task was completed"; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...rc/main/java/io/miragon/miranum/platform/example/application/domain/SendNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.miragon.miranum.platform.example.application.domain; | ||
|
||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
|
||
@Builder | ||
public record SendNotification( | ||
List<String> receivers, | ||
String subject, | ||
String body | ||
) { } |
13 changes: 13 additions & 0 deletions
13
...main/java/io/miragon/miranum/platform/example/application/port/in/NotificationInPort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.miragon.miranum.platform.example.application.port.in; | ||
|
||
import io.miragon.miranum.platform.example.application.domain.Notification; | ||
|
||
import java.util.List; | ||
|
||
public interface NotificationInPort { | ||
|
||
void notifyUsers(final List<String> users, final Notification notification); | ||
|
||
void notifyGroup(final List<String> groups, final Notification notification); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...ava/io/miragon/miranum/platform/example/application/port/out/SendNotificationOutPort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.miragon.miranum.platform.example.application.port.out; | ||
|
||
import io.miragon.miranum.platform.example.application.domain.SendNotification; | ||
|
||
public interface SendNotificationOutPort { | ||
|
||
void notify(final SendNotification sendNotification); | ||
|
||
} |
12 changes: 6 additions & 6 deletions
12
.../main/java/io/miragon/miranum/platform/example/shared/security/SecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ndaAuthenticationFilterConfiguration.java → ...ndaAuthenticationFilterConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../sso/CamundaUserAuthenticationFilter.java → .../sso/CamundaUserAuthenticationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ne/sso/TokenParsingOAuth2UserService.java → ...ed/sso/TokenParsingOAuth2UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...gine/sso/TokenParsingOidcUserService.java → ...ared/sso/TokenParsingOidcUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../engine/sso/init/AuthorizationHelper.java → .../shared/sso/init/AuthorizationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...engine/sso/rest/RestExceptionHandler.java → ...shared/sso/rest/RestExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ContainerBasedAuthenticationProvider.java → ...ContainerBasedAuthenticationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...engine/sso/webapp/OAuthLogoutHandler.java → ...shared/sso/webapp/OAuthLogoutHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...eadOnlyIdentityProviderConfiguration.java → ...eadOnlyIdentityProviderConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.