Search in sources :

Example 11 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class PepXServiceTest method shouldGiveAnExceptionIfTheOriginalIsNotPresentOnTheSequence.

/*
	 * Specification has changed look at:
	 * shouldReturnAnEmptryListIfTheVariantIsNotConaintedInThePeptide
	 * 
	 * @Test(expected=NextProtException.class) public void
	 * shouldGiveAnExceptionIfTheVariantIsNotConaintedInThePeptide() throws
	 * Exception { try {
	 * 
	 * //Taking example NX_Q9H6T3 String peptide = "GANAP"; boolean
	 * modeIsoleucine = true; String isoName = "NX_Q9H6T3-3";
	 * 
	 * Isoform isoform = mock(Isoform.class);
	 * when(isoform.getIsoformAccession()).thenReturn(isoName);
	 * //https://cdn.rawgit.com/calipho-sib/sequence-viewer/master/examples/
	 * simple.html (check that page to format the sequence) //GANAL is present
	 * instead of GANAP when(isoform.getSequence()).thenReturn(
	 * "MDADPYNPVLPTNRASAYFRLKKFAVAESDCNLAVALNRSYTKAYSRRGAARFALQKLEEAKKDYERVLELEPNNFEATNELRKISQALASKENSYPKEADIVIKSTEGERKQIEAQQNKQQAISEKDRGNGFFKEGKYERAIECYTRGIAADGANALLPANRAMAYLKIQKYEEAEKDCTQAILLDGSYSKAFARRGTARTFLGKLNEAKQDFETVLLLEPGNKQAVTELSKIKKELIEKGHWDDVFLDSTQRQNVVKPIDNPPHPGSTKPLKKVIIEETGNLIQTIDVPDSTTAAAPENNPINLANVIAATGTTSKKNSSQDDLFPTSDTPRAKVLKIEEVSDTSSLQPQASLKQDVCQSYSEKMPIEIEQKPAQFATTVLPPIPANSFQLESDFRQLKSSPDMLYQYLKQIEPSLYPKLFQKNLDPDVFNQIVKILHDFYIEKEKPLLIFEILQRLSELKRFDMAVMFMSETEKKIARALFNHIDKSGLKDSSVEELKKRYGG"
	 * );
	 * 
	 * List<Pair<String, Integer>> isosAndPositions = Arrays.asList(new
	 * Pair<String, Integer>(isoName, 154)); //Position of the begin of peptide
	 * List<Annotation> annots = Arrays.asList(getMockedAnnotation("L", "Z",
	 * 158, isoName, true)); List<Isoform> isoforms = Arrays.asList(isoform);
	 * 
	 * PepXServiceImpl.buildEntryWithVirtualAnnotations(peptide, modeIsoleucine,
	 * isosAndPositions, annots, isoforms); //empty or null annotations
	 * }catch(NextProtException e){ if(e.getMessage().contains(
	 * "No valid variants found for isoform ")){ throw e; //success tests }else
	 * fail(); }
	 * 
	 * }
	 */
// because we have variants in nextprot which do not have original aa is not equal to isoform aa at that variant position (inconsistency)
@Ignore
@Test(expected = NextProtException.class)
public void shouldGiveAnExceptionIfTheOriginalIsNotPresentOnTheSequence() throws Exception {
    try {
        // Taking example NX_Q9H6T3
        String peptide = "GANAP";
        boolean modeIsoleucine = true;
        String isoName = "NX_Q9H6T3-3";
        Isoform isoform = mock(Isoform.class);
        when(isoform.getIsoformAccession()).thenReturn(isoName);
        // https://cdn.rawgit.com/calipho-sib/sequence-viewer/master/examples/simple.html
        // (check that page to format the sequence)
        // GANAL is present instead of GANAP
        when(isoform.getSequence()).thenReturn("MDADPYNPVLPTNRASAYFRLKKFAVAESDCNLAVALNRSYTKAYSRRGAARFALQKLEEAKKDYERVLELEPNNFEATNELRKISQALASKENSYPKEADIVIKSTEGERKQIEAQQNKQQAISEKDRGNGFFKEGKYERAIECYTRGIAADGANALLPANRAMAYLKIQKYEEAEKDCTQAILLDGSYSKAFARRGTARTFLGKLNEAKQDFETVLLLEPGNKQAVTELSKIKKELIEKGHWDDVFLDSTQRQNVVKPIDNPPHPGSTKPLKKVIIEETGNLIQTIDVPDSTTAAAPENNPINLANVIAATGTTSKKNSSQDDLFPTSDTPRAKVLKIEEVSDTSSLQPQASLKQDVCQSYSEKMPIEIEQKPAQFATTVLPPIPANSFQLESDFRQLKSSPDMLYQYLKQIEPSLYPKLFQKNLDPDVFNQIVKILHDFYIEKEKPLLIFEILQRLSELKRFDMAVMFMSETEKKIARALFNHIDKSGLKDSSVEELKKRYGG");
        PepXIsoformMatch pepXIsoformMatch = new PepXIsoformMatch(isoName, 154);
        // Original is not contained in the sequence, should be a L L->P
        // (GANAL)
        List<Annotation> annots = Arrays.asList(getMockedAnnotation("O", "P", 158, isoName, true));
        List<Isoform> isoforms = Arrays.asList(isoform);
        // empty
        PepXServiceImpl.buildEntryWithVirtualAnnotations(peptide, modeIsoleucine, Arrays.asList(pepXIsoformMatch), annots, isoforms);
    // or
    // null
    // annotations
    } catch (NextProtException e) {
        if (e.getMessage().contains("The amino acid")) {
            // success tests
            throw e;
        } else
            fail();
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) PepXIsoformMatch(org.nextprot.api.web.domain.PepXResponse.PepXIsoformMatch) Isoform(org.nextprot.api.core.domain.Isoform) Annotation(org.nextprot.api.core.domain.annotation.Annotation) Ignore(org.junit.Ignore) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 12 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class GitHubServiceImpl method getNews.

@Override
@Cacheable(value = "github-news")
public List<NextProtNews> getNews() {
    List<NextProtNews> news = new ArrayList<>();
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        GHTree tree = repo.getTreeRecursive(githubDocBranch, 1);
        newsFileNames.clear();
        for (GHTreeEntry te : tree.getTree()) {
            if (te.getPath().startsWith("news")) {
                // Add only file on news
                if (te.getType().equalsIgnoreCase("blob")) {
                    // file
                    String fileName = te.getPath().replaceAll("news/", "");
                    NextProtNews n = parseGitHubNewsFilePath(fileName);
                    if (n != null) {
                        news.add(n);
                        String fileEncoded = URLEncoder.encode(fileName.replace(".md", ""), "UTF-8").replace("+", "%20");
                        newsFileNames.put(n.getUrl(), fileEncoded);
                    }
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("News not available, sorry for the inconvenience");
    }
    Collections.sort(news);
    return news;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) ArrayList(java.util.ArrayList) GHTree(org.kohsuke.github.GHTree) IOException(java.io.IOException) NextProtNews(org.nextprot.api.web.domain.NextProtNews) GHTreeEntry(org.kohsuke.github.GHTree.GHTreeEntry) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 13 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class SolrIndexer method addRemaing.

public void addRemaing() {
    try {
        if (docs.size() > 0) // There are some prepared docs not yet sent to solr server
        {
            solrServer.add(docs);
            docs.clear();
        }
    } catch (SolrServerException | IOException e) {
        throw new NextProtException(e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 14 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class SolrIndexer method add.

public void add(T t) {
    try {
        SolrInputDocument doc = this.convertToSolrDocument(t);
        if (doc == null)
            return;
        docs.add(doc);
        if (docs.size() % BATCH_SIZE == 0) {
            // System.err.println("sent " +docs.size() + " docs to solr so far");
            this.solrServer.add(docs);
            docs.clear();
        }
    } catch (SolrServerException | IOException e) {
        throw new NextProtException(e);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) NextProtException(org.nextprot.api.commons.exception.NextProtException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 15 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class SparqlProxyEndpointImpl method sparqlInternal.

private ResponseEntity<String> sparqlInternal(String queryString) {
    ResponseEntity<String> responseEntity;
    String url = sparqlEndpoint.getUrl() + ((queryString != null) ? ("?" + queryString) : "");
    try {
        RestTemplate template = new RestTemplate();
        responseEntity = template.getForEntity(new URI(url), String.class);
        return responseEntity;
    } catch (HttpServerErrorException | HttpClientErrorException e) {
        throw new NextProtException(e.getResponseBodyAsString(), e);
    } catch (RestClientException | URISyntaxException e) {
        throw new NextProtException(e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException)

Aggregations

NextProtException (org.nextprot.api.commons.exception.NextProtException)68 IOException (java.io.IOException)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ApiMethod (org.jsondoc.core.annotation.ApiMethod)8 OutputStream (java.io.OutputStream)7 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)7 Cacheable (org.springframework.cache.annotation.Cacheable)6 Isoform (org.nextprot.api.core.domain.Isoform)5 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 NextprotMediaType (org.nextprot.api.core.service.export.format.NextprotMediaType)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 java.util (java.util)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 CvTerm (org.nextprot.api.core.domain.CvTerm)3 AnnotationVariant (org.nextprot.api.core.domain.annotation.AnnotationVariant)3 Query (org.nextprot.api.solr.Query)3 SearchResult (org.nextprot.api.solr.SearchResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2