Search in sources :

Example 1 with NotFoundException

use of org.finos.waltz.common.exception.NotFoundException in project waltz by khartec.

the class MeasurableRatingDao method save.

// --- save
public Operation save(SaveMeasurableRatingCommand command, boolean ignoreReadOnly) {
    MeasurableRatingRecord record = TO_RECORD_MAPPER.apply(command);
    boolean exists = dsl.fetchExists(DSL.select(MEASURABLE_RATING.fields()).from(MEASURABLE_RATING).where(MEASURABLE_RATING.MEASURABLE_ID.eq(command.measurableId())).and(MEASURABLE_RATING.ENTITY_ID.eq(command.entityReference().id())).and(MEASURABLE_RATING.ENTITY_KIND.eq(command.entityReference().kind().name())));
    if (exists) {
        int updateCount = dsl.update(MEASURABLE_RATING).set(MEASURABLE_RATING.RATING, String.valueOf(command.rating())).set(MEASURABLE_RATING.DESCRIPTION, command.description()).set(MEASURABLE_RATING.LAST_UPDATED_BY, command.lastUpdate().by()).set(MEASURABLE_RATING.LAST_UPDATED_AT, command.lastUpdate().atTimestamp()).set(MEASURABLE_RATING.PROVENANCE, command.provenance()).where(MEASURABLE_RATING.ENTITY_ID.eq(command.entityReference().id())).and(MEASURABLE_RATING.ENTITY_KIND.eq(command.entityReference().kind().name())).and(MEASURABLE_RATING.MEASURABLE_ID.eq(command.measurableId())).and(ignoreReadOnly ? DSL.trueCondition() : MEASURABLE_RATING.IS_READONLY.isFalse()).execute();
        if (updateCount == 0) {
            throw new NotFoundException("MR_SAVE_UPDATE_FAILED", format("Could find writable associated record to update for rating: %s", command));
        }
        ;
        return Operation.UPDATE;
    } else {
        if (dsl.executeInsert(record) != 1) {
            throw new NotFoundException("MR_SAVE_INSERT_FAILED", format("Creation of record failed: %s", command));
        }
        ;
        return Operation.ADD;
    }
}
Also used : MeasurableRatingRecord(org.finos.waltz.schema.tables.records.MeasurableRatingRecord) NotFoundException(org.finos.waltz.common.exception.NotFoundException)

Aggregations

NotFoundException (org.finos.waltz.common.exception.NotFoundException)1 MeasurableRatingRecord (org.finos.waltz.schema.tables.records.MeasurableRatingRecord)1