use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class FileResource method uploadSequence.
/**
* this creates an entry if an id is not specified in the form data
*/
@POST
@Path("sequence")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response uploadSequence(@FormDataParam("file") InputStream fileInputStream, @FormDataParam("entryRecordId") String recordId, @FormDataParam("entryType") String entryType, @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {
try {
final String fileName = contentDispositionHeader.getFileName();
String userId = getUserId();
PartSequence partSequence;
if (StringUtils.isEmpty(recordId)) {
if (entryType == null) {
entryType = "PART";
}
EntryType type = EntryType.nameToType(entryType);
partSequence = new PartSequence(userId, type);
} else {
partSequence = new PartSequence(userId, recordId);
}
SequenceInfo info = partSequence.parseSequenceFile(fileInputStream, fileName);
if (info == null)
throw new WebApplicationException(Response.serverError().build());
return Response.status(Response.Status.OK).entity(info).build();
} catch (Exception e) {
Logger.error(e);
ErrorResponse response = new ErrorResponse();
response.setMessage(e.getMessage());
throw new WebApplicationException(Response.serverError().entity(response).build());
}
}
use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class FileResource method getUploadCSV.
@GET
@Path("upload/{type}")
public Response getUploadCSV(@PathParam("type") final String type, @QueryParam("link") final String linkedType) {
EntryType entryAddType = EntryType.nameToType(type);
EntryType linked;
if (linkedType != null) {
linked = EntryType.nameToType(linkedType);
} else {
linked = null;
}
final StreamingOutput stream = output -> {
byte[] template = FileBulkUpload.getCSVTemplateBytes(entryAddType, linked, "existing".equalsIgnoreCase(linkedType));
ByteArrayInputStream input = new ByteArrayInputStream(template);
ByteStreams.copy(input, output);
};
String filename = type.toLowerCase();
if (linkedType != null) {
filename += ("_" + linkedType.toLowerCase());
}
return addHeaders(Response.ok(stream), filename + "_csv_upload.csv");
}
use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class HibernateSearch method executeSearchNoTerms.
public SearchResults executeSearchNoTerms(String userId, HashMap<String, SearchResult> blastResults, SearchQuery searchQuery) {
ArrayList<EntryType> entryTypes = searchQuery.getEntryTypes();
if (entryTypes == null || entryTypes.isEmpty()) {
entryTypes = new ArrayList<>();
entryTypes.addAll(Arrays.asList(EntryType.values()));
}
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
int resultCount;
FullTextSession fullTextSession = Search.getFullTextSession(session);
BooleanQuery.Builder builder = new BooleanQuery.Builder();
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Entry.class).get();
ArrayList<Query> except = new ArrayList<>();
for (EntryType type : EntryType.values()) {
if (entryTypes.contains(type))
continue;
except.add(qb.keyword().onField("recordType").matching(type.getName()).createQuery());
}
// add terms for record types
Query[] queries = new Query[] {};
Query recordTypeQuery = qb.all().except(except.toArray(queries)).createQuery();
builder.add(recordTypeQuery, BooleanClause.Occur.FILTER);
// visibility
Query visibilityQuery = qb.keyword().onField("visibility").matching(Visibility.OK.getValue()).createQuery();
builder.add(visibilityQuery, BooleanClause.Occur.FILTER);
// bio safety level
BioSafetyOption option = searchQuery.getBioSafetyOption();
if (option != null) {
TermContext bslContext = qb.keyword();
Query biosafetyQuery = bslContext.onField("bioSafetyLevel").ignoreFieldBridge().matching(option.getIntValue()).createQuery();
builder.add(biosafetyQuery, BooleanClause.Occur.FILTER);
}
// check filter filters
if (searchQuery.getFieldFilters() != null && !searchQuery.getFieldFilters().isEmpty()) {
for (FieldFilter fieldFilter : searchQuery.getFieldFilters()) {
String searchField = SearchFieldFactory.searchFieldForEntryField(fieldFilter.getField());
if (StringUtils.isEmpty(searchField))
continue;
Query filterQuery = qb.keyword().onField(searchField).matching(fieldFilter.getFilter()).createQuery();
builder.add(filterQuery, BooleanClause.Occur.MUST);
}
}
// check if there is a blast results
createBlastFilterQuery(fullTextSession, blastResults, builder);
// wrap Lucene query in a org.hibernate.Query
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(builder.build(), Entry.class);
// get sorting values
Sort sort = getSort(searchQuery.getParameters().isSortAscending(), searchQuery.getParameters().getSortField());
fullTextQuery.setSort(sort);
// enable security filter if needed
checkEnableSecurityFilter(userId, fullTextQuery);
// enable has attachment/sequence/sample (if needed)
checkEnableHasAttribute(fullTextQuery, searchQuery.getParameters());
// set paging params
fullTextQuery.setFirstResult(searchQuery.getParameters().getStart());
fullTextQuery.setMaxResults(searchQuery.getParameters().getRetrieveCount());
resultCount = fullTextQuery.getResultSize();
List result = fullTextQuery.list();
LinkedList<SearchResult> searchResults = new LinkedList<>();
for (Object object : result) {
Entry entry = (Entry) object;
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(1f);
PartData info = ModelToInfoFactory.createTableViewData(userId, entry, true);
searchResult.setEntryInfo(info);
}
searchResult.setMaxScore(1f);
searchResults.add(searchResult);
}
SearchResults results = new SearchResults();
results.setResultCount(resultCount);
results.setResults(searchResults);
Logger.info(userId + ": obtained " + resultCount + " results for empty query");
return results;
}
use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class Entries method getEntriesFromSelectionContext.
public List<Long> getEntriesFromSelectionContext(EntrySelection context) {
boolean all = context.isAll();
EntryType entryType = context.getEntryType();
if (context.getSelectionType() == null)
return context.getEntries();
switch(context.getSelectionType()) {
default:
case FOLDER:
if (!context.getEntries().isEmpty()) {
return context.getEntries();
} else {
long folderId = Long.decode(context.getFolderId());
return getFolderEntries(folderId, all, entryType);
}
case SEARCH:
return getSearchResults(context.getSearchQuery());
case COLLECTION:
if (!context.getEntries().isEmpty()) {
return context.getEntries();
} else {
return getCollectionEntries(context.getFolderId(), all, entryType);
}
}
}
use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class SearchFieldFactory method entryFields.
public static HashSet<String> entryFields(List<EntryType> types) {
HashSet<String> fields = new HashSet<>();
for (EntryType type : types) {
switch(type) {
case STRAIN:
fields.addAll(strainFields);
break;
case PLASMID:
fields.addAll(plasmidFields);
break;
case ARABIDOPSIS:
fields.addAll(seedFields);
break;
}
}
fields.addAll(commonFields);
return fields;
}
Aggregations