<commit_before>package org.innovateuk.ifs.application.forms.saver;

import org.innovateuk.ifs.application.resource.QuestionResource;
import org.innovateuk.ifs.commons.error.Error;
import org.innovateuk.ifs.commons.rest.ValidationMessages;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static org.innovateuk.ifs.util.CollectionFunctions.*;


/**
 * Abstract application saver for Question and Section
 */
abstract class AbstractApplicationSaver {

    @Autowired
    private ApplicationQuestionFileSaver fileSaver;

    @Autowired
    private ApplicationQuestionNonFileSaver nonFileSaver;

    protected static final String MARKED_AS_COMPLETE_KEY = "application.validation.MarkAsCompleteFailed";

    protected ValidationMessages sortValidationMessages(ValidationMessages validationMessages) {
        List<Error> markAsCompleteError = simpleFilter(validationMessages.getErrors(), e -> e.getErrorKey().equals(MARKED_AS_COMPLETE_KEY));
        List<Error> allExceptMarkAsCompleteError = simpleFilterNot(validationMessages.getErrors(), e -> e.getErrorKey().equals(MARKED_AS_COMPLETE_KEY));

        List<Error> sortedErrors = combineLists(markAsCompleteError, allExceptMarkAsCompleteError);

        validationMessages.setErrors(sortedErrors);
        return validationMessages;
    }

    protected String getFormInputKey(Long formInputId) {
        return "formInput[" + formInputId + "]";
    }

    protected String getFormCostInputKey(Long formInputId) {
        return "formInput[cost-" + formInputId + "]";
    }

    protected ValidationMessages saveQuestionResponses(HttpServletRequest request,
                                                     List<QuestionResource> questions, Long userId,
                                                     Long processRoleId, Long applicationId, boolean ignoreEmpty) {
        ValidationMessages errors = new ValidationMessages();

        errors.addAll(nonFileSaver.saveNonFileUploadQuestions(questions, request, userId, applicationId, ignoreEmpty));
        errors.addAll(fileSaver.saveFileUploadQuestionsIfAny(questions, request.getParameterMap(), request, applicationId, processRoleId));

        return errors;
    }
}<commit_msg>IFS-346 Formatting<commit_after>package org.innovateuk.ifs.application.forms.saver;

import org.innovateuk.ifs.application.resource.QuestionResource;
import org.innovateuk.ifs.commons.error.Error;
import org.innovateuk.ifs.commons.rest.ValidationMessages;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static org.innovateuk.ifs.util.CollectionFunctions.*;


/**
 * Abstract application saver for Question and Section
 */
abstract class AbstractApplicationSaver {

    @Autowired
    private ApplicationQuestionFileSaver fileSaver;

    @Autowired
    private ApplicationQuestionNonFileSaver nonFileSaver;

    protected static final String MARKED_AS_COMPLETE_KEY = "application.validation.MarkAsCompleteFailed";

    protected ValidationMessages sortValidationMessages(ValidationMessages validationMessages) {
        List<Error> markAsCompleteError = simpleFilter(validationMessages.getErrors(), e -> e.getErrorKey().equals(MARKED_AS_COMPLETE_KEY));
        List<Error> allExceptMarkAsCompleteError = simpleFilterNot(validationMessages.getErrors(), e -> e.getErrorKey().equals(MARKED_AS_COMPLETE_KEY));

        List<Error> sortedErrors = combineLists(markAsCompleteError, allExceptMarkAsCompleteError);

        validationMessages.setErrors(sortedErrors);
        return validationMessages;
    }

    protected String getFormInputKey(Long formInputId) {
        return "formInput[" + formInputId + "]";
    }

    protected String getFormCostInputKey(Long formInputId) {
        return "formInput[cost-" + formInputId + "]";
    }

    protected ValidationMessages saveQuestionResponses(HttpServletRequest request, List<QuestionResource> questions, Long userId,
                                                       Long processRoleId, Long applicationId, boolean ignoreEmpty) {
        ValidationMessages errors = new ValidationMessages();

        errors.addAll(nonFileSaver.saveNonFileUploadQuestions(questions, request, userId, applicationId, ignoreEmpty));
        errors.addAll(fileSaver.saveFileUploadQuestionsIfAny(questions, request.getParameterMap(), request, applicationId, processRoleId));

        return errors;
    }
}
{'fraction_non_alphanumeric': 0.08226164079822616, 'fraction_numerical': 0.0006651884700665188, 'mean_word_length': 4.307058823529411, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2776504', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1133, 'n_words': 213}