Search in sources :

Example 11 with UserQuery

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);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) UserQuery(org.nextprot.api.user.domain.UserQuery) Date(java.util.Date) SparqlEndpoint(org.nextprot.api.rdf.service.SparqlEndpoint) SparqlProxyEndpoint(org.nextprot.api.rdf.service.SparqlProxyEndpoint) NextProtException(org.nextprot.api.commons.exception.NextProtException) PrintWriter(java.io.PrintWriter)

Example 12 with UserQuery

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;
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) NextProtException(org.nextprot.api.commons.exception.NextProtException) HashSet(java.util.HashSet)

Example 13 with UserQuery

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);
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) ApiMethod(org.jsondoc.core.annotation.ApiMethod)

Example 14 with UserQuery

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ResultSet(java.sql.ResultSet) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) UserQuery(org.nextprot.api.user.domain.UserQuery)

Example 15 with UserQuery

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ResultSet(java.sql.ResultSet) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) UserQuery(org.nextprot.api.user.domain.UserQuery)

Aggregations

UserQuery (org.nextprot.api.user.domain.UserQuery)33 Test (org.junit.Test)20 UserResourceBaseTest (org.nextprot.api.user.dao.test.base.UserResourceBaseTest)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 MVCBaseSecurityTest (org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)4 ResultSet (java.sql.ResultSet)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 AbstractUnitBaseTest (org.nextprot.api.commons.dbunit.AbstractUnitBaseTest)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 List (java.util.List)1 SearchQueryException (org.nextprot.api.commons.exception.SearchQueryException)1 SparqlEndpoint (org.nextprot.api.rdf.service.SparqlEndpoint)1