Skip to content

Commit f3be3fa

Browse files
authored
Merge pull request #2045 from steve-community/refactor-ChargePointForm
refactor: split ChargePointForm into Create and Update parts
2 parents 9f2c6c0 + ab64c52 commit f3be3fa

10 files changed

Lines changed: 80 additions & 36 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import de.rwth.idsg.steve.repository.dto.ChargePointRegistration;
2525
import de.rwth.idsg.steve.repository.dto.ChargePointSelect;
2626
import de.rwth.idsg.steve.repository.dto.ConnectorStatus;
27-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
27+
import de.rwth.idsg.steve.web.dto.ChargePointFormForCreate;
28+
import de.rwth.idsg.steve.web.dto.ChargePointFormForUpdate;
2829
import de.rwth.idsg.steve.web.dto.ChargePointQueryForm;
2930
import de.rwth.idsg.steve.web.dto.ConnectorStatusForm;
3031
import org.jetbrains.annotations.Nullable;
@@ -56,7 +57,7 @@ public interface ChargePointRepository {
5657
List<Integer> getNonZeroConnectorIds(String chargeBoxId);
5758

5859
void addChargePointList(List<String> chargeBoxIdList);
59-
int addChargePoint(ChargePointForm form);
60-
void updateChargePoint(ChargePointForm form);
60+
int addChargePoint(ChargePointFormForCreate form);
61+
void updateChargePoint(ChargePointFormForUpdate form);
6162
void deleteChargePoint(int chargeBoxPk);
6263
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import de.rwth.idsg.steve.repository.dto.ConnectorStatus;
3030
import de.rwth.idsg.steve.utils.DateTimeUtils;
3131
import de.rwth.idsg.steve.utils.JsonUtils;
32-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
32+
import de.rwth.idsg.steve.web.dto.ChargePointFormForCreate;
33+
import de.rwth.idsg.steve.web.dto.ChargePointFormForUpdate;
3334
import de.rwth.idsg.steve.web.dto.ChargePointQueryForm;
3435
import de.rwth.idsg.steve.web.dto.ConnectorStatusForm;
3536
import jooq.steve.db.enums.EvseTopologySource;
@@ -361,7 +362,7 @@ public void addChargePointList(List<String> chargeBoxIdList) {
361362
}
362363

363364
@Override
364-
public int addChargePoint(ChargePointForm form) {
365+
public int addChargePoint(ChargePointFormForCreate form) {
365366
return ctx.transactionResult(configuration -> {
366367
DSLContext ctx = DSL.using(configuration);
367368
try {
@@ -376,7 +377,7 @@ public int addChargePoint(ChargePointForm form) {
376377
}
377378

378379
@Override
379-
public void updateChargePoint(ChargePointForm form) {
380+
public void updateChargePoint(ChargePointFormForUpdate form) {
380381
ctx.transaction(configuration -> {
381382
DSLContext ctx = DSL.using(configuration);
382383
try {
@@ -415,7 +416,7 @@ private SelectConditionStep<Record1<Integer>> selectAddressId(int chargeBoxPk) {
415416
.where(CHARGE_BOX.CHARGE_BOX_PK.eq(chargeBoxPk));
416417
}
417418

418-
private int addChargePointInternal(DSLContext ctx, ChargePointForm form, Integer addressPk) {
419+
private int addChargePointInternal(DSLContext ctx, ChargePointFormForCreate form, Integer addressPk) {
419420
var query = ctx.insertInto(CHARGE_BOX)
420421
.set(CHARGE_BOX.CHARGE_BOX_ID, form.getChargeBoxId())
421422
.set(CHARGE_BOX.DESCRIPTION, form.getDescription())
@@ -435,7 +436,7 @@ private int addChargePointInternal(DSLContext ctx, ChargePointForm form, Integer
435436
.getChargeBoxPk();
436437
}
437438

438-
private static void updateChargePointInternal(DSLContext ctx, ChargePointForm form, Integer addressPk) {
439+
private static void updateChargePointInternal(DSLContext ctx, ChargePointFormForUpdate form, Integer addressPk) {
439440
var query = ctx.update(CHARGE_BOX)
440441
.set(CHARGE_BOX.DESCRIPTION, form.getDescription())
441442
.set(CHARGE_BOX.INSERT_CONNECTOR_STATUS_AFTER_TRANSACTION_MSG, form.getInsertConnectorStatusAfterTransactionMsg())
@@ -453,7 +454,7 @@ private static void updateChargePointInternal(DSLContext ctx, ChargePointForm fo
453454
.execute();
454455
}
455456

456-
private static void updateDeviceModel(DSLContext ctx, ChargePointForm form) {
457+
private static void updateDeviceModel(DSLContext ctx, ChargePointFormForUpdate form) {
457458
var evses = form.getDeviceModelForm().getEvses();
458459
if (CollectionUtils.isEmpty(evses)) {
459460
return;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
import de.rwth.idsg.steve.service.notification.OcppStationSecurityProfileChanged;
3939
import de.rwth.idsg.steve.utils.ConnectorStatusCountFilter;
4040
import de.rwth.idsg.steve.utils.DateTimeUtils;
41-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
41+
import de.rwth.idsg.steve.web.dto.ChargePointFormForCreate;
42+
import de.rwth.idsg.steve.web.dto.ChargePointFormForUpdate;
4243
import de.rwth.idsg.steve.web.dto.ChargePointQueryForm;
4344
import de.rwth.idsg.steve.web.dto.ConnectorStatusForm;
4445
import de.rwth.idsg.steve.web.dto.OcppJsonStatus;
@@ -130,12 +131,12 @@ public void addChargePointList(List<String> chargeBoxIdList) {
130131
chargePointRepository.addChargePointList(chargeBoxIdList);
131132
}
132133

133-
public int addChargePoint(ChargePointForm form) {
134+
public int addChargePoint(ChargePointFormForCreate form) {
134135
encodePasswordIfNeeded(form);
135136
return chargePointRepository.addChargePoint(form);
136137
}
137138

138-
public void updateChargePoint(ChargePointForm form) {
139+
public void updateChargePoint(ChargePointFormForUpdate form) {
139140
var chargeBoxId = form.getChargeBoxId();
140141
var newRawPassword = form.getAuthPassword();
141142
var newSecurityProfile = form.getSecurityProfile();
@@ -182,7 +183,7 @@ public void deleteChargePoint(int chargeBoxPk) {
182183
}
183184
}
184185

185-
private void encodePasswordIfNeeded(ChargePointForm form) {
186+
private void encodePasswordIfNeeded(ChargePointFormForCreate form) {
186187
String encodedPwd = StringUtils.isEmpty(form.getAuthPassword())
187188
? null
188189
: passwordEncoder.encode(form.getAuthPassword());

src/main/java/de/rwth/idsg/steve/utils/mapper/ChargePointDetailsMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import de.rwth.idsg.steve.repository.dto.ChargePoint;
2626
import de.rwth.idsg.steve.web.dto.ChargePointDeviceModelForm;
2727
import de.rwth.idsg.steve.web.dto.ChargePointDeviceModelForm.EvseConnectorForm;
28-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
28+
import de.rwth.idsg.steve.web.dto.ChargePointFormForUpdate;
2929
import jooq.steve.db.tables.records.ChargeBoxRecord;
3030
import jooq.steve.db.tables.records.EvseConnectorRecord;
3131
import jooq.steve.db.tables.records.EvseRecord;
@@ -45,10 +45,10 @@
4545
@NoArgsConstructor(access = AccessLevel.PRIVATE)
4646
public final class ChargePointDetailsMapper {
4747

48-
public static ChargePointForm mapToForm(ChargePoint.Details cp) {
48+
public static ChargePointFormForUpdate mapToForm(ChargePoint.Details cp) {
4949
ChargeBoxRecord chargeBox = cp.getChargeBox();
5050

51-
ChargePointForm form = new ChargePointForm();
51+
ChargePointFormForUpdate form = new ChargePointFormForUpdate();
5252
form.setChargeBoxPk(chargeBox.getChargeBoxPk());
5353
form.setChargeBoxId(chargeBox.getChargeBoxId());
5454
form.setNote(chargeBox.getNote());

src/main/java/de/rwth/idsg/steve/web/controller/ChargePointsController.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import de.rwth.idsg.steve.utils.ControllerHelper;
2424
import de.rwth.idsg.steve.utils.mapper.ChargePointDetailsMapper;
2525
import de.rwth.idsg.steve.web.dto.ChargePointBatchInsertForm;
26-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
26+
import de.rwth.idsg.steve.web.dto.ChargePointFormForCreate;
27+
import de.rwth.idsg.steve.web.dto.ChargePointFormForUpdate;
2728
import de.rwth.idsg.steve.web.dto.ChargePointQueryForm;
2829
import lombok.RequiredArgsConstructor;
2930
import org.springframework.stereotype.Controller;
@@ -98,7 +99,7 @@ private void initList(Model model, ChargePointQueryForm params) {
9899
@GetMapping(DETAILS_PATH)
99100
public String getDetails(@PathVariable("chargeBoxPk") int chargeBoxPk, Model model) {
100101
ChargePoint.Details cp = chargePointService.getDetails(chargeBoxPk);
101-
ChargePointForm form = ChargePointDetailsMapper.mapToForm(cp);
102+
ChargePointFormForUpdate form = ChargePointDetailsMapper.mapToForm(cp);
102103

103104
model.addAttribute("chargePointForm", form);
104105
model.addAttribute("cp", cp);
@@ -109,13 +110,13 @@ public String getDetails(@PathVariable("chargeBoxPk") int chargeBoxPk, Model mod
109110

110111
@GetMapping(ADD_PATH)
111112
public String addGet(Model model) {
112-
model.addAttribute("chargePointForm", new ChargePointForm());
113+
model.addAttribute("chargePointForm", new ChargePointFormForCreate());
113114
setCommonAttributesForSingleAdd(model);
114115
return "data-man/chargepointAdd";
115116
}
116117

117118
@PostMapping(params = "add", value = ADD_SINGLE_PATH)
118-
public String addSinglePost(@Valid @ModelAttribute("chargePointForm") ChargePointForm chargePointForm,
119+
public String addSinglePost(@Valid @ModelAttribute("chargePointForm") ChargePointFormForCreate chargePointForm,
119120
BindingResult result, Model model) {
120121
if (result.hasErrors()) {
121122
setCommonAttributesForSingleAdd(model);
@@ -132,7 +133,7 @@ public String addBatchPost(@Valid @ModelAttribute("batchChargePointForm") Charge
132133
BindingResult result, Model model) {
133134
if (result.hasErrors()) {
134135
addCountryCodes(model);
135-
model.addAttribute("chargePointForm", new ChargePointForm());
136+
model.addAttribute("chargePointForm", new ChargePointFormForCreate());
136137
return "data-man/chargepointAdd";
137138
}
138139

@@ -141,7 +142,7 @@ public String addBatchPost(@Valid @ModelAttribute("batchChargePointForm") Charge
141142
}
142143

143144
@PostMapping(params = "update", value = UPDATE_PATH)
144-
public String update(@Valid @ModelAttribute("chargePointForm") ChargePointForm chargePointForm,
145+
public String update(@Valid @ModelAttribute("chargePointForm") ChargePointFormForUpdate chargePointForm,
145146
BindingResult result, Model model) {
146147
if (result.hasErrors()) {
147148
setCommonAttributesForSingleAdd(model);
@@ -203,7 +204,7 @@ private void setCommonAttributesForSingleAdd(Model model) {
203204
model.addAttribute("batchChargePointForm", new ChargePointBatchInsertForm());
204205
}
205206

206-
private void add(ChargePointForm form) {
207+
private void add(ChargePointFormForCreate form) {
207208
chargePointService.addChargePoint(form);
208209
chargePointService.removeUnknown(Collections.singletonList(form.getChargeBoxId()));
209210
}

src/main/java/de/rwth/idsg/steve/web/dto/ChargePointForm.java renamed to src/main/java/de/rwth/idsg/steve/web/dto/ChargePointFormForCreate.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@Setter
4444
@ToString
4545
@SecurityProfileValid
46-
public class ChargePointForm {
46+
public class ChargePointFormForCreate {
4747

4848
// Internal database id
4949
private Integer chargeBoxPk;
@@ -85,7 +85,4 @@ public class ChargePointForm {
8585

8686
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
8787
private boolean hasAuthPassword;
88-
89-
@Valid
90-
private ChargePointDeviceModelForm deviceModelForm = new ChargePointDeviceModelForm();
9188
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
3+
* Copyright (C) 2013-2026 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.web.dto;
20+
21+
import lombok.Getter;
22+
import lombok.Setter;
23+
import lombok.ToString;
24+
25+
import jakarta.validation.Valid;
26+
27+
/**
28+
* @author Sevket Goekay <sevketgokay@gmail.com>
29+
* @since 20.05.2026
30+
*/
31+
@Getter
32+
@Setter
33+
@ToString(callSuper = true)
34+
public class ChargePointFormForUpdate extends ChargePointFormForCreate {
35+
36+
@Valid
37+
private ChargePointDeviceModelForm deviceModelForm = new ChargePointDeviceModelForm();
38+
}

src/main/java/de/rwth/idsg/steve/web/validation/SecurityProfileValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import de.rwth.idsg.steve.ocpp.OcppSecurityProfile;
2222
import de.rwth.idsg.steve.service.ChargePointService;
23-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
23+
import de.rwth.idsg.steve.web.dto.ChargePointFormForCreate;
2424
import lombok.RequiredArgsConstructor;
2525
import org.springframework.stereotype.Component;
2626
import org.springframework.util.StringUtils;
@@ -30,12 +30,12 @@
3030

3131
@Component
3232
@RequiredArgsConstructor
33-
public class SecurityProfileValidator implements ConstraintValidator<SecurityProfileValid, ChargePointForm> {
33+
public class SecurityProfileValidator implements ConstraintValidator<SecurityProfileValid, ChargePointFormForCreate> {
3434

3535
private final ChargePointService chargePointService;
3636

3737
@Override
38-
public boolean isValid(ChargePointForm form, ConstraintValidatorContext context) {
38+
public boolean isValid(ChargePointFormForCreate form, ConstraintValidatorContext context) {
3939
OcppSecurityProfile securityProfile = form.getSecurityProfile();
4040
String newAuthPassword = form.getAuthPassword();
4141

src/test/java/de/rwth/idsg/steve/repository/impl/ChargePointRepositoryImplIT.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import de.rwth.idsg.steve.ocpp.ws.JsonObjectMapper;
2424
import de.rwth.idsg.steve.repository.ChargePointRepository;
2525
import de.rwth.idsg.steve.web.dto.Address;
26-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
26+
import de.rwth.idsg.steve.web.dto.ChargePointFormForCreate;
27+
import de.rwth.idsg.steve.web.dto.ChargePointFormForUpdate;
2728
import de.rwth.idsg.steve.web.dto.ChargePointQueryForm;
2829
import de.rwth.idsg.steve.web.dto.ConnectorStatusForm;
2930
import ocpp.cs._2015._10.RegistrationStatus;
@@ -168,7 +169,7 @@ public void addChargePoint() {
168169

169170
@Test
170171
public void updateChargePoint() {
171-
var form = chargePointForm(KNOWN_CHARGE_BOX_ID);
172+
var form = chargePointFormForUpdate(KNOWN_CHARGE_BOX_ID);
172173
Integer chargeBoxPk = dslContext.select(CHARGE_BOX.CHARGE_BOX_PK)
173174
.from(CHARGE_BOX)
174175
.where(CHARGE_BOX.CHARGE_BOX_ID.eq(KNOWN_CHARGE_BOX_ID))
@@ -226,8 +227,12 @@ public void auditTimestamps() {
226227
assertAuditTimestampsAfterUpdate(before.value1(), before.value2(), after.value1(), after.value2());
227228
}
228229

229-
private static ChargePointForm chargePointForm(String chargeBoxId) {
230-
var form = new ChargePointForm();
230+
private static ChargePointFormForCreate chargePointForm(String chargeBoxId) {
231+
return chargePointFormForUpdate(chargeBoxId);
232+
}
233+
234+
private static ChargePointFormForUpdate chargePointFormForUpdate(String chargeBoxId) {
235+
var form = new ChargePointFormForUpdate();
231236
form.setChargeBoxId(chargeBoxId);
232237
form.setRegistrationStatus(RegistrationStatus.ACCEPTED);
233238
form.setInsertConnectorStatusAfterTransactionMsg(true);

src/test/java/de/rwth/idsg/steve/web/validation/SecurityProfileValidatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import de.rwth.idsg.steve.ocpp.ws.JsonObjectMapper;
2323
import de.rwth.idsg.steve.repository.dto.ChargePointRegistration;
2424
import de.rwth.idsg.steve.service.ChargePointService;
25-
import de.rwth.idsg.steve.web.dto.ChargePointForm;
25+
import de.rwth.idsg.steve.web.dto.ChargePointFormForCreate;
2626
import org.junit.jupiter.api.Assertions;
2727
import org.junit.jupiter.api.extension.ExtendWith;
2828
import org.junit.jupiter.params.ParameterizedTest;
@@ -81,7 +81,7 @@ public void testInputValidation(int securityProfileNumber,
8181
boolean isValid) {
8282
OcppSecurityProfile securityProfile = OcppSecurityProfile.fromValue(securityProfileNumber);
8383

84-
ChargePointForm form = new ChargePointForm();
84+
ChargePointFormForCreate form = new ChargePointFormForCreate();
8585
form.setSecurityProfile(securityProfile);
8686
form.setAuthPassword(authPassword);
8787

0 commit comments

Comments
 (0)