Snippets

OICP 2.1 Push Charge Detail Record | Java

Created by Gregor Schermuly last modified Julius Poessnecker
1
2
3
4
5
6
7
The service description can be found in the OICP 2.1.

Section:
3.1.5 eRoamingChargeDetailRecord

To download the latest OICP Version, please visit our website:
https://www.hubject.com/downloads/
/**
 * Creates a new PushChargeDetailRecord request.
 *
 * @param ChargeDetailRecord the charge detail record for this request.
 * @return a new PushChargeDetailRecord request builder object.
 */
public PushChargeDetailRecordRequest PushChargeDetailRecord(final ChargeDetailRecord  ChargeDetailRecord)
{ ... }

/**
 * Creates a new ChargeDetailRecordBuilder request builder object.
 *
 * @param SessionId the unique identification of the EV charging session for this request.
 * @param SessionId the OICP session identification from the Authorize Start request.
 * @param PartnerSessionId The OICP session identification from the Authorize Start request.
 * @param PartnerProductId The ev charging product identification.
 * @param EVSEId The EVSE identification.
 * @param AuthToken An optional (RFID) user identification.
 * @param QRCode_EVCOId An optional EVCO user identification.
 * @param QRCode_PIN An optional EVCO user identification PIN.
 * @param PnC_EVCOId  An optional plug-and-charge EVCO user identification.
 * @param Remote_EVCOId  An optional remote EVCO user identification.
 * @param ChargingStart An optional charging start timestamp.
 * @param ChargingEnd  An optional charging end timestamp.
 * @param SessionStart The session start timestamp.
 * @param SessionEnd The session end timestamp.
 * @param MeterValueStart An optional initial value of the energy meter.
 * @param MeterValueEnd An optional final value of the energy meter.
 * @param MeterValuesInBetween An optional stream of meter values during the charging session.
 * @param ConsumedEnergy The optional amount of consumed energy.
 * @param MeteringSignature An optional signature for the metering values.
 * @param HubOperatorId An optional identification of the hub operator.
 * @param HubProviderId An optional identification of the hub provider.
 */
public ChargeDetailRecord(final ChargingSession_Id  SessionId,
                          final ChargingSession_Id  PartnerSessionId,
                          final ChargingProduct_Id  PartnerProductId,
                          final EVSE_Id             EVSEId,
                          final Auth_Token          AuthToken,
                          final EVCO_Id             QRCode_EVCOId,
                          final PIN                 QRCode_PIN,
                          final EVCO_Id             PnC_EVCOId,
                          final EVCO_Id             Remote_EVCOId,
                          final Instant             ChargingStart,
                          final Instant             ChargingEnd,
                          final Instant             SessionStart,
                          final Instant             SessionEnd,
                          final Double              MeterValueStart,
                          final Double              MeterValueEnd,
                          final Stream<Double>      MeterValuesInBetween,
                          final Double              ConsumedEnergy,
                          final String              MeteringSignature,
                          final HubOperator_Id      HubOperatorId,
                          final HubProvider_Id      HubProviderId)
{ ... }


/**
 * Creates a new ChargeDetailRecordBuilder request builder object.
 *
 * @param SessionId the unique identification of the EV charging session for this request.
 */
public ChargeDetailRecordBuilder(final ChargingSession_Id SessionId)
{ ... }
EVSEOperator_Id EVSEOperatorId  = EVSEOperator_Id.Parse("DE*GEF");
EVSE_Id         EVSEId          = EVSE_Id.        Parse("DE*GEF*E123456789*1");
Auth_Token      AuthToken       = Auth_Token.     Parse("12345678");

CPOClient       HubjectCPO      = new CPOClient("api.playground.hubject.com").

CompletableFuture req = HubjectCPO.

    AuthorizeStart(EVSEOperatorId,
                   EVSEId,
                   AuthToken).

    Run(StartResult -> {

        if (StartResult.getAuthorizationStatus() == AuthorizationStatus.Authorized)
        {

            System.out.println("AuthorizeStart: success!");

            try {

                Thread.sleep(1000);

                HubjectCPO.
                    AuthorizeStop(EVSEOperatorId,
                                  StartResult.getSessionId(),
                                  AuthToken).

                    Run(StopResult -> {

                        if (StopResult.getAuthorizationStatus() == AuthorizationStatus.Authorized)
                        {

                            System.out.println("AuthorizeStop: success!");

                            try {

                                Thread.sleep(1000);

                                ChargeDetailRecord CDR = ChargeDetailRecord.
                                    Create                  (StartResult.getSessionId()).
                                    setEVSEId               (EVSEId).
                                    setPartnerProductId     (ChargingProduct_Id.Parse("AC1")).
                                    setAuthToken            (AuthToken).
                                    setSessionStart         (Instant.now().minus(Duration.ofHours(3))).
                                    setChargingStart        (Instant.now().minus(Duration.ofHours(3))).
                                    setChargingEnd          (Instant.now()).
                                    setMeterValueStart      (1.0).
                                    setMeterValueEnd        (5.1).
                                    setMeterValuesInBetween (1.0, 2.1, 3.4, 4.8, 5.1, 5.1, 5.1).
                                    setConsumedEnergy       (4.1).
                                    setSessionEnd           (Instant.now()).
                                    build();

                                HubjectCPO.
                                    PushChargeDetailRecord(CDR).

                                    Run(ack -> {

                                        if (ack.hasResult())
                                            System.out.println("PushChargeDetailRecord: success!");

                                        else {
                                            System.out.println(ack.getStatusCode().getCode());
                                            System.out.println(ack.getStatusCode().getDescription());
                                            System.out.println(ack.getStatusCode().getAdditionalInfo());
                                        }

                                    });

                            } catch (Exception e) {
                                System.out.println(e.getMessage());
                            }

                        }

                        else {
                            System.out.println(StopResult.getStatusCode().getCode());
                            System.out.println(StopResult.getStatusCode().getDescription());
                            System.out.println(StopResult.getStatusCode().getAdditionalInfo());
                        }

                    });

            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }

        else {
            System.out.println(StartResult.getStatusCode().getCode());
            System.out.println(StartResult.getStatusCode().getDescription());
            System.out.println(StartResult.getStatusCode().getAdditionalInfo());
        }

    });

// Wait for the future to complete...
req.get();

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.