use of org.jbei.ice.lib.entry.sequence.InputStreamWrapper in project ice by JBEI.
the class FileResource method getAttachment.
@GET
@Path("attachment/{fileId}")
public Response getAttachment(@PathParam("fileId") String fileId) {
String userId = requireUserId();
try {
InputStreamWrapper wrapper = attachments.getAttachmentByFileId(userId, fileId);
if (wrapper == null) {
return respond(Response.Status.NOT_FOUND);
}
StreamingOutput stream = output -> IOUtils.copy(wrapper.getInputStream(), output);
return addHeaders(Response.ok(stream), wrapper.getName());
} catch (IOException e) {
Logger.error(e);
throw new WebApplicationException(e);
}
}
use of org.jbei.ice.lib.entry.sequence.InputStreamWrapper in project ice by JBEI.
the class RemoteEntriesAsCSV method writeDataEntries.
protected void writeDataEntries(RemotePartner partner, List<PartData> entries, List<EntryFieldLabel> fields, CSVWriter writer, ZipOutputStream zos) {
if (entries == null)
return;
for (PartData partData : entries) {
String[] line = new String[fields.size() + 4];
line[0] = partner.getUrl();
line[1] = new Date(partData.getCreationTime()).toString();
line[2] = partData.getPartId();
int i = 2;
for (EntryFieldLabel field : fields) {
line[i + 1] = PartDataUtil.entryFieldToValue(partData, field);
i += 1;
}
// write sequence to zip file
if (partData.isHasSequence()) {
try {
// get remote sequence
FeaturedDNASequence featuredDNASequence = remoteEntries.getPublicEntrySequence(partner.getId(), Long.toString(partData.getId()));
if (featuredDNASequence != null) {
String name = partData.getPartId() + ".gb";
// write sequence to zip
line[i + 1] = name;
Sequence sequence = SequenceUtil.dnaSequenceToSequence(featuredDNASequence);
GenbankFormatter genbankFormatter = new GenbankFormatter(name);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
genbankFormatter.format(sequence, byteStream);
ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray());
InputStreamWrapper wrapper = new InputStreamWrapper(inputStream, name);
putZipEntry(wrapper, zos);
} else {
line[i + 1] = "";
}
} catch (Exception e) {
line[i + 1] = "";
}
} else {
line[i + 1] = "";
}
writer.writeNext(line);
}
}
use of org.jbei.ice.lib.entry.sequence.InputStreamWrapper in project ice by JBEI.
the class RemoteEntriesAsCSV method writeZip.
private boolean writeZip(File tmpZip, ZipOutputStream zos) {
try {
// write the csv file
FileInputStream fis = new FileInputStream(csvPath.toFile());
InputStreamWrapper wrapper = new InputStreamWrapper(fis, "entries.csv");
putZipEntry(wrapper, zos);
zos.close();
csvPath = tmpZip.toPath();
return true;
} catch (Exception e) {
Logger.error(e);
return false;
}
}
use of org.jbei.ice.lib.entry.sequence.InputStreamWrapper in project ice by JBEI.
the class RemoteSequence method get.
public InputStreamWrapper get(String type) {
FeaturedDNASequence featuredDNASequence = remoteContact.getPublicEntrySequence(partner.getUrl(), Long.toString(remotePartId), partner.getApiKey());
if (featuredDNASequence == null)
return new InputStreamWrapper(new byte[] { '\0' }, "no_sequence");
String name = featuredDNASequence.getName();
try {
Sequence sequence = SequenceUtil.dnaSequenceToSequence(featuredDNASequence);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
AbstractFormatter formatter;
switch(type.toLowerCase()) {
case "genbank":
default:
name = name + ".gb";
formatter = new GenbankFormatter(name);
break;
case "fasta":
formatter = new FastaFormatter();
break;
case "sbol1":
formatter = new SBOLFormatter();
name = name + ".xml";
break;
case "sbol2":
formatter = new SBOL2Formatter();
name = name + ".xml";
break;
case "gff3":
formatter = new GFF3Formatter();
name = name + ".gff3";
break;
}
formatter.format(sequence, byteStream);
return new InputStreamWrapper(byteStream.toByteArray(), name);
} catch (Exception e) {
Logger.error(e);
return new InputStreamWrapper(new byte[] { '\0' }, "no_sequence");
}
}
use of org.jbei.ice.lib.entry.sequence.InputStreamWrapper in project ice by JBEI.
the class RemoteTransfer method performTransfer.
/**
* Transfers the sequence file for the part and any parts that are linked to it.
* If the attached sequence was uploaded as a file or pasted, the system
* transfers that. If not if attempts to convert the attached sequence to genbank format
* and transfers that
*
* @param partner destination for the sequence transfer
* @param data data for part whose sequences are to be transferred
*/
protected void performTransfer(RemotePartner partner, PartData data) {
String url = partner.getUrl();
// check main entry for sequence
if (sequenceDAO.hasSequence(data.getId())) {
InputStreamWrapper wrapper = new SequenceAsString(SequenceFormat.GENBANK, data.getId(), true).get();
if (wrapper != null && wrapper.getInputStream() != null) {
try {
String sequenceString = new String(wrapper.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
remoteContact.transferSequence(url, data.getRecordId(), data.getType(), sequenceString);
} catch (IOException e) {
Logger.error("Cannot transfer sequence", e);
}
}
}
// check child entries
if (data.getLinkedParts() == null)
return;
for (PartData linked : data.getLinkedParts()) {
performTransfer(partner, linked);
}
}
Aggregations