Search in sources :

Example 1 with SequenceController

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

the class EntryCreator method copyPart.

/**
     * Creates a copy of
     *
     * @param userId   identifier for user making request
     * @param sourceId unique identifier for part acting as source of copy. Can be the part id, uuid or id
     * @return wrapper around the id and record id of the newly created entry
     * @throws IllegalArgumentException if the source part for the copy cannot be located using the identifier
     */
public PartData copyPart(String userId, String sourceId) {
    Entry entry = getEntry(sourceId);
    if (entry == null)
        throw new IllegalArgumentException("Could not retrieve entry \"" + sourceId + "\" for copy");
    // check permission (expecting read permission)
    entryAuthorization.expectRead(userId, entry);
    Sequence sequence = null;
    if (sequenceDAO.hasSequence(entry.getId())) {
        sequence = sequenceDAO.getByEntry(entry);
    }
    // copy to data model and back ??
    PartData partData = ModelToInfoFactory.getInfo(entry);
    entry = InfoToModelFactory.infoToEntry(partData);
    // create entry
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    entry.setName(entry.getName() + " (copy)");
    entry.setRecordId(Utils.generateUUID());
    entry.setVersionId(entry.getRecordId());
    entry.setOwnerEmail(account.getEmail());
    entry.setOwner(account.getFullName());
    entry = createEntry(account, entry, new ArrayList<>());
    // check sequence
    if (sequence != null) {
        SequenceController sequenceController = new SequenceController();
        FeaturedDNASequence dnaSequence = sequenceController.sequenceToDNASequence(sequence);
        sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
        sequence.setEntry(entry);
        sequenceDAO.saveSequence(sequence);
        BlastPlus.scheduleBlastIndexRebuildTask(true);
    }
    PartData copy = new PartData(EntryType.nameToType(entry.getRecordType()));
    copy.setId(entry.getId());
    copy.setRecordId(entry.getRecordId());
    return copy;
}
Also used : PartData(org.jbei.ice.lib.dto.entry.PartData) ArrayList(java.util.ArrayList) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 2 with SequenceController

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

the class EntriesAsCSV method writeZip.

private boolean writeZip(String userId, Set<Long> sequenceSet) {
    SequenceController sequenceController = new SequenceController();
    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) {
                ByteArrayWrapper wrapper = sequenceController.getSequenceFile(userId, entryId, format);
                putZipEntry(wrapper, zos);
            }
        }
        // write the csv file
        FileInputStream fis = new FileInputStream(csvPath.toFile());
        ByteArrayWrapper wrapper = new ByteArrayWrapper(IOUtils.toByteArray(fis), "entries.csv");
        putZipEntry(wrapper, zos);
        zos.close();
        csvPath = tmpZip.toPath();
        return true;
    } catch (Exception e) {
        Logger.error(e);
        return false;
    }
}
Also used : Path(java.nio.file.Path) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) ZipOutputStream(java.util.zip.ZipOutputStream) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController)

Aggregations

SequenceController (org.jbei.ice.lib.entry.sequence.SequenceController)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 ByteArrayWrapper (org.jbei.ice.lib.entry.sequence.ByteArrayWrapper)1