Skip to content

Mail user on TransactionStop and SuspendedEV event #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 62 commits into
base: master
Choose a base branch
from

Conversation

fnkbsi
Copy link
Contributor

@fnkbsi fnkbsi commented Oct 12, 2023

Send a email to the transaction user in case of SuspendedEV and Transaction Stop, if the email address of the user is stored in the database.

Tester and others added 18 commits August 2, 2023 19:19
…nd(String subject, String body, String RecipientAddresses)" use addresses from setting if RecipientAddresses is empty; adding method "sendAsync(String subject, String body, String RecipientAddresses)"
…nded notification)" adding send mail to user (if email address is in the database), adding createContent method for user mail
…ublishing a event if the status is "SuspendedEV"
…tionStatusSuspendedEV notification) to send a mail to the user
@Zeppel
Copy link

Zeppel commented Dec 22, 2023

Steve tries infinitely to send mails for every tag without a user. After some time the server becomes unstable.

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Dec 22, 2023

@Zeppel: Thanks for the feedback.
I try to reproduce the behavior. It would help if you can answer some the following questions.
On which event starts SteVe to try sending mails?
Which notification are selected on the setting-website? Is the List of recipients empty?
Are the OCPP-Tags without user blocked or active? (Does SteVe try to send to both?)
Is the transaction started with an OCPP-Tag without a user?
Can you provide a log file?

@Zeppel
Copy link

Zeppel commented Dec 25, 2023

@fnkbsi
Event: occures at SuspendedEV event

Selected Notifies:
image

1 entry in recipients

OCPP-Tag is active and started the transcation without an user.

Log attached - Exception occures 10x per second until a user is found, no mails will be send. If a user is selected for the tag afterwards, mails are send to the user and recipient email. Errors stop then.
steve.log

occurred location:
src/main/java/de/rwth/idsg/steve/repository/UserRepository.java
User.Details getDetails

Expected behavior:
return and do nothing

@juherr
Copy link
Contributor

juherr commented Jun 19, 2024

@goekay Please review, this PR is improving the product

@goekay
Copy link
Member

goekay commented Jun 23, 2024

what if the user does not want to receive emails?

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Jun 23, 2024

what if the user does not want to receive emails?

Currently the mail-address must removed. I admit this works not with all business cases. Better solution would be to save the user decision in the DB. I can add a column to the user table or adding a new table (user_pk, send_mail), which should it be?

update: with this commit the solution with a new column is added

fnkbsi and others added 11 commits August 8, 2024 14:57
… a new row of the user table as comma separated list.
# resoled Conflicts:
#	src/main/resources/db/migration/V1_0_6__update.sql
# relsolved Conflicts:
#	src/main/java/de/rwth/idsg/steve/service/MailService.java
# resolved Conflicts:
#	src/main/java/de/rwth/idsg/steve/service/MailService.java
# ressolved Conflicts:
#	src/main/java/de/rwth/idsg/steve/service/MailService.java
	-> implementation moved to MailServiceDefault
# resolved Conflicts:
#	src/main/resources/checkstyle.xml
@goekay
Copy link
Member

goekay commented Apr 20, 2025

hey @fnkbsi, i want to proceed with this PR and here is my feedback:

  • i think two new TransactionRepository methods are not necessary. you are making 2 DB calls (worst case) in your NotificationService impl: first for "is there an active transaction" and second for "give me data of this transaction". this can be done in one call. we can extend getTransactions(TransactionQueryForm form) to support connectorId as query param. then, you would have everything you need and can use one DB call.
  • i personally think list of UserNotificationFeatures for the user overview page might be too crowded. it should be enough/fine to see them only on user detail page. WDYT?
  • StringUtils.isValidAddress should not be necessary during operation (i.e. check when sending email). if an email is invalid, it should not enter our system and database. validation should occur during input. see @Email validation. why do you think this is needed, additionally?
  • i think NotificationService became too crowded handling two concerns: system/admin mails, and user mails. what about creating a UserNotificationService and leaving NotificationService as is? you can put the @EventListener on its methods just fine. then, this event will have two listeners.
  • the if-else block nesting is a bit too much NotificationService. i would kindly suggest to us the early exit (or early return) pattern to keep the flow linear.
  • String recipientAddresses should not enter a business service (MailService) like this IMO. it should be List<String> recipientAddresses. data transformation etc. should be handled outside of it.

thanks!

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Apr 26, 2025

hey @fnkbsi, i want to proceed with this PR and here is my feedback:

  • i think two new TransactionRepository methods are not necessary. you are making 2 DB calls (worst case) in your NotificationService impl: first for "is there an active transaction" and second for "give me data of this transaction". this can be done in one call. we can extend getTransactions(TransactionQueryForm form) to support connectorId as query param. then, you would have everything you need and can use one DB call.
    -->Good point, pls check the revised version
  • i personally think list of UserNotificationFeatures for the user overview page might be too crowded. it should be enough/fine to see them only on user detail page. WDYT?
    --> My idea behind this was: the Detail-Site is for changes, the overview also for users with less rights. So the user with less rights can also check if notification should be send. Not sure this is really a use-case. If not it's easy to remove it from the js-file.
  • StringUtils.isValidAddress should not be necessary during operation (i.e. check when sending email). if an email is invalid, it should not enter our system and database. validation should occur during input. see @Email validation. why do you think this is needed, additionally?
    --> Should be true. But I didn't changed it yet.
  • i think NotificationService became too crowded handling two concerns: system/admin mails, and user mails. what about creating a UserNotificationService and leaving NotificationService as is? you can put the @EventListener on its methods just fine. then, this event will have two listeners.
    --> may be a good idea, but I have no time to implement and test it
  • the if-else block nesting is a bit too much NotificationService. i would kindly suggest to us the early exit (or early return) pattern to keep the flow linear.
    --> accepted and changed
  • String recipientAddresses should not enter a business service (MailService) like this IMO. it should be List<String> recipientAddresses. data transformation etc. should be handled outside of it.
    --> accepted and changed

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants