Search in sources :

Example 1 with SteveException

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

the class OcppTagRepositoryImpl method getOverview.

@Override
@SuppressWarnings("unchecked")
public List<Overview> getOverview(OcppTagQueryForm form) {
    SelectQuery selectQuery = ctx.selectQuery();
    selectQuery.addFrom(OCPP_TAG);
    OcppTag parentTable = OCPP_TAG.as("parent");
    selectQuery.addSelect(OCPP_TAG.OCPP_TAG_PK, parentTable.OCPP_TAG_PK, OCPP_TAG.ID_TAG, OCPP_TAG.PARENT_ID_TAG, OCPP_TAG.EXPIRY_DATE, OCPP_TAG.IN_TRANSACTION, OCPP_TAG.BLOCKED);
    selectQuery.addJoin(parentTable, JoinType.LEFT_OUTER_JOIN, parentTable.ID_TAG.eq(OCPP_TAG.PARENT_ID_TAG));
    if (form.isIdTagSet()) {
        selectQuery.addConditions(OCPP_TAG.ID_TAG.eq(form.getIdTag()));
    }
    if (form.isParentIdTagSet()) {
        selectQuery.addConditions(OCPP_TAG.PARENT_ID_TAG.eq(form.getParentIdTag()));
    }
    switch(form.getExpired()) {
        case ALL:
            break;
        case TRUE:
            selectQuery.addConditions(OCPP_TAG.EXPIRY_DATE.lessOrEqual(CustomDSL.utcTimestamp()));
            break;
        case FALSE:
            selectQuery.addConditions(OCPP_TAG.EXPIRY_DATE.isNull().or(OCPP_TAG.EXPIRY_DATE.greaterThan(CustomDSL.utcTimestamp())));
            break;
        default:
            throw new SteveException("Unknown enum type");
    }
    processBooleanType(selectQuery, OCPP_TAG.IN_TRANSACTION, form.getInTransaction());
    processBooleanType(selectQuery, OCPP_TAG.BLOCKED, form.getBlocked());
    return selectQuery.fetch().map(new UserMapper());
}
Also used : SelectQuery(org.jooq.SelectQuery) OcppTag(jooq.steve.db.tables.OcppTag) SteveException(de.rwth.idsg.steve.SteveException)

Example 2 with SteveException

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

the class UserRepositoryImpl method delete.

@Override
public void delete(int userPk) {
    ctx.transaction(configuration -> {
        DSLContext ctx = DSL.using(configuration);
        try {
            addressRepository.delete(ctx, selectAddressId(userPk));
            deleteInternal(ctx, userPk);
        } catch (DataAccessException e) {
            throw new SteveException("Failed to delete the user", e);
        }
    });
}
Also used : DSLContext(org.jooq.DSLContext) DataAccessException(org.jooq.exception.DataAccessException) SteveException(de.rwth.idsg.steve.SteveException)

Example 3 with SteveException

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

the class UserRepositoryImpl method add.

@Override
public void add(UserForm form) {
    ctx.transaction(configuration -> {
        DSLContext ctx = DSL.using(configuration);
        try {
            Integer addressId = addressRepository.updateOrInsert(ctx, form.getAddress());
            addInternal(ctx, form, addressId);
        } catch (DataAccessException e) {
            throw new SteveException("Failed to add the user", e);
        }
    });
}
Also used : DSLContext(org.jooq.DSLContext) DataAccessException(org.jooq.exception.DataAccessException) SteveException(de.rwth.idsg.steve.SteveException)

Example 4 with SteveException

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

the class ChargePointRepositoryImpl method getOverviewInternal.

@SuppressWarnings("unchecked")
private Result<Record5<Integer, String, String, String, DateTime>> getOverviewInternal(ChargePointQueryForm form) {
    SelectQuery selectQuery = ctx.selectQuery();
    selectQuery.addFrom(CHARGE_BOX);
    selectQuery.addSelect(CHARGE_BOX.CHARGE_BOX_PK, CHARGE_BOX.CHARGE_BOX_ID, CHARGE_BOX.DESCRIPTION, CHARGE_BOX.OCPP_PROTOCOL, CHARGE_BOX.LAST_HEARTBEAT_TIMESTAMP);
    if (form.isSetOcppVersion()) {
        // http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
        selectQuery.addConditions(CHARGE_BOX.OCPP_PROTOCOL.like(form.getOcppVersion().getValue() + "_"));
    }
    if (form.isSetDescription()) {
        selectQuery.addConditions(includes(CHARGE_BOX.DESCRIPTION, form.getDescription()));
    }
    if (form.isSetChargeBoxId()) {
        selectQuery.addConditions(includes(CHARGE_BOX.CHARGE_BOX_ID, form.getChargeBoxId()));
    }
    switch(form.getHeartbeatPeriod()) {
        case ALL:
            break;
        case TODAY:
            selectQuery.addConditions(date(CHARGE_BOX.LAST_HEARTBEAT_TIMESTAMP).eq(date(DateTime.now())));
            break;
        case YESTERDAY:
            selectQuery.addConditions(date(CHARGE_BOX.LAST_HEARTBEAT_TIMESTAMP).eq(date(DateTime.now().minusDays(1))));
            break;
        case EARLIER:
            selectQuery.addConditions(date(CHARGE_BOX.LAST_HEARTBEAT_TIMESTAMP).lessThan(date(DateTime.now().minusDays(1))));
            break;
        default:
            throw new SteveException("Unknown enum type");
    }
    // Default order
    selectQuery.addOrderBy(CHARGE_BOX.CHARGE_BOX_PK.asc());
    return selectQuery.fetch();
}
Also used : SelectQuery(org.jooq.SelectQuery) SteveException(de.rwth.idsg.steve.SteveException)

Example 5 with SteveException

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

the class ChargePointRepositoryImpl method deleteChargePoint.

@Override
public void deleteChargePoint(int chargeBoxPk) {
    ctx.transaction(configuration -> {
        DSLContext ctx = DSL.using(configuration);
        try {
            addressRepository.delete(ctx, selectAddressId(chargeBoxPk));
            deleteChargePointInternal(ctx, chargeBoxPk);
        } catch (DataAccessException e) {
            throw new SteveException("Failed to delete the charge point", e);
        }
    });
}
Also used : DSLContext(org.jooq.DSLContext) DataAccessException(org.jooq.exception.DataAccessException) 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