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();
}
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;
}
Aggregations