Search in sources :

Example 56 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class CollectionEntries method getPersonalEntries.

/**
     * Retrieves entries owned by user
     *
     * @param field  sort field
     * @param asc    sort order
     * @param offset paging start
     * @param limit  maximum number of entries to retrieve
     * @param filter optional text to filter entries by
     * @return wrapper around list of parts that conform to the parameters and the maximum number
     * of such entries that are available
     * @throws PermissionException on null user id which is required for owner entries
     */
protected Results<PartData> getPersonalEntries(ColumnField field, boolean asc, int offset, int limit, String filter) {
    if (userId == null || userId.isEmpty())
        throw new PermissionException("User id is required to retrieve owner entries");
    OwnerEntries ownerEntries = new OwnerEntries(userId, userId);
    final List<PartData> entries = ownerEntries.retrieveOwnerEntries(field, asc, offset, limit, filter);
    final long count = ownerEntries.getNumberOfOwnerEntries();
    Results<PartData> results = new Results<>();
    results.setResultCount(count);
    results.setData(entries);
    return results;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Results(org.jbei.ice.lib.dto.common.Results) PartData(org.jbei.ice.lib.dto.entry.PartData) OwnerEntries(org.jbei.ice.lib.entry.OwnerEntries)

Example 57 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class UserResource method getProfileEntries.

/**
     * @return collection for user's part entries
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entries")
public FolderDetails getProfileEntries(@PathParam("id") long userId, @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("15") @QueryParam("limit") int limit, @DefaultValue("created") @QueryParam("sort") String sort, @DefaultValue("false") @QueryParam("asc") boolean asc, @DefaultValue("") @QueryParam("filter") String filter) {
    String userIdString = getUserId();
    ColumnField field = ColumnField.valueOf(sort.toUpperCase());
    OwnerEntries ownerEntries = new OwnerEntries(userIdString, userId);
    List<PartData> entries = ownerEntries.retrieveOwnerEntries(field, asc, offset, limit, filter);
    long count = ownerEntries.getNumberOfOwnerEntries();
    FolderDetails details = new FolderDetails();
    details.getEntries().addAll(entries);
    details.setCount(count);
    return details;
}
Also used : ColumnField(org.jbei.ice.lib.shared.ColumnField) PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) OwnerEntries(org.jbei.ice.lib.entry.OwnerEntries)

Example 58 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class HibernateSearch method executeSearch.

@SuppressWarnings("unchecked")
public SearchResults executeSearch(String userId, HashMap<String, QueryType> terms, SearchQuery searchQuery, HashMap<String, SearchResult> blastResults) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    int resultCount;
    FullTextSession fullTextSession = Search.getFullTextSession(session);
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    // get classes for search
    HashSet<String> fields = new HashSet<>();
    fields.addAll(SearchFieldFactory.entryFields(searchQuery.getEntryTypes()));
    Class<?>[] classes = SearchFieldFactory.classesForTypes(searchQuery.getEntryTypes());
    // generate queries for terms filtering stop words
    for (Map.Entry<String, QueryType> entry : terms.entrySet()) {
        String term = cleanQuery(entry.getKey());
        if (term.trim().isEmpty() || StandardAnalyzer.STOP_WORDS_SET.contains(term))
            continue;
        BioSafetyOption safetyOption = searchQuery.getBioSafetyOption();
        generateQueriesForType(fullTextSession, fields, builder, term, entry.getValue(), safetyOption);
    }
    // check for blast search results filter
    createBlastFilterQuery(fullTextSession, blastResults, builder);
    // wrap Lucene query in a org.hibernate.Query
    FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(builder.build(), classes);
    // get max score
    fullTextQuery.setFirstResult(0);
    fullTextQuery.setMaxResults(1);
    fullTextQuery.setProjection(FullTextQuery.SCORE);
    List result = fullTextQuery.list();
    float maxScore = -1f;
    if (result.size() == 1) {
        maxScore = (Float) ((Object[]) (result.get(0)))[0];
    }
    // end get max score
    // get sorting values
    Sort sort = getSort(searchQuery.getParameters().isSortAscending(), searchQuery.getParameters().getSortField());
    fullTextQuery.setSort(sort);
    // projection (specified properties must be stored in the index @Field(store=Store.YES))
    fullTextQuery.setProjection(FullTextQuery.SCORE, FullTextQuery.THIS);
    // enable security filter if needed
    fullTextQuery = checkEnableSecurityFilter(userId, fullTextQuery);
    // check sample
    checkEnableHasAttribute(fullTextQuery, searchQuery.getParameters());
    // set paging params
    fullTextQuery.setFirstResult(searchQuery.getParameters().getStart());
    fullTextQuery.setMaxResults(searchQuery.getParameters().getRetrieveCount());
    resultCount = fullTextQuery.getResultSize();
    // execute search
    result = fullTextQuery.list();
    Logger.info(resultCount + " results for \"" + searchQuery.getQueryString() + "\"");
    LinkedList<SearchResult> searchResults = new LinkedList<>();
    for (Object[] objects : (Iterable<Object[]>) result) {
        float score = (Float) objects[0];
        Entry entry = (Entry) objects[1];
        SearchResult searchResult;
        if (blastResults != null) {
            searchResult = blastResults.get(Long.toString(entry.getId()));
            if (// this should not really happen since we already filter
            searchResult == null)
                continue;
        } else {
            searchResult = new SearchResult();
            searchResult.setScore(score);
            PartData info = ModelToInfoFactory.createTableViewData(userId, entry, true);
            if (info == null)
                continue;
            searchResult.setEntryInfo(info);
        }
        searchResult.setMaxScore(maxScore);
        searchResults.add(searchResult);
    }
    SearchResults results = new SearchResults();
    results.setResultCount(resultCount);
    results.setResults(searchResults);
    return results;
}
Also used : FullTextSession(org.hibernate.search.FullTextSession) QueryBuilder(org.hibernate.search.query.dsl.QueryBuilder) BioSafetyOption(org.jbei.ice.lib.shared.BioSafetyOption) SearchResults(org.jbei.ice.lib.dto.search.SearchResults) Entry(org.jbei.ice.storage.model.Entry) SearchResult(org.jbei.ice.lib.dto.search.SearchResult) PartData(org.jbei.ice.lib.dto.entry.PartData) FullTextQuery(org.hibernate.search.FullTextQuery) QueryType(org.jbei.ice.lib.search.QueryType) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 59 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class BulkEntryCreatorTest method testUpdateEntry.

@Test
public void testUpdateEntry() throws Exception {
    Account account = AccountCreator.createTestAccount("testUpdateEntry", false);
    PartData strainData = new PartData(EntryType.STRAIN);
    PartData plasmidData = new PartData(EntryType.PLASMID);
    strainData.setPrincipalInvestigator("test 1");
    plasmidData.setPrincipalInvestigator("test 2");
    // create bulk upload
    BulkUploadController controller = new BulkUploadController();
    BulkUploadInfo info = new BulkUploadInfo();
    info.setAccount(account.toDataTransferObject());
    info = controller.create(account.getEmail(), info);
    Assert.assertNotNull(info);
    Assert.assertEquals(info.getStatus(), BulkUploadStatus.IN_PROGRESS);
    // create strain entry
    strainData = creator.createEntry(account.getEmail(), info.getId(), strainData);
    Assert.assertNotNull(strainData);
    Assert.assertTrue(strainData.getId() > 0);
    // link plasmid
    strainData.getLinkedParts().add(plasmidData);
    strainData = creator.updateEntry(account.getEmail(), info.getId(), strainData.getId(), strainData);
    Assert.assertNotNull(strainData);
    // retrieve
    BulkUploadInfo retrieved = controller.getBulkImport(account.getEmail(), info.getId(), 0, 10);
    Assert.assertNotNull(retrieved);
    Assert.assertEquals(retrieved.getEntryList().size(), 1);
    PartData retrievedPart = retrieved.getEntryList().get(0);
    Assert.assertTrue(retrievedPart.getLinkedParts().size() == 1);
}
Also used : Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData)

Example 60 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class TestEntryCreator method createTestPart.

public static long createTestPart(String userId) throws Exception {
    PartData data = new PartData(EntryType.PART);
    data.setShortDescription("summary for test");
    data.setName("pTest " + userId);
    data.setBioSafetyLevel(1);
    return new EntryCreator().createPart(userId, data).getId();
}
Also used : EntryCreator(org.jbei.ice.lib.entry.EntryCreator) PartData(org.jbei.ice.lib.dto.entry.PartData)

Aggregations

PartData (org.jbei.ice.lib.dto.entry.PartData)62 Entry (org.jbei.ice.storage.model.Entry)22 Account (org.jbei.ice.storage.model.Account)18 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 Results (org.jbei.ice.lib.dto.common.Results)5 EntryField (org.jbei.ice.lib.dto.entry.EntryField)4 Group (org.jbei.ice.storage.model.Group)4 Strain (org.jbei.ice.storage.model.Strain)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 PermissionException (org.jbei.ice.lib.access.PermissionException)3 SearchResult (org.jbei.ice.lib.dto.search.SearchResult)3 SearchResults (org.jbei.ice.lib.dto.search.SearchResults)3 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)3 GroupController (org.jbei.ice.lib.group.GroupController)3 EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)3 Plasmid (org.jbei.ice.storage.model.Plasmid)3 RemotePartner (org.jbei.ice.storage.model.RemotePartner)3