Search in sources :

Example 31 with NextProtException

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

the class ExportController method exportList.

@RequestMapping("/export/lists/{listId}")
public void exportList(HttpServletResponse response, HttpServletRequest request, @ApiQueryParam(name = "listname", description = "The list id") @PathVariable("listId") String listId) {
    UserProteinList pl = this.proteinListService.getUserProteinListByPublicId(listId);
    String fileName = pl.getName() + ".txt";
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    // http://alpha-api.nextprot.org/export/lists/3C5KYA1M
    try {
        if (pl.getDescription() != null) {
            response.getWriter().write("#" + pl.getDescription() + StringUtils.CR_LF);
        }
        if (pl.getAccessionNumbers() != null) {
            for (String s : pl.getAccessionNumbers()) {
                response.getWriter().write(s);
                response.getWriter().write(StringUtils.CR_LF);
            }
        }
    } catch (Exception e) {
        throw new NextProtException(e.getMessage(), e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) UserProteinList(org.nextprot.api.user.domain.UserProteinList) NextProtException(org.nextprot.api.commons.exception.NextProtException) IOException(java.io.IOException)

Example 32 with NextProtException

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

the class UserDaoImpl method deleteUser.

@Override
public void deleteUser(User user) {
    final String DELETE_SQL = sqlDictionary.getSQLQuery("delete-user");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("user_id", user.getId());
    int affectedRows = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).update(DELETE_SQL, params);
    if (affectedRows != 1) {
        String msg = "oops something wrong occurred" + affectedRows + " rows were affected instead of only 1.";
        Logger.error(msg);
        throw new NextProtException(msg);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 33 with NextProtException

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

the class SeoController method getSeoTags.

@RequestMapping(value = { "/seo/tags/**" }, method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public SeoTags getSeoTags(HttpServletRequest request) {
    try {
        String fullUrl = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString();
        String url = fullUrl.substring("/seo/tags".length());
        SeoTags tags = seoTagsService.getGitHubSeoTags(url);
        if (tags != null)
            return tags;
        String firstElement = RelativeUrlUtils.getPathElements(url)[0];
        if ("entry".equals(firstElement)) {
            return seoTagsService.getEntrySeoTags(url);
        }
        if ("term".equals(firstElement)) {
            return seoTagsService.getTermSeoTags(url);
        }
        if ("publication".equals(firstElement)) {
            return seoTagsService.getPublicationSeoTags(url);
        }
        if ("news".equals(firstElement)) {
            return seoTagsService.getNewsSeoTags(url);
        }
        // default behavior
        Logger.warn("No explicit SEO tags were found for this page: " + url);
        return seoTagsService.getDefaultSeoTags(url);
    } catch (Exception e) {
        throw new NextProtException("Error while search SEO tags for this page: " + url, e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) SeoTags(org.nextprot.api.web.seo.domain.SeoTags) NextProtException(org.nextprot.api.commons.exception.NextProtException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 34 with NextProtException

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

the class ExpasySearchController method expasySearch.

@RequestMapping(value = "/expasy-search", method = { RequestMethod.POST, RequestMethod.GET })
public String expasySearch(@RequestParam String query, @RequestParam(required = false) String type, Model model, HttpServletResponse response) {
    try {
        QueryRequest qr = new QueryRequest();
        qr.setQuality("gold-and-silver");
        qr.setQuery(query);
        Query bq = queryBuilderService.buildQueryForSearch(qr, "entry");
        SearchResult result = queryService.executeQuery(bq);
        model.addAttribute("count", result.getFound());
        model.addAttribute("url", "https://www.nextprot.org/proteins/search?quality=gold-and-silver&query=" + query);
        model.addAttribute("description", "Entries matching the query " + query + " in neXtProt");
    } catch (NextProtException e) {
        LOGGER.error(e.getLocalizedMessage());
        e.printStackTrace();
        response.setStatus(500);
        model.addAttribute("count", -1);
        model.addAttribute("url", "error message " + e.getMessage());
    } catch (Exception e) {
        LOGGER.error(e.getLocalizedMessage());
        e.printStackTrace();
        response.setStatus(500);
        model.addAttribute("count", -1);
    }
    return "expasy-search";
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) NextProtException(org.nextprot.api.commons.exception.NextProtException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with NextProtException

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

the class StatementETLServiceImpl method loadStatements.

void loadStatements(Set<Statement> rawStatements, Set<Statement> mappedStatements, boolean load, ReportBuilder report) {
    try {
        if (load) {
            report.addInfo("Loading raw statements: " + rawStatements.size());
            long start = System.currentTimeMillis();
            statementLoadService.loadRawStatementsForSource(new HashSet<>(rawStatements), NextProtSource.BioEditor);
            report.addInfo("Finish load in " + (System.currentTimeMillis() - start) / 1000 + " seconds");
            report.addInfo("Loading entry statements: " + mappedStatements.size());
            start = System.currentTimeMillis();
            statementLoadService.loadStatementsMappedToEntrySpecAnnotationsForSource(mappedStatements, NextProtSource.BioEditor);
            report.addInfo("Finish load in " + (System.currentTimeMillis() - start) / 1000 + " seconds");
        } else {
            report.addInfo("skipping load of " + rawStatements.size() + " raw statements and " + mappedStatements.size() + " mapped statements");
        }
    } catch (SQLException e) {
        throw new NextProtException("Failed to load " + e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) SQLException(java.sql.SQLException)

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