Search in sources :

Example 36 with UserProteinList

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);
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) ApiMethod(org.jsondoc.core.annotation.ApiMethod)

Example 37 with UserProteinList

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) UserProteinList(org.nextprot.api.user.domain.UserProteinList)

Example 38 with 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));
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) MVCBaseSecurityTest(org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)

Example 39 with UserProteinList

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());
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) UserProteinList(org.nextprot.api.user.domain.UserProteinList) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) MVCBaseSecurityTest(org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)

Example 40 with UserProteinList

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();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) UserService(org.nextprot.api.user.service.UserService) UserProteinListService(org.nextprot.api.user.service.UserProteinListService) UserProteinList(org.nextprot.api.user.domain.UserProteinList)

Aggregations

UserProteinList (org.nextprot.api.user.domain.UserProteinList)51 Test (org.junit.Test)38 UserResourceBaseTest (org.nextprot.api.user.dao.test.base.UserResourceBaseTest)13 UserProteinListServiceTest.createUserProteinList (org.nextprot.api.user.service.UserProteinListServiceTest.createUserProteinList)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 MVCBaseSecurityTest (org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)8 HashSet (java.util.HashSet)5 AbstractUnitBaseTest (org.nextprot.api.commons.dbunit.AbstractUnitBaseTest)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)3 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 NextProtException (org.nextprot.api.commons.exception.NextProtException)2 UserQuery (org.nextprot.api.user.domain.UserQuery)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)2 IOException (java.io.IOException)1 List (java.util.List)1 AutocompleteSearchResult (org.nextprot.api.solr.AutocompleteSearchResult)1 Query (org.nextprot.api.solr.Query)1 SearchResult (org.nextprot.api.solr.SearchResult)1