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;
}
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;
}
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;
}
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);
}
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();
}
Aggregations