Search in sources :

Example 31 with UserProteinList

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

the class UserProteinListDaoTest method testDuplicateUserProteinList.

@Test(expected = DuplicateKeyException.class)
public void testDuplicateUserProteinList() {
    UserProteinList l = new UserProteinList();
    l.setName("mylist");
    l.setOwnerId(23);
    l.setPublicId("00000001");
    proteinListDao.createUserProteinList(l);
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 32 with UserProteinList

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

the class UserProteinListDaoTest method testCreateUserProteinList2.

@Test
public void testCreateUserProteinList2() {
    int ownerId = 24;
    String desc = "my list";
    String name = "my list of proteins";
    String publicId = "00000006";
    UserProteinList list = new UserProteinList();
    list.setName(name);
    list.setOwnerId(ownerId);
    list.setDescription(desc);
    list.setPublicId(publicId);
    long id = proteinListDao.createUserProteinList(list);
    list = proteinListDao.getUserProteinListById(id);
    assertNotNull(list);
    assertEquals(ownerId, list.getOwnerId());
    assertEquals(desc, list.getDescription());
    assertEquals(name, list.getName());
    assertEquals(publicId, list.getPublicId());
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 33 with UserProteinList

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

the class UserProteinListDaoTest method testUpdateUserProteinList2.

@Test
public void testUpdateUserProteinList2() {
    UserProteinList l = new UserProteinList();
    l.setId(156);
    l.setName("ma liste");
    l.setDescription("la liste de bob leponge");
    l.setAccessions(Sets.newHashSet("NX_Q14249"));
    proteinListDao.updateUserProteinListMetadata(l);
    UserProteinList l2 = proteinListDao.getUserProteinListById(l.getId());
    assertExpectedProteinList(l2, 156, "ma liste", "la liste de bob leponge", 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)

Example 34 with UserProteinList

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

the class UserProteinListUtils method combine.

/**
 * Apply the given operator to two user protein lists in a new instance of
 * {@code UserProteinList}
 *
 * @param l1 first user protein list
 * @param l2 second user protein list
 * @param operator operator applied to operands
 * @param username combined list user name
 * @param name combined list name
 * @param description combined list description
 * @return a new user protein list combining l1 and l2
 */
public static UserProteinList combine(UserProteinList l1, UserProteinList l2, Operator operator, String username, String name, String description) {
    NPreconditions.checkNotNull(l1, "The first user protein list should not be null");
    NPreconditions.checkNotNull(l2, "The second user protein list should not be null");
    NPreconditions.checkNotNull(operator, "The combine operator should not be null");
    NPreconditions.checkNotNull(name, "The user protein list name should not be null");
    NPreconditions.checkNotNull(username, "The user protein list user name should not be null");
    NPreconditions.checkTrue(!l1.equals(l2), "Can't make combination with the same lists");
    Set<String> combined = new HashSet<>();
    if (operator.equals(Operator.AND)) {
        combined.addAll(Sets.intersection(l1.getAccessionNumbers(), l2.getAccessionNumbers()));
    } else if (operator.equals(Operator.OR)) {
        combined = Sets.union(l1.getAccessionNumbers(), l2.getAccessionNumbers());
    } else if (operator.equals(Operator.NOT_IN)) {
        combined.addAll(Sets.difference(l1.getAccessionNumbers(), l2.getAccessionNumbers()));
    }
    if (combined.isEmpty())
        throw new NextProtException("The combined list is empty. Only combinations resulting on non-empty lists are saved.");
    UserProteinList combinedProteinList = new UserProteinList();
    combinedProteinList.setName(name);
    combinedProteinList.setOwner(username);
    combinedProteinList.setDescription(description);
    combinedProteinList.setAccessions(combined);
    return combinedProteinList;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) UserProteinList(org.nextprot.api.user.domain.UserProteinList) HashSet(java.util.HashSet)

Example 35 with UserProteinList

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

the class UserProteinListController method deleteUserProteinList.

// Delete a list
@ApiMethod(verb = ApiVerb.DELETE, description = "Deletes 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}", method = { RequestMethod.DELETE })
public void deleteUserProteinList(@PathVariable("listid") String id) {
    UserProteinList userProteinList = proteinListService.getUserProteinListById(Long.parseLong(id));
    this.proteinListService.deleteUserProteinList(userProteinList);
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) ApiMethod(org.jsondoc.core.annotation.ApiMethod)

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