Example usage for org.springframework.dao DuplicateKeyException getMessage

List of usage examples for org.springframework.dao DuplicateKeyException getMessage

Introduction

In this page you can find the example usage for org.springframework.dao DuplicateKeyException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:org.opentestsystem.authoring.testauth.service.impl.ScoringRuleServiceImpl.java

@Override
public ScoringRule saveScoringRule(final String scoringRuleId, final ScoringRule scoringRule) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Saving scoringRule");
    }/*from w  ww .  j  a v a  2 s  .c  o  m*/

    if (scoringRuleId != null && (scoringRule == null || StringUtils.isEmpty(scoringRule.getId())
            || !scoringRuleId.equals(scoringRule.getId()))) {
        throw new LocalizedException("scoringRule.invalid.id");
    }

    checkForLockedAssessment(scoringRule.getAssessmentId());
    this.scoringRuleHelper.validateScoringRule(scoringRule);

    ScoringRule existingScoringRule = null;
    if (StringUtils.isNotBlank(scoringRule.getId())) {
        existingScoringRule = getScoringRule(scoringRule.getId());
    }

    ScoringRule savedScoringRule = null;
    try {
        savedScoringRule = this.scoringRuleRepository.save(scoringRule);
        // check if this scoring rule is associated with reporting measure
        if (existingScoringRule != null) {
            if (existingScoringRule.getBlueprintReferenceType() != scoringRule.getBlueprintReferenceType()
                    || existingScoringRule.getBlueprintDenotationType() != scoringRule
                            .getBlueprintDenotationType()) {
                removeScoringRulesFromReportingMeasures(scoringRule);
            } else if (!StringUtils.equals(existingScoringRule.getBlueprintReferenceId(),
                    scoringRule.getBlueprintReferenceId())) {
                updateRelatedReportingMeasures(existingScoringRule.getBlueprintReferenceId(),
                        scoringRule.getBlueprintReferenceId());
            }
        }
    } catch (final DuplicateKeyException dke) {
        if (StringUtils.contains(dke.getMessage(), ScoringRule.ORDER_INDEX_NAME)) {
            throw new LocalizedException("scoringRule.already.exists.order",
                    paramArray(scoringRule.getAssessmentId(), String.valueOf(scoringRule.getOrder())), dke);
        } else {
            throw new LocalizedException("scoringRule.already.exists.label",
                    paramArray(scoringRule.getAssessmentId(), scoringRule.getLabel()), dke);
        }
    }
    return savedScoringRule;
}