Skip to content

Commit 49026fe

Browse files
authored
Merge pull request #1816 from steve-community/367-chargingprofilepurpose-missing-parameter-for-txprofile
transactionId support for SetChargingProfile (i.e. TxProfile support for ChargingProfilePurpose)
2 parents 169a1ec + d76674d commit 49026fe

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,15 @@ protected static void checkAdditionalConstraints(SetChargingProfileRequest reque
6565
&& request.getConnectorId() < 1) {
6666
throw new SteveException("TxProfile should only be set at Charge Point ConnectorId > 0");
6767
}
68+
69+
if (ChargingProfilePurposeType.TX_PROFILE == purpose
70+
&& request.getCsChargingProfiles().getTransactionId() == null) {
71+
throw new SteveException("transaction id is required for TxProfile");
72+
}
73+
74+
if (ChargingProfilePurposeType.TX_PROFILE != purpose
75+
&& request.getCsChargingProfiles().getTransactionId() != null) {
76+
throw new SteveException("transaction id should only be set for TxProfile");
77+
}
6878
}
6979
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
public class SetChargingProfileTaskFromDB extends SetChargingProfileTask {
4343

4444
private final int connectorId;
45+
private final Integer transactionId;
4546
private final ChargingProfile.Details details;
4647
private final ChargingProfileRepository chargingProfileRepository;
4748

@@ -50,6 +51,7 @@ public SetChargingProfileTaskFromDB(SetChargingProfileParams params,
5051
ChargingProfileRepository chargingProfileRepository) {
5152
super(params);
5253
this.connectorId = params.getConnectorId();
54+
this.transactionId = params.getTransactionId();
5355
this.details = details;
5456
this.chargingProfileRepository = chargingProfileRepository;
5557
}
@@ -59,9 +61,10 @@ public OcppCallback<String> defaultCallback() {
5961
return new DefaultOcppCallback<String>() {
6062
@Override
6163
public void success(String chargeBoxId, String statusValue) {
64+
ChargingProfilePurposeType purpose = ChargingProfilePurposeType.fromValue(details.getProfile().getChargingProfilePurpose());
6265
addNewResponse(chargeBoxId, statusValue);
6366

64-
if ("Accepted".equalsIgnoreCase(statusValue)) {
67+
if ("Accepted".equalsIgnoreCase(statusValue) && ChargingProfilePurposeType.TX_PROFILE != purpose) {
6568
int chargingProfilePk = details.getProfile().getChargingProfilePk();
6669
chargingProfileRepository.setProfile(chargingProfilePk, chargeBoxId, connectorId);
6770
}
@@ -71,7 +74,7 @@ public void success(String chargeBoxId, String statusValue) {
7174

7275
@Override
7376
public SetChargingProfileRequest getOcpp16Request() {
74-
ocpp.cp._2015._10.ChargingProfile ocppProfile = ChargingProfileDetailsMapper.mapToOcpp(details);
77+
ocpp.cp._2015._10.ChargingProfile ocppProfile = ChargingProfileDetailsMapper.mapToOcpp(details, transactionId);
7578

7679
var request = new SetChargingProfileRequest()
7780
.withConnectorId(connectorId)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public final int remoteStartTransaction(RemoteStartTransactionParams params,
205205
Integer chargingProfilePk = params.getChargingProfilePk();
206206
if (chargingProfilePk != null) {
207207
ChargingProfile.Details details = chargingProfileRepository.getDetails(chargingProfilePk);
208-
chargingProfile = ChargingProfileDetailsMapper.mapToOcpp(details);
208+
chargingProfile = ChargingProfileDetailsMapper.mapToOcpp(details, null);
209209
if (chargingProfile.getChargingProfilePurpose() != ChargingProfilePurposeType.TX_PROFILE) {
210210
throw new SteveException("ChargingProfilePurposeType is not TX_PROFILE");
211211
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
@NoArgsConstructor(access = AccessLevel.PRIVATE)
4242
public final class ChargingProfileDetailsMapper {
4343

44-
public static ocpp.cp._2015._10.ChargingProfile mapToOcpp(ChargingProfile.Details details) {
44+
public static ocpp.cp._2015._10.ChargingProfile mapToOcpp(ChargingProfile.Details details,
45+
Integer transactionId) {
4546
ChargingProfileRecord profile = details.getProfile();
4647

4748
List<ChargingSchedulePeriod> schedulePeriods =
@@ -65,6 +66,7 @@ public static ocpp.cp._2015._10.ChargingProfile mapToOcpp(ChargingProfile.Detail
6566

6667
return new ocpp.cp._2015._10.ChargingProfile()
6768
.withChargingProfileId(profile.getChargingProfilePk())
69+
.withTransactionId(transactionId)
6870
.withStackLevel(profile.getStackLevel())
6971
.withChargingProfilePurpose(ChargingProfilePurposeType.fromValue(profile.getChargingProfilePurpose()))
7072
.withChargingProfileKind(ChargingProfileKindType.fromValue(profile.getChargingProfileKind()))

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ public class SetChargingProfileParams extends MultipleChargePointSelect {
4040
@NotNull
4141
@Positive
4242
private Integer chargingProfilePk;
43+
44+
@Positive
45+
private Integer transactionId;
4346
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<td>Connector ID (integer):</td>
3535
<td><form:input path="connectorId" placeholder="0 = charge point as a whole"/></td>
3636
</tr>
37+
<tr>
38+
<td>Transaction ID (integer):</td>
39+
<td><form:input path="transactionId" placeholder="only necessary for TxProfile"/></td>
40+
</tr>
3741
<tr><td></td><td><div class="submit-button"><input type="submit" value="Perform"></div></td></tr>
3842
</table>
3943
</form:form>

0 commit comments

Comments
 (0)