Skip to content

Commit 4ba01b0

Browse files
committed
shift mail "subject" construction after early exits
reason: dont do if not needed.
1 parent be663b1 commit 4ba01b0

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/main/java/de/rwth/idsg/steve/service/NotificationServiceForUser.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public class NotificationServiceForUser {
5858
public void ocppStationStatusFailure(OcppStationStatusFailure event) {
5959
log.debug("Processing: {}", event);
6060

61-
String subject = format("Connector '%s' of charging station '%s' is FAULTED",
62-
event.getConnectorId(),
63-
event.getChargeBoxId()
64-
);
65-
6661
var transaction = transactionService.getActiveTransaction(event.getChargeBoxId(), event.getConnectorId());
6762
if (transaction == null) {
6863
return;
@@ -73,6 +68,11 @@ public void ocppStationStatusFailure(OcppStationStatusFailure event) {
7368
return;
7469
}
7570

71+
String subject = format("Connector '%s' of charging station '%s' is FAULTED",
72+
event.getConnectorId(),
73+
event.getChargeBoxId()
74+
);
75+
7676
// send email if user with eMail address found
7777
String bodyUserMail =
7878
format("User: %s \n\n Connector %d of charging station %s notifies FAULTED! \n\n Error code: %s",
@@ -81,6 +81,7 @@ public void ocppStationStatusFailure(OcppStationStatusFailure event) {
8181
event.getChargeBoxId(),
8282
event.getErrorCode()
8383
);
84+
8485
mailService.send(subject, addTimestamp(bodyUserMail), List.of(user.getEmail()));
8586
}
8687

@@ -89,17 +90,17 @@ public void ocppStationStatusFailure(OcppStationStatusFailure event) {
8990
public void ocppTransactionStarted(OcppTransactionStarted event) {
9091
log.debug("Processing: {}", event);
9192

92-
String subject = format("Transaction '%s' has started on charging station '%s' on connector '%s'",
93-
event.getTransactionId(),
94-
event.getParams().getChargeBoxId(),
95-
event.getParams().getConnectorId()
96-
);
97-
9893
var user = getUserForMail(event.getParams().getIdTag(), NotificationFeature.OcppTransactionStarted);
9994
if (user == null) {
10095
return;
10196
}
10297

98+
String subject = format("Transaction '%s' has started on charging station '%s' on connector '%s'",
99+
event.getTransactionId(),
100+
event.getParams().getChargeBoxId(),
101+
event.getParams().getConnectorId()
102+
);
103+
103104
// send email if user with eMail address found
104105
String bodyUserMail =
105106
format("User: %s started transaction '%d' on connector '%s' of charging station '%s'",
@@ -108,6 +109,7 @@ public void ocppTransactionStarted(OcppTransactionStarted event) {
108109
event.getParams().getConnectorId(),
109110
event.getParams().getChargeBoxId()
110111
);
112+
111113
mailService.send(subject, addTimestamp(bodyUserMail), List.of(user.getEmail()));
112114
}
113115

@@ -116,11 +118,6 @@ public void ocppTransactionStarted(OcppTransactionStarted event) {
116118
public void ocppStationStatusSuspendedEV(OcppStationStatusSuspendedEV event) {
117119
log.debug("Processing: {}", event);
118120

119-
String subject = format("EV stopped charging at charging station %s, Connector %d",
120-
event.getChargeBoxId(),
121-
event.getConnectorId()
122-
);
123-
124121
var transaction = transactionService.getActiveTransaction(event.getChargeBoxId(), event.getConnectorId());
125122
if (transaction == null) {
126123
return;
@@ -131,13 +128,19 @@ public void ocppStationStatusSuspendedEV(OcppStationStatusSuspendedEV event) {
131128
return;
132129
}
133130

131+
String subject = format("EV stopped charging at charging station %s, Connector %d",
132+
event.getChargeBoxId(),
133+
event.getConnectorId()
134+
);
135+
134136
// send email if user with eMail address found
135137
String bodyUserMail =
136138
format("User: %s \n\n Connector %d of charging station %s notifies Suspended_EV",
137139
user.getName(),
138140
event.getConnectorId(),
139141
event.getChargeBoxId()
140142
);
143+
141144
mailService.send(subject, addTimestamp(bodyUserMail), List.of(user.getEmail()));
142145
}
143146

@@ -146,18 +149,18 @@ public void ocppStationStatusSuspendedEV(OcppStationStatusSuspendedEV event) {
146149
public void ocppTransactionEnded(OcppTransactionEnded event) {
147150
log.debug("Processing: {}", event);
148151

149-
String subject = format("Transaction '%s' has ended on charging station '%s'",
150-
event.getParams().getTransactionId(),
151-
event.getParams().getChargeBoxId()
152-
);
153-
154152
var transaction = transactionService.getTransaction(event.getParams().getTransactionId());
155153

156154
var user = getUserForMail(transaction.getOcppIdTag(), NotificationFeature.OcppTransactionEnded);
157155
if (user == null) {
158156
return;
159157
}
160158

159+
String subject = format("Transaction '%s' has ended on charging station '%s'",
160+
event.getParams().getTransactionId(),
161+
event.getParams().getChargeBoxId()
162+
);
163+
161164
mailService.send(subject, addTimestamp(createContent(transaction, user)), List.of(user.getEmail()));
162165
}
163166

0 commit comments

Comments
 (0)