Skip to content

Commit

Permalink
Refactor to avoid #return statements > 4
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobm committed Jul 5, 2024
1 parent bd25d95 commit 6115f90
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,15 @@ class SmartChargingClientHandler(
}
}

private suspend fun setDefaultChargingProfile(
ocppSessionInfo: OcppSession.Info,
private suspend fun validateSetDefaultChargingProfile(
connector: ChargePointConnectorDAO,
request: SetChargingProfileRequest
): Boolean {
if (request.csChargingProfiles.chargingProfilePurpose != ChargingProfilePurposeType.TxDefaultProfile) {
return false
}

val connector = getConnector(
ocppSessionInfo = ocppSessionInfo,
connectorId = request.connectorId
)

if (connector == null) {
return false
}

if (request.connectorId != 0) {
GlobalLogger.warn(connector, "TxDefault must be on connector 0")
return false
}
val chargingProfile = request.csChargingProfiles

if (chargingProfile.chargingProfilePurpose != ChargingProfilePurposeType.TxDefaultProfile) {
GlobalLogger.warn(connector, "rejected charging profile, chargingProfilePurpose is not TxDefaultProfile")
return false
Expand All @@ -118,6 +104,22 @@ class SmartChargingClientHandler(
return false
}

return true
}

private suspend fun setDefaultChargingProfile(
ocppSessionInfo: OcppSession.Info,
request: SetChargingProfileRequest
): Boolean {
if (request.csChargingProfiles.chargingProfilePurpose != ChargingProfilePurposeType.TxDefaultProfile) {
return false
}

val connector = getConnector(ocppSessionInfo = ocppSessionInfo, connectorId = request.connectorId) ?: return false
if (!validateSetDefaultChargingProfile(connector, request)) {
return false
}

val chargePoint = chargePointService.getByIdentity(
ocppSessionInfo.identity
)
Expand Down

0 comments on commit 6115f90

Please sign in to comment.