<commit_before>package org.zalando.nakadi.controller;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.NativeWebRequest;
import org.zalando.nakadi.config.SecuritySettings;
import org.zalando.nakadi.domain.Storage;
import org.zalando.nakadi.security.Client;
import org.zalando.nakadi.service.Result;
import org.zalando.nakadi.service.StorageService;
import org.zalando.problem.spring.web.advice.Responses;

import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.ResponseEntity.status;

@RestController
public class StoragesController {

    private final SecuritySettings securitySettings;
    private final StorageService storageService;

    @Autowired
    public StoragesController(final SecuritySettings securitySettings, final StorageService storageService) {
        this.securitySettings = securitySettings;
        this.storageService = storageService;
    }

    @RequestMapping(value = "/storages", method = RequestMethod.GET)
    public ResponseEntity<?> listStorages(final Client client) {
        if (isNotAdmin(client)) {
            return ResponseEntity.status(FORBIDDEN).build();
        }
        return status(HttpStatus.OK).body(storageService.listStorages());
    }

    @RequestMapping(value = "/storages", method = RequestMethod.POST)
    public ResponseEntity<?> createStorage(@RequestBody final String body,
                                           final NativeWebRequest request,
                                           final Client client) {
        if (isNotAdmin(client)) {
            return ResponseEntity.status(FORBIDDEN).build();
        }
        final Result<Storage> result = storageService.createStorage(new JSONObject(body));
        if (result.isSuccessful()) {
            return status(HttpStatus.OK).body(result.getValue());
        }
        return Responses.create(result.getProblem(), request);
    }

    @RequestMapping(value = "/storages/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> getStorage(@PathVariable("id") final String id, final NativeWebRequest request,
                                        final Client client) {
        if (isNotAdmin(client)) {
            return ResponseEntity.status(FORBIDDEN).build();<commit_msg>ARUHA-523 Refactorying<commit_after>package org.zalando.nakadi.controller;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.NativeWebRequest;
import org.zalando.nakadi.config.SecuritySettings;
import org.zalando.nakadi.domain.Storage;
import org.zalando.nakadi.security.Client;
import org.zalando.nakadi.service.Result;
import org.zalando.nakadi.service.StorageService;
import org.zalando.problem.spring.web.advice.Responses;

import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.ResponseEntity.status;

@RestController
public class StoragesController {

    private final SecuritySettings securitySettings;
    private final StorageService storageService;

    @Autowired
    public StoragesController(final SecuritySettings securitySettings, final StorageService storageService) {
        this.securitySettings = securitySettings;
        this.storageService = storageService;
    }

    @RequestMapping(value = "/storages", method = RequestMethod.GET)
    public ResponseEntity<?> listStorages(final Client client) {
        if (isNotAdmin(client)) {
            return status(FORBIDDEN).build();
        }
        return status(HttpStatus.OK).body(storageService.listStorages());
    }

    @RequestMapping(value = "/storages", method = RequestMethod.POST)
    public ResponseEntity<?> createStorage(@RequestBody final String body,
                                           final NativeWebRequest request,
                                           final Client client) {
        if (isNotAdmin(client)) {
            return ResponseEntity.status(FORBIDDEN).build();
        }
        final Result<Storage> result = storageService.createStorage(new JSONObject(body));
        if (result.isSuccessful()) {
            return status(HttpStatus.OK).body(result.getValue());
        }
        return Responses.create(result.getProblem(), request);
    }

    @RequestMapping(value = "/storages/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> getStorage(@PathVariable("id") final String id, final NativeWebRequest request,
                                        final Client client) {
        if (isNotAdmin(client)) {
            return ResponseEntity.status(FORBIDDEN).build();
{'fraction_non_alphanumeric': 0.09609061015710632, 'fraction_numerical': 0.0005480453050785532, 'mean_word_length': 3.639830508474576, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '679189', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1374, 'n_words': 262}