public void addWebSocket(String chargingStationIdentifier, WebSocket webSocket) { WebSocketWrapper existingWrapper = sockets.get(chargingStationIdentifier); if (existingWrapper != null && !webSocket.equals(existingWrapper.getWebSocket())) { LOG.info("Found existing websocket connection when adding new websocket for {}. Closing existing one", chargingStationIdentifier); closeAndRemoveWebSocket(chargingStationIdentifier, existingWrapper.getWebSocket()); } sockets.put(chargingStationIdentifier, new WebSocketWrapper(new ChargingStationId(chargingStationIdentifier), webSocket, wampMessageHandler, gson)); }
@Override public void onTextStream(WebSocket webSocket, Reader reader) throws IOException { String chargingStationId = determineIdentifier(webSocket); ocppJsonService.handleMessage(new ChargingStationId(chargingStationId), reader); }
@Override public HeartbeatResponse heartbeat(HeartbeatRequest parameters, String chargeBoxIdentity) { domainService.heartbeat(new ChargingStationId(chargeBoxIdentity), addOnIdentity); HeartbeatResponse response = new HeartbeatResponse(); response.setCurrentTime(new Date()); return response; }
@Override public HeartbeatResponse heartbeat(HeartbeatRequest parameters, String chargeBoxIdentity) { domainService.heartbeat(new ChargingStationId(chargeBoxIdentity), addOnIdentity); HeartbeatResponse response = new HeartbeatResponse(); response.setCurrentTime(new Date()); return response; }
@Override public MeterValuesResponse meterValues(MeterValuesRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); //OCPP 1.2 does not contain transactionId references in it's metervalue communication TransactionId transactionId = null; List<MeterValue> meterValues = new ArrayList<>(); for (io.motown.ocpp.v12.soap.centralsystem.schema.MeterValue mv : request.getValues()) { meterValues.add(new MeterValue(mv.getTimestamp(), Integer.toString(mv.getValue()))); } domainService.meterValues(chargingStationId, transactionId, new EvseId(request.getConnectorId()), meterValues, addOnIdentity); return new MeterValuesResponse(); }
@Override public DiagnosticsStatusNotificationResponse diagnosticsStatusNotification(DiagnosticsStatusNotificationRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); DiagnosticsStatus diagnosticsStatus = request.getStatus(); domainService.diagnosticsUploadStatusUpdate(chargingStationId, DiagnosticsStatus.UPLOADED.equals(diagnosticsStatus), addOnIdentity); return new DiagnosticsStatusNotificationResponse(); }
@Override public DiagnosticsStatusNotificationResponse diagnosticsStatusNotification(DiagnosticsStatusNotificationRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); DiagnosticsStatus diagnosticsStatus = request.getStatus(); domainService.diagnosticsUploadStatusUpdate(chargingStationId, DiagnosticsStatus.UPLOADED.equals(diagnosticsStatus), addOnIdentity); return new DiagnosticsStatusNotificationResponse(); }
@Override public StopTransactionResponse stopTransaction(StopTransactionRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); NumberedTransactionId transactionId = new NumberedTransactionId(chargingStationId, PROTOCOL_IDENTIFIER, request.getTransactionId()); IdentifyingToken identifyingToken = new TextualToken(request.getIdTag()); //OCPP 1.2 does not include the meter values in a stop transaction message List<MeterValue> meterValues = new ArrayList<>(); domainService.stopTransaction(chargingStationId, transactionId, identifyingToken, request.getMeterStop(), request.getTimestamp(), meterValues, addOnIdentity); return new StopTransactionResponse(); }
@Override public DataTransferResponse dataTransfer(final DataTransferRequest request, final String chargeBoxIdentity) { final DataTransferFutureEventCallback future = new DataTransferFutureEventCallback(); final ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); FutureRequestHandler<DataTransferResponse, IncomingDataTransferResult> handler = new FutureRequestHandler<>(context.getMessageContext(), continuationTimeout); return handler.handle(future, new CallInitiator() { @Override public void initiateCall() { domainService.incomingDataTransfer(chargingStationId, request.getData(), request.getVendorId(), request.getMessageId(), future, addOnIdentity); } }, new IncomingDataTransferResponseFactory(), new ResponseFactory<DataTransferResponse>() { @Override public DataTransferResponse createResponse() { LOG.error("Error while io.motown.configuration.simple.handling incoming 'data transfer' request, returning rejected"); DataTransferResponse response = new DataTransferResponse(); response.setStatus(DataTransferStatus.REJECTED); return response; } }); }
/** * {@inheritDoc} */ @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), SetChargingStationOpeningTimesCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), SetChargingStationOpeningTimesCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { SetChargingStationOpeningTimesApiCommand command = gson.fromJson(commandObject, SetChargingStationOpeningTimesApiCommand.class); commandGateway.send(new SetChargingStationOpeningTimesCommand(csId, command.getOpeningTimes(), identityContext)); } } catch (JsonSyntaxException e) { throw new IllegalArgumentException("Set charging station opening times command not able to parse the payload, is your JSON correctly formatted?", e); } } }
/** * {@inheritDoc} */ @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), AddChargingStationOpeningTimesCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), AddChargingStationOpeningTimesCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { AddChargingStationOpeningTimesApiCommand command = gson.fromJson(commandObject, AddChargingStationOpeningTimesApiCommand.class); commandGateway.send(new AddChargingStationOpeningTimesCommand(csId, command.getOpeningTimes(), identityContext)); } } catch (JsonSyntaxException e) { throw new IllegalArgumentException("Set charging station opening times command not able to parse the payload, is your JSON correctly formatted?", e); } } }
/** * {@inheritDoc} */ @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestDataTransferCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestDataTransferCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { DataTransferMessage dataTransferMessage = gson.fromJson(commandObject, DataTransferMessage.class); commandGateway.send(new RequestDataTransferCommand(csId, dataTransferMessage, identityContext), new CorrelationToken()); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Data transfer command not able to parse the payload, is your json correctly formatted?", ex); } } }
@Override public FirmwareStatusNotificationResponse firmwareStatusNotification(FirmwareStatusNotificationRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); FirmwareStatus status = request.getStatus(); io.motown.domain.api.chargingstation.FirmwareStatus firmwareStatus; if (FirmwareStatus.INSTALLED.equals(status)) { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.INSTALLED; } else if (FirmwareStatus.DOWNLOADED.equals(status)) { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.DOWNLOADED; } else if (FirmwareStatus.INSTALLATION_FAILED.equals(status)) { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.INSTALLATION_FAILED; } else { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.DOWNLOAD_FAILED; } domainService.firmwareStatusUpdate(chargingStationId, firmwareStatus, addOnIdentity); return new FirmwareStatusNotificationResponse(); }
@Override public FirmwareStatusNotificationResponse firmwareStatusNotification(FirmwareStatusNotificationRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); FirmwareStatus status = request.getStatus(); io.motown.domain.api.chargingstation.FirmwareStatus firmwareStatus; if (FirmwareStatus.INSTALLED.equals(status)) { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.INSTALLED; } else if (FirmwareStatus.DOWNLOADED.equals(status)) { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.DOWNLOADED; } else if (FirmwareStatus.INSTALLATION_FAILED.equals(status)) { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.INSTALLATION_FAILED; } else { firmwareStatus = io.motown.domain.api.chargingstation.FirmwareStatus.DOWNLOAD_FAILED; } domainService.firmwareStatusUpdate(chargingStationId, firmwareStatus, addOnIdentity); return new FirmwareStatusNotificationResponse(); }
@Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), MoveChargingStationCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), MoveChargingStationCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { MoveChargingStationApiCommand command = gson.fromJson(commandObject, MoveChargingStationApiCommand.class); commandGateway.send(new MoveChargingStationCommand(csId, command.getCoordinates(), command.getAddress(), command.getAccessibility(), identityContext)); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Move charging station command not able to parse the payload, is your JSON correctly formatted?", ex); } } }
@Override public StatusNotificationResponse statusNotification(StatusNotificationRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); EvseId evseId = new EvseId(request.getConnectorId()); ComponentStatus componentStatus = getComponentStatusFromChargePointStatus(request.getStatus()); String errorCode = request.getErrorCode() != null ? request.getErrorCode().value() : null; Date timestamp = new Date(); AttributeMap<String, String> attributes = new AttributeMap<>(); attributes.putIfValueNotNull(AttributeMapKeys.STATUS_NOTIFICATION_ERROR_CODE_KEY, errorCode); domainService.statusNotification(chargingStationId, evseId, new StatusNotification(componentStatus, timestamp, attributes), addOnIdentity); return new StatusNotificationResponse(); }
/** * {@inheritDoc} */ @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestAuthorizationListVersionCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestAuthorizationListVersionCommand.class); } ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { commandGateway.send(new RequestAuthorizationListVersionCommand(csId, identityContext), new CorrelationToken()); } } }
/** * {@inheritDoc} */ @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestClearCacheCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestClearCacheCommand.class); } ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { commandGateway.send(new RequestClearCacheCommand(csId, identityContext), new CorrelationToken()); } } }
@Override public StatusNotificationResponse statusNotification(StatusNotificationRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); EvseId evseId = new EvseId(request.getConnectorId()); ComponentStatus componentStatus = getComponentStatusFromChargePointStatus(request.getStatus()); String errorCode = request.getErrorCode() != null ? request.getErrorCode().value() : null; Date timestamp = request.getTimestamp(); if (timestamp == null) { timestamp = new Date(); } Map<String, String> attributes = new AttributeMap<String, String>(). putIfValueNotNull(AttributeMapKeys.STATUS_NOTIFICATION_ERROR_CODE_KEY, errorCode). putIfValueNotNull(AttributeMapKeys.STATUS_NOTIFICATION_INFO_KEY, request.getInfo()). putIfValueNotNull(AttributeMapKeys.VENDOR_ID, request.getVendorId()). putIfValueNotNull(AttributeMapKeys.STATUS_NOTIFICATION_VENDOR_ERROR_CODE_KEY, request.getVendorErrorCode()); domainService.statusNotification(chargingStationId, evseId, new StatusNotification(componentStatus, timestamp, attributes), addOnIdentity); return new StatusNotificationResponse(); }
@Override public MeterValuesResponse meterValues(MeterValuesRequest request, String chargeBoxIdentity) { ChargingStationId chargingStationId = new ChargingStationId(chargeBoxIdentity); TransactionId transactionId = request.getTransactionId() != null ? new NumberedTransactionId(chargingStationId, PROTOCOL_IDENTIFIER, request.getTransactionId()) : null; List<MeterValue> meterValues = new ArrayList<>(); for (io.motown.ocpp.v15.soap.centralsystem.schema.MeterValue mv : request.getValues()) { for (io.motown.ocpp.v15.soap.centralsystem.schema.MeterValue.Value value : mv.getValue()) { ReadingContext readingContext = new ReadingContextTranslator(value.getContext()).translate(); ValueFormat valueFormat = new ValueFormatTranslator(value.getFormat()).translate(); Measurand measurand = new MeasurandTranslator(value.getMeasurand()).translate(); Location location = new LocationTranslator(value.getLocation()).translate(); UnitOfMeasure unitOfMeasure = new UnitOfMeasureTranslator(value.getUnit()).translate(); meterValues.add(new MeterValue(mv.getTimestamp(), value.getValue(), readingContext, valueFormat, measurand, location, unitOfMeasure)); } } domainService.meterValues(chargingStationId, transactionId, new EvseId(request.getConnectorId()), meterValues, addOnIdentity); return new MeterValuesResponse(); }