Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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 @@ -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
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
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 Down Expand Up @@ -64,7 +63,7 @@ public void success(String chargeBoxId, String statusValue) {
addNewResponse(chargeBoxId, statusValue);

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

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

List<ChargingSchedulePeriod> schedulePeriods = details.getPeriods().stream()
.map(k -> {
ChargingSchedulePeriod p = new ChargingSchedulePeriod();
Expand All @@ -86,23 +83,23 @@ public SetChargingProfileRequest getOcpp16Request() {
.collect(Collectors.toList());

ChargingSchedule schedule = new ChargingSchedule()
.withDuration(profile.getDurationInSeconds())
.withStartSchedule(toOffsetDateTime(profile.getStartSchedule()))
.withChargingRateUnit(ChargingRateUnitType.fromValue(profile.getChargingRateUnit()))
.withMinChargingRate(profile.getMinChargingRate())
.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()))
.withChargingProfileId(details.getChargingProfilePk())
.withStackLevel(details.getStackLevel())
.withChargingProfilePurpose(ChargingProfilePurposeType.fromValue(details.getChargingProfilePurpose()))
.withChargingProfileKind(ChargingProfileKindType.fromValue(details.getChargingProfileKind()))
.withRecurrencyKind(
profile.getRecurrencyKind() == null
details.getRecurrencyKind() == null
? null
: RecurrencyKindType.fromValue(profile.getRecurrencyKind()))
.withValidFrom(toOffsetDateTime(profile.getValidFrom()))
.withValidTo(toOffsetDateTime(profile.getValidTo()))
: RecurrencyKindType.fromValue(details.getRecurrencyKind()))
.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 @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
*/
package de.rwth.idsg.steve.repository;

import de.rwth.idsg.steve.repository.dto.WebUser;
import de.rwth.idsg.steve.service.dto.WebUserOverview;
import de.rwth.idsg.steve.web.dto.WebUserQueryForm;
import jooq.steve.db.tables.records.WebUserRecord;
import org.jooq.JSON;
import org.jooq.Record4;
import org.jooq.Result;

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

Comment on lines +21 to 27
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Layering breach: repository imports a service DTO.

import de.rwth.idsg.steve.service.dto.WebUserOverview; couples repository -> service. That inverts intended layering and conflicts with the PR goal. Move WebUserOverview under a repository- (or core-) scoped DTO package and import from there.

Example fix:

-import de.rwth.idsg.steve.service.dto.WebUserOverview;
+import de.rwth.idsg.steve.repository.dto.WebUserOverview;

Also ensure the class is relocated accordingly.

📝 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
import de.rwth.idsg.steve.repository.dto.WebUser;
import de.rwth.idsg.steve.service.dto.WebUserOverview;
import de.rwth.idsg.steve.web.dto.WebUserQueryForm;
import jooq.steve.db.tables.records.WebUserRecord;
import org.jooq.JSON;
import org.jooq.Record4;
import org.jooq.Result;
import java.util.List;
import java.util.Optional;
import de.rwth.idsg.steve.repository.dto.WebUser;
import de.rwth.idsg.steve.repository.dto.WebUserOverview;
import de.rwth.idsg.steve.web.dto.WebUserQueryForm;
import java.util.List;
import java.util.Optional;
🤖 Prompt for AI Agents
In steve-core/src/main/java/de/rwth/idsg/steve/repository/WebUserRepository.java
around lines 21 to 27, the file imports
de.rwth.idsg.steve.service.dto.WebUserOverview which creates a layering breach
by coupling repository to the service layer; to fix, move the WebUserOverview
DTO to a repository- (or core-) scoped package such as
de.rwth.idsg.steve.repository.dto (or de.rwth.idsg.steve.core.dto), update the
DTO's package declaration and relocate the source file accordingly, then change
the import in WebUserRepository to the new package and update any
references/usages across the codebase and build files to the new package name so
compilation and layering are consistent.

public interface WebUserRepository {

void createUser(WebUserRecord user);
void createUser(WebUser user);

void updateUser(WebUserRecord user);
void updateUser(WebUser user);

void updateUserByPk(WebUserRecord user);
void updateUserByPk(WebUser user);

void deleteUser(String username);

Expand All @@ -48,9 +49,9 @@ public interface WebUserRepository {

boolean userExists(String username);

WebUserRecord loadUserByUserPk(Integer webUserPk);
Optional<WebUser> loadUserByUserPk(Integer webUserPk);

WebUserRecord loadUserByUsername(String username);
Optional<WebUser> loadUserByUsername(String username);

Result<Record4<Integer, String, Boolean, JSON>> getOverview(WebUserQueryForm form);
List<WebUserOverview> getOverview(WebUserQueryForm form);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
package de.rwth.idsg.steve.repository.dto;

import jooq.steve.db.tables.records.AddressRecord;
import jooq.steve.db.tables.records.ChargeBoxRecord;
import com.neovisionaries.i18n.CountryCode;
import de.rwth.idsg.steve.web.dto.Address;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;
import java.time.Instant;

/**
Expand All @@ -40,9 +40,32 @@ public static final class Overview {
}

@Getter
@RequiredArgsConstructor
@Builder
public static final class Details {
private final ChargeBoxRecord chargeBox;
private final AddressRecord address;
private final Integer chargeBoxPk;
private final String chargeBoxId;
private final String ocppProtocol;
private final String description;
private final BigDecimal locationLatitude;
private final BigDecimal locationLongitude;
private final String note;
private final String adminAddress;
private final boolean insertConnectorStatusAfterTransactionMsg;
private final String registrationStatus;
private final String street;
private final String houseNumber;
private final String zipCode;
private final String city;
private final CountryCode country;

public Address getAddress() {
var address = new Address();
address.setStreet(street);
address.setHouseNumber(houseNumber);
address.setZipCode(zipCode);
address.setCity(city);
address.setCountry(country);
return address;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
*/
package de.rwth.idsg.steve.repository.dto;

import jooq.steve.db.tables.records.ChargingProfileRecord;
import jooq.steve.db.tables.records.ChargingSchedulePeriodRecord;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.List;

Expand Down Expand Up @@ -58,9 +57,29 @@ public static final class Overview {
}

@Getter
@RequiredArgsConstructor
@Builder
public static final class Details {
private final ChargingProfileRecord profile;
private final List<ChargingSchedulePeriodRecord> periods;
// from ChargingProfileRecord
private final int chargingProfilePk;
private final int stackLevel;
private final String chargingProfilePurpose;
private final String chargingProfileKind;
private final String recurrencyKind;
private final Instant validFrom;
private final Instant validTo;
private final Integer durationInSeconds;
private final Instant startSchedule;
private final String chargingRateUnit;
private final BigDecimal minChargingRate;
// from ChargingSchedulePeriodRecord
private final List<ChargingSchedulePeriod> periods;
}
Comment on lines 60 to +78
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Include description and note in Details to prevent data loss in edit flows.

ChargingProfileForm.fromDetails(...) can’t populate description/note because Details doesn’t expose them. Editing other fields risks overwriting these columns with nulls on update.

 @Getter
 @Builder
 public static final class Details {
-        // from ChargingProfileRecord
+        // from ChargingProfileRecord
         private final int chargingProfilePk;
         private final int stackLevel;
+        private final String description;
+        private final String note;
         private final String chargingProfilePurpose;
         private final String chargingProfileKind;
         private final String recurrencyKind;
         private final Instant validFrom;
         private final Instant validTo;
         private final Integer durationInSeconds;
         private final Instant startSchedule;
         private final String chargingRateUnit;
         private final BigDecimal minChargingRate;
         // from ChargingSchedulePeriodRecord
         private final List<ChargingSchedulePeriod> periods;
 }

Follow-up: update the mapper and ChargingProfileForm.fromDetails(...) to copy these two fields.

📝 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
@Getter
@RequiredArgsConstructor
@Builder
public static final class Details {
private final ChargingProfileRecord profile;
private final List<ChargingSchedulePeriodRecord> periods;
// from ChargingProfileRecord
private final int chargingProfilePk;
private final int stackLevel;
private final String chargingProfilePurpose;
private final String chargingProfileKind;
private final String recurrencyKind;
private final Instant validFrom;
private final Instant validTo;
private final Integer durationInSeconds;
private final Instant startSchedule;
private final String chargingRateUnit;
private final BigDecimal minChargingRate;
// from ChargingSchedulePeriodRecord
private final List<ChargingSchedulePeriod> periods;
}
@Getter
@Builder
public static final class Details {
// from ChargingProfileRecord
private final int chargingProfilePk;
private final int stackLevel;
private final String description;
private final String note;
private final String chargingProfilePurpose;
private final String chargingProfileKind;
private final String recurrencyKind;
private final Instant validFrom;
private final Instant validTo;
private final Integer durationInSeconds;
private final Instant startSchedule;
private final String chargingRateUnit;
private final BigDecimal minChargingRate;
// from ChargingSchedulePeriodRecord
private final List<ChargingSchedulePeriod> periods;
}
🤖 Prompt for AI Agents
In
steve-core/src/main/java/de/rwth/idsg/steve/repository/dto/ChargingProfile.java
around lines 59-76, the Details DTO lacks description and note so edit flows can
drop those values; add final String description and final String note to the
Details class (with @Getter/@Builder) and update the mapper that constructs
Details from DB records to populate these two fields from ChargingProfileRecord,
then update ChargingProfileForm.fromDetails(...) to copy description and note
into the form so edits do not overwrite existing values with null.


@Getter
@RequiredArgsConstructor
public static final class ChargingSchedulePeriod {
private final int startPeriodInSeconds;
private final BigDecimal powerLimit;
private final Integer numberPhases;
}
}
Loading
Loading