Skip to content

Commit 9fe8946

Browse files
authored
Merge pull request #1809 from steve-community/1759-txprofile-within-remotestarttransactionreq
TxProfile within RemoteStartTransaction.req
2 parents 49fde1f + 1e77a62 commit 9fe8946

File tree

8 files changed

+90
-38
lines changed

8 files changed

+90
-38
lines changed

src/main/java/de/rwth/idsg/steve/ocpp/task/RemoteStartTransactionTask.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
*/
3131
public class RemoteStartTransactionTask extends CommunicationTask<RemoteStartTransactionParams, String> {
3232

33-
public RemoteStartTransactionTask(RemoteStartTransactionParams params) {
33+
private final ocpp.cp._2015._10.ChargingProfile chargingProfile;
34+
35+
public RemoteStartTransactionTask(RemoteStartTransactionParams params,
36+
ocpp.cp._2015._10.ChargingProfile chargingProfile) {
3437
super(params);
38+
this.chargingProfile = chargingProfile;
3539
}
3640

3741
@Override
@@ -53,14 +57,12 @@ public ocpp.cp._2012._06.RemoteStartTransactionRequest getOcpp15Request() {
5357
.withConnectorId(params.getConnectorId());
5458
}
5559

56-
/**
57-
* TODO: RemoteStartTransactionRequest.chargingProfile not implemented
58-
*/
5960
@Override
6061
public ocpp.cp._2015._10.RemoteStartTransactionRequest getOcpp16Request() {
6162
return new ocpp.cp._2015._10.RemoteStartTransactionRequest()
6263
.withIdTag(params.getIdTag())
63-
.withConnectorId(params.getConnectorId());
64+
.withConnectorId(params.getConnectorId())
65+
.withChargingProfile(chargingProfile);
6466
}
6567

6668
@Override

src/main/java/de/rwth/idsg/steve/ocpp/task/SetChargingProfileTaskFromDB.java

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import de.rwth.idsg.steve.ocpp.OcppCallback;
2222
import de.rwth.idsg.steve.repository.ChargingProfileRepository;
2323
import de.rwth.idsg.steve.repository.dto.ChargingProfile;
24+
import de.rwth.idsg.steve.utils.mapper.ChargingProfileDetailsMapper;
2425
import de.rwth.idsg.steve.web.dto.ocpp.SetChargingProfileParams;
2526
import jooq.steve.db.tables.records.ChargingProfileRecord;
2627
import ocpp.cp._2015._10.ChargingProfileKindType;
@@ -70,36 +71,7 @@ public void success(String chargeBoxId, String statusValue) {
7071

7172
@Override
7273
public SetChargingProfileRequest getOcpp16Request() {
73-
ChargingProfileRecord profile = details.getProfile();
74-
75-
List<ChargingSchedulePeriod> schedulePeriods =
76-
details.getPeriods()
77-
.stream()
78-
.map(k -> {
79-
ChargingSchedulePeriod p = new ChargingSchedulePeriod();
80-
p.setStartPeriod(k.getStartPeriodInSeconds());
81-
p.setLimit(k.getPowerLimit());
82-
p.setNumberPhases(k.getNumberPhases());
83-
return p;
84-
})
85-
.collect(Collectors.toList());
86-
87-
ChargingSchedule schedule = new ChargingSchedule()
88-
.withDuration(profile.getDurationInSeconds())
89-
.withStartSchedule(profile.getStartSchedule())
90-
.withChargingRateUnit(ChargingRateUnitType.fromValue(profile.getChargingRateUnit()))
91-
.withMinChargingRate(profile.getMinChargingRate())
92-
.withChargingSchedulePeriod(schedulePeriods);
93-
94-
ocpp.cp._2015._10.ChargingProfile ocppProfile = new ocpp.cp._2015._10.ChargingProfile()
95-
.withChargingProfileId(profile.getChargingProfilePk())
96-
.withStackLevel(profile.getStackLevel())
97-
.withChargingProfilePurpose(ChargingProfilePurposeType.fromValue(profile.getChargingProfilePurpose()))
98-
.withChargingProfileKind(ChargingProfileKindType.fromValue(profile.getChargingProfileKind()))
99-
.withRecurrencyKind(profile.getRecurrencyKind() == null ? null : RecurrencyKindType.fromValue(profile.getRecurrencyKind()))
100-
.withValidFrom(profile.getValidFrom())
101-
.withValidTo(profile.getValidTo())
102-
.withChargingSchedule(schedule);
74+
ocpp.cp._2015._10.ChargingProfile ocppProfile = ChargingProfileDetailsMapper.mapToOcpp(details);
10375

10476
var request = new SetChargingProfileRequest()
10577
.withConnectorId(connectorId)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package de.rwth.idsg.steve.service;
2020

21+
import de.rwth.idsg.steve.SteveException;
2122
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2223
import de.rwth.idsg.steve.ocpp.ChargePointServiceInvokerImpl;
2324
import de.rwth.idsg.steve.ocpp.OcppCallback;
@@ -48,6 +49,7 @@
4849
import de.rwth.idsg.steve.repository.dto.ChargingProfile;
4950
import de.rwth.idsg.steve.repository.dto.InsertReservationParams;
5051
import de.rwth.idsg.steve.service.dto.EnhancedReserveNowParams;
52+
import de.rwth.idsg.steve.utils.mapper.ChargingProfileDetailsMapper;
5153
import de.rwth.idsg.steve.web.dto.ocpp.CancelReservationParams;
5254
import de.rwth.idsg.steve.web.dto.ocpp.ChangeAvailabilityParams;
5355
import de.rwth.idsg.steve.web.dto.ocpp.ChangeConfigurationParams;
@@ -199,7 +201,17 @@ public final int updateFirmware(UpdateFirmwareParams params,
199201
@SafeVarargs
200202
public final int remoteStartTransaction(RemoteStartTransactionParams params,
201203
OcppCallback<String>... callbacks) {
202-
RemoteStartTransactionTask task = new RemoteStartTransactionTask(params);
204+
ocpp.cp._2015._10.ChargingProfile chargingProfile = null;
205+
Integer chargingProfilePk = params.getChargingProfilePk();
206+
if (chargingProfilePk != null) {
207+
ChargingProfile.Details details = chargingProfileRepository.getDetails(chargingProfilePk);
208+
chargingProfile = ChargingProfileDetailsMapper.mapToOcpp(details);
209+
if (chargingProfile.getChargingProfilePurpose() != ChargingProfilePurposeType.TX_PROFILE) {
210+
throw new SteveException("ChargingProfilePurposeType is not TX_PROFILE");
211+
}
212+
}
213+
214+
RemoteStartTransactionTask task = new RemoteStartTransactionTask(params, chargingProfile);
203215

204216
for (var callback : callbacks) {
205217
task.addCallback(callback);

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
import ocpp.cp._2015._10.ChargingProfileKindType;
2828
import ocpp.cp._2015._10.ChargingProfilePurposeType;
2929
import ocpp.cp._2015._10.ChargingRateUnitType;
30+
import ocpp.cp._2015._10.ChargingSchedule;
31+
import ocpp.cp._2015._10.ChargingSchedulePeriod;
3032
import ocpp.cp._2015._10.RecurrencyKindType;
3133

3234
import java.util.List;
35+
import java.util.stream.Collectors;
3336

3437
/**
3538
* @author Sevket Goekay <[email protected]>
@@ -38,6 +41,39 @@
3841
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3942
public final class ChargingProfileDetailsMapper {
4043

44+
public static ocpp.cp._2015._10.ChargingProfile mapToOcpp(ChargingProfile.Details details) {
45+
ChargingProfileRecord profile = details.getProfile();
46+
47+
List<ChargingSchedulePeriod> schedulePeriods =
48+
details.getPeriods()
49+
.stream()
50+
.map(k -> {
51+
ChargingSchedulePeriod p = new ChargingSchedulePeriod();
52+
p.setStartPeriod(k.getStartPeriodInSeconds());
53+
p.setLimit(k.getPowerLimit());
54+
p.setNumberPhases(k.getNumberPhases());
55+
return p;
56+
})
57+
.collect(Collectors.toList());
58+
59+
ChargingSchedule schedule = new ChargingSchedule()
60+
.withDuration(profile.getDurationInSeconds())
61+
.withStartSchedule(profile.getStartSchedule())
62+
.withChargingRateUnit(ChargingRateUnitType.fromValue(profile.getChargingRateUnit()))
63+
.withMinChargingRate(profile.getMinChargingRate())
64+
.withChargingSchedulePeriod(schedulePeriods);
65+
66+
return new ocpp.cp._2015._10.ChargingProfile()
67+
.withChargingProfileId(profile.getChargingProfilePk())
68+
.withStackLevel(profile.getStackLevel())
69+
.withChargingProfilePurpose(ChargingProfilePurposeType.fromValue(profile.getChargingProfilePurpose()))
70+
.withChargingProfileKind(ChargingProfileKindType.fromValue(profile.getChargingProfileKind()))
71+
.withRecurrencyKind(profile.getRecurrencyKind() == null ? null : RecurrencyKindType.fromValue(profile.getRecurrencyKind()))
72+
.withValidFrom(profile.getValidFrom())
73+
.withValidTo(profile.getValidTo())
74+
.withChargingSchedule(schedule);
75+
}
76+
4177
public static ChargingProfileForm mapToForm(ChargingProfile.Details details) {
4278
ChargingProfileRecord profile = details.getProfile();
4379
List<ChargingSchedulePeriodRecord> periods = details.getPeriods();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ public class Ocpp12Controller {
8181
// Helpers
8282
// -------------------------------------------------------------------------
8383

84+
/**
85+
* https://github.com/steve-community/steve/issues/1759
86+
* used to create form in order to send charging profile within remote start tx for ocpp 1.6.
87+
*/
88+
protected void setCommonAttributesForRemoteStartTx(Model model) {
89+
// nothing to do for versions below 1.6
90+
}
91+
8492
protected void setCommonAttributesForTx(Model model) {
8593
setCommonAttributes(model);
8694
}
@@ -149,6 +157,7 @@ public String getGetDiag(Model model) {
149157
public String getRemoteStartTx(Model model) {
150158
setCommonAttributesForTx(model);
151159
setActiveUserIdTagList(model);
160+
setCommonAttributesForRemoteStartTx(model);
152161
model.addAttribute(PARAMS, new RemoteStartTransactionParams());
153162
return getPrefix() + REMOTE_START_TX_PATH;
154163
}
@@ -232,6 +241,7 @@ public String postRemoteStartTx(@Valid @ModelAttribute(PARAMS) RemoteStartTransa
232241
if (result.hasErrors()) {
233242
setCommonAttributesForTx(model);
234243
setActiveUserIdTagList(model);
244+
setCommonAttributesForRemoteStartTx(model);
235245
return getPrefix() + REMOTE_START_TX_PATH;
236246
}
237247
return REDIRECT_TASKS_PATH + chargePointServiceClient.remoteStartTransaction(params);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public class Ocpp16Controller extends Ocpp15Controller {
7070
// Helpers
7171
// -------------------------------------------------------------------------
7272

73+
protected void setCommonAttributesForRemoteStartTx(Model model) {
74+
model.addAttribute("profileForRemoteStartTx", Boolean.TRUE);
75+
model.addAttribute("profileList", chargingProfileRepository.getBasicInfo());
76+
}
77+
7378
@Override
7479
protected void setCommonAttributesForTx(Model model) {
7580
model.addAttribute("cpList", chargePointHelperService.getChargePoints(OcppVersion.V_16));

src/main/java/de/rwth/idsg/steve/web/dto/ocpp/RemoteStartTransactionParams.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,25 @@
2424

2525
import jakarta.validation.constraints.Min;
2626
import jakarta.validation.constraints.NotBlank;
27+
import jakarta.validation.constraints.Positive;
2728

2829
/**
2930
* @author Sevket Goekay <[email protected]>
3031
* @since 01.01.2015
3132
*/
3233
@Getter
34+
@Setter
3335
public class RemoteStartTransactionParams extends SingleChargePointSelect {
3436

3537
@Min(value = 0, message = "Connector ID must be at least {value}")
3638
private Integer connectorId;
3739

3840
@NotBlank(message = "User ID Tag is required")
3941
@IdTag
40-
@Setter private String idTag;
42+
private String idTag;
43+
44+
@Positive
45+
private Integer chargingProfilePk;
4146

4247
/**
4348
* Not for a specific connector, when frontend sends the value 0.

src/main/resources/webapp/WEB-INF/views/op-forms/RemoteStartTransactionForm.jsp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
</form:select>
3434
</td>
3535
</tr>
36+
<c:if test="${profileForRemoteStartTx}">
37+
<tr>
38+
<td>Charging Profile ID:</td>
39+
<td><form:select path="chargingProfilePk">
40+
<option value="" selected>-- Empty --</option>
41+
<form:options items="${profileList}" itemLabel="itemDescription" itemValue="chargingProfilePk"/>
42+
</form:select>
43+
</td>
44+
</tr>
45+
</c:if>
3646
<tr><td></td><td><div class="submit-button"><input type="submit" value="Perform"></div></td></tr>
3747
</table>
38-
</form:form>
48+
</form:form>

0 commit comments

Comments
 (0)