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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations