Skip to content

Commit

Permalink
refactor ChargePointSelect to use OcppProtocol
Browse files Browse the repository at this point in the history
this DTO should include the protocol which contains transport and version info.
this would enable to unify some logic wrt. Invoker and Client classes.
  • Loading branch information
goekay committed Jan 5, 2025
1 parent 415e1d5 commit c7fa907
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/main/java/de/rwth/idsg/steve/ocpp/OcppProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,21 +30,21 @@
@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() {
return !("-".equals(endpointAddress));
}

public boolean isSoap() {
return OcppTransport.SOAP == ocppTransport;
return OcppTransport.SOAP == ocppProtocol.getTransport();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public List<ChargePointSelect> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ private List<ChargePointSelect> getChargePoints(OcppProtocol protocol, List<Regi
? jsonEndpoint.getChargeBoxIdList()
: jsonEndpoint.getChargeBoxIdList().stream().filter(chargeBoxIdFilter::contains).collect(Collectors.toList());

var jsonProtocol = OcppProtocol.from(jsonEndpoint.getVersion(), OcppTransport.JSON);

for (String chargeBoxId : chargeBoxIdList) {
returnList.add(new ChargePointSelect(OcppTransport.JSON, chargeBoxId));
returnList.add(new ChargePointSelect(jsonProtocol, chargeBoxId));
}

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

import de.rwth.idsg.steve.ocpp.OcppTransport;
import de.rwth.idsg.steve.ocpp.OcppProtocol;
import de.rwth.idsg.steve.repository.dto.ChargePointSelect;

import java.beans.PropertyEditorSupport;
Expand All @@ -34,11 +34,11 @@ public void setAsText(String text) {
if (!text.isEmpty()) {
String[] chargePointItem = text.split(";");

// chargePointItem[0] : ocpp transport type
// chargePointItem[0] : ocpp protocol
// chargePointItem[1] : chargebox id
// chargePointItem[2] : endpoint (IP) address
ChargePointSelect cps = new ChargePointSelect(
OcppTransport.fromName(chargePointItem[0]),
OcppProtocol.valueOf(chargePointItem[0]),
chargePointItem[1],
chargePointItem[2]
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/webapp/WEB-INF/views/00-cp-multiple.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<td>
<form:select path="chargePointSelectList" size="5" multiple="true">
<c:forEach items="${cpList}" var="cp">
<form:option value="${cp.ocppTransport};${cp.chargeBoxId};${cp.endpointAddress}" label="${cp.chargeBoxId}"/>
<form:option value="${cp.ocppProtocol};${cp.chargeBoxId};${cp.endpointAddress}" label="${cp.chargeBoxId}"/>
</c:forEach>
</form:select>
</td>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/webapp/WEB-INF/views/00-cp-single.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<td>
<form:select path="chargePointSelectList" size="5" multiple="false">
<c:forEach items="${cpList}" var="cp">
<form:option value="${cp.ocppTransport};${cp.chargeBoxId};${cp.endpointAddress}" label="${cp.chargeBoxId}"/>
<form:option value="${cp.ocppProtocol};${cp.chargeBoxId};${cp.endpointAddress}" label="${cp.chargeBoxId}"/>
</c:forEach>
</form:select>
</td>
Expand Down

0 comments on commit c7fa907

Please sign in to comment.