Skip to content

Commit 3b8b05e

Browse files
committed
tighten the constraints of accepting reservations
reason: check whether the reservation details sent by the charging station match the details in the database. and prevent overwriting/reusing reservations (status check).
1 parent 11cbdf0 commit 3b8b05e

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import de.rwth.idsg.steve.repository.dto.Reservation;
55
import de.rwth.idsg.steve.web.dto.ReservationQueryForm;
66
import org.jooq.DSLContext;
7+
import org.jooq.Record1;
8+
import org.jooq.Select;
79

810
import java.util.List;
911

@@ -30,5 +32,6 @@ public interface ReservationRepository {
3032

3133
void accepted(int reservationId);
3234
void cancelled(int reservationId);
33-
void used(DSLContext ctx, int reservationId, int transactionId);
35+
void used(DSLContext ctx, Select<Record1<Integer>> connectorPkSelect, String ocppIdTag,
36+
int reservationId, int transactionId);
3437
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public Integer insertTransaction(InsertTransactionParams p) {
202202
// -------------------------------------------------------------------------
203203

204204
if (p.isSetReservationId()) {
205-
reservationRepository.used(ctx, p.getReservationId(), transactionId);
205+
reservationRepository.used(ctx, connectorPkQuery, p.getIdTag(), p.getReservationId(), transactionId);
206206
}
207207

208208
// -------------------------------------------------------------------------

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jooq.Record1;
1515
import org.jooq.Record10;
1616
import org.jooq.RecordMapper;
17+
import org.jooq.Select;
1718
import org.jooq.SelectConditionStep;
1819
import org.jooq.SelectQuery;
1920
import org.jooq.exception.DataAccessException;
@@ -137,12 +138,21 @@ public void cancelled(int reservationId) {
137138
}
138139

139140
@Override
140-
public void used(DSLContext ctx, int reservationId, int transactionId) {
141-
ctx.update(RESERVATION)
142-
.set(RESERVATION.STATUS, ReservationStatus.USED.name())
143-
.set(RESERVATION.TRANSACTION_PK, transactionId)
144-
.where(RESERVATION.RESERVATION_PK.equal(reservationId))
145-
.execute();
141+
public void used(DSLContext ctx, Select<Record1<Integer>> connectorPkSelect, String ocppIdTag,
142+
int reservationId, int transactionId) {
143+
int count = ctx.update(RESERVATION)
144+
.set(RESERVATION.STATUS, ReservationStatus.USED.name())
145+
.set(RESERVATION.TRANSACTION_PK, transactionId)
146+
.where(RESERVATION.RESERVATION_PK.equal(reservationId))
147+
.and(RESERVATION.ID_TAG.equal(ocppIdTag))
148+
.and(RESERVATION.CONNECTOR_PK.equal(connectorPkSelect))
149+
.and(RESERVATION.STATUS.eq(ReservationStatus.ACCEPTED.name()))
150+
.execute();
151+
152+
if (count != 1) {
153+
log.warn("Could not mark the reservation '{}' as used: Problems occurred due to sent reservation id, " +
154+
"charge box connector, user id tag or the reservation was used already.", reservationId);
155+
}
146156
}
147157

148158
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)