<commit_before>package com.truward.brikar.test.exposure.controller;

import com.truward.brikar.error.HttpRestErrorException;
import com.truward.brikar.error.RestErrors;
import com.truward.brikar.error.StandardRestErrorCode;
import com.truward.brikar.error.model.ErrorV1;
import com.truward.brikar.server.controller.DefaultRestExceptionHandler;
import com.truward.brikar.test.exposure.ServiceErrors;
import com.truward.brikar.test.exposure.model.ExposureModel;
import com.truward.brikar.test.exposure.service.ExposureRestService;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.Resource;

/**
 * @author <NAME>
 */
@Controller
@RequestMapping("/api/test")
@ParametersAreNonnullByDefault
public final class ExposureRestController implements ExposureRestService, DefaultRestExceptionHandler {
  public static final String ACCESS_DENIED = "No access for non-admin";

  @Resource
  private ServiceErrors errors;

  @ExceptionHandler(AccessDeniedException.class)
  @ResponseStatus(HttpStatus.UNAUTHORIZED)
  @ResponseBody
  public ErrorV1.ErrorResponse accessDeniedException(AccessDeniedException e) {
    return ErrorV1.ErrorResponse.newBuilder()
        .setError(getRestErrors().errorBuilder(StandardRestErrorCode.FORBIDDEN).setMessage(ACCESS_DENIED).build())
        .build();
  }

  @Override
  public ExposureModel.HelloResponse greet(@RequestBody ExposureModel.HelloRequest request) {
    if (request.getPerson().isEmpty()) {
      return ExposureModel.HelloResponse.newBuilder().build(); // empty greeting
    }

    final String person = request.getPerson();

    if (person.equals("admin")) {
      throw new AccessDeniedException(ACCESS_DENIED);
    }

    if (person.equals("R2D2")) {
      throw new IllegalArgumentException("name");
    }

    if (person.equals("<NAME>")) {
      throw new UnsupportedOperationException("name");<commit_msg>Use error handler<commit_after>package com.truward.brikar.test.exposure.controller;

import com.truward.brikar.error.RestErrors;
import com.truward.brikar.error.StandardRestErrorCode;
import com.truward.brikar.error.model.ErrorV1;
import com.truward.brikar.server.controller.DefaultRestExceptionHandler;
import com.truward.brikar.test.exposure.ServiceErrors;
import com.truward.brikar.test.exposure.model.ExposureModel;
import com.truward.brikar.test.exposure.service.ExposureRestService;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.ParametersAreNonnullByDefault;

/**
 * @author <NAME>
 */
@Controller
@RequestMapping("/api/test")
@ParametersAreNonnullByDefault
public final class ExposureRestController implements ExposureRestService, DefaultRestExceptionHandler {
  public static final String ACCESS_DENIED = "No access for non-admin";

  private ServiceErrors errors;

  public ExposureRestController(ServiceErrors errors) {
    this.errors = errors;
  }

  @ExceptionHandler(AccessDeniedException.class)
  @ResponseStatus(HttpStatus.UNAUTHORIZED)
  @ResponseBody
  public ErrorV1.ErrorResponse accessDeniedException(AccessDeniedException e) {
    return ErrorV1.ErrorResponse.newBuilder()
        .setError(errors.errorBuilder(StandardRestErrorCode.FORBIDDEN)
        .setMessage(ACCESS_DENIED))
        .build();
  }

  @Override
  public ExposureModel.HelloResponse greet(@RequestBody ExposureModel.HelloRequest request) {
    if (request.getPerson().isEmpty()) {
      return ExposureModel.HelloResponse.newBuilder().build(); // empty greeting
    }

    final String person = request.getPerson();

    if (person.equals("admin")) {
      throw new AccessDeniedException(ACCESS_DENIED);
    }

    if (person.equals("R2D2")) {
      throw new IllegalArgumentException("name");
    }

    if (person.equals("<NAME>")) {
      throw new UnsupportedOperationException("name");
{'fraction_non_alphanumeric': 0.10353110737448955, 'fraction_numerical': 0.0024021138601969735, 'mean_word_length': 5.485981308411215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5457769', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1175, 'n_words': 196}