Skip to content

Commit d45ced3

Browse files
committed
refactor
1 parent af66951 commit d45ced3

File tree

5 files changed

+71
-39
lines changed

5 files changed

+71
-39
lines changed

src/main/java/de/rwth/idsg/steve/repository/TransactionRepository.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
* @since 19.08.2014
3131
*/
3232
public interface TransactionRepository {
33-
Transaction getTransaction(int transactionPk);
34-
35-
Transaction getActiveTransaction(String chargeBoxId, Integer connectorId);
36-
3733
List<Transaction> getTransactions(TransactionQueryForm form);
3834

3935
void writeTransactionsCSV(TransactionQueryForm form, Writer writer);

src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,6 @@ public class TransactionRepositoryImpl implements TransactionRepository {
6363

6464
private final DSLContext ctx;
6565

66-
@Override
67-
public Transaction getTransaction(int transactionPk) {
68-
TransactionQueryForm form = new TransactionQueryForm();
69-
form.setTransactionPk(transactionPk);
70-
form.setReturnCSV(false);
71-
form.setType(TransactionQueryForm.QueryType.ALL);
72-
return getInternal(form).fetch()
73-
.map(new TransactionMapper()).get(0);
74-
}
75-
76-
@Override
77-
public Transaction getActiveTransaction(String chargeBoxId, Integer connectorId) {
78-
Transaction retVal = null;
79-
TransactionQueryForm form = new TransactionQueryForm();
80-
form.setChargeBoxId(chargeBoxId);
81-
form.setConnectorId(connectorId);
82-
form.setReturnCSV(false);
83-
form.setType(TransactionQueryForm.QueryType.ACTIVE);
84-
Record12<Integer, String, Integer, String, DateTime, String,
85-
DateTime, String, String, Integer, Integer, TransactionStopEventActor>
86-
transactionRecord = getInternal(form).fetchAny();
87-
if (transactionRecord != null) {
88-
TransactionMapper mapper = new TransactionMapper();
89-
retVal = mapper.map(transactionRecord);
90-
}
91-
return retVal;
92-
}
93-
9466
@Override
9567
public List<Transaction> getTransactions(TransactionQueryForm form) {
9668
return getInternal(form).fetch()
@@ -309,7 +281,7 @@ private SelectQuery addConditions(SelectQuery selectQuery, TransactionQueryForm
309281
selectQuery.addConditions(CONNECTOR.CHARGE_BOX_ID.eq(form.getChargeBoxId()));
310282
}
311283

312-
if (form.isConnectorId()) {
284+
if (form.isConnectorIdSet()) {
313285
selectQuery.addConditions(CONNECTOR.CONNECTOR_ID.eq(form.getConnectorId()));
314286
}
315287

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
public class NotificationService {
6565

6666
private final MailService mailService;
67-
private final TransactionRepository transactionRepository;
67+
private final TransactionService transactionService;
6868
private final UserRepository userRepository;
6969
private final DelegatingTaskExecutor asyncTaskExecutor;
7070

@@ -136,7 +136,7 @@ public void ocppStationStatusFailure(OcppStationStatusFailure notification) {
136136

137137
private void userNotificationOcppStationStatusFailure(OcppStationStatusFailure notification, String subject) {
138138

139-
Transaction transaction = transactionRepository.getActiveTransaction(notification.getChargeBoxId(),
139+
Transaction transaction = transactionService.getActiveTransaction(notification.getChargeBoxId(),
140140
notification.getConnectorId());
141141
if (transaction == null) {
142142
return;
@@ -267,7 +267,7 @@ public void ocppStationStatusSuspendedEV(OcppStationStatusSuspendedEV notificati
267267

268268
private void userNotificationActionSuspendedEV(OcppStationStatusSuspendedEV notification, String subject) {
269269

270-
Transaction transaction = transactionRepository.getActiveTransaction(notification.getChargeBoxId(),
270+
Transaction transaction = transactionService.getActiveTransaction(notification.getChargeBoxId(),
271271
notification.getConnectorId());
272272
if (transaction == null) {
273273
return;
@@ -338,7 +338,7 @@ private void userNotificationActionTransactionEnded(OcppTransactionEnded notific
338338
String eMailAddress = null;
339339
UserRecord userRecord = new UserRecord();
340340

341-
Transaction transActParams = transactionRepository.getTransaction(notification.getParams().getTransactionId());
341+
Transaction transActParams = transactionService.getTransaction(notification.getParams().getTransactionId());
342342

343343
// if the Transactionstop is received within the first Minute don't send an E-Mail
344344
if (!transActParams.getStopTimestamp().isAfter(transActParams.getStartTimestamp().plusMinutes(1))) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
3+
* Copyright (C) 2013-2025 SteVe Community Team
4+
* All Rights Reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package de.rwth.idsg.steve.service;
20+
21+
import de.rwth.idsg.steve.repository.TransactionRepository;
22+
import de.rwth.idsg.steve.repository.dto.Transaction;
23+
import de.rwth.idsg.steve.web.dto.TransactionQueryForm;
24+
import lombok.RequiredArgsConstructor;
25+
import lombok.extern.slf4j.Slf4j;
26+
import org.springframework.stereotype.Service;
27+
28+
/**
29+
* @author Sevket Goekay <[email protected]>
30+
* @since 02.10.2025
31+
*/
32+
@Slf4j
33+
@Service
34+
@RequiredArgsConstructor
35+
public class TransactionService {
36+
37+
private final TransactionRepository transactionRepository;
38+
39+
public Transaction getTransaction(int transactionPk) {
40+
TransactionQueryForm form = new TransactionQueryForm();
41+
form.setTransactionPk(transactionPk);
42+
form.setReturnCSV(false);
43+
form.setType(TransactionQueryForm.QueryType.ALL);
44+
45+
return transactionRepository.getTransactions(form).getFirst();
46+
}
47+
48+
public Transaction getActiveTransaction(String chargeBoxId, Integer connectorId) {
49+
TransactionQueryForm form = new TransactionQueryForm();
50+
form.setChargeBoxId(chargeBoxId);
51+
form.setConnectorId(connectorId);
52+
form.setReturnCSV(false);
53+
form.setType(TransactionQueryForm.QueryType.ACTIVE);
54+
55+
var transactions = transactionRepository.getTransactions(form);
56+
if (transactions.isEmpty()) {
57+
return null;
58+
} else if (transactions.size() == 1) {
59+
return transactions.get(0);
60+
} else {
61+
throw new IllegalStateException("There are multiple active transactions with the same charge box id and connector id");
62+
}
63+
}
64+
}

src/main/java/de/rwth/idsg/steve/web/dto/TransactionQueryForm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class TransactionQueryForm extends QueryForm {
4141
private Integer transactionPk;
4242

4343
@Schema(description = "ID of the connector")
44-
Integer connectorId;
44+
private Integer connectorId;
4545

4646
@Schema(description = "Disabled for the Web APIs. Do not use and set", hidden = true)
4747
private boolean returnCSV = false;
@@ -64,7 +64,7 @@ public boolean isTransactionPkSet() {
6464
}
6565

6666
@Schema(hidden = true)
67-
public boolean isConnectorId() {
67+
public boolean isConnectorIdSet() {
6868
return connectorId != null;
6969
}
7070

0 commit comments

Comments
 (0)