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