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