<commit_before>/*
 * European Variation Archive (EVA) - Open-access database of all types of genetic
 * variation data from all species
 *
 * Copyright 2014-2016 EMBL - European Bioinformatics Institute
 *
 * 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 uk.ac.ebi.eva.server.ws;

import com.google.common.base.Splitter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import uk.ac.ebi.eva.lib.utils.DBAdaptorConnector;
import uk.ac.ebi.eva.lib.utils.QueryOptions;
import uk.ac.ebi.eva.lib.utils.QueryResponse;
import uk.ac.ebi.eva.lib.utils.QueryResult;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class EvaWSServer {

    protected final String version = "v1";

    @Autowired
    protected HttpServletRequest httpServletRequest;

    protected QueryOptions queryOptions;
    protected long startTime;
    protected long endTime;

    protected static Logger logger = LoggerFactory.getLogger(EvaWSServer.class);

    @Autowired
    protected DBAdaptorConnector dbAdaptorConnector;

//    @Bean
//    public Jackson2ObjectMapperBuilder jacksonBuilder() {
//        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
//                       .mixIn(VariantSourceEntry.class, VariantSourceEntryJsonMixin.class)
//                       .mixIn(Genotype.class, GenotypeJsonMixin.class)
//                       .mixIn(VariantStats.class, VariantStatsJsonMixin.class)
//                       .mixIn(VariantSource.class, VariantSourceJsonMixin.class)
//                       .serializationInclusion(Include.NON_NULL);
//
//        SimpleModule module = new SimpleModule();
//        module.addSerializer(VariantStats.class, new VariantStatsJsonSerializer());
//        builder.modules(module);
//
//        return builder;
//    }
    
    public EvaWSServer() { }

    protected void initializeQuery() {
        startTime = System.currentTimeMillis();
        initializeQueryOptions();
    }

    private void initializeQueryOptions() {
        this.queryOptions = new QueryOptions();
        Map<String, String[]> multivaluedMap = httpServletRequest.getParameterMap();

        boolean metadata = (multivaluedMap.get("metadata") != null) ? multivaluedMap.get("metadata")[0].equals("true") : true ;
        int limit = (multivaluedMap.get("limit") != null) ? Integer.parseInt(multivaluedMap.get("limit")[0]) : -1;
        int skip = (multivaluedMap.get("skip") != null) ? Integer.parseInt(multivaluedMap.get("skip")[0]) : -1;
        boolean count = (multivaluedMap.get("count") != null) ? multivaluedMap.get("count")[0].equals("true") : false ;

        String[] exclude = multivaluedMap.get("exclude");
        String[] include = multivaluedMap.get("include");

        queryOptions.put("metadata", metadata);
        queryOptions.put("exclude", (exclude != null && exclude.length > 0) ? Splitter.on(",").splitToList(exclude[0]) : null);
        queryOptions.put("include", (include != null && include.length > 0) ? Splitter.on(",").splitToList(include[0]) : null);
        queryOptions.put("limit", (limit > 0) ? limit : -1);
        queryOptions.put("skip", (skip > 0) ? skip : -1);<commit_msg>Removed commented out code<commit_after>/*
 * European Variation Archive (EVA) - Open-access database of all types of genetic
 * variation data from all species
 *
 * Copyright 2014-2016 EMBL - European Bioinformatics Institute
 *
 * 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 uk.ac.ebi.eva.server.ws;

import com.google.common.base.Splitter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import uk.ac.ebi.eva.lib.utils.DBAdaptorConnector;
import uk.ac.ebi.eva.lib.utils.QueryOptions;
import uk.ac.ebi.eva.lib.utils.QueryResponse;
import uk.ac.ebi.eva.lib.utils.QueryResult;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class EvaWSServer {

    protected final String version = "v1";

    @Autowired
    protected HttpServletRequest httpServletRequest;

    protected QueryOptions queryOptions;
    protected long startTime;
    protected long endTime;

    protected static Logger logger = LoggerFactory.getLogger(EvaWSServer.class);

    @Autowired
    protected DBAdaptorConnector dbAdaptorConnector;
    
    public EvaWSServer() { }

    protected void initializeQuery() {
        startTime = System.currentTimeMillis();
        initializeQueryOptions();
    }

    private void initializeQueryOptions() {
        this.queryOptions = new QueryOptions();
        Map<String, String[]> multivaluedMap = httpServletRequest.getParameterMap();

        boolean metadata = (multivaluedMap.get("metadata") != null) ? multivaluedMap.get("metadata")[0].equals("true") : true ;
        int limit = (multivaluedMap.get("limit") != null) ? Integer.parseInt(multivaluedMap.get("limit")[0]) : -1;
        int skip = (multivaluedMap.get("skip") != null) ? Integer.parseInt(multivaluedMap.get("skip")[0]) : -1;
        boolean count = (multivaluedMap.get("count") != null) ? multivaluedMap.get("count")[0].equals("true") : false ;

        String[] exclude = multivaluedMap.get("exclude");
        String[] include = multivaluedMap.get("include");

        queryOptions.put("metadata", metadata);
        queryOptions.put("exclude", (exclude != null && exclude.length > 0) ? Splitter.on(",").splitToList(exclude[0]) : null);
        queryOptions.put("include", (include != null && include.length > 0) ? Splitter.on(",").splitToList(include[0]) : null);
        queryOptions.put("limit", (limit > 0) ? limit : -1);
        queryOptions.put("skip", (skip > 0) ? skip : -1);
{'fraction_non_alphanumeric': 0.12167852475678816, 'fraction_numerical': 0.008857267315231596, 'mean_word_length': 3.6603518267929633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4555191', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1945, 'n_words': 495}