public EvseId getEvseId() { return new EvseId(Integer.valueOf(evseId)); }
@Override public EvseId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (!json.isJsonPrimitive()) { throw new JsonParseException("EvseId must be a JSON primitive"); } int evseId; try { evseId = json.getAsInt(); } catch (ClassCastException | IllegalStateException | NumberFormatException e) { throw new JsonParseException("EvseId must be a JSON integer", e); } return new EvseId(evseId); }
/** * Gets a default EVSE with the given identifier. * * @param identifier the identifier for the EVSE. * @return a default EVSE with the given identifier. */ public static Evse getEvse(int identifier) { return new Evse(new EvseId(identifier), getConnectors(NUMBER_OF_CONNECTORS)); }
@Override public void handle(ChangeChargingStationAvailabilityToInoperativeRequestedEvent event, CorrelationToken correlationToken) { ocppJsonService.changeAvailability(event.getChargingStationId(), new EvseId(0), Changeavailability.Type.INOPERATIVE, correlationToken); }
/** * Retrieves a set of {@code io.motown.domain.api.chargingstation.Evse}s based on the vendor and model. * * @param vendor vendor code. * @param model model code. * @return set of Evses if they can be found, otherwise an empty set. */ public Set<io.motown.domain.api.chargingstation.Evse> getEvses(String vendor, String model) { List<ChargingStationType> items = chargingStationTypeRepository.findByCodeAndManufacturerCode(model, vendor); Set<io.motown.domain.api.chargingstation.Evse> result = new HashSet<>(); int resultSize = items.size(); if (resultSize > 0) { ChargingStationType chargingStationType = items.get(0); for (Evse evse : chargingStationType.getEvses()) { result.add(new io.motown.domain.api.chargingstation.Evse(new EvseId(evse.getIdentifier()), convertViewModelConnectorsToDomain(evse.getConnectors()))); } } return result; }
@Override public void handle(ChangeChargingStationAvailabilityToInoperativeRequestedEvent event, CorrelationToken correlationToken) { LOG.info("OCPP 1.2 ChangeChargingStationAvailabilityToInoperativeRequestedEvent"); EvseId chargingStationEvseId = new EvseId(0); RequestResult requestResult = chargingStationOcpp12Client.changeAvailabilityToInoperative(event.getChargingStationId(), chargingStationEvseId); switch (requestResult) { case SUCCESS: domainService.changeChargingStationAvailabilityToInoperative(event.getChargingStationId(), correlationToken, addOnIdentity); break; case FAILURE: LOG.info("Failed to set availability of chargingstation {} to inoperative", event.getChargingStationId().getId()); break; default: throw new AssertionError(String.format("Unknown status for change availability to inoperative: '%s'", requestResult)); } }
@Override public void handle(ChangeChargingStationAvailabilityToInoperativeRequestedEvent event, CorrelationToken correlationToken) { LOG.info("OCPP 1.5 ChangeChargingStationAvailabilityToInoperativeRequestedEvent"); EvseId chargingStationEvseId = new EvseId(0); RequestResult requestResult = chargingStationOcpp15Client.changeAvailabilityToInoperative(event.getChargingStationId(), chargingStationEvseId); switch (requestResult) { case SUCCESS: domainService.changeChargingStationAvailabilityToInoperative(event.getChargingStationId(), correlationToken, addOnIdentity); break; case FAILURE: LOG.info("Failed to set availability of chargingstation {} to inoperative", event.getChargingStationId().getId()); break; default: throw new AssertionError(String.format("Unkown status for change availability to inoperative: '%s'", requestResult)); } }
@Override public void handle(ChangeChargingStationAvailabilityToOperativeRequestedEvent event, @MetaData(CorrelationToken.KEY) CorrelationToken correlationToken) { ocppJsonService.changeAvailability(event.getChargingStationId(), new EvseId(0), Changeavailability.Type.OPERATIVE, correlationToken); }
@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 void handle(ChangeChargingStationAvailabilityToOperativeRequestedEvent event, @MetaData(CorrelationToken.KEY) CorrelationToken correlationToken) { LOG.info("OCPP 1.2 ChangeChargingStationAvailabilityToOperativeRequestedEvent"); EvseId chargingStationEvseId = new EvseId(0); RequestResult requestResult = chargingStationOcpp12Client.changeAvailabilityToOperative(event.getChargingStationId(), chargingStationEvseId); switch (requestResult) { case SUCCESS: domainService.changeChargingStationAvailabilityToOperative(event.getChargingStationId(), correlationToken, addOnIdentity); break; case FAILURE: LOG.info("Failed to set availability of chargingstation {} to operative", event.getChargingStationId().getId()); break; default: throw new AssertionError(String.format("Unknown status for change availability to operative: '%s'", requestResult)); } }
@Override public void handle(ChangeChargingStationAvailabilityToOperativeRequestedEvent event, @MetaData(CorrelationToken.KEY) CorrelationToken correlationToken) { LOG.info("OCPP 1.5 ChangeChargingStationAvailabilityToOperativeRequestedEvent"); EvseId chargingStationEvseId = new EvseId(0); RequestResult requestResult = chargingStationOcpp15Client.changeAvailabilityToOperative(event.getChargingStationId(), chargingStationEvseId); switch (requestResult) { case SUCCESS: domainService.changeChargingStationAvailabilityToOperative(event.getChargingStationId(), correlationToken, addOnIdentity); break; case FAILURE: LOG.info("Failed to set availability of chargingstation {} to operative", event.getChargingStationId().getId()); break; default: throw new AssertionError(String.format("Unkown status for change availability to operative: '%s'", requestResult)); } }
@Override public void initiateCall() { domainService.startTransaction(chargingStationId, new EvseId(parameters.getConnectorId()), new TextualToken(parameters.getIdTag()), future, addOnIdentity); } }, new StartTransactionResponseFactory(), new ResponseFactory<StartTransactionResponse>() {
@Override public void initiateCall() { domainService.startTransaction(chargingStationId, new EvseId(parameters.getConnectorId()), new TextualToken(parameters.getIdTag()), future, addOnIdentity); } }, new StartTransactionResponseFactory(), new ResponseFactory<StartTransactionResponse>() {
@Override public void handleRequest(ChargingStationId chargingStationId, String callId, String payload, WebSocketWrapper webSocketWrapper) { Starttransaction request = gson.fromJson(payload, Starttransaction.class); AttributeMap<String, String> attributes = new AttributeMap<String, String>(). putIfValueNotNull(AttributeMapKeys.RESERVATION_ID, request.getReservationId() != null ? request.getReservationId().toString() : null); StartTransactionInfo startTransactionInfo = new StartTransactionInfo(new EvseId(request.getConnectorId()), request.getMeterStart(), request.getTimestamp(), new TextualToken(request.getIdTag()), attributes); FutureEventCallback futureEventCallback = new StartTransactionFutureEventCallback(callId, webSocketWrapper, chargingStationId, protocolIdentifier, startTransactionInfo, domainService, addOnIdentity); // futureEventCallback will handle authorize result and trigger a startTransaction command domainService.authorize(chargingStationId, request.getIdTag(), futureEventCallback, addOnIdentity); } }
@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(); }
@CommandHandler public void handle(RequestUnlockEvseCommand command, MetaData metaData) { checkCommandAllowed(command.getIdentityContext(), command.getClass()); checkCommunicationAllowed(); if (command.getEvseId().getNumberedId() > numberOfEvses) { apply(new EvseNotFoundEvent(id, command.getEvseId(), command.getIdentityContext()), metaData); } else { if (command.getEvseId() == Evse.ALL) { for (int i = 1; i <= numberOfEvses; i++) { apply(new UnlockEvseRequestedEvent(id, protocol, new EvseId(i), command.getIdentityContext()), metaData); } } else { apply(new UnlockEvseRequestedEvent(id, protocol, command.getEvseId(), command.getIdentityContext()), metaData); } } }
@Override public void handleRequest(ChargingStationId chargingStationId, String callId, String payload, WebSocketWrapper webSocketWrapper) { Statusnotification request = gson.fromJson(payload, Statusnotification.class); String errorCode = request.getErrorCode() != null ? request.getErrorCode().toString() : null; Date timestamp = request.getTimestamp(); if(timestamp == null) { timestamp = new Date(); } AttributeMap<String, String> attributes = new AttributeMap<String, String>(). putIfValueNotNull(AttributeMapKeys.STATUS_NOTIFICATION_VENDOR_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, new EvseId(request.getConnectorId()), new StatusNotification(getComponentStatusFromChargePointStatus(request.getStatus()), timestamp, attributes), addOnIdentity); writeResponse(webSocketWrapper, new StatusnotificationResponse(), callId, MessageProcUri.STATUS_NOTIFICATION); }
@Override public void handleRequest(ChargingStationId chargingStationId, String callId, String payload, WebSocketWrapper webSocketWrapper) { Metervalues request = gson.fromJson(payload, Metervalues.class); List<MeterValue> meterValues = new ArrayList<>(); for (Value meterValue : request.getValues()) { for (Value_ value : meterValue.getValues()) { ReadingContext readingContext = new ReadingContextTranslator(value.getContext()).translate(); ValueFormat valueFormat = new ValueFormatTranslator(value.getFormat()).translate(); Location location = new LocationTranslator(value.getLocation()).translate(); Measurand measurand = new MeasurandTranslator(value.getMeasurand()).translate(); UnitOfMeasure unitOfMeasure = new UnitOfMeasureTranslator(value.getUnit()).translate(); meterValues.add(new MeterValue(meterValue.getTimestamp(), value.getValue(), readingContext, valueFormat, measurand, location, unitOfMeasure)); } } TransactionId transactionId = null; Integer requestTransactionId = request.getTransactionId(); if (requestTransactionId != null && requestTransactionId > 0) { transactionId = new NumberedTransactionId(chargingStationId, protocolIdentifier, requestTransactionId); } domainService.meterValues(chargingStationId, transactionId, new EvseId(request.getConnectorId()), meterValues, addOnIdentity); writeResponse(webSocketWrapper, new MetervaluesResponse(), callId, MessageProcUri.METERVALUES); }
@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(); }