Search in sources :

Example 26 with NextProtException

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

the class UserApplicationDaoImpl method deleteUserApplication.

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

Example 27 with NextProtException

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

the class UserProteinListDaoImpl method updateUserProteinListMetadata.

@Override
public void updateUserProteinListMetadata(UserProteinList src) {
    final String UPDATE_SQL = sqlDictionary.getSQLQuery("update-user-protein-list");
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    // key to identify application to be updated
    namedParameters.addValue("list_id", src.getId());
    // values to update
    namedParameters.addValue("description", src.getDescription());
    namedParameters.addValue("list_name", src.getName());
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
    int affectedRows = jdbcTemplate.update(UPDATE_SQL, namedParameters);
    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) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 28 with NextProtException

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

the class EntryController method getListOfIsoformAcMd5Sequence.

@ApiMethod(path = "/isoforms", verb = ApiVerb.GET, description = "Retrieves all isoforms", produces = { MediaType.APPLICATION_JSON_VALUE, NextprotMediaType.TSV_MEDIATYPE_VALUE })
@RequestMapping(value = "/isoforms", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE, NextprotMediaType.TSV_MEDIATYPE_VALUE })
public void getListOfIsoformAcMd5Sequence(HttpServletRequest request, HttpServletResponse response) {
    NextprotMediaType mediaType = NextprotMediaType.valueOf(request);
    try {
        List<SlimIsoform> isoforms = isoformService.findListOfIsoformAcMd5Sequence();
        if (mediaType == NextprotMediaType.JSON) {
            JSONObjectsWriter<SlimIsoform> writer = new JSONObjectsWriter<>(response.getOutputStream());
            writer.write(isoforms);
        } else if (mediaType == NextprotMediaType.TSV) {
            SlimIsoformTSVWriter writer = new SlimIsoformTSVWriter(response.getOutputStream());
            writer.write(isoforms);
            writer.close();
        }
    } catch (IOException e) {
        throw new NextProtException("cannot get isoforms in " + mediaType.getExtension() + " format", e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) SlimIsoformTSVWriter(org.nextprot.api.core.service.export.io.SlimIsoformTSVWriter) NextprotMediaType(org.nextprot.api.core.service.export.format.NextprotMediaType) IOException(java.io.IOException) JSONObjectsWriter(org.nextprot.api.web.service.impl.writer.JSONObjectsWriter) ApiMethod(org.jsondoc.core.annotation.ApiMethod)

Example 29 with NextProtException

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

the class EntryPublicationController method getEntryPublicationsByPubId.

@ApiMethod(path = "/entry-publications/pubid/{pubid}", verb = ApiVerb.GET, description = "Exports identified publication associated with neXtProt entries", produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/entry-publications/pubid/{pubid}", method = { RequestMethod.GET })
@ResponseBody
public PublicationView getEntryPublicationsByPubId(@ApiPathParam(name = "pubid", description = "A publication id", allowedvalues = { "630194" }) @PathVariable("pubid") long publicationId, @ApiQueryParam(name = "limit", description = "The maximum number of returned results", allowedvalues = { "500" }) @RequestParam(value = "limit", required = false) String limit) {
    List<EntryPublication> eps = publicationService.getEntryPublications(publicationId);
    QueryRequest qr = new QueryRequest();
    qr.setQuality("gold");
    qr.setRows((limit != null) ? limit : "500");
    PublicationView view = new PublicationView();
    view.setPublication(publicationService.findPublicationById(publicationId));
    // return the n first results
    view.addEntryPublicationList(eps.stream().limit(Integer.parseInt(qr.getRows())).collect(Collectors.toList()));
    qr.setEntryAccessionSet(view.getEntryPublicationMap().keySet());
    Query q = queryBuilderService.buildQueryForSearch(qr, "entry");
    try {
        SearchResult searchResult = solrService.executeQuery(q);
        view.setRelatedEntryCount(eps.size());
        searchResult.getResults().forEach(result -> view.putEntrySolrResult(result));
    } catch (SearchQueryException e) {
        throw new NextProtException(e.getMessage());
    }
    return view;
}
Also used : SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) 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) ApiMethod(org.jsondoc.core.annotation.ApiMethod)

Example 30 with NextProtException

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

the class ExportController method streamEntrySubPart.

@RequestMapping(value = "/export/entry/{entry}/{blockOrSubpart}", method = { RequestMethod.GET })
public void streamEntrySubPart(HttpServletRequest request, HttpServletResponse response, @PathVariable("entry") String entryName, @PathVariable("blockOrSubpart") String blockOrSubpart) {
    Entry entry = entryBuilderService.build(EntryConfig.newConfig(entryName).with(blockOrSubpart).withBed(true));
    try {
        EntryPartWriter writer = EntryPartWriter.valueOf(NextprotMediaType.valueOf(request), EntryPartExporterImpl.fromSubPart(blockOrSubpart), response.getOutputStream());
        writer.write(entry);
    } catch (IOException e) {
        throw new NextProtException("cannot export " + entryName + " " + blockOrSubpart + " in " + NextprotMediaType.valueOf(request) + " format", e);
    }
}
Also used : Entry(org.nextprot.api.core.domain.Entry) NextProtException(org.nextprot.api.commons.exception.NextProtException) EntryPartWriter(org.nextprot.api.core.export.EntryPartWriter) IOException(java.io.IOException)

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