use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListController method uploadProteinList.
@ApiMethod(path = "/user/me/lists/{listid}/upload", verb = ApiVerb.POST, description = "Uploads a user protein list for the current logged user", produces = { MediaType.APPLICATION_JSON_VALUE }, consumes = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/user/me/lists/{listid}/upload", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public void uploadProteinList(@RequestParam("file") MultipartFile file, @PathVariable(value = "listid") long listId, @RequestParam(value = "ignoreNotFoundEntries", defaultValue = "false") boolean ignoreNotFoundEntries) throws IOException {
UserProteinList pl = proteinListService.getUserProteinListById(listId);
Set<String> acs = UserProteinListUtils.parseAccessionNumbers(file, masterIdentifierService.findUniqueNames(), ignoreNotFoundEntries);
pl.addAccessions(acs);
this.proteinListService.updateUserProteinList(pl);
}
use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListDaoImpl method getUserProteinListById.
@Override
public UserProteinList getUserProteinListById(long listId) throws DataAccessException {
String sql = sqlDictionary.getSQLQuery("read-user-protein-list-by-id");
SqlParameterSource namedParams = new MapSqlParameterSource("list_id", listId);
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
UserProteinList userProteinList = template.queryForObject(sql, namedParams, new ProteinListRowMapper());
userProteinList.setAccessions(getAccessionsByListId(listId));
return userProteinList;
}
use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListControllerIntegrationTest method sheldonShouldBeAbleToCreateProteinList.
// --------------------------------- POST -------------------------------------------------------------
@Test
public void sheldonShouldBeAbleToCreateProteinList() throws Exception {
String sheldonUser = "Sheldon";
String sheldonToken = generateTokenWithExpirationDate("Sheldon", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
String content = "{\"id\":0,\"name\":\"my list\",\"description\":\"no desc\",\"accessionNumbers\":[\"NX_45465\"],\"entriesCount\":1,\"ownerId\":0,\"owner\":\"sheldon\",\"ownerName\":\"sheldon\"}";
// call UserProteinList createUserProteinList()
String responseString = this.mockMvc.perform(post("/user/me/lists").contentType(MediaType.APPLICATION_JSON).content(content).header("Authorization", "Bearer " + sheldonToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
UserProteinList userProteinList = new ObjectMapper().readValue(responseString, UserProteinList.class);
assertTrue(userProteinList.getOwnerId() > 1);
assertTrue(userProteinList.getOwner().equals(sheldonUser));
}
use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToLookAtHisOwnProteinLists.
// --------------------------------- GET --------------------------------------------------------------
// --------------------------------- GET PROTEINS LISTS -----------------------------------------------
@Test
public void leonardShouldBeAbleToLookAtHisOwnProteinLists() throws Exception {
String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
// call List<UserProteinList> getUserProteinLists()
String responseString = this.mockMvc.perform(get("/user/me/lists").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
List<UserProteinList> list = new ObjectMapper().readValue(responseString, new TypeReference<List<UserProteinList>>() {
});
assertTrue(!list.isEmpty());
assertEquals(2, list.size());
assertTrue(list.get(0).getAccessionNumbers().isEmpty());
assertTrue(list.get(1).getAccessionNumbers().isEmpty());
assertEquals(23, list.get(0).getOwnerId());
assertEquals(23, list.get(1).getOwnerId());
}
use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.
the class PopulateRDBMSWithProteinListsApp method main.
public static void main(String[] args) {
System.setProperty("spring.profiles.active", "pro");
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/core-context.xml");
UserProteinListService userProteinListService = ctx.getBean(UserProteinListService.class);
UserService userService = ctx.getBean(UserService.class);
String username = "ddtxra@gmail.com";
for (int i = 0; i < 10; i++) {
UserProteinList pl = new UserProteinList();
pl.setName("some name" + i);
pl.setDescription("some description" + i);
pl.setEntriesCount(5);
pl.setOwner(username);
pl.setOwnerId(userService.getUser(username).getId());
userProteinListService.createUserProteinList(pl);
}
ctx.close();
}
Aggregations