Skip to content
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

Mail user on TransactionStop and SuspendedEV event #1263

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0005fa7
StringUtils: add method to check mail address
Aug 2, 2023
4cbea6f
UserRepository: add method "User.Details getDetails(String ocppTag)"
Aug 2, 2023
75fd4fa
TransactionRepository: add method "Transaction getTransaction(int tra…
Aug 2, 2023
e254786
MailService: change method "send(String subject, String body)" to "se…
Aug 2, 2023
4eadaa8
NotificationService: in method "ocppTransactionEnded(OcppTransactionE…
Aug 2, 2023
dd6fc78
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Aug 2, 2023
1b366b4
OcppStationStatusSuspendedEV.java added
Aug 2, 2023
e38a108
NotificationFeature.java: added NotificationFeature "OcppStationStatu…
Aug 2, 2023
f51a3da
CentralSystemService16_Service.java: on a statusNotification, added p…
Aug 2, 2023
df0b5c4
OcppServerRepository: add method getConnectorPK
Aug 2, 2023
7f73ecd
TransactionRepository: add method getOcppTagOfActiveTransaction(integ…
Aug 2, 2023
4ca23a6
NotificationService: added Event ocppStationStatusSuspendedEV(OcppSta…
Aug 2, 2023
64707ee
NotificationService & CentralSystemService16_Service: Format and Comm…
Aug 4, 2023
00853ff
NotificationService: added mail to "admin" in OcppStationStatusSuspen…
Aug 5, 2023
bf113ab
NotificationService: formated mail text in OcppStationStatusSuspended…
Aug 5, 2023
4392296
NotificationService.java & OcppStationStatusSuspend: commeting and fo…
Oct 12, 2023
fac303d
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Oct 12, 2023
ee0e608
Merge origin/MailUserAtTransactionStop into MailUserAtTransactionStop
Oct 12, 2023
8e44e38
style correction
Oct 12, 2023
472b75d
style correction
Oct 17, 2023
a38d588
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Nov 28, 2023
d1f586d
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Dec 13, 2023
416c838
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Dec 23, 2023
953abb4
TransactionRepositoryImpl, method getOcppTagOfActiveTransaction: orde…
Dec 23, 2023
48d7a68
NotificationService, SuspendedEV & TransactionStop: catch exception i…
Dec 23, 2023
6a2a702
Removed unnecessary code
Dec 25, 2023
eb64190
NotificationService: shorten the error log message (no stack info)
Dec 25, 2023
102ea16
BeanConfiguration: add @EnableAsync to activate @Async in Notificatio…
Dec 25, 2023
1798ba9
BeanConfiguration: removed @EnableAsync because it's notcompiling und…
Dec 26, 2023
14ac662
NotificationService: removing @Async annotations. Realizing async ins…
Dec 26, 2023
817bc5d
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Jan 15, 2024
6a9091c
OcppServerRepository remove method getConnectorPk
Jan 23, 2024
3d26aa2
TransactionRepository: add method getActiveTransactionId(String chage…
Jan 23, 2024
4c66f00
add timestamp to SUSPENDED_EV notification
Jan 23, 2024
4d2963a
adapt methode notificationActionSuspendedEV -> removed ocppServerRepo…
Jan 23, 2024
230c1ee
getActiveTransactionId(String chargeBox, Integer connectorId) method,…
Jan 23, 2024
a1d5ce1
Merge origin/MailUserAtTransactionStop into MailUserAtTransactionStop
Jan 23, 2024
f7919f7
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Feb 1, 2024
2c46260
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Feb 6, 2024
0563e46
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Feb 19, 2024
26442d3
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Mar 28, 2024
f61a428
Merge branch 'master' into MailUserAtTransactionStop
fnkbsi Apr 3, 2024
9faa7b4
Restore @override annotation after reslove conflict
fnkbsi Apr 3, 2024
a85bbef
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Apr 19, 2024
199b45c
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi May 13, 2024
f5edb5d
Merge branch 'steve-community:master' into MailUserAtTransactionStop
fnkbsi Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style correction
  • Loading branch information
fnkbsi committed Oct 12, 2023
commit 8e44e3891f12ae3ce7c5941aab3ec00e3e4c8850
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface OcppServerRepository {
void updateChargeboxHeartbeat(String chargeBoxIdentity, DateTime ts);

void insertConnectorStatus(InsertConnectorStatusParams params);
public Integer getConnectorPk(String chargeBoxId, int connectorId);
Integer getConnectorPk(String chargeBoxId, int connectorId);

void insertMeterValues(String chargeBoxIdentity, List<MeterValue> list, int connectorId, Integer transactionId);
void insertMeterValues(String chargeBoxIdentity, List<MeterValue> list, int transactionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @since 19.08.2014
*/
public interface TransactionRepository {
Transaction getTransaction(int transaction_pk);
Transaction getTransaction(int transactionPk);

List<Transaction> getTransactions(TransactionQueryForm form);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ public void insertConnectorStatus(InsertConnectorStatusParams p) {
}

@Override
public Integer getConnectorPk(String chargeBoxId, int connectorId){
public Integer getConnectorPk(String chargeBoxId, int connectorId) {
return ctx.select(CONNECTOR.CONNECTOR_PK)
.from(CONNECTOR)
.where(CONNECTOR.CHARGE_BOX_ID.equal(chargeBoxId))
.and(CONNECTOR.CONNECTOR_ID.equal(connectorId))
.fetchOne().value1();
.fetchOne().value1();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public TransactionRepositoryImpl(DSLContext ctx) {
}

@Override
public Transaction getTransaction(int transaction_pk) {
public Transaction getTransaction(int transactionPk) {
TransactionQueryForm form = new TransactionQueryForm();
form.setTransactionPk(transaction_pk);
form.setTransactionPk(transactionPk);
form.setReturnCSV(false);
form.setType(TransactionQueryForm.QueryType.ALL);
return getInternal(form).fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ public User.Details getDetails(int userPk) {

@Override
public User.Details getDetails(String ocppIdTag) {

Integer ocppPk = ctx.select(OCPP_TAG.OCPP_TAG_PK)
.from(OCPP_TAG)
.where(OCPP_TAG.ID_TAG.eq(ocppIdTag))
.fetchOne(OCPP_TAG.OCPP_TAG_PK);

if (ocppPk == null) {
throw new SteveException("There is no OCPP_Tag: '%s'", ocppIdTag);
}
Expand Down
76 changes: 41 additions & 35 deletions src/main/java/de/rwth/idsg/steve/service/NotificationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
return;
}

String subject = format("Connector '%s' of charging station '%s' is FAULTED",
String subject = format("Connector '%s' of charging station '%s' is FAULTED",
notification.getConnectorId(),
notification.getChargeBoxId()
);
Expand All @@ -135,63 +135,71 @@

@EventListener
@Async
public void ocppStationStatusSuspendedEV(OcppStationStatusSuspendedEV notification){
Integer connectorPk = ocppServerRepository.getConnectorPk(notification.getChargeBoxId(), notification.getConnectorId());
public void ocppStationStatusSuspendedEV(OcppStationStatusSuspendedEV notification) {
Integer connectorPk = ocppServerRepository.getConnectorPk(notification.getChargeBoxId(),

Check failure on line 139 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 Line has trailing spaces. Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:139:0: error: Line has trailing spaces. (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
notification.getConnectorId()
);
String ocppTag = transactionRepository.getOcppTagOfActiveTransaction(connectorPk);

String subject = format("EV stopped charging at charging station %s, Connector %d",
notification.getChargeBoxId(),
notification.getConnectorId());
String subject = format("EV stopped charging at charging station %s, Connector %d",
notification.getChargeBoxId(),
notification.getConnectorId()
);
if (ocppTag != null){

Check failure on line 148 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 '{' is not preceded with whitespace. Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:148:29: error: '{' is not preceded with whitespace. (com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck)

UserRecord userRecord = userRepository.getDetails(ocppTag).getUserRecord();
String eMailAddy = userRecord.getEMail();
// send email if user with eMail address found
if (!Strings.isNullOrEmpty(eMailAddy)){
String bodyUserMail = format("User: %s %s \n\n Connector %d of charging station %s notifies Suspended_EV",
userRecord.getFirstName(),
userRecord.getLastName(),
notification.getConnectorId(),
notification.getChargeBoxId()
);

mailService.sendAsync( subject, addTimestamp(bodyUserMail), eMailAddy);
if (!Strings.isNullOrEmpty(eMailAddy)) {
String bodyUserMail =

Check failure on line 154 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 Line has trailing spaces. Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:154:0: error: Line has trailing spaces. (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
format("User: %s %s \n\n Connector %d of charging station %s notifies Suspended_EV",
userRecord.getFirstName(),
userRecord.getLastName(),
notification.getConnectorId(),
notification.getChargeBoxId()
);

mailService.sendAsync(subject, addTimestamp(bodyUserMail), eMailAddy);
}
}

/* mail defined in settings */

Check failure on line 166 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 Line has trailing spaces. Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:166:0: error: Line has trailing spaces. (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
if (isDisabled(OcppStationStatusSuspendedEV)) {
return;
}
String body = format("Connector %d of charging station %s notifies Suspended_EV",
String body = format("Connector %d of charging station %s notifies Suspended_EV",
notification.getConnectorId(),
notification.getChargeBoxId());
mailService.sendAsync( subject, addTimestamp(body), "");
notification.getChargeBoxId()
);
mailService.sendAsync(subject, addTimestamp(body), "");
}

@EventListener
@Async
public void ocppTransactionEnded(OcppTransactionEnded notification) {
Transaction TransActParams = transactionRepository.getTransaction(notification.getParams().getTransactionId());
Transaction transActParams = transactionRepository.getTransaction(notification.getParams().getTransactionId());

TransActParams.getOcppTagPk();
UserRecord userRecord = userRepository.getDetails(TransActParams.getOcppIdTag()).getUserRecord();
transActParams.getOcppTagPk();
UserRecord userRecord = userRepository.getDetails(transActParams.getOcppIdTag()).getUserRecord();
String eMailAddress = userRecord.getEMail();

// mail to user
if (!Strings.isNullOrEmpty(eMailAddress)) {
String subjectUserMail = format("Transaction '%s' has ended on charging station '%s'",
TransActParams.getId(),
TransActParams.getChargeBoxId()
String subjectUserMail = format("Transaction '%s' has ended on charging station '%s'",
transActParams.getId(),
transActParams.getChargeBoxId()
);

// if the Transactionstop is received within the first Minute don't send an E-Mail
if (TransActParams.getStopTimestamp().isAfter(TransActParams.getStartTimestamp().plusMinutes(1))){
mailService.sendAsync(subjectUserMail, addTimestamp(createContent(TransActParams, userRecord)), eMailAddress);
if (transActParams.getStopTimestamp().isAfter(transActParams.getStartTimestamp().plusMinutes(1))) {
mailService.sendAsync(subjectUserMail,
addTimestamp(createContent(transActParams, userRecord)),
eMailAddress
);
}
}

/* mail defined in settings */

Check failure on line 202 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 Line has trailing spaces. Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:202:0: error: Line has trailing spaces. (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
if (isDisabled(OcppTransactionEnded)) {
return;
}
Expand Down Expand Up @@ -233,23 +241,21 @@
.toString();
}

private static String createContent(Transaction params, UserRecord userRecord) {
private static String createContent(Transaction params, UserRecord userRecord) {
Double meterValueDiff;
Integer meterValueStop;
Integer meterValueStart;
String str_meterValueDiff = "-";
try
{
String strMeterValueDiff = "-";
try {
meterValueStop = Integer.valueOf(params.getStopValue());
meterValueStart = Integer.valueOf(params.getStartValue());
meterValueDiff = (meterValueStop - meterValueStart)/1000.0; // --> kWh
str_meterValueDiff = meterValueDiff.toString() + " kWh";
meterValueDiff = (meterValueStop - meterValueStart) / 1000.0; // --> kWh
strMeterValueDiff = meterValueDiff.toString() + " kWh";
}

Check failure on line 254 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 '}' at column 9 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally). Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:254:9: error: '}' at column 9 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally). (com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck)
catch(NumberFormatException e)
{
catch(NumberFormatException e) {

Check failure on line 255 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 'catch' is not followed by whitespace. Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:255:9: error: 'catch' is not followed by whitespace. (com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck)
log.error("Failed to calculate charged energy! ", e);
}

Check failure on line 258 in src/main/java/de/rwth/idsg/steve/service/NotificationService.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 Line has trailing spaces. Raw Output: /github/workspace/./src/main/java/de/rwth/idsg/steve/service/NotificationService.java:258:0: error: Line has trailing spaces. (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
return new StringBuilder("User: ")
.append(userRecord.getFirstName()).append(" ").append(userRecord.getLastName())
.append(System.lineSeparator())
Expand All @@ -263,7 +269,7 @@
.append("- stopTimestamp (UTC): ").append(params.getStopTimestamp()).append(System.lineSeparator())
.append("- stopMeterValue: ").append(params.getStopValue()).append(System.lineSeparator())
.append("- stopReason: ").append(params.getStopReason()).append(System.lineSeparator())
.append("- charged energy: ").append(str_meterValueDiff).append(System.lineSeparator())
.append("- charged energy: ").append(strMeterValueDiff).append(System.lineSeparator())
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
/**
* @author fnkbsi
* @since 12.10.2022
*
*/

@Data
public class OcppStationStatusSuspendedEV {

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/de/rwth/idsg/steve/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ public static String getLastBitFromUrl(final String input) {

// https://www.baeldung.com/java-email-validation-regex
public static boolean isValidAddress(String emailAddress) {
String regexPattern = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$"; // Strict Regular Expression Validation
//String regexPattern = "^(?=.{1,64}@)[\\p{L}0-9_-]+(\\.[\\p{L}0-9_-]+)*@[^-][\\p{L}0-9-]+(\\.[\\p{L}0-9-]+)*(\\.[\\p{L}]{2,})$"; //Regular Expression for Validation of Non-Latin or Unicode Characters Email
//String regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$" // Regular Expression by RFC 5322 for Email Validation
// Strict Regular Expression Validation
String regexPattern =
"^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";
//Regular Expression for Validation of Non-Latin or Unicode Characters Email
//String regexPattern =
// "^(?=.{1,64}@)[\\p{L}0-9_-]+(\\.[\\p{L}0-9_-]+)*@[^-][\\p{L}0-9-]+(\\.[\\p{L}0-9-]+)*(\\.[\\p{L}]{2,})$";
// Regular Expression by RFC 5322 for Email Validation
//String regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"
return Pattern.compile(regexPattern)
.matcher(emailAddress)
.matches();
Expand Down
Loading