Search in sources :

Example 1 with EntriesAsCSV

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

the class FileResource method downloadCSV.

/**
     * Extracts the csv information and writes it to the temp dir and returns the file uuid. Then
     * the client is expected to make another rest call with the uuid in a separate window. This
     * workaround is due to not being able to download files using XHR or sumsuch
     */
@POST
@Path("csv")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response downloadCSV(@QueryParam("sequenceFormats") final List<String> sequenceFormats, @QueryParam("entryFields") final List<String> fields, EntrySelection selection) {
    String userId = super.requireUserId();
    EntriesAsCSV entriesAsCSV = new EntriesAsCSV(sequenceFormats.toArray(new String[sequenceFormats.size()]));
    List<EntryField> entryFields = new ArrayList<>();
    try {
        if (fields != null) {
            entryFields.addAll(fields.stream().map(EntryField::fromString).collect(Collectors.toList()));
        }
    } catch (Exception e) {
        Logger.error(e);
    }
    boolean success = entriesAsCSV.setSelectedEntries(userId, selection, entryFields.toArray(new EntryField[entryFields.size()]));
    if (!success)
        return super.respond(false);
    final File file = entriesAsCSV.getFilePath().toFile();
    if (file.exists()) {
        return Response.ok(new Setting("key", file.getName())).build();
    }
    return Response.serverError().build();
}
Also used : Setting(org.jbei.ice.lib.dto.Setting) ArrayList(java.util.ArrayList) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV) EntryField(org.jbei.ice.lib.dto.entry.EntryField)

Example 2 with EntriesAsCSV

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

the class Manuscripts method generateZip.

public Manuscript generateZip(long id) {
    ManuscriptModel model = dao.get(id);
    if (model == null)
        return null;
    // get folder
    List<Long> entryIds = this.folderDAO.getFolderContentIds(model.getFolder().getId(), null, true);
    EntriesAsCSV entriesAsCSV = new EntriesAsCSV("GENBANK", "SBOL2");
    entriesAsCSV.setEntries(this.userId, entryIds);
    Manuscript manuscript = model.toDataTransferObject();
    manuscript.setZipFileName(entriesAsCSV.getFilePath().getFileName().toString());
    return manuscript;
}
Also used : ManuscriptModel(org.jbei.ice.storage.model.ManuscriptModel) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV)

Aggregations

EntriesAsCSV (org.jbei.ice.lib.entry.EntriesAsCSV)2 ArrayList (java.util.ArrayList)1 Setting (org.jbei.ice.lib.dto.Setting)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 ManuscriptModel (org.jbei.ice.storage.model.ManuscriptModel)1