Search in sources :

Example 11 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class BulkUploadController method addSequence.

public SequenceInfo addSequence(String userId, long bulkUploadId, long entryId, String sequenceString, String fileName) {
    BulkUpload upload = dao.get(bulkUploadId);
    if (upload == null)
        return null;
    authorization.expectWrite(userId, upload);
    PartSequence partSequence = new PartSequence(userId, Long.toString(entryId));
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(sequenceString.getBytes(StandardCharsets.UTF_8));
        return partSequence.parseSequenceFile(inputStream, fileName);
    } catch (IOException e) {
        Logger.error(e);
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) IOException(java.io.IOException)

Example 12 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence 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 13 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class Entries method copy.

/**
 * Creates a copy of referenced part
 *
 * @param sourceId unique identifier for part acting as source of copy. Can be the part id, uuid or id
 * @return wrapper around the id and record id of the newly created entry
 * @throws IllegalArgumentException if the source part for the copy cannot be located using the identifier
 */
public PartData copy(String sourceId) {
    Entry entry = getEntry(sourceId);
    if (entry == null)
        throw new IllegalArgumentException("Could not retrieve entry \"" + sourceId + "\" for copy");
    // check permission (expecting read permission)
    authorization.expectRead(userId, entry);
    Sequence sequence = null;
    if (sequenceDAO.hasSequence(entry.getId())) {
        sequence = sequenceDAO.getByEntry(entry);
    }
    // copy to data model and back ??
    PartData partData = ModelToInfoFactory.getInfo(entry);
    entry = InfoToModelFactory.infoToEntry(partData);
    // create entry
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    entry.setName(entry.getName() + " (copy)");
    entry.setRecordId(Utils.generateUUID());
    entry.setVersionId(entry.getRecordId());
    entry.setOwnerEmail(account.getEmail());
    entry.setOwner(account.getFullName());
    entry = createEntry(account, entry, new ArrayList<>());
    // check sequence
    if (sequence != null) {
        PartSequence partSequence = new PartSequence(userId, sourceId);
        new PartSequence(userId, entry.getPartNumber()).save(partSequence.get(true));
    }
    PartData copy = new PartData(EntryType.nameToType(entry.getRecordType()));
    copy.setId(entry.getId());
    copy.setRecordId(entry.getRecordId());
    return copy;
}
Also used : PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence)

Example 14 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class BulkUploadResource method deleteEntrySequence.

/**
 * @param uploadId
 * @param entryId
 * @return OK response if sequence is deleted
 */
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entry/{entryId}/sequence")
public Response deleteEntrySequence(@PathParam("id") long uploadId, @PathParam("entryId") String entryId) {
    String userId = getUserId();
    PartSequence partSequence = new PartSequence(userId, entryId);
    partSequence.delete();
    return Response.ok().build();
}
Also used : PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence)

Example 15 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class PartResource method getSequence.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/sequence")
public Response getSequence(@PathParam("id") final String partId, @DefaultValue("false") @QueryParam("remote") boolean isRemote, @QueryParam("token") String remoteUserToken, @QueryParam("userId") String remoteUserId, @QueryParam("folderId") long fid, @DefaultValue("true") @QueryParam("annotations") boolean includeAnnotations) {
    final FeaturedDNASequence sequence;
    final String userId = getUserId();
    Sequences sequences = new Sequences(userId);
    if (isRemote) {
        // entry exists remotely
        sequence = remoteEntries.getSequence(userId, fid, partId);
    } else {
        // what request is being responded to (local or remote)
        if (StringUtils.isEmpty(userId)) {
            RegistryPartner partner = requireWebPartner();
            if (StringUtils.isEmpty(remoteUserToken) || fid == 0) {
                sequence = new PartSequence(userId, partId).get(includeAnnotations);
            } else {
                sequence = sequences.getRequestedSequence(partner, remoteUserId, remoteUserToken, partId, fid);
            }
        } else {
            // user id can be null if partId is public
            sequence = new PartSequence(userId, partId).get(includeAnnotations);
        }
    }
    return Response.status(Response.Status.OK).entity(sequence).build();
}
Also used : PartTraceSequences(org.jbei.ice.lib.entry.sequence.PartTraceSequences) Sequences(org.jbei.ice.lib.entry.sequence.Sequences) TraceSequences(org.jbei.ice.lib.entry.sequence.analysis.TraceSequences) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Aggregations

PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)16 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 EntryType (org.jbei.ice.lib.dto.entry.EntryType)3 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)3 InputStreamWrapper (org.jbei.ice.lib.entry.sequence.InputStreamWrapper)3 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)2 EntryFieldLabel (org.jbei.ice.lib.dto.entry.EntryFieldLabel)2 Entry (org.jbei.ice.storage.model.Entry)2 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ZipEntry (java.util.zip.ZipEntry)1 javax.ws.rs (javax.ws.rs)1