Search in sources :

Example 1 with PartTraceSequences

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

the class PartResource method getTraces.

/**
 * @return traces for the part
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/traces")
public Response getTraces(@PathParam("id") final long partId, @DefaultValue("100") @QueryParam("limit") int limit, @DefaultValue("0") @QueryParam("start") int start) {
    final String userId = getUserId();
    PartTraceSequences partTraceSequences = new PartTraceSequences(userId, partId);
    Results<TraceSequenceAnalysis> results = partTraceSequences.getTraces(start, limit);
    // hack for trace sequence viewer without having to modify it
    if (StringUtils.isEmpty(sessionId))
        return super.respond(new ArrayList<>(results.getData()));
    return super.respond(results);
}
Also used : ArrayList(java.util.ArrayList) PartTraceSequences(org.jbei.ice.lib.entry.sequence.PartTraceSequences)

Example 2 with PartTraceSequences

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

the class PartResource method addTraceSequence.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/traces")
public Response addTraceSequence(@PathParam("id") final long partId, @FormDataParam("file") final InputStream fileInputStream, @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) {
    final String userId = getUserId();
    final String fileName = contentDispositionHeader.getFileName();
    final String tmpDir = Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY);
    final File file = Paths.get(tmpDir, fileName).toFile();
    try {
        FileUtils.copyInputStreamToFile(fileInputStream, file);
    } catch (final IOException e) {
        Logger.error(e);
        return respond(Response.Status.INTERNAL_SERVER_ERROR);
    }
    PartTraceSequences partTraceSequences = new PartTraceSequences(userId, partId);
    final boolean success = partTraceSequences.addTraceSequence(file, fileName);
    return respond(success);
}
Also used : IOException(java.io.IOException) File(java.io.File) PartTraceSequences(org.jbei.ice.lib.entry.sequence.PartTraceSequences)

Example 3 with PartTraceSequences

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

the class PartResource method getAllTraces.

@GET
@Path("/{id}/traces/all")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getAllTraces(@PathParam("id") final long partId, @QueryParam("sid") String sid) {
    if (StringUtils.isEmpty(sessionId))
        sessionId = sid;
    final String userId = requireUserId();
    PartTraceSequences partTraceSequences = new PartTraceSequences(userId, partId);
    try (ByteArrayOutputStream outputStream = partTraceSequences.getAll()) {
        StreamingOutput stream = outputStream::writeTo;
        return Response.ok(stream).header("Content-Disposition", "attachment;filename=\"data.zip\"").build();
    } catch (IOException e) {
        Logger.error(e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) PartTraceSequences(org.jbei.ice.lib.entry.sequence.PartTraceSequences)

Aggregations

PartTraceSequences (org.jbei.ice.lib.entry.sequence.PartTraceSequences)3 IOException (java.io.IOException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1