use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class SparqlQueryRunnerController method runSparqlQueries.
private void runSparqlQueries(HttpServletResponse response, HttpServletRequest request, String tags, AccessMode accessMode) {
String fileName = "run-sparql-queries.tsv";
response.setContentType("text/tab-separated-values");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
long t0 = System.currentTimeMillis();
List<String> expectedTagList = Arrays.asList(tags.split(","));
List<UserQuery> queryList = UserQueryUtils.filterByTagList(userQueryService.getNxqQueries(), expectedTagList);
try {
// write header
PrintWriter w = response.getWriter();
w.write("SPARQL end point" + TAB + sparqlEndpoint.getUrl() + CRLF);
w.write("Access mode\t" + accessMode.toString() + CRLF);
w.write("Running queries with tags\t" + tags + CRLF);
w.write("Query count\t" + queryList.size() + CRLF);
w.write("Starting at\t" + new Date() + CRLF);
w.write(CRLF);
w.write("Results" + CRLF);
w.flush();
for (String col : COLUMNS) w.write(col + TAB);
w.write(CRLF);
// write output of each query
int errorCount = 0;
int queryNum = 0;
for (UserQuery q : queryList) {
queryNum++;
Map<String, String> result = getQueryResult(q, accessMode);
if (result.get(COL_STATUS).equals("error"))
errorCount++;
for (String col : COLUMNS) w.write(result.get(col) + TAB);
w.write(CRLF);
w.flush();
System.out.println(new Date() + " - query " + String.valueOf(queryNum) + "/" + String.valueOf(queryList.size()) + " - " + result.get(COL_ID) + " - " + result.get(COL_STATUS) + " - " + result.get(COL_ROWS));
}
long t = (System.currentTimeMillis() - t0) / 1000;
w.write(CRLF);
w.write("Total duration[s]" + TAB + String.valueOf(t) + CRLF);
w.write("Total error(s)" + TAB + String.valueOf(errorCount) + CRLF);
w.write("Status" + TAB + (errorCount == 0 ? "OK" : "ERROR(S)") + CRLF);
w.write("Ending at\t" + new Date() + CRLF);
w.write("End" + CRLF);
w.flush();
} catch (Exception e) {
throw new NextProtException(e.getMessage(), e);
}
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class SparqlQueryDictionary method buildSparqlQueryFromRawContent.
private UserQuery buildSparqlQueryFromRawContent(String rawContent) {
UserQuery dsq = new UserQuery();
Map<String, String> rawProps = getMetaInfo(rawContent);
dsq.setSparql(rawProps.get("query"));
dsq.setTitle(rawProps.get("title"));
dsq.setOwner("nextprot");
dsq.setOwnerId(-1);
dsq.setDescription(rawProps.get("comment"));
try {
dsq.setPublicId(rawProps.get("id"));
dsq.setUserQueryId(Long.valueOf(rawProps.get("id").replaceAll("NXQ_", "")));
} catch (Exception e) {
dsq.setUserQueryId(0);
}
if (rawProps.get("tags") != null) {
dsq.setTags(Sets.newHashSet(rawProps.get("tags").split(",")));
} else
dsq.setTags(new HashSet<String>());
return dsq;
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryController method updateAdvancedQuery.
// UPDATE
@ApiMethod(path = "/user/me/queries/{id}", verb = ApiVerb.PUT, description = "Updates an advanced query for the current logged user", produces = { MediaType.APPLICATION_JSON_VALUE }, consumes = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/user/me/queries/{id}", method = { RequestMethod.PUT })
@ResponseBody
public UserQuery updateAdvancedQuery(@PathVariable("id") String id, @RequestBody UserQuery advancedUserQuery, Model model) {
// Never trust what the users sends to you! Set the correct username, so it will be verified by the service,
// TODO Is this done on the aspect
UserQuery q = userQueryService.getUserQueryById(advancedUserQuery.getUserQueryId());
advancedUserQuery.setOwner(q.getOwner());
advancedUserQuery.setOwnerId(q.getOwnerId());
return userQueryService.updateUserQuery(advancedUserQuery);
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryDaoImpl method getUserQueryById.
@Override
public UserQuery getUserQueryById(long queryId) {
String sql = sqlDictionary.getSQLQuery("read-user-query-by-id");
MapSqlParameterSource namedParameters = new MapSqlParameterSource();
namedParameters.addValue("query_id", queryId);
UserQuery query = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).queryForObject(sql, namedParameters, new UserQueryRowMapper());
Map<Long, Set<String>> tags = getQueryTags(Arrays.asList(query.getUserQueryId()));
query.setTags(tags.get(queryId));
return query;
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryDaoImpl method getUserQueryByPublicId.
@Override
public UserQuery getUserQueryByPublicId(String publicId) {
String sql = sqlDictionary.getSQLQuery("read-user-query-by-pubid");
MapSqlParameterSource namedParameters = new MapSqlParameterSource();
namedParameters.addValue("public_id", publicId);
UserQuery query = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).queryForObject(sql, namedParameters, new UserQueryRowMapper());
long queryId = query.getUserQueryId();
Map<Long, Set<String>> tags = getQueryTags(Arrays.asList(queryId));
query.setTags(tags.get(queryId));
return query;
}
Aggregations