use of org.nextprot.api.user.domain.UserProteinList 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.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToUpdateHisProteinList.
// --------------------------------- PUT --------------------------------------------------------------
@Test
public void leonardShouldBeAbleToUpdateHisProteinList() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
String content = "{\"id\":0,\"name\":\"leonardslist10\",\"description\":\"no desc\",\"accessionNumbers\":[\"NX_45465\"],\"entriesCount\":1,\"ownerId\":0,\"owner\":\"leonard\",\"ownerName\":\"leonard\"}";
// UserProteinList updateUserProteinListMetadata()
String responseString = this.mockMvc.perform(put("/user/me/lists/157").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).content(content)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
});
assertEquals(23, userProteinList.getOwnerId());
assertEquals(Sets.newHashSet("NX_45465", "NX_P05185", "NX_Q8N5Z0", "NX_Q14239"), userProteinList.getAccessionNumbers());
}
use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToOrCombineProteinLists.
@Test
public void leonardShouldBeAbleToOrCombineProteinLists() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
// call UserProteinList combineUserProteinList()
String responseString = this.mockMvc.perform(get("/user/me/lists/combine?listname=leonardslist3&listname1=leonardslist1&listname2=leonardslist2&op=OR").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
});
assertEquals(23, userProteinList.getOwnerId());
assertEquals(Sets.newHashSet("NX_Q14239", "NX_Q8N5Z0", "NX_P05185", "NX_Q14249", "NX_P05165"), userProteinList.getAccessionNumbers());
}
use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToUpdateHisProteinListWithDuplicateAccessionNumber.
@Test
public void leonardShouldBeAbleToUpdateHisProteinListWithDuplicateAccessionNumber() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
String content = "{\"id\":0,\"name\":\"leonardslist1\",\"description\":\"no desc\",\"accessionNumbers\":[\"NX_45465\",\"NX_P05185\"],\"entriesCount\":2,\"ownerId\":0,\"owner\":\"leonard\",\"ownerName\":\"leonard\"}";
// UserProteinList updateUserProteinListMetadata()
String responseString = this.mockMvc.perform(put("/user/me/lists/157").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).content(content)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
});
assertEquals(23, userProteinList.getOwnerId());
assertEquals(Sets.newHashSet("NX_45465", "NX_P05185", "NX_Q8N5Z0", "NX_Q14239"), userProteinList.getAccessionNumbers());
}
use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToLookAtHisOwnProteinList.
/* This test is not relevant anymore
@Test
public void sheldonIsForbiddenToLookAtLeonardsProteinLists() throws Exception {
String sheldonToken = generateTokenWithExpirationDate("sheldon", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER" ));
// call List<UserProteinList> getUserProteinLists()
this.mockMvc.perform(get("/user/me/lists/157").
header("Authorization", "Bearer " + sheldonToken).accept(MediaType.APPLICATION_JSON)).
andExpect(status().isForbidden());
}
@Test
public void othersAreUnauthorizedToLookAtLeonardsProteinLists() throws Exception {
// call List<UserProteinList> getUserProteinLists()
this.mockMvc.perform(get("/user/me/lists").accept(MediaType.APPLICATION_JSON)).
andExpect(status().isForbidden());
}*/
// --------------------------------- GET PROTEINS LIST ------------------------------------------------
@Test
public void leonardShouldBeAbleToLookAtHisOwnProteinList() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
// call UserProteinList getUserProteinList()
String responseString = this.mockMvc.perform(get("/user/me/lists/157").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
});
assertEquals(23, userProteinList.getOwnerId());
assertEquals(Sets.newHashSet("NX_Q14239", "NX_Q8N5Z0", "NX_P05185"), userProteinList.getAccessionNumbers());
}
Aggregations