Search in sources :

Example 16 with SteveException

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

the class UserRepositoryImpl method getDetails.

@Override
public User.Details getDetails(int userPk) {
    // -------------------------------------------------------------------------
    // 1. user table
    // -------------------------------------------------------------------------
    UserRecord ur = ctx.selectFrom(USER).where(USER.USER_PK.equal(userPk)).fetchOne();
    if (ur == null) {
        throw new SteveException("There is no user with id '%s'", userPk);
    }
    // -------------------------------------------------------------------------
    // 2. address table
    // -------------------------------------------------------------------------
    AddressRecord ar = addressRepository.get(ctx, ur.getAddressPk());
    // -------------------------------------------------------------------------
    // 3. ocpp_tag table
    // -------------------------------------------------------------------------
    String ocppIdTag = null;
    if (ur.getOcppTagPk() != null) {
        Record1<String> record = ctx.select(OCPP_TAG.ID_TAG).from(OCPP_TAG).where(OCPP_TAG.OCPP_TAG_PK.eq(ur.getOcppTagPk())).fetchOne();
        if (record != null) {
            ocppIdTag = record.value1();
        }
    }
    return User.Details.builder().userRecord(ur).address(ar).ocppIdTag(Optional.ofNullable(ocppIdTag)).build();
}
Also used : UserRecord(jooq.steve.db.tables.records.UserRecord) AddressRecord(jooq.steve.db.tables.records.AddressRecord) SteveException(de.rwth.idsg.steve.SteveException)

Example 17 with SteveException

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

the class UserRepositoryImpl method update.

@Override
public void update(UserForm form) {
    ctx.transaction(configuration -> {
        DSLContext ctx = DSL.using(configuration);
        try {
            Integer addressId = addressRepository.updateOrInsert(ctx, form.getAddress());
            updateInternal(ctx, form, addressId);
        } catch (DataAccessException e) {
            throw new SteveException("Failed to update the user", 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