public CommandProcessingResult deleteScoringFeature()

in scorecard-plugin/src/main/java/org/apache/fineract/portfolio/creditscorecard/service/CreditScorecardWritePlatformServiceImpl.java [336:358]


    public CommandProcessingResult deleteScoringFeature(Long entityId) {

        this.context.authenticatedUser();

        final CreditScorecardFeature featureForDelete = this.featureRepository.findById(entityId)
                .orElseThrow(() -> new FeatureNotFoundException(entityId));
        if (featureForDelete.isDeleted()) {
            throw new FeatureNotFoundException(entityId);
        }

        final Collection<LoanProduct> loanProducts = this.loanProductRepository.retrieveLoanProductsByScorecardFeatureId(entityId);

        if (!loanProducts.isEmpty()) {
            throw new FeatureCannotBeDeletedException("error.msg.scorecard.feature.cannot.be.deleted.it.is.already.used.in.loan",
                    "This Scoring Feature cannot be deleted, it is already used in loan");
        }

        featureForDelete.delete();

        this.featureRepository.save(featureForDelete);

        return new CommandProcessingResultBuilder().withEntityId(featureForDelete.getId()).build();
    }