use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class BulkFileSBOLUpload method processUpload.
public long processUpload() throws IOException {
BulkUploads controller = new BulkUploads();
long bulkUploadId = 0;
SBOLDocument document = SBOLFactory.read(inputStream);
try {
// walk top level object
for (SBOLRootObject rootObject : document.getContents()) {
ICESBOLParserVisitor visitor = new ICESBOLParserVisitor(addType);
rootObject.accept(visitor);
BulkUploadAutoUpdate update = visitor.getUpdate();
update.setBulkUploadId(bulkUploadId);
Logger.info(userId + ": " + update.toString());
update = controller.autoUpdateBulkUpload(userId, update);
if (bulkUploadId == 0)
bulkUploadId = update.getBulkUploadId();
// get "user sequence"
// todo : sequence user
String sequenceUser = getSequenceDocument(rootObject);
// DNASequence dnaSequence = visitor.getFeaturedDNASequence();
// Sequence sequence = Sequences.dnaSequenceToSequence(dnaSequence);
// // Entry entry = DAOFactory.getEntryDAO().get(entryId);
// // sequence.setEntry(entry);
// if (sequenceUser != null)
// sequence.setSequenceUser(sequenceUser);
new PartSequence(userId, Long.toString(update.getEntryId())).update(visitor.getFeaturedDNASequence(), false);
}
} catch (Exception e) {
Logger.error(e);
throw new IOException(e);
}
return bulkUploadId;
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class BulkUploadEntries method saveSequence.
private void saveSequence(PartData data, Entry entry, HashMap<String, InputStream> files) throws IOException {
// check main entry
if (!StringUtils.isEmpty(data.getSequenceFileName())) {
String sequenceName = data.getSequenceFileName();
PartSequence partSequence = new PartSequence(entry.getOwnerEmail(), entry.getRecordId());
partSequence.parseSequenceFile(files.get(sequenceName), sequenceName, false);
}
// check linked
if (data.getLinkedParts() != null && !data.getLinkedParts().isEmpty()) {
Iterator<Entry> entryIterator = entry.getLinkedEntries().iterator();
if (entryIterator.hasNext()) {
saveSequence(data.getLinkedParts().get(0), entryIterator.next(), files);
}
}
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class EntriesAsCSV method customize.
public ByteArrayOutputStream customize(EntrySelection selection, SequenceFormat format, boolean onePerFolder) throws IOException {
Entries retriever = new Entries(this.userId);
this.entries = retriever.getEntriesFromSelectionContext(selection);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
for (long entryId : this.entries) {
// get the entry
Entry entry = DAOFactory.getEntryDAO().get(entryId);
if (entry == null) {
// write to csv file
Logger.error("ERROR : no entry " + entryId);
continue;
}
if (!sequenceDAO.hasSequence(entry.getId())) {
continue;
}
// get the sequence
InputStreamWrapper wrapper = new PartSequence(userId, Long.toString(entryId)).toFile(format, onePerFolder);
if (wrapper == null) {
Logger.error("ERROR : no sequence " + entryId);
continue;
}
if (onePerFolder)
wrapper.setName(entry.getPartNumber() + File.separatorChar + wrapper.getName());
else
wrapper.setName(wrapper.getName());
putZipEntry(wrapper, zos);
}
this.includeSequences = false;
writeList(selection.getFields().toArray(new EntryFieldLabel[0]));
// write the csv file to zip file
FileInputStream fis = new FileInputStream(csvPath.toFile());
InputStreamWrapper wrapper = new InputStreamWrapper(fis, "entries.csv");
putZipEntry(wrapper, zos);
}
return baos;
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class EntriesAsCSV method writeZip.
private void writeZip(Set<Long> sequenceSet) {
Path tmpPath = Paths.get(Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY));
try {
File tmpZip = File.createTempFile("zip-", ".zip", tmpPath.toFile());
// out
FileOutputStream fos = new FileOutputStream(tmpZip);
ZipOutputStream zos = new ZipOutputStream(fos);
// get sequence formats
for (long entryId : sequenceSet) {
for (String format : formats) {
InputStreamWrapper wrapper = new PartSequence(userId, Long.toString(entryId)).toFile(SequenceFormat.fromString(format), true);
putZipEntry(wrapper, zos);
}
}
// 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();
} catch (Exception e) {
Logger.error(e);
}
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class BulkEntryCreator method saveFiles.
protected void saveFiles(PartData data, Entry entry, HashMap<String, InputStream> files) {
// check sequence
try {
String sequenceName = data.getSequenceFileName();
if (!StringUtils.isBlank(sequenceName)) {
PartSequence partSequence = new PartSequence(entry.getOwnerEmail(), entry.getRecordId());
partSequence.parseSequenceFile(files.get(sequenceName), sequenceName);
}
} catch (IOException e) {
Logger.error(e);
}
// check attachment
try {
if (data.getAttachments() != null && !data.getAttachments().isEmpty()) {
String attachmentName = data.getAttachments().get(0).getFilename();
InputStream attachmentStream = files.get(attachmentName);
// clear
List<Attachment> attachments = DAOFactory.getAttachmentDAO().getByEntry(entry);
if (attachments != null && !attachments.isEmpty()) {
for (Attachment attachment : attachments) {
String dataDir = Utils.getConfigValue(ConfigurationKey.DATA_DIRECTORY);
File attachmentDir = Paths.get(dataDir, "attachments").toFile();
DAOFactory.getAttachmentDAO().delete(attachmentDir, attachment);
}
}
Attachment attachment = new Attachment();
attachment.setEntry(entry);
attachment.setDescription("");
String fileId = Utils.generateUUID();
attachment.setFileId(fileId);
attachment.setFileName(attachmentName);
String dataDir = Utils.getConfigValue(ConfigurationKey.DATA_DIRECTORY);
File attachmentDir = Paths.get(dataDir, "attachments").toFile();
DAOFactory.getAttachmentDAO().save(attachmentDir, attachment, attachmentStream);
}
} catch (Exception e) {
Logger.error(e);
}
}
Aggregations