<commit_before>package pl.warsjawa.decisionmaker

import com.wordnik.swagger.annotations.Api
import com.wordnik.swagger.annotations.ApiOperation
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import pl.warsjawa.decisionmaker.worker.PropagationWorker

import javax.validation.constraints.NotNull
import java.util.concurrent.Callable

import static DecisionMakerApi.*

@CompileStatic
@Slf4j
@RestController
@RequestMapping(API_URL)
@Api(value = "loanApplication", description = "Decides whether to grant loan or not")
class DecisionController {

    private final PropagationWorker propagationWorker

    @Autowired
    DecisionController(PropagationWorker propagationWorker) {
        this.propagationWorker = propagationWorker
    }

    @RequestMapping(
            value = LOAN_APPLICATION_URL,
            method = RequestMethod.PUT,
            consumes = API_VERSION_1,
            produces = API_VERSION_1)
    @ApiOperation(value = "Async granting of loan",
            notes = "This will asynchronously verify whether the user can get a loan")
    Callable<Void> decideOnLoanGranting(@PathVariable @NotNull String loanApplicationId, @RequestBody @NotNull String loanApplicationDetails) {
        return {
            propagationWorker.makeDecisionAndPropagate(loanApplicationId, loanApplicationDetails)
        }
    }
}<commit_msg>Endpoint for finding a decision for a loan with provided application identifier.<commit_after>package pl.warsjawa.decisionmaker

import com.wordnik.swagger.annotations.Api
import com.wordnik.swagger.annotations.ApiOperation
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import pl.warsjawa.decisionmaker.domain.Decision
import pl.warsjawa.decisionmaker.repository.DecisionRepository
import pl.warsjawa.decisionmaker.worker.PropagationWorker

import javax.validation.constraints.NotNull
import java.util.concurrent.Callable

import static DecisionMakerApi.*

@Slf4j
@RestController
@RequestMapping(API_URL)
@Api(value = "loanApplication", description = "Decides whether to grant loan or not")
class DecisionController {

    private final PropagationWorker propagationWorker
    private final DecisionRepository decisionRepository

    @Autowired
    DecisionController(PropagationWorker propagationWorker, DecisionRepository decisionRepository) {
        this.decisionRepository = decisionRepository
        this.propagationWorker = propagationWorker
    }

    @RequestMapping(
            value = LOAN_APPLICATION_URL,
            method = RequestMethod.PUT,
            consumes = API_VERSION_1,
            produces = API_VERSION_1)
    @ApiOperation(value = "Async granting of loan",
            notes = "This will asynchronously verify whether the user can get a loan")
    Callable<Void> decideOnLoanGranting(@PathVariable @NotNull String loanApplicationId, @RequestBody @NotNull String loanApplicationDetails) {
        return {
            propagationWorker.makeDecisionAndPropagate(loanApplicationId, loanApplicationDetails)
        }
    }

    @RequestMapping(
            value = LOAN_APPLICATION_URL,
            method = RequestMethod.GET,
            consumes = API_VERSION_1,
            produces = API_VERSION_1)
    @ApiOperation(value = "Finds asynchronously decision of granting a loan",
            notes = "This will asynchronously finds decision taken for the loan with given identifier")
    Callable<String> getLoanDecision(@PathVariable @NotNull String loanApplicationid) {
        return {
            Decision foundDecision = decisionRepository.findById(loanApplicationid)
            return prepareJsonResponse(foundDecision)
        }
    }

    private String prepareJsonResponse(Decision foundDecision) {
        def builder = new groovy.json.JsonBuilder()
        builder {
            loanApplicationId foundDecision.loanApplicationId
            decision foundDecision.decision
        }

        return builder.toString()
    }
}
{'fraction_non_alphanumeric': 0.06513409961685823, 'fraction_numerical': 0.0023946360153256703, 'mean_word_length': 3.8569767441860465, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1463874', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1050, 'n_words': 250}