Search in sources :

Example 6 with SteveException

use of de.rwth.idsg.steve.SteveException in project steve by RWTH-i5-IDSG.

the class ChargePointRepositoryImpl method getDetails.

@Override
public ChargePoint.Details getDetails(int chargeBoxPk) {
    ChargeBoxRecord cbr = ctx.selectFrom(CHARGE_BOX).where(CHARGE_BOX.CHARGE_BOX_PK.equal(chargeBoxPk)).fetchOne();
    if (cbr == null) {
        throw new SteveException("Charge point not found");
    }
    AddressRecord ar = addressRepository.get(ctx, cbr.getAddressPk());
    return new ChargePoint.Details(cbr, ar);
}
Also used : AddressRecord(jooq.steve.db.tables.records.AddressRecord) ChargeBoxRecord(jooq.steve.db.tables.records.ChargeBoxRecord) SteveException(de.rwth.idsg.steve.SteveException)

Example 7 with SteveException

use of de.rwth.idsg.steve.SteveException in project steve by RWTH-i5-IDSG.

the class ChargePointRepositoryImpl method updateChargePoint.

@Override
public void updateChargePoint(ChargePointForm form) {
    ctx.transaction(configuration -> {
        DSLContext ctx = DSL.using(configuration);
        try {
            Integer addressId = addressRepository.updateOrInsert(ctx, form.getAddress());
            updateChargePointInternal(ctx, form, addressId);
        } catch (DataAccessException e) {
            throw new SteveException("Failed to update the charge point with chargeBoxId '%s'", form.getChargeBoxId(), e);
        }
    });
}
Also used : DSLContext(org.jooq.DSLContext) DataAccessException(org.jooq.exception.DataAccessException) SteveException(de.rwth.idsg.steve.SteveException)

Example 8 with SteveException

use of de.rwth.idsg.steve.SteveException in project steve by RWTH-i5-IDSG.

the class AbstractChargePointServiceInvoker method run.

/**
 * Actual processing
 */
private void run(String chargeBoxId, CommunicationTask task) {
    RequestType request = task.getRequest();
    String messageId = UUID.randomUUID().toString();
    ActionResponsePair pair = typeStore.findActionResponse(request);
    if (pair == null) {
        throw new SteveException("Action name is not found");
    }
    OcppJsonCall call = new OcppJsonCall();
    call.setMessageId(messageId);
    call.setPayload(request);
    call.setAction(pair.getAction());
    FutureResponseContext frc = new FutureResponseContext(task, pair.getResponseClass());
    CommunicationContext context = new CommunicationContext(endpoint.getSession(chargeBoxId), chargeBoxId);
    context.setOutgoingMessage(call);
    context.setFutureResponseContext(frc);
    outgoingCallPipeline.accept(context);
}
Also used : CommunicationContext(de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext) ActionResponsePair(de.rwth.idsg.steve.ocpp.ws.data.ActionResponsePair) OcppJsonCall(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall) FutureResponseContext(de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext) RequestType(de.rwth.idsg.steve.ocpp.RequestType) SteveException(de.rwth.idsg.steve.SteveException)

Example 9 with SteveException

use of de.rwth.idsg.steve.SteveException in project steve by RWTH-i5-IDSG.

the class Deserializer method handleError.

/**
 * Do NOT catch and handle exceptions for incoming RESPONSEs. Let the processing fail.
 * There is no mechanism in OCPP to report back such erroneous messages.
 */
private void handleError(CommunicationContext context, String messageId, JsonParser parser) {
    FutureResponseContext responseContext = futureResponseContextStore.get(context.getSession(), messageId);
    if (responseContext == null) {
        throw new SteveException("An error message was received as response to a not-sent call. The message was: %s", context.getIncomingString());
    }
    ErrorCode code;
    String desc;
    String details = null;
    try {
        parser.nextToken();
        code = ErrorCode.fromValue(parser.getText());
        parser.nextToken();
        desc = parser.getText();
        // ErrorDescription - Should be filled in if possible, otherwise a clear empty string "".
        if ("".equals(desc)) {
            desc = null;
        }
        // From spec:
        // ErrorDetails - This JSON object describes error details in an undefined way.
        // If there are no error details you should fill in an empty object {}, missing or null is not allowed
        parser.nextToken();
        TreeNode detailsNode = parser.readValueAsTree();
        if (detailsNode != null && detailsNode.size() != 0) {
            details = mapper.writeValueAsString(detailsNode);
        }
    } catch (IOException e) {
        throw new SteveException("Deserialization of incoming error message failed", e);
    }
    OcppJsonError error = new OcppJsonError();
    error.setMessageId(messageId);
    error.setErrorCode(code);
    error.setErrorDescription(desc);
    error.setErrorDetails(details);
    context.setIncomingMessage(error);
    context.createErrorHandler(responseContext.getTask());
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) OcppJsonError(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError) ErrorCode(de.rwth.idsg.steve.ocpp.ws.data.ErrorCode) IOException(java.io.IOException) FutureResponseContext(de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext) SteveException(de.rwth.idsg.steve.SteveException)

Example 10 with SteveException

use of de.rwth.idsg.steve.SteveException in project steve by RWTH-i5-IDSG.

the class Deserializer method accept.

/**
 * Parsing with streaming API is cumbersome, but only it allows to parse the String step for step
 * and build, if any, a corresponding error message.
 */
@Override
public void accept(CommunicationContext context) {
    try (JsonParser parser = mapper.getFactory().createParser(context.getIncomingString())) {
        // set cursor to '['
        parser.nextToken();
        parser.nextToken();
        int messageTypeNr = parser.getIntValue();
        parser.nextToken();
        String messageId = parser.getText();
        MessageType messageType = MessageType.fromTypeNr(messageTypeNr);
        switch(messageType) {
            case CALL:
                handleCall(context, messageId, parser);
                break;
            case CALL_RESULT:
                handleResult(context, messageId, parser);
                break;
            case CALL_ERROR:
                handleError(context, messageId, parser);
                break;
            default:
                throw new SteveException("Unknown enum type");
        }
    } catch (IOException e) {
        throw new SteveException("Deserialization of incoming string failed: %s", context.getIncomingString(), e);
    }
}
Also used : IOException(java.io.IOException) MessageType(de.rwth.idsg.steve.ocpp.ws.data.MessageType) JsonParser(com.fasterxml.jackson.core.JsonParser) SteveException(de.rwth.idsg.steve.SteveException)

Aggregations

SteveException (de.rwth.idsg.steve.SteveException)17 DataAccessException (org.jooq.exception.DataAccessException)6 DSLContext (org.jooq.DSLContext)5 FutureResponseContext (de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext)4 IOException (java.io.IOException)3 AddressRecord (jooq.steve.db.tables.records.AddressRecord)2 DateTime (org.joda.time.DateTime)2 SelectQuery (org.jooq.SelectQuery)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 TreeNode (com.fasterxml.jackson.core.TreeNode)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 RequestType (de.rwth.idsg.steve.ocpp.RequestType)1 ResponseType (de.rwth.idsg.steve.ocpp.ResponseType)1 ActionResponsePair (de.rwth.idsg.steve.ocpp.ws.data.ActionResponsePair)1 CommunicationContext (de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext)1 ErrorCode (de.rwth.idsg.steve.ocpp.ws.data.ErrorCode)1 MessageType (de.rwth.idsg.steve.ocpp.ws.data.MessageType)1 OcppJsonCall (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall)1 OcppJsonError (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError)1 OcppJsonResult (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult)1