<commit_before>/*
 * Copyright 2015 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.vcfdump.cellbasewsclient;

import org.opencb.datastore.core.QueryResponse;
import org.opencb.datastore.core.QueryResult;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.net.URISyntaxException;
import java.util.Set;

/**
 * This class encapsulates CellBaseClient adding some operations to its API
 */
public class CellbaseWSClient {
    private final String species;

    private final String cellbaseRestURL;

    private final String cellbaseRestVersion;

    public CellbaseWSClient(String species, String cellbaseRestURL, String cellbaseRestVersion)
            throws URISyntaxException {
        this.species = species.split("_")[0];
        this.cellbaseRestURL = cellbaseRestURL;
        this.cellbaseRestVersion = cellbaseRestVersion;
    }

    public Set<String> getChromosomes() {
        // call cellbase chromosomes WS
        RestTemplate restTemplate = new RestTemplate();
        ParameterizedTypeReference<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>> responseType =
                new ParameterizedTypeReference<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>>() {
                };
        ResponseEntity<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>> wsOutput =
                restTemplate.exchange(
                        cellbaseRestURL + "/" + cellbaseRestVersion + "/" + species + "/genomic/chromosome/all",
                        HttpMethod.GET, null, responseType);

        // parse WS output and return all chromosome names
        QueryResponse<QueryResult<CellbaseChromosomesWSOutput>> response = wsOutput.getBody();
        QueryResult<CellbaseChromosomesWSOutput> result = response.getResponse().get(0);
        CellbaseChromosomesWSOutput results = result.getResult().get(0);
        return results.getAllChromosomeNames();
    }

    public String getVersion() {
        return cellbaseRestVersion;
    }
}<commit_msg>Added exception for getting a more informative message when an error accessing cellbase WS happens<commit_after>/*
 * Copyright 2015 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.vcfdump.cellbasewsclient;

import org.opencb.datastore.core.QueryResponse;
import org.opencb.datastore.core.QueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.net.URISyntaxException;
import java.util.Set;

/**
 * This class encapsulates CellBaseClient adding some operations to its API
 */
public class CellbaseWSClient {
    private final String species;

    private final String cellbaseRestURL;

    private final String cellbaseRestVersion;

    private static final Logger logger = LoggerFactory.getLogger(CellbaseWSClient.class);

    public CellbaseWSClient(String species, String cellbaseRestURL, String cellbaseRestVersion)
            throws URISyntaxException {
        this.species = species.split("_")[0];
        this.cellbaseRestURL = cellbaseRestURL;
        this.cellbaseRestVersion = cellbaseRestVersion;
    }

    public Set<String> getChromosomes() {
        try {
            // call cellbase chromosomes WS
            RestTemplate restTemplate = new RestTemplate();
            ParameterizedTypeReference<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>> responseType =
                    new ParameterizedTypeReference<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>>() {
                    };

            String cellbaseGetChromosomesUrl =
                    cellbaseRestURL + "/" + cellbaseRestVersion + "/" + species + "/genomic/chromosome/all";
            logger.debug("Getting chromosomes list from {} ...", cellbaseGetChromosomesUrl);
            ResponseEntity<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>> wsOutput =
                    restTemplate.exchange(cellbaseGetChromosomesUrl, HttpMethod.GET, null, responseType);

            // parse WS output and return all chromosome names
            QueryResponse<QueryResult<CellbaseChromosomesWSOutput>> response = wsOutput.getBody();
            QueryResult<CellbaseChromosomesWSOutput> result = response.getResponse().get(0);
            CellbaseChromosomesWSOutput results = result.getResult().get(0);
            return results.getAllChromosomeNames();
        } catch (Exception e) {
            logger.debug("Error retrieving list of chromosomes: {}", e.getMessage());
            throw new RuntimeException("Error retrieving list of chromosomes", e);
        }
    }

    public String getVersion() {
        return cellbaseRestVersion;
    }
}
{'fraction_non_alphanumeric': 0.07945385754235894, 'fraction_numerical': 0.003948017766079948, 'mean_word_length': 3.554307116104869, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '2282741', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1502, 'n_words': 433}