Search in sources :

Example 1 with AddressRecord

use of jooq.steve.db.tables.records.AddressRecord 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 2 with AddressRecord

use of jooq.steve.db.tables.records.AddressRecord 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)

Aggregations

SteveException (de.rwth.idsg.steve.SteveException)2 AddressRecord (jooq.steve.db.tables.records.AddressRecord)2 ChargeBoxRecord (jooq.steve.db.tables.records.ChargeBoxRecord)1 UserRecord (jooq.steve.db.tables.records.UserRecord)1