Search in sources :

Example 1 with UserProteinList

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

the class QueryBuilderServiceImpl method buildQueryForSearch.

@Override
public Query buildQueryForSearch(QueryRequest queryRequest, String indexName) {
    Logger.debug(queryRequest.toPrettyString());
    if (queryRequest.isEntryAccessionSetDefined()) {
        Logger.debug("queryRequest.hasEntryAccessionList()");
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(queryRequest.getEntryAccessionSet()));
    } else if (queryRequest.hasList()) {
        Logger.debug("queryRequest.hasList()");
        UserProteinList proteinList;
        if (StringUtils.isWholeNumber(queryRequest.getListId())) {
            // Private id is used
            proteinList = this.proteinListService.getUserProteinListById(Long.valueOf(queryRequest.getListId()));
        } else {
            // public id is used
            proteinList = this.proteinListService.getUserProteinListByPublicId(queryRequest.getListId());
        }
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(proteinList.getAccessionNumbers()));
    } else if (queryRequest.hasNextProtQuery()) {
        Logger.debug("queryRequest.hasNextProtQuery()");
        UserQuery uq;
        // TODO  i don t think this is used anymore, checkout the logs
        if (StringUtils.isWholeNumber(queryRequest.getQueryId())) {
            // Private id is used
            Logger.fatal("Yes I am beeing used!!!");
            uq = userQueryService.getUserQueryById(Long.valueOf(queryRequest.getQueryId()));
        } else {
            // public id is used
            uq = userQueryService.getUserQueryByPublicId(queryRequest.getQueryId());
        }
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(new HashSet<>(sparqlService.findEntries(uq.getSparql(), sparqlEndpoint.getUrl(), queryRequest.getSparqlTitle()))));
    } else if (queryRequest.hasSparql()) {
        Logger.debug("queryRequest.hasSparql()");
        return buildQueryForSearchIndexes(indexName, queryRequest, buildQueryStringFromEntryAccessions(new HashSet<>(sparqlService.findEntries(queryRequest.getSparql(), sparqlEndpoint.getUrl(), queryRequest.getSparqlTitle()))));
    } else {
        Logger.debug("queryRequest.default for simple search");
        if (queryRequest.getQuery() == null) {
            queryRequest.setQuery("");
        }
        return queryService.buildQueryForSearchIndexes(indexName, "simple", queryRequest);
    }
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) UserProteinList(org.nextprot.api.user.domain.UserProteinList) HashSet(java.util.HashSet)

Example 2 with UserProteinList

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

the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToUpdateHisProteinList.

// --------------------------------- PUT --------------------------------------------------------------
@Test
public void leonardShouldBeAbleToUpdateHisProteinList() throws Exception {
    String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
    String content = "{\"id\":0,\"name\":\"leonardslist10\",\"description\":\"no desc\",\"accessionNumbers\":[\"NX_45465\"],\"entriesCount\":1,\"ownerId\":0,\"owner\":\"leonard\",\"ownerName\":\"leonard\"}";
    // UserProteinList updateUserProteinListMetadata()
    String responseString = this.mockMvc.perform(put("/user/me/lists/157").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).content(content)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
    });
    assertEquals(23, userProteinList.getOwnerId());
    assertEquals(Sets.newHashSet("NX_45465", "NX_P05185", "NX_Q8N5Z0", "NX_Q14239"), userProteinList.getAccessionNumbers());
}
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 3 with UserProteinList

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

the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToOrCombineProteinLists.

@Test
public void leonardShouldBeAbleToOrCombineProteinLists() throws Exception {
    String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
    // call UserProteinList combineUserProteinList()
    String responseString = this.mockMvc.perform(get("/user/me/lists/combine?listname=leonardslist3&listname1=leonardslist1&listname2=leonardslist2&op=OR").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
    });
    assertEquals(23, userProteinList.getOwnerId());
    assertEquals(Sets.newHashSet("NX_Q14239", "NX_Q8N5Z0", "NX_P05185", "NX_Q14249", "NX_P05165"), userProteinList.getAccessionNumbers());
}
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 4 with UserProteinList

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

the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToUpdateHisProteinListWithDuplicateAccessionNumber.

@Test
public void leonardShouldBeAbleToUpdateHisProteinListWithDuplicateAccessionNumber() throws Exception {
    String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
    String content = "{\"id\":0,\"name\":\"leonardslist1\",\"description\":\"no desc\",\"accessionNumbers\":[\"NX_45465\",\"NX_P05185\"],\"entriesCount\":2,\"ownerId\":0,\"owner\":\"leonard\",\"ownerName\":\"leonard\"}";
    // UserProteinList updateUserProteinListMetadata()
    String responseString = this.mockMvc.perform(put("/user/me/lists/157").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).content(content)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
    });
    assertEquals(23, userProteinList.getOwnerId());
    assertEquals(Sets.newHashSet("NX_45465", "NX_P05185", "NX_Q8N5Z0", "NX_Q14239"), userProteinList.getAccessionNumbers());
}
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 5 with UserProteinList

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

the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToLookAtHisOwnProteinList.

/* This test is not relevant anymore 
	@Test
	public void sheldonIsForbiddenToLookAtLeonardsProteinLists() throws Exception {

		String sheldonToken = generateTokenWithExpirationDate("sheldon", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER" ));

		// call List<UserProteinList> getUserProteinLists()
		this.mockMvc.perform(get("/user/me/lists/157").
				header("Authorization", "Bearer " + sheldonToken).accept(MediaType.APPLICATION_JSON)).
				andExpect(status().isForbidden());
	}

	@Test
	public void othersAreUnauthorizedToLookAtLeonardsProteinLists() throws Exception {

		// call List<UserProteinList> getUserProteinLists()
		this.mockMvc.perform(get("/user/me/lists").accept(MediaType.APPLICATION_JSON)).
				andExpect(status().isForbidden());
	}*/
// --------------------------------- GET PROTEINS LIST ------------------------------------------------
@Test
public void leonardShouldBeAbleToLookAtHisOwnProteinList() throws Exception {
    String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
    // call UserProteinList getUserProteinList()
    String responseString = this.mockMvc.perform(get("/user/me/lists/157").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
    });
    assertEquals(23, userProteinList.getOwnerId());
    assertEquals(Sets.newHashSet("NX_Q14239", "NX_Q8N5Z0", "NX_P05185"), userProteinList.getAccessionNumbers());
}
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)

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