From c7fa90753a457e175904cb9457a2cb958731069f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sevket=20G=C3=B6kay?= Date: Sun, 5 Jan 2025 15:50:38 +0100 Subject: [PATCH] refactor ChargePointSelect to use OcppProtocol this DTO should include the protocol which contains transport and version info. this would enable to unify some logic wrt. Invoker and Client classes. --- src/main/java/de/rwth/idsg/steve/ocpp/OcppProtocol.java | 9 +++++++++ .../idsg/steve/repository/dto/ChargePointSelect.java | 9 +++++---- .../steve/repository/impl/ChargePointRepositoryImpl.java | 2 +- .../idsg/steve/service/ChargePointHelperService.java | 4 +++- .../de/rwth/idsg/steve/web/ChargePointSelectEditor.java | 6 +++--- .../resources/webapp/WEB-INF/views/00-cp-multiple.jsp | 2 +- src/main/resources/webapp/WEB-INF/views/00-cp-single.jsp | 2 +- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/rwth/idsg/steve/ocpp/OcppProtocol.java b/src/main/java/de/rwth/idsg/steve/ocpp/OcppProtocol.java index f9c9081df..ede74ef21 100644 --- a/src/main/java/de/rwth/idsg/steve/ocpp/OcppProtocol.java +++ b/src/main/java/de/rwth/idsg/steve/ocpp/OcppProtocol.java @@ -65,4 +65,13 @@ public static OcppProtocol fromCompositeValue(String v) { } throw new IllegalArgumentException(v); } + + public static OcppProtocol from(OcppVersion version, OcppTransport transport) { + for (OcppProtocol value : OcppProtocol.values()) { + if (value.getVersion() == version && value.getTransport() == transport) { + return value; + } + } + throw new IllegalArgumentException("Could not find OcppProtocol for " + version + " and " + transport); + } } diff --git a/src/main/java/de/rwth/idsg/steve/repository/dto/ChargePointSelect.java b/src/main/java/de/rwth/idsg/steve/repository/dto/ChargePointSelect.java index 84af7f736..8aec91fac 100644 --- a/src/main/java/de/rwth/idsg/steve/repository/dto/ChargePointSelect.java +++ b/src/main/java/de/rwth/idsg/steve/repository/dto/ChargePointSelect.java @@ -18,6 +18,7 @@ */ package de.rwth.idsg.steve.repository.dto; +import de.rwth.idsg.steve.ocpp.OcppProtocol; import de.rwth.idsg.steve.ocpp.OcppTransport; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -29,14 +30,14 @@ @RequiredArgsConstructor @Getter public final class ChargePointSelect { - private final OcppTransport ocppTransport; + private final OcppProtocol ocppProtocol; private final String chargeBoxId; private final String endpointAddress; - public ChargePointSelect(OcppTransport ocppTransport, String chargeBoxId) { + public ChargePointSelect(OcppProtocol ocppProtocol, String chargeBoxId) { // Provide a non-null value (or placeholder if you will) to frontend for JSON charge points. // This is clearly a hack. Not my proudest moment. - this(ocppTransport, chargeBoxId, "-"); + this(ocppProtocol, chargeBoxId, "-"); } public boolean isEndpointAddressSet() { @@ -44,6 +45,6 @@ public boolean isEndpointAddressSet() { } public boolean isSoap() { - return OcppTransport.SOAP == ocppTransport; + return OcppTransport.SOAP == ocppProtocol.getTransport(); } } diff --git a/src/main/java/de/rwth/idsg/steve/repository/impl/ChargePointRepositoryImpl.java b/src/main/java/de/rwth/idsg/steve/repository/impl/ChargePointRepositoryImpl.java index 905d4f4b4..b6af1ca6f 100644 --- a/src/main/java/de/rwth/idsg/steve/repository/impl/ChargePointRepositoryImpl.java +++ b/src/main/java/de/rwth/idsg/steve/repository/impl/ChargePointRepositoryImpl.java @@ -100,7 +100,7 @@ public List getChargePointSelect(OcppProtocol protocol, List< .and(CHARGE_BOX.REGISTRATION_STATUS.in(inStatusFilter)) .and(chargeBoxIdCondition) .fetch() - .map(r -> new ChargePointSelect(protocol.getTransport(), r.value1(), r.value2())); + .map(r -> new ChargePointSelect(protocol, r.value1(), r.value2())); } @Override diff --git a/src/main/java/de/rwth/idsg/steve/service/ChargePointHelperService.java b/src/main/java/de/rwth/idsg/steve/service/ChargePointHelperService.java index 83f64d69e..28c8bc7b4 100644 --- a/src/main/java/de/rwth/idsg/steve/service/ChargePointHelperService.java +++ b/src/main/java/de/rwth/idsg/steve/service/ChargePointHelperService.java @@ -229,8 +229,10 @@ private List getChargePoints(OcppProtocol protocol, List - + diff --git a/src/main/resources/webapp/WEB-INF/views/00-cp-single.jsp b/src/main/resources/webapp/WEB-INF/views/00-cp-single.jsp index 75e2f2a3a..d9ab333d5 100644 --- a/src/main/resources/webapp/WEB-INF/views/00-cp-single.jsp +++ b/src/main/resources/webapp/WEB-INF/views/00-cp-single.jsp @@ -25,7 +25,7 @@ - +