Search in sources :

Example 1 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class QueryBuilderServiceImpl method buildQueryForSearch.

@Override
public Query buildQueryForSearch(QueryRequest queryRequest, String indexName) {
    Logger.debug(queryRequest.toPrettyString());
    if (queryRequest.isEntryAccessionSetDefined()) {
        Logger.debug("queryRequest.hasEntryAccessionList()");
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(queryRequest.getEntryAccessionSet()));
    } else if (queryRequest.hasList()) {
        Logger.debug("queryRequest.hasList()");
        UserProteinList proteinList;
        if (StringUtils.isWholeNumber(queryRequest.getListId())) {
            // Private id is used
            proteinList = this.proteinListService.getUserProteinListById(Long.valueOf(queryRequest.getListId()));
        } else {
            // public id is used
            proteinList = this.proteinListService.getUserProteinListByPublicId(queryRequest.getListId());
        }
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(proteinList.getAccessionNumbers()));
    } else if (queryRequest.hasNextProtQuery()) {
        Logger.debug("queryRequest.hasNextProtQuery()");
        UserQuery uq;
        // TODO  i don t think this is used anymore, checkout the logs
        if (StringUtils.isWholeNumber(queryRequest.getQueryId())) {
            // Private id is used
            Logger.fatal("Yes I am beeing used!!!");
            uq = userQueryService.getUserQueryById(Long.valueOf(queryRequest.getQueryId()));
        } else {
            // public id is used
            uq = userQueryService.getUserQueryByPublicId(queryRequest.getQueryId());
        }
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(new HashSet<>(sparqlService.findEntries(uq.getSparql(), sparqlEndpoint.getUrl(), queryRequest.getSparqlTitle()))));
    } else if (queryRequest.hasSparql()) {
        Logger.debug("queryRequest.hasSparql()");
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(new HashSet<>(sparqlService.findEntries(queryRequest.getSparql(), sparqlEndpoint.getUrl(), queryRequest.getSparqlTitle()))));
    } else {
        Logger.debug("queryRequest.default for simple search");
        if (queryRequest.getQuery() == null) {
            queryRequest.setQuery("");
        }
        return queryService.buildQueryForSearchIndexes(indexName, "simple", queryRequest);
    }
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) UserProteinList(org.nextprot.api.user.domain.UserProteinList) HashSet(java.util.HashSet)

Example 2 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserQueryControllerIntegrationTest method sheldonShouldBeAbleToCreateHisSuperGeniousQuery.

// --------------------------------- POST -------------------------------------------------------------
@Test
public void sheldonShouldBeAbleToCreateHisSuperGeniousQuery() throws Exception {
    String sheldonUser = "Sheldon";
    String sheldonToken = generateTokenWithExpirationDate("Sheldon", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
    String content = "{\"userQueryId\":0,\"title\":\"Super Genious Query\",\"description\":null,\"sparql\":\"some sparql\",\"published\":false,\"owner\":\"test@nextprot.org\",\"ownerId\":0,\"tags\":null,\"ownerName\":\"test@nextprot.org\"}";
    // call UserQuery createAdvancedQuery()
    String responseString = this.mockMvc.perform(post("/user/me/queries").contentType(MediaType.APPLICATION_JSON).content(content).header("Authorization", "Bearer " + sheldonToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    UserQuery uq = new ObjectMapper().readValue(responseString, UserQuery.class);
    // assert that an id was given
    assertTrue(uq.getUserQueryId() > 1);
    // asserts that the owner of the query is bob
    assertTrue(uq.getOwner().equals(sheldonUser));
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) MVCBaseSecurityTest(org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)

Example 3 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserQueryDaoTest method testGetUserQueryByPublicId.

@Test
public void testGetUserQueryByPublicId() {
    UserQuery userQuery = userQueryDao.getUserQueryByPublicId("00000001");
    assertExpectedUserQuery(userQuery, 15, "spongebob", "myquery", "my first query", false, "sparql query", "00000001", new HashSet<String>());
    userQuery = userQueryDao.getUserQueryByPublicId("ZZZZZU8V");
    assertExpectedUserQuery(userQuery, 16, "spongebob", "myquery2", "my second query", true, "another sparql query", "ZZZZZU8V", Sets.newHashSet("public"));
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 4 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserQueryDaoTest method testCreate2UserQueriesWithDuplicatePublicIdFail.

@Test(expected = DuplicateKeyException.class)
public void testCreate2UserQueriesWithDuplicatePublicIdFail() {
    UserQuery query = new UserQuery();
    query.setTitle("ma requete");
    query.setSparql("yet another sparql query");
    query.setPublicId("00000002");
    query.setOwnerId(24);
    long id = userQueryDao.createUserQuery(query);
    assertTrue(id > 0);
    query = new UserQuery();
    query.setTitle("ma requete 2");
    query.setSparql("yet another  3 sparql query");
    query.setPublicId("00000002");
    query.setOwnerId(24);
    userQueryDao.createUserQuery(query);
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 5 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserQueryDaoTest method testUpdateUserQuery.

@Test
public void testUpdateUserQuery() {
    UserQuery query = new UserQuery();
    query.setUserQueryId(16);
    query.setTitle("ma requete");
    query.setDescription("une simple requete");
    query.setSparql("yet another sparql query");
    query.setPublished(true);
    userQueryDao.updateUserQuery(query);
    query = userQueryDao.getUserQueryById(16);
    assertExpectedUserQuery(query, 16, "spongebob", "ma requete", "une simple requete", true, "yet another sparql query", "ZZZZZU8V", Sets.newHashSet("public"));
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

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