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());
}
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);
}
});
}
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);
}
});
}
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();
}
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);
}
});
}
Aggregations