use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryDaoImpl method queryList.
/**
* Get user query list and extract tags
*
* @param sql the select from user_queries sql query
* @param source
* @return
*/
private List<UserQuery> queryList(String sql, SqlParameterSource source) {
List<UserQuery> userQueryList = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).query(sql, source, new UserQueryRowMapper());
if (!userQueryList.isEmpty()) {
List<Long> queryIds = Lists.transform(userQueryList, UserQueryUtils.EXTRACT_QUERY_ID);
Map<Long, Set<String>> tags = getQueryTags(queryIds);
for (UserQuery query : userQueryList) {
Set<String> tagSet = tags.get(query.getUserQueryId());
// use hashset because google implementation is not serializable
query.setTags(new HashSet<String>(tagSet));
}
}
return userQueryList;
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryController method deleteUserQuery.
// DELETE
@ApiMethod(verb = ApiVerb.DELETE, description = "Deletes 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.DELETE })
public void deleteUserQuery(@PathVariable("id") String id, Model model) {
// Never trust what the users sends to you! Send the query with the correct username, so it will be verified by the service,
// TODO Is this done on the aspect
UserQuery q = userQueryService.getUserQueryById(Long.parseLong(id));
userQueryService.deleteUserQuery(q);
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryControllerIntegrationTest method leonardShouldBeAbleToLookAtHisQueries.
@Test
public void leonardShouldBeAbleToLookAtHisQueries() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
// List<UserQuery> getUserQueries()
String responseString = this.mockMvc.perform(get("/user/me/queries").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
List<UserQuery> uqs = new ObjectMapper().readValue(responseString, new TypeReference<List<UserQuery>>() {
});
assertTrue(!uqs.isEmpty());
assertEquals(uqs.size(), 1);
assertEquals(123456789, uqs.get(0).getUserQueryId());
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryControllerIntegrationTest method leonardShouldBeAbleToUpdateHisQuery.
/* @Test not applicable anymore
public void othersShouldNotBeAbleToLookAtLeonardsQueries() throws Exception {
// List<UserQuery> getUserQueries()
this.mockMvc.perform(get("/user/me/queries").accept(MediaType.APPLICATION_JSON)).
andExpect(status().isForbidden());
}*/
// --------------------------------- PUT --------------------------------------------------------------
@Test
public void leonardShouldBeAbleToUpdateHisQuery() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
String content = "{\"userQueryId\":123456789,\"title\":\"Awesomely Genious Query\",\"description\":null,\"sparql\":\"some sparql\",\"published\":false,\"owner\":\"test@nextprot.org\",\"ownerId\":0,\"tags\":null,\"ownerName\":\"test@nextprot.org\"}";
// UserQuery updateAdvancedQuery()
String responseString = this.mockMvc.perform(put("/user/me/queries/123456789").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).content(content)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
UserQuery uq = new ObjectMapper().readValue(responseString, UserQuery.class);
assertEquals("Awesomely Genious Query", uq.getTitle());
assertTrue(uq.getOwner().equals("leonard"));
}
use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.
the class UserQueryControllerIntegrationTest method leonardShouldBeAbleToLookAtHisQuery.
@Test
public void leonardShouldBeAbleToLookAtHisQuery() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
// UserQuery getUserQuery()
String responseString = this.mockMvc.perform(get("/user/me/queries/123456789").header("Authorization", "Bearer " + leonardToken).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() == 123456789);
// asserts that the owner of the query is bob
assertTrue(uq.getOwner().equals("leonard"));
}
Aggregations