Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ResponseEntity<ApiChargePoint> create(@RequestBody @Valid ChargePointForm
var body = toDto(chargePointsService.getDetails(chargepointPk));
var location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(body.getChargeBoxPk())
.buildAndExpand(chargepointPk)
.toUri();
return ResponseEntity.created(location).body(body);
}
Expand Down Expand Up @@ -105,8 +105,7 @@ private static ApiChargePoint toDto(ChargePoint.Overview overview) {
}

private static ApiChargePoint toDto(ChargePoint.Details details) {
return new ApiChargePoint(
details.getChargeBox().getChargeBoxPk(), details.getChargeBox().getChargeBoxId());
return new ApiChargePoint(details.getChargeBoxPk(), details.getChargeBoxId());
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ResponseEntity<Reservation> addReservation(@Valid @RequestBody Reservatio
public Reservation deleteReservation(@PathVariable int id) {
var reservation = reservationsService
.getReservation(id)
.orElseThrow(() -> new SteveException.NotFound("Reservation with id %d not found", id));
.orElseThrow(() -> new SteveException.NotFound("Reservation with id %d not found".formatted(id)));
reservationsService.deleteReservation(id);
return reservation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ResponseEntity<User.Details> addUser(@Valid @RequestBody UserForm form) {
var body = usersService.add(form);
var location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(body.getUserRecord().getUserPk())
.buildAndExpand(body.getUserPk())
.toUri();
return ResponseEntity.created(location).body(body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import de.rwth.idsg.steve.repository.dto.ChargePoint;
import de.rwth.idsg.steve.service.ChargePointsService;
import de.rwth.idsg.steve.web.dto.ChargePointForm;
import jooq.steve.db.tables.records.ChargeBoxRecord;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -108,10 +107,10 @@ public void testGetOne_found() {
}

private static ChargePoint.Details createDetails(Integer pk, String chargeBoxId) {
ChargeBoxRecord cbr = new ChargeBoxRecord();
cbr.setChargeBoxPk(pk);
cbr.setChargeBoxId(chargeBoxId);
return new ChargePoint.Details(cbr, null);
return ChargePoint.Details.builder()
.chargeBoxPk(pk)
.chargeBoxId(chargeBoxId)
.build();
}

@Test
Expand Down Expand Up @@ -161,9 +160,7 @@ public void testPut() throws Exception {
@Test
@DisplayName("DELETE: Entity deleted, expected 200")
public void testDelete() {
var rec = new ChargeBoxRecord();
rec.setChargeBoxPk(1);
var result = new ChargePoint.Details(rec, null);
var result = createDetails(1, "test-cb");
when(chargePointsService.getDetails(1)).thenReturn(result);

assertThat(mockMvc.perform(delete("/api/v1/chargeboxes/1"))).hasStatusOk();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ public void test18() throws Exception {

// when
when(ocppTagsService.addOcppTag(form))
.thenThrow(new SteveException.AlreadyExists("A user with idTag '%s' already exists.", ocppTagPk));
.thenThrow(new SteveException.AlreadyExists(
"A user with idTag '%s' already exists.".formatted(ocppTagPk)));

Comment on lines +456 to 458
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Wrong placeholder content: using ocppTagPk where idTag is expected

Message says idTag but formats with ocppTagPk (123). Use the actual idTag to keep user-facing text correct.

-                .thenThrow(new SteveException.AlreadyExists(
-                        "A user with idTag '%s' already exists.".formatted(ocppTagPk)));
+                .thenThrow(new SteveException.AlreadyExists(
+                        "A user with idTag '%s' already exists.".formatted(form.getIdTag())));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.thenThrow(new SteveException.AlreadyExists(
"A user with idTag '%s' already exists.".formatted(ocppTagPk)));
.thenThrow(new SteveException.AlreadyExists(
"A user with idTag '%s' already exists.".formatted(form.getIdTag())));
🤖 Prompt for AI Agents
In
steve-api/src/test/java/de/rwth/idsg/steve/web/api/OcppTagsRestControllerTest.java
around lines 456 to 458, the thrown SteveException.AlreadyExists message says "A
user with idTag '%s' already exists." but is formatted with ocppTagPk; update
the formatted argument to use the actual idTag variable (the idTag string used
in the test) instead of ocppTagPk so the user-facing text reflects the idTag
value.

// then
assertThat(mockMvc.perform(post("/api/v1/ocppTags")
Expand Down
4 changes: 0 additions & 4 deletions steve-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<artifactId>steve-core</artifactId>

<dependencies>
<dependency>
<groupId>de.rwth.idsg</groupId>
<artifactId>steve-jooq</artifactId>
</dependency>
<dependency>
<groupId>de.rwth.idsg</groupId>
<artifactId>steve-ocpp-1-x</artifactId>
Expand Down
54 changes: 10 additions & 44 deletions steve-core/src/main/java/de/rwth/idsg/steve/SteveException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package de.rwth.idsg.steve;

import static java.lang.String.format;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 28.08.2014
Expand All @@ -36,26 +34,6 @@ protected SteveException(String message, Throwable cause) {
super(message, cause);
}

// -------------------------------------------------------------------------
// No String/variable interpolation in Java. Use format instead.
// -------------------------------------------------------------------------

protected SteveException(String template, Object arg1) {
this(format(template, arg1));
}

protected SteveException(String template, Object arg1, Throwable cause) {
this(format(template, arg1), cause);
}

protected SteveException(String template, Object arg1, Object arg2) {
this(format(template, arg1, arg2));
}

protected SteveException(String template, Object arg1, Object arg2, Throwable cause) {
this(format(template, arg1, arg2), cause);
}

// -------------------------------------------------------------------------
// Custom/extending classes
// -------------------------------------------------------------------------
Expand All @@ -69,28 +47,16 @@ public InternalError(String message) {
public InternalError(String message, Throwable cause) {
super(message, cause);
}

public InternalError(String template, Object arg1) {
this(format(template, arg1));
}

public InternalError(String template, Object arg1, Throwable cause) {
this(format(template, arg1), cause);
}

public InternalError(String template, Object arg1, Object arg2) {
this(format(template, arg1, arg2));
}

protected InternalError(String template, Object arg1, Object arg2, Throwable cause) {
this(format(template, arg1, arg2), cause);
}
}

public static class AlreadyExists extends SteveException {

public AlreadyExists(String template, Object arg1) {
super(format(template, arg1));
public AlreadyExists(String message) {
super(message);
}

public AlreadyExists(String message, Throwable cause) {
super(message, cause);
}
}

Expand All @@ -100,8 +66,8 @@ public NotFound(String message) {
super(message);
}

public NotFound(String template, Object arg1) {
this(format(template, arg1));
public NotFound(String message, Throwable cause) {
super(message, cause);
}
}

Expand All @@ -110,8 +76,8 @@ public BadRequest(String message) {
super(message);
}

public BadRequest(String template, Object arg1) {
this(format(template, arg1));
public BadRequest(String message, Throwable cause) {
super(message, cause);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import de.rwth.idsg.steve.repository.ChargingProfileRepository;
import de.rwth.idsg.steve.repository.dto.ChargingProfile;
import de.rwth.idsg.steve.web.dto.ocpp.SetChargingProfileParams;
import jooq.steve.db.tables.records.ChargingProfileRecord;
import ocpp.cp._2015._10.ChargingProfileKindType;
import ocpp.cp._2015._10.ChargingProfilePurposeType;
import ocpp.cp._2015._10.ChargingRateUnitType;
Expand All @@ -31,8 +30,7 @@
import ocpp.cp._2015._10.RecurrencyKindType;
import ocpp.cp._2015._10.SetChargingProfileRequest;

import java.util.List;
import java.util.stream.Collectors;
import java.util.Optional;

import static de.rwth.idsg.steve.utils.DateTimeUtils.toOffsetDateTime;

Expand Down Expand Up @@ -64,7 +62,7 @@ public void success(String chargeBoxId, String statusValue) {
addNewResponse(chargeBoxId, statusValue);

if ("Accepted".equalsIgnoreCase(statusValue)) {
int chargingProfilePk = details.getProfile().getChargingProfilePk();
var chargingProfilePk = details.getChargingProfilePk();
chargingProfileRepository.setProfile(chargingProfilePk, chargeBoxId, connectorId);
}
}
Expand All @@ -73,36 +71,35 @@ public void success(String chargeBoxId, String statusValue) {

@Override
public SetChargingProfileRequest getOcpp16Request() {
ChargingProfileRecord profile = details.getProfile();

List<ChargingSchedulePeriod> schedulePeriods = details.getPeriods().stream()
var schedulePeriods = details.getPeriods().stream()
.map(k -> {
ChargingSchedulePeriod p = new ChargingSchedulePeriod();
p.setStartPeriod(k.getStartPeriodInSeconds());
p.setLimit(k.getPowerLimit());
p.setNumberPhases(k.getNumberPhases());
return p;
})
.collect(Collectors.toList());
.toList();

ChargingSchedule schedule = new ChargingSchedule()
.withDuration(profile.getDurationInSeconds())
.withStartSchedule(toOffsetDateTime(profile.getStartSchedule()))
.withChargingRateUnit(ChargingRateUnitType.fromValue(profile.getChargingRateUnit()))
.withMinChargingRate(profile.getMinChargingRate())
var schedule = new ChargingSchedule()
.withDuration(details.getDurationInSeconds())
.withStartSchedule(toOffsetDateTime(details.getStartSchedule()))
.withChargingRateUnit(ChargingRateUnitType.fromValue(details.getChargingRateUnit()))
.withMinChargingRate(details.getMinChargingRate())
.withChargingSchedulePeriod(schedulePeriods);

ocpp.cp._2015._10.ChargingProfile ocppProfile = new ocpp.cp._2015._10.ChargingProfile()
.withChargingProfileId(profile.getChargingProfilePk())
.withStackLevel(profile.getStackLevel())
.withChargingProfilePurpose(ChargingProfilePurposeType.fromValue(profile.getChargingProfilePurpose()))
.withChargingProfileKind(ChargingProfileKindType.fromValue(profile.getChargingProfileKind()))
.withRecurrencyKind(
profile.getRecurrencyKind() == null
? null
: RecurrencyKindType.fromValue(profile.getRecurrencyKind()))
.withValidFrom(toOffsetDateTime(profile.getValidFrom()))
.withValidTo(toOffsetDateTime(profile.getValidTo()))
var ocppProfile = new ocpp.cp._2015._10.ChargingProfile()
.withChargingProfileId(details.getChargingProfilePk())
.withStackLevel(details.getStackLevel())
// .withDescription(details.getDescription())
// .withNote(details.getNote())
.withChargingProfilePurpose(ChargingProfilePurposeType.fromValue(details.getChargingProfilePurpose()))
.withChargingProfileKind(ChargingProfileKindType.fromValue(details.getChargingProfileKind()))
.withRecurrencyKind(Optional.ofNullable(details.getRecurrencyKind())
.map(RecurrencyKindType::fromValue)
.orElse(null))
.withValidFrom(toOffsetDateTime(details.getValidFrom()))
.withValidTo(toOffsetDateTime(details.getValidTo()))
.withChargingSchedule(schedule);

var request =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@
package de.rwth.idsg.steve.repository;

import de.rwth.idsg.steve.web.dto.Address;
import jooq.steve.db.tables.records.AddressRecord;
import org.jooq.DSLContext;
import org.jooq.Record1;
import org.jooq.SelectConditionStep;
import org.jspecify.annotations.Nullable;

import java.util.Optional;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 24.11.2015
*/
public interface AddressRepository {
@Nullable AddressRecord get(DSLContext ctx, Integer addressPk);
Optional<Address> get(Integer addressPk);

@Nullable Integer updateOrInsert(DSLContext ctx, Address address);
@Nullable Integer updateOrInsert(Address address);

void delete(DSLContext ctx, SelectConditionStep<Record1<Integer>> addressPkSelect);
void delete(Integer addressPk);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import de.rwth.idsg.steve.repository.dto.DbVersion;
import de.rwth.idsg.steve.web.dto.Statistics;

import java.util.Optional;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 19.08.2014
Expand All @@ -35,5 +37,5 @@ public interface GenericRepository {
* Returns database version of SteVe and last database update timestamp
*
*/
DbVersion getDBVersion();
Optional<DbVersion> getDBVersion();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Breaking API: verify all call sites and implementors handle Optional.

Search for invocations that still expect DbVersion and adjust to Optional usage to avoid NPEs or compile errors.

Run:


🏁 Script executed:

#!/bin/bash
# Calls
rg -nP '\bgetDBVersion\s*\(' -C2

# Implementations
rg -nP 'class\s+\w+\s+implements\s+GenericRepository\b' -C2

Length of output: 2487


Unwrap Optional in AboutSettingsController#getAbout
Change

model.addAttribute("db", genericRepository.getDBVersion());

to

model.addAttribute("db", genericRepository.getDBVersion().orElse(null));
🤖 Prompt for AI Agents
In steve-core/src/main/java/de/rwth/idsg/steve/repository/GenericRepository.java
around line 40 and specifically in AboutSettingsController#getAbout, the
Optional<DbVersion> returned by genericRepository.getDBVersion() is being passed
directly to the model; change the call site to unwrap the Optional by using
orElse(null) so the model receives either the DbVersion or null (e.g., replace
model.addAttribute("db", genericRepository.getDBVersion()) with
model.addAttribute("db", genericRepository.getDBVersion().orElse(null))).

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
package de.rwth.idsg.steve.repository;

import de.rwth.idsg.steve.repository.dto.OcppTag;
import de.rwth.idsg.steve.repository.dto.OcppTagActivity;
import de.rwth.idsg.steve.web.dto.OcppTagForm;
import de.rwth.idsg.steve.web.dto.OcppTagQueryForm;
import jooq.steve.db.tables.records.OcppTagActivityRecord;
import org.jooq.Result;

import java.util.List;
import java.util.Optional;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
Expand All @@ -33,13 +33,13 @@
public interface OcppTagRepository {
List<OcppTag.OcppTagOverview> getOverview(OcppTagQueryForm form);

Result<OcppTagActivityRecord> getRecords();
List<OcppTagActivity> getRecords();

Result<OcppTagActivityRecord> getRecords(List<String> idTagList);
List<OcppTagActivity> getRecords(List<String> idTagList);

OcppTagActivityRecord getRecord(String idTag);
Optional<OcppTagActivity> getRecord(String idTag);

OcppTagActivityRecord getRecord(int ocppTagPk);
Optional<OcppTagActivity> getRecord(int ocppTagPk);

List<String> getIdTags();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import de.rwth.idsg.steve.repository.dto.InsertReservationParams;
import de.rwth.idsg.steve.repository.dto.Reservation;
import de.rwth.idsg.steve.web.dto.ReservationQueryForm;
import org.jooq.Record1;
import org.jooq.Select;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -54,5 +52,5 @@ public interface ReservationRepository {

void cancelled(int reservationId);

void used(Select<Record1<Integer>> connectorPkSelect, String ocppIdTag, int reservationId, int transactionId);
void used(int connectorPk, String ocppIdTag, int reservationId, int transactionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ public interface TransactionRepository {

Optional<Integer> getActiveTransactionId(String chargeBoxId, int connectorId);

TransactionDetails getDetails(int transactionPk);
Optional<TransactionDetails> getDetails(int transactionPk);
}
Loading
Loading