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

import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.zalando.nakadi.domain.Storage;
import org.zalando.nakadi.repository.db.StorageDbRepository;
import org.zalando.problem.Problem;

import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static org.zalando.problem.MoreStatus.UNPROCESSABLE_ENTITY;

@Service
public class StorageService {

    final ObjectMapper objectMapper;
    final StorageDbRepository storageDbRepository;

    @Autowired
    public StorageService(final ObjectMapper objectMapper, final StorageDbRepository storageDbRepository) {
        this.objectMapper = objectMapper;
        this.storageDbRepository = storageDbRepository;
    }

    public List<Storage> listStorages() {
        return storageDbRepository.listStorages();
    }

    public Result<Storage> getStorage(final String id) {
        final Optional<Storage> storage = storageDbRepository.getStorage(id);
        if (storage.isPresent()) {
            return Result.ok(storage.get());
        }
        else {
            return Result.problem(Problem.valueOf(Response.Status.NOT_FOUND, "No storage with id " + id));
        }
    }

    public Result<Storage> createStorage(final JSONObject storageDetails) {
        final String type = storageDetails.getString("type");
        final String configuration = storageDetails.get("configuration").toString();
        final Storage storage = new Storage();
        storage.setId(UUID.randomUUID().toString());
        storage.setType(Storage.Type.valueOf(type.toUpperCase()));
        try {<commit_msg>ARUHA-523 Rename 'type' to 'storage_type'<commit_after>package org.zalando.nakadi.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.zalando.nakadi.domain.Storage;
import org.zalando.nakadi.repository.db.StorageDbRepository;
import org.zalando.problem.Problem;

import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static org.zalando.problem.MoreStatus.UNPROCESSABLE_ENTITY;

@Service
public class StorageService {

    final ObjectMapper objectMapper;
    final StorageDbRepository storageDbRepository;

    @Autowired
    public StorageService(final ObjectMapper objectMapper, final StorageDbRepository storageDbRepository) {
        this.objectMapper = objectMapper;
        this.storageDbRepository = storageDbRepository;
    }

    public List<Storage> listStorages() {
        return storageDbRepository.listStorages();
    }

    public Result<Storage> getStorage(final String id) {
        final Optional<Storage> storage = storageDbRepository.getStorage(id);
        if (storage.isPresent()) {
            return Result.ok(storage.get());
        }
        else {
            return Result.problem(Problem.valueOf(Response.Status.NOT_FOUND, "No storage with id " + id));
        }
    }

    public Result<Storage> createStorage(final JSONObject storageDetails) {
        final String type = storageDetails.getString("storage_type");
        final String configuration = storageDetails.get("configuration").toString();
        final Storage storage = new Storage();
        storage.setId(UUID.randomUUID().toString());
        storage.setType(Storage.Type.valueOf(type.toUpperCase()));
        try {
{'fraction_non_alphanumeric': 0.09751585623678646, 'fraction_numerical': 0.0007928118393234672, 'mean_word_length': 4.019893899204244, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5561890', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1009, 'n_words': 204}