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