Search in sources :

Example 26 with UserProteinList

use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.

the class ExportController method exportList.

@RequestMapping("/export/lists/{listId}")
public void exportList(HttpServletResponse response, HttpServletRequest request, @ApiQueryParam(name = "listname", description = "The list id") @PathVariable("listId") String listId) {
    UserProteinList pl = this.proteinListService.getUserProteinListByPublicId(listId);
    String fileName = pl.getName() + ".txt";
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    // http://alpha-api.nextprot.org/export/lists/3C5KYA1M
    try {
        if (pl.getDescription() != null) {
            response.getWriter().write("#" + pl.getDescription() + StringUtils.CR_LF);
        }
        if (pl.getAccessionNumbers() != null) {
            for (String s : pl.getAccessionNumbers()) {
                response.getWriter().write(s);
                response.getWriter().write(StringUtils.CR_LF);
            }
        }
    } catch (Exception e) {
        throw new NextProtException(e.getMessage(), e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) UserProteinList(org.nextprot.api.user.domain.UserProteinList) NextProtException(org.nextprot.api.commons.exception.NextProtException) IOException(java.io.IOException)

Example 27 with UserProteinList

use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.

the class UserProteinListServiceImpl method updateUserProteinList.

@Override
@Transactional
public void updateUserProteinList(UserProteinList proteinList) {
    proteinListDao.updateUserProteinListMetadata(proteinList);
    Set<String> accs = proteinList.getAccessionNumbers();
    if (accs != null && !accs.isEmpty()) {
        UserProteinList currentProteinList = proteinListDao.getUserProteinListById(proteinList.getId());
        Set<String> accsToInsert = Sets.difference(accs, currentProteinList.getAccessionNumbers());
        if (!accsToInsert.isEmpty())
            proteinListDao.createUserProteinListItems(proteinList.getId(), accsToInsert);
    }
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with UserProteinList

use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.

the class UserProteinListDaoTest method testDeleteProteinListItems.

@Test
public void testDeleteProteinListItems() {
    Set<String> accs = new HashSet<String>();
    accs.add("NX_Q14249");
    accs.add("NX_P05165");
    int count = proteinListDao.deleteProteinListItems(156, accs);
    assertEquals(2, count);
    UserProteinList list = proteinListDao.getUserProteinListById(156);
    assertExpectedProteinList(list, 156, "mylist", "my proteins", username, 23, 1, Sets.newHashSet("NX_Q8N5Z0"), "ZZZZZU8V");
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) HashSet(java.util.HashSet) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 29 with UserProteinList

use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.

the class UserProteinListDaoTest method testCreateUserProteinList.

@Test
public void testCreateUserProteinList() {
    UserProteinList list = new UserProteinList();
    list.setOwnerId(24);
    list.setPublicId("00000001");
    long id = proteinListDao.createUserProteinList(list);
    assertTrue(id > 0);
    UserProteinList list2 = proteinListDao.getUserProteinListById(id);
    assertNotNull(list2);
    assertEquals(list.getOwnerId(), list2.getOwnerId());
    assertNull(list2.getDescription());
    assertNull(list2.getName());
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 30 with UserProteinList

use of org.nextprot.api.user.domain.UserProteinList in project nextprot-api by calipho-sib.

the class UserProteinListDaoTest method testGetUserProteinListById.

@Test
public void testGetUserProteinListById() {
    UserProteinList list = proteinListDao.getUserProteinListById(156);
    assertNotNull(list);
    assertExpectedProteinList(list, 156, "mylist", "my proteins", username, 23, 3, Sets.newHashSet("NX_Q14249", "NX_Q8N5Z0", "NX_P05165"), "ZZZZZU8V");
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

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