Search in sources :

Example 6 with EntryType

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());
    }
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence)

Example 7 with EntryType

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");
}
Also used : RemoteSequence(org.jbei.ice.lib.net.RemoteSequence) AttachmentInfo(org.jbei.ice.lib.dto.entry.AttachmentInfo) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) Setting(org.jbei.ice.lib.dto.Setting) SequenceAnalysisController(org.jbei.ice.lib.entry.sequence.SequenceAnalysisController) ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) EntryField(org.jbei.ice.lib.dto.entry.EntryField) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Entries(org.jbei.ice.lib.entry.Entries) Sequence(org.jbei.ice.storage.model.Sequence) MediaType(javax.ws.rs.core.MediaType) ConfigurationController(org.jbei.ice.lib.config.ConfigurationController) DAOFactory(org.jbei.ice.storage.DAOFactory) Logger(org.jbei.ice.lib.common.logging.Logger) FileBulkUpload(org.jbei.ice.lib.bulkupload.FileBulkUpload) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) PigeonSBOLv(org.jbei.ice.lib.entry.sequence.composers.pigeon.PigeonSBOLv) Entry(org.jbei.ice.storage.model.Entry) EntryType(org.jbei.ice.lib.dto.entry.EntryType) URI(java.net.URI) Utils(org.jbei.ice.lib.utils.Utils) AttachmentController(org.jbei.ice.lib.entry.attachment.AttachmentController) EntrySelection(org.jbei.ice.lib.entry.EntrySelection) FileUtils(org.apache.commons.io.FileUtils) StreamingOutput(javax.ws.rs.core.StreamingOutput) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController) Collectors(java.util.stream.Collectors) RemoteEntries(org.jbei.ice.lib.net.RemoteEntries) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) java.io(java.io) Paths(java.nio.file.Paths) ByteStreams(com.google.common.io.ByteStreams) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) ShotgunSequenceDAO(org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO) TraceSequence(org.jbei.ice.storage.model.TraceSequence) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) EntryType(org.jbei.ice.lib.dto.entry.EntryType) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 8 with EntryType

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;
}
Also used : FullTextSession(org.hibernate.search.FullTextSession) SearchQuery(org.jbei.ice.lib.dto.search.SearchQuery) FullTextQuery(org.hibernate.search.FullTextQuery) QueryBuilder(org.hibernate.search.query.dsl.QueryBuilder) BioSafetyOption(org.jbei.ice.lib.shared.BioSafetyOption) QueryBuilder(org.hibernate.search.query.dsl.QueryBuilder) SearchResults(org.jbei.ice.lib.dto.search.SearchResults) TermContext(org.hibernate.search.query.dsl.TermContext) Entry(org.jbei.ice.storage.model.Entry) SearchResult(org.jbei.ice.lib.dto.search.SearchResult) FieldFilter(org.jbei.ice.lib.dto.search.FieldFilter) EntryType(org.jbei.ice.lib.dto.entry.EntryType) PartData(org.jbei.ice.lib.dto.entry.PartData) FullTextQuery(org.hibernate.search.FullTextQuery) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 9 with EntryType

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);
            }
    }
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType)

Example 10 with 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;
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType) HashSet(java.util.HashSet)

Aggregations

EntryType (org.jbei.ice.lib.dto.entry.EntryType)11 Entry (org.jbei.ice.storage.model.Entry)3 HashSet (java.util.HashSet)2 EntryField (org.jbei.ice.lib.dto.entry.EntryField)2 PartData (org.jbei.ice.lib.dto.entry.PartData)2 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)2 SearchQuery (org.jbei.ice.lib.dto.search.SearchQuery)2 PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)2 ByteStreams (com.google.common.io.ByteStreams)1 java.io (java.io)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 javax.ws.rs (javax.ws.rs)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1