<commit_before>/**
 * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gravitee.repository.mongodb.management;

import io.gravitee.repository.exceptions.TechnicalException;
import io.gravitee.repository.management.api.ParameterRepository;
import io.gravitee.repository.management.model.Parameter;
import io.gravitee.repository.mongodb.management.internal.api.ParameterMongoRepository;
import io.gravitee.repository.mongodb.management.internal.model.ParameterMongo;
import io.gravitee.repository.mongodb.management.mapper.GraviteeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author <NAME> (azize.elamrani at graviteesource.com)
 * @author GraviteeSource Team
 */
@Component
public class MongoParameterRepository implements ParameterRepository {

    private static final Logger LOGGER = LoggerFactory.getLogger(MongoParameterRepository.class);

    @Autowired
    private ParameterMongoRepository internalParameterRepo;

    @Autowired
    private GraviteeMapper mapper;

    @Override
    public Optional<Parameter> findById(String parameterKey) throws TechnicalException {
        LOGGER.debug("Find parameter by key [{}]", parameterKey);
        final ParameterMongo parameter = internalParameterRepo.findOne(parameterKey);
        LOGGER.debug("Find parameter by key [{}] - Done", parameterKey);
        return Optional.ofNullable(mapper.map(parameter, Parameter.class));
    }

    @Override
    public Parameter create(Parameter parameter) throws TechnicalException {
        LOGGER.debug("Create parameter [{}]", parameter);<commit_msg>feat(settings): move constants.json config to database<commit_after>/**
 * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gravitee.repository.mongodb.management;

import io.gravitee.repository.exceptions.TechnicalException;
import io.gravitee.repository.management.api.ParameterRepository;
import io.gravitee.repository.management.model.Parameter;
import io.gravitee.repository.mongodb.management.internal.api.ParameterMongoRepository;
import io.gravitee.repository.mongodb.management.internal.model.ParameterMongo;
import io.gravitee.repository.mongodb.management.mapper.GraviteeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * @author <NAME> (azize.elamrani at graviteesource.com)
 * @author GraviteeSource Team
 */
@Component
public class MongoParameterRepository implements ParameterRepository {

    private static final Logger LOGGER = LoggerFactory.getLogger(MongoParameterRepository.class);

    @Autowired
    private ParameterMongoRepository internalParameterRepo;

    @Autowired
    private GraviteeMapper mapper;

    @Override
    public Optional<Parameter> findById(String parameterKey) throws TechnicalException {
        LOGGER.debug("Find parameter by key [{}]", parameterKey);
        final ParameterMongo parameter = internalParameterRepo.findOne(parameterKey);
        LOGGER.debug("Find parameter by key [{}] - Done", parameterKey);
        return Optional.ofNullable(mapper.map(parameter, Parameter.class));
    }

    @Override
    public List<Parameter> findAll(List<String> keys) throws TechnicalException  {
        LOGGER.debug("Find parameters by keys [{}]", keys);
        Iterable<ParameterMongo> all = internalParameterRepo.findAll(keys);
        LOGGER.debug("Find parameters by keys [{}] - Done", keys);
        return StreamSupport.stream(all.spliterator(), false)
                .map(parameter -> mapper.map(parameter, Parameter.class))
                .collect(Collectors.toList());
    }

    @Override
    public Parameter create(Parameter parameter) throws TechnicalException {
        LOGGER.debug("Create parameter [{}]", parameter);
{'fraction_non_alphanumeric': 0.09266704958835918, 'fraction_numerical': 0.003829216925138809, 'mean_word_length': 4.569296375266524, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1922996', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1367, 'n_words': 384}