Skip to content

Commit

Permalink
move validation to abstract parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
goekay committed Feb 16, 2025
1 parent a45cedc commit 2ee8160
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/
package de.rwth.idsg.steve.ocpp.task;

import de.rwth.idsg.steve.SteveException;
import de.rwth.idsg.steve.ocpp.Ocpp16AndAboveTask;
import de.rwth.idsg.steve.web.dto.ocpp.SetChargingProfileParams;
import ocpp.cp._2015._10.ChargingProfilePurposeType;
import ocpp.cp._2015._10.SetChargingProfileRequest;

/**
* @author Sevket Goekay <[email protected]>
Expand All @@ -30,4 +33,21 @@ public abstract class SetChargingProfileTask extends Ocpp16AndAboveTask<SetCharg
public SetChargingProfileTask(SetChargingProfileParams params) {
super(params);
}

/**
* Do some additional checks defined by OCPP spec, which cannot be captured with javax.validation
*/
protected static void checkAdditionalConstraints(SetChargingProfileRequest request) {
ChargingProfilePurposeType purpose = request.getCsChargingProfiles().getChargingProfilePurpose();

if (ChargingProfilePurposeType.CHARGE_POINT_MAX_PROFILE == purpose
&& request.getConnectorId() != 0) {
throw new SteveException("ChargePointMaxProfile can only be set at Charge Point ConnectorId 0");
}

if (ChargingProfilePurposeType.TX_PROFILE == purpose
&& request.getConnectorId() < 1) {
throw new SteveException("TxProfile should only be set at Charge Point ConnectorId > 0");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public SetChargingProfileTaskAdhoc(SetChargingProfileParams params,
SetChargingProfileRequest request) {
super(params);
this.request = request;
checkAdditionalConstraints(request);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ public SetChargingProfileRequest getOcpp16Request() {
.withValidTo(profile.getValidTo())
.withChargingSchedule(schedule);

return new SetChargingProfileRequest()
var request = new SetChargingProfileRequest()
.withConnectorId(params.getConnectorId())
.withCsChargingProfiles(ocppProfile);

checkAdditionalConstraints(request);

return request;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package de.rwth.idsg.steve.service;

import de.rwth.idsg.steve.SteveException;
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
import de.rwth.idsg.steve.ocpp.ChargePointServiceInvokerImpl;
import de.rwth.idsg.steve.ocpp.OcppCallback;
Expand Down Expand Up @@ -402,8 +401,6 @@ public final int setChargingProfile(SetChargingProfileParams params,
OcppCallback<String>... callbacks) {
ChargingProfile.Details details = chargingProfileRepository.getDetails(params.getChargingProfilePk());

checkAdditionalConstraints(params, details);

SetChargingProfileTaskFromDB task = new SetChargingProfileTaskFromDB(params, details, chargingProfileRepository);

return setChargingProfile(task, callbacks);
Expand Down Expand Up @@ -441,22 +438,4 @@ public final int getCompositeSchedule(GetCompositeScheduleParams params,
return taskStore.add(task);
}

/**
* Do some additional checks defined by OCPP spec, which cannot be captured with javax.validation
*/
private static void checkAdditionalConstraints(SetChargingProfileParams params, ChargingProfile.Details details) {
ChargingProfilePurposeType purpose = ChargingProfilePurposeType.fromValue(details.getProfile().getChargingProfilePurpose());

if (ChargingProfilePurposeType.CHARGE_POINT_MAX_PROFILE == purpose
&& params.getConnectorId() != null
&& params.getConnectorId() != 0) {
throw new SteveException("ChargePointMaxProfile can only be set at Charge Point ConnectorId 0");
}

if (ChargingProfilePurposeType.TX_PROFILE == purpose
&& params.getConnectorId() != null
&& params.getConnectorId() < 1) {
throw new SteveException("TxProfile should only be set at Charge Point ConnectorId > 0");
}
}
}

0 comments on commit 2ee8160

Please sign in to comment.