Search in sources :

Example 6 with PartSequence

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;
}
Also used : SBOLDocument(org.sbolstandard.core.SBOLDocument) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) SBOLRootObject(org.sbolstandard.core.SBOLRootObject) ICESBOLParserVisitor(org.jbei.ice.lib.parsers.sbol.ICESBOLParserVisitor) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with PartSequence

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);
        }
    }
}
Also used : Entry(org.jbei.ice.storage.model.Entry) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence)

Example 8 with PartSequence

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;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) ZipEntry(java.util.zip.ZipEntry) InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) ZipOutputStream(java.util.zip.ZipOutputStream) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) EntryFieldLabel(org.jbei.ice.lib.dto.entry.EntryFieldLabel)

Example 9 with PartSequence

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);
    }
}
Also used : Path(java.nio.file.Path) InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) ZipOutputStream(java.util.zip.ZipOutputStream) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence)

Example 10 with PartSequence

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);
    }
}
Also used : InputStream(java.io.InputStream) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) PermissionException(org.jbei.ice.lib.access.PermissionException)

Aggregations

PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)16 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 EntryType (org.jbei.ice.lib.dto.entry.EntryType)3 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)3 InputStreamWrapper (org.jbei.ice.lib.entry.sequence.InputStreamWrapper)3 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)2 EntryFieldLabel (org.jbei.ice.lib.dto.entry.EntryFieldLabel)2 Entry (org.jbei.ice.storage.model.Entry)2 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ZipEntry (java.util.zip.ZipEntry)1 javax.ws.rs (javax.ws.rs)1