Skip to content

Commit e2c8bba

Browse files
Merge pull request #14 from RWTH-i5-IDSG/master
merge
2 parents 9e95051 + 297d494 commit e2c8bba

33 files changed

+717
-498
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ before_script:
1717
# start the actual build
1818
script:
1919
- mvn -Dmaven.javadoc.skip=true clean package -Ptest -B -V
20-
- java -Djava.net.preferIPv4Stack=true -jar target/steve-*.jar &
20+
- java -Djava.net.preferIPv4Stack=true -jar target/steve.jar &
2121
- sleep 30
2222
- 'grep -C 50 -e "Exception: " ~/logs/steve.log && exit 255 || true'
2323
- elinks -dump -no-references http://localhost:8080/steve/manager/signin

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ SteVe is designed to run standalone, a java servlet container / web server (e.g.
8181
To start the application run (please do not run SteVe as root):
8282
8383
```
84-
# java -jar target/steve-X.X.X.jar
84+
# java -jar target/steve.jar
8585
```
8686
8787
# First Steps

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
<goal>shade</goal>
173173
</goals>
174174
<configuration>
175+
<finalName>${project.artifactId}</finalName>
175176
<minimizeJar>false</minimizeJar>
176177
<createDependencyReducedPom>false</createDependencyReducedPom>
177178
<transformers>

src/main/java/de/rwth/idsg/steve/SteveConfiguration.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ public enum SteveConfiguration {
1414
CONFIG;
1515

1616
// Root mapping for Spring
17-
private String springMapping = "/";
17+
private final String springMapping = "/";
1818
// Web frontend
19-
private String springManagerMapping = "/manager/*";
19+
private final String springManagerMapping = "/manager/*";
2020
// Mapping for CXF SOAP services
21-
private String cxfMapping = "/services/*";
21+
private final String cxfMapping = "/services/*";
2222
// Dummy service path
23-
private String routerEndpointPath = "/CentralSystemService";
23+
private final String routerEndpointPath = "/CentralSystemService";
2424
// Time zone for the application and database connections
25-
private String timeZoneId = "UTC"; // or ZoneId.systemDefault().getId();
25+
private final String timeZoneId = "UTC"; // or ZoneId.systemDefault().getId();
2626

2727
// -------------------------------------------------------------------------
2828
// main.properties
2929
// -------------------------------------------------------------------------
3030

31-
private String contextPath;
32-
private String steveVersion;
33-
private ApplicationProfile profile;
34-
private Ocpp ocpp;
35-
private Auth auth;
36-
private DB db;
37-
private Jetty jetty;
31+
private final String contextPath;
32+
private final String steveVersion;
33+
private final ApplicationProfile profile;
34+
private final Ocpp ocpp;
35+
private final Auth auth;
36+
private final DB db;
37+
private final Jetty jetty;
3838

3939
SteveConfiguration() {
4040
PropertiesFileLoader p = new PropertiesFileLoader("main.properties");
@@ -103,43 +103,43 @@ private void validate() {
103103
// Jetty configuration
104104
@Builder @Getter
105105
public static class Jetty {
106-
private String serverHost;
107-
private boolean gzipEnabled;
106+
private final String serverHost;
107+
private final boolean gzipEnabled;
108108

109109
// HTTP
110-
private boolean httpEnabled;
111-
private int httpPort;
110+
private final boolean httpEnabled;
111+
private final int httpPort;
112112

113113
// HTTPS
114-
private boolean httpsEnabled;
115-
private int httpsPort;
116-
private String keyStorePath;
117-
private String keyStorePassword;
114+
private final boolean httpsEnabled;
115+
private final int httpsPort;
116+
private final String keyStorePath;
117+
private final String keyStorePassword;
118118
}
119119

120120
// Database configuration
121121
@Builder @Getter
122122
public static class DB {
123-
private String ip;
124-
private int port;
125-
private String schema;
126-
private String userName;
127-
private String password;
128-
private boolean sqlLogging;
123+
private final String ip;
124+
private final int port;
125+
private final String schema;
126+
private final String userName;
127+
private final String password;
128+
private final boolean sqlLogging;
129129
}
130130

131131
// Credentials for Web interface access
132132
@Builder @Getter
133133
public static class Auth {
134-
private String userName;
135-
private String password;
134+
private final String userName;
135+
private final String password;
136136
}
137137

138138
// OCPP-related configuration
139139
@Builder @Getter
140140
public static class Ocpp {
141-
private boolean autoRegisterUnknownStations;
142-
private WsSessionSelectStrategyEnum wsSessionSelectStrategy;
141+
private final boolean autoRegisterUnknownStations;
142+
private final WsSessionSelectStrategyEnum wsSessionSelectStrategy;
143143
}
144144

145145
}

src/main/java/de/rwth/idsg/steve/ocpp/CommunicationTask.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import de.rwth.idsg.steve.repository.dto.ChargePointSelect;
55
import de.rwth.idsg.steve.utils.StringUtils;
66
import de.rwth.idsg.steve.web.dto.ocpp.ChargePointSelection;
7-
import de.rwth.idsg.steve.web.dto.task.RequestResult;
8-
import de.rwth.idsg.steve.web.dto.task.RequestTaskOrigin;
97
import lombok.AccessLevel;
108
import lombok.Getter;
119
import org.joda.time.DateTime;
@@ -32,7 +30,7 @@ public abstract class CommunicationTask<S extends ChargePointSelection, RESPONSE
3230

3331
private final OcppVersion ocppVersion;
3432
private final String operationName;
35-
private final RequestTaskOrigin origin;
33+
private final TaskOrigin origin;
3634
private final String caller;
3735
protected final S params;
3836

@@ -52,13 +50,13 @@ public abstract class CommunicationTask<S extends ChargePointSelection, RESPONSE
5250
private ArrayList<OcppCallback<RESPONSE>> callbackList = new ArrayList<>(2);
5351

5452
public CommunicationTask(OcppVersion ocppVersion, S params) {
55-
this(ocppVersion, params, RequestTaskOrigin.INTERNAL, "SteVe");
53+
this(ocppVersion, params, TaskOrigin.INTERNAL, "SteVe");
5654
}
5755

5856
/**
5957
* Do not expose the constructor, make it package-private
6058
*/
61-
CommunicationTask(OcppVersion ocppVersion, S params, RequestTaskOrigin origin, String caller) {
59+
CommunicationTask(OcppVersion ocppVersion, S params, TaskOrigin origin, String caller) {
6260
List<ChargePointSelect> cpsList = params.getChargePointSelectList();
6361

6462
this.ocppVersion = ocppVersion;

src/main/java/de/rwth/idsg/steve/ocpp/OcppCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface OcppCallback<T> {
1515

1616
/**
1717
* Relevant to WebSocket/JSON transport: Even though we have an error, this object is still a valid response from
18-
* charge point and RequestTask should treat it as such. {@link CommunicationTask#addNewError(String, String)}
18+
* charge point and the implementation should treat it as such. {@link CommunicationTask#addNewError(String, String)}
1919
* should be used when the request could not be delivered and there is a Java exception.
2020
*/
2121
void success(String chargeBoxId, OcppJsonError error);

src/main/java/de/rwth/idsg/steve/web/dto/task/RequestResult.java renamed to src/main/java/de/rwth/idsg/steve/ocpp/RequestResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package de.rwth.idsg.steve.web.dto.task;
1+
package de.rwth.idsg.steve.ocpp;
22

33
import lombok.Getter;
44
import lombok.Setter;

src/main/java/de/rwth/idsg/steve/web/dto/task/RequestTaskOrigin.java renamed to src/main/java/de/rwth/idsg/steve/ocpp/TaskOrigin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package de.rwth.idsg.steve.web.dto.task;
1+
package de.rwth.idsg.steve.ocpp;
22

33
import lombok.RequiredArgsConstructor;
44

@@ -7,7 +7,7 @@
77
* @since 23.11.2015
88
*/
99
@RequiredArgsConstructor
10-
public enum RequestTaskOrigin {
10+
public enum TaskOrigin {
1111

1212
// When the action was triggered by SteVe internally (e.g. by the admin/user)
1313
INTERNAL,

src/main/java/de/rwth/idsg/steve/ocpp/converter/Server15to16Impl.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ public DataTransferResponse convertResponse(ocpp.cs._2015._10.DataTransferRespon
229229
* but something else might make more sense at this place
230230
*/
231231
private static ChargePointStatus customMapStatus(ocpp.cs._2012._06.ChargePointStatus status) {
232-
if (status.equals(ocpp.cs._2012._06.ChargePointStatus.OCCUPIED)) {
233-
return ChargePointStatus.CHARGING;
234-
} else {
235-
return ChargePointStatus.fromValue(status.value());
232+
switch (status) {
233+
case OCCUPIED:
234+
return ChargePointStatus.CHARGING;
235+
default:
236+
return ChargePointStatus.fromValue(status.value());
236237
}
237238
}
238239

@@ -241,10 +242,27 @@ private static ChargePointStatus customMapStatus(ocpp.cs._2012._06.ChargePointSt
241242
* Update: According to the 1.6 specification, MODE_3_ERROR was simply renamed to EV_COMMUNICATION_ERROR
242243
*/
243244
private static ChargePointErrorCode customMapErrorCode(ocpp.cs._2012._06.ChargePointErrorCode errorCode15) {
244-
if (errorCode15.equals(ocpp.cs._2012._06.ChargePointErrorCode.MODE_3_ERROR)) {
245-
return ChargePointErrorCode.EV_COMMUNICATION_ERROR;
246-
} else {
247-
return ChargePointErrorCode.fromValue(errorCode15.value());
245+
switch (errorCode15) {
246+
case MODE_3_ERROR:
247+
return ChargePointErrorCode.EV_COMMUNICATION_ERROR;
248+
default:
249+
return ChargePointErrorCode.fromValue(errorCode15.value());
250+
}
251+
}
252+
253+
/**
254+
* AMP and VOLT are shortened to A and V, respectively.
255+
*
256+
* https://github.com/RWTH-i5-IDSG/steve/issues/59
257+
*/
258+
private static UnitOfMeasure convertUnit(ocpp.cs._2012._06.UnitOfMeasure unit) {
259+
switch (unit) {
260+
case AMP:
261+
return UnitOfMeasure.A;
262+
case VOLT:
263+
return UnitOfMeasure.V;
264+
default:
265+
return UnitOfMeasure.fromValue(unit.value());
248266
}
249267
}
250268

@@ -268,7 +286,7 @@ private static SampledValue toOcpp16SampledValue(ocpp.cs._2012._06.MeterValue.Va
268286
.withFormat(f.isSetFormat() ? ValueFormat.fromValue(f.getFormat().value()) : null)
269287
.withLocation(f.isSetLocation() ? Location.fromValue(f.getLocation().value()) : null)
270288
.withMeasurand(f.isSetMeasurand() ? Measurand.fromValue(f.getMeasurand().value()) : null)
271-
.withUnit(f.isSetUnit() ? UnitOfMeasure.fromValue(f.getUnit().value()) : null)
289+
.withUnit(f.isSetUnit() ? convertUnit(f.getUnit()) : null)
272290
.withValue(f.getValue());
273291
}
274292

@@ -284,12 +302,9 @@ private static MeterValue toOcpp16MeterValue(ocpp.cs._2012._06.MeterValue e) {
284302
}
285303

286304
private static List<MeterValue> toOcpp16TransactionData(List<TransactionData> transactionData) {
287-
List<ocpp.cs._2012._06.MeterValue> combinedList = transactionData.stream()
288-
.flatMap(data -> data.getValues().stream())
289-
.collect(Collectors.toList());
290-
291-
return combinedList.stream()
292-
.map(Server15to16Impl::toOcpp16MeterValue)
293-
.collect(Collectors.toList());
305+
return transactionData.stream()
306+
.flatMap(data -> data.getValues().stream())
307+
.map(Server15to16Impl::toOcpp16MeterValue)
308+
.collect(Collectors.toList());
294309
}
295310
}

src/main/java/de/rwth/idsg/steve/ocpp/ws/AbstractWebSocketEndpoint.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private void handleTextMessage(WebSocketSession session, TextMessage webSocketMe
8282
String incomingString = webSocketMessage.getPayload();
8383
String chargeBoxId = getChargeBoxId(session);
8484

85-
log.info("[chargeBoxId={}, sessionId={}] Received message: {}", chargeBoxId, session.getId(), incomingString);
85+
WebSocketLogger.receivedText(chargeBoxId, session, incomingString);
8686

8787
CommunicationContext context = new CommunicationContext(session, chargeBoxId);
8888
context.setIncomingString(incomingString);
@@ -91,15 +91,17 @@ private void handleTextMessage(WebSocketSession session, TextMessage webSocketMe
9191
}
9292

9393
private void handlePongMessage(WebSocketSession session) {
94-
log.debug("[id={}] Received pong message", session.getId());
94+
WebSocketLogger.receivedPong(getChargeBoxId(session), session);
9595

9696
// TODO: Not sure about the following. Should update DB? Should call directly repo?
9797
ocppServerRepository.updateChargeboxHeartbeat(getChargeBoxId(session), DateTime.now());
9898
}
9999

100100
@Override
101101
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
102-
log.info("New connection established: {}", session);
102+
String chargeBoxId = getChargeBoxId(session);
103+
104+
WebSocketLogger.connected(chargeBoxId, session);
103105

104106
// Just to keep the connection alive, such that the servers do not close
105107
// the connection because of a idle timeout, we ping-pong at fixed intervals.
@@ -109,8 +111,6 @@ public void afterConnectionEstablished(WebSocketSession session) throws Exceptio
109111
WebSocketConfiguration.PING_INTERVAL,
110112
TimeUnit.MINUTES);
111113

112-
String chargeBoxId = getChargeBoxId(session);
113-
114114
futureResponseContextStore.addSession(session);
115115

116116
int sizeBeforeAdd;
@@ -129,10 +129,10 @@ public void afterConnectionEstablished(WebSocketSession session) throws Exceptio
129129

130130
@Override
131131
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
132-
log.warn("[id={}] Connection was closed, status: {}", session.getId(), closeStatus);
133-
134132
String chargeBoxId = getChargeBoxId(session);
135133

134+
WebSocketLogger.closed(chargeBoxId, session, closeStatus);
135+
136136
futureResponseContextStore.removeSession(session);
137137

138138
int sizeAfterRemove;

src/main/java/de/rwth/idsg/steve/ocpp/ws/FutureResponseContextStoreImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ public class FutureResponseContextStoreImpl implements FutureResponseContextStor
2626

2727
@Override
2828
public void addSession(WebSocketSession session) {
29-
Map<String, FutureResponseContext> contextMap = lookupTable.get(session);
30-
if (contextMap == null) {
31-
log.debug("Creating new store for sessionId '{}'", session.getId());
32-
lookupTable.put(session, new ConcurrentHashMap<>());
33-
}
29+
lookupTable.computeIfAbsent(session, webSocketSession -> {
30+
log.debug("Creating new store for sessionId '{}'", webSocketSession.getId());
31+
return new ConcurrentHashMap<>();
32+
});
3433
}
3534

3635
@Override

src/main/java/de/rwth/idsg/steve/ocpp/ws/SessionContextStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
public interface SessionContextStore {
1616
void add(String chargeBoxId, WebSocketSession session, ScheduledFuture pingSchedule);
1717
void remove(String chargeBoxId, WebSocketSession session);
18+
WebSocketSession getSession(String chargeBoxId);
1819
int getSize(String chargeBoxId);
20+
int getNumberOfChargeBoxes();
1921
List<String> getChargeBoxIdList();
2022
Map<String, Deque<SessionContext>> getACopy();
21-
int getNumberOfChargeBoxes();
22-
WebSocketSession getSession(String chargeBoxId);
2323
}

0 commit comments

Comments
 (0)