<commit_before>package uk.gov.ons.ctp.response.caseframe.service.impl;

import java.sql.Timestamp;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import lombok.extern.slf4j.Slf4j;
import uk.gov.ons.ctp.response.caseframe.domain.model.Questionnaire;
import uk.gov.ons.ctp.response.caseframe.domain.repository.CaseRepository;
import uk.gov.ons.ctp.response.caseframe.domain.repository.QuestionnaireRepository;
import uk.gov.ons.ctp.response.caseframe.service.QuestionnaireService;

/**
 * A QuestionnaireService implementation which encapsulates all business logic
 * operating on the Questionnaire entity model.
 */
@Named
@Slf4j
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class QuestionnaireServiceImpl implements QuestionnaireService {

  public static final String OPERATION_FAILED = "Response operation failed for questionnaireid";
  public static final String CLOSED = "CLOSED";

  /**
   * Spring Data Repository for Case entities.
   */
  @Inject
  private CaseRepository caseRepo;

  /**
   * Spring Data Repository for Questionnaire Entities.
   */
  @Inject
  private QuestionnaireRepository questionnaireRepo;

  /**
   * Find Questionnaire entity by Internet Access Code.
   * 
   * @param IAC
   * @return Questionnaire object or null
   */
  @Override
  public Questionnaire findQuestionnaireByIac(String iac) {
    log.debug("Entering findQuestionnaireByIac with {}", iac);
    return questionnaireRepo.findByIac(iac);
  }

  /**
   * Find Questionnaire entities associated with a Case.
   * 
   * @param Case Id
   * @return List of Questionnaire entities or empty List
   */
  @Override
  public List<Questionnaire> findQuestionnairesByCaseId(Integer caseId) {
    log.debug("Entering findQuestionnairesByCaseId with {}", caseId);
    return questionnaireRepo.findByCaseId(caseId);
  }

  /**
   * Update a Questionnaire and Case object to record a response has been
   * received in the Survey Data Exchange.
   * 
   * @param Questionnaire Id
   * @return Updated Questionnaire object or null
   */
  @Transactional(propagation = Propagation.REQUIRED, readOnly = false, timeout=30)
  public Questionnaire recordResponse(Integer questionnaireid) {
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    Questionnaire questionnaire = questionnaireRepo.findOne(questionnaireid);<commit_msg>CheckStyle changes<commit_after>package uk.gov.ons.ctp.response.caseframe.service.impl;

import java.sql.Timestamp;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import lombok.extern.slf4j.Slf4j;
import uk.gov.ons.ctp.response.caseframe.domain.model.Questionnaire;
import uk.gov.ons.ctp.response.caseframe.domain.repository.CaseRepository;
import uk.gov.ons.ctp.response.caseframe.domain.repository.QuestionnaireRepository;
import uk.gov.ons.ctp.response.caseframe.service.QuestionnaireService;

/**
 * A QuestionnaireService implementation which encapsulates all business logic
 * operating on the Questionnaire entity model.
 */
@Named
@Slf4j
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class QuestionnaireServiceImpl implements QuestionnaireService {

  public static final String OPERATION_FAILED = "Response operation failed for questionnaireid";
  public static final String CLOSED = "CLOSED";
  static final int TRANSACTION_TIMEOUT = 30;

  /**
   * Spring Data Repository for Case entities.
   */
  @Inject
  private CaseRepository caseRepo;

  /**
   * Spring Data Repository for Questionnaire Entities.
   */
  @Inject
  private QuestionnaireRepository questionnaireRepo;

  /**
   * Find Questionnaire entity by Internet Access Code.
   * 
   * @param IAC
   * @return Questionnaire object or null
   */
  @Override
  public Questionnaire findQuestionnaireByIac(String iac) {
    log.debug("Entering findQuestionnaireByIac with {}", iac);
    return questionnaireRepo.findByIac(iac);
  }

  /**
   * Find Questionnaire entities associated with a Case.
   * 
   * @param Case Id
   * @return List of Questionnaire entities or empty List
   */
  @Override
  public List<Questionnaire> findQuestionnairesByCaseId(Integer caseId) {
    log.debug("Entering findQuestionnairesByCaseId with {}", caseId);
    return questionnaireRepo.findByCaseId(caseId);
  }

  /**
   * Update a Questionnaire and Case object to record a response has been
   * received in the Survey Data Exchange.
   * 
   * @param Questionnaire Id
   * @return Updated Questionnaire object or null
   */
  @Transactional(propagation = Propagation.REQUIRED, readOnly = false, timeout=TRANSACTION_TIMEOUT)
  public Questionnaire recordResponse(Integer questionnaireid) {
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    Questionnaire questionnaire = questionnaireRepo.findOne(questionnaireid);
{'fraction_non_alphanumeric': 0.08462291870714986, 'fraction_numerical': 0.0019588638589618022, 'mean_word_length': 4.635761589403973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5941529', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1393, 'n_words': 369}