use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.
the class EntryLinks method getParents.
/**
* Retrieves list of this entry's parents that user has read access to
*
* @return list of parents of entry
*/
public List<PartData> getParents() {
List<Entry> parents = this.entryDAO.getParents(this.entry.getId());
List<PartData> parentData = new ArrayList<>(parents.size());
for (Entry parent : parents) {
if (!entryAuthorization.canRead(this.userId, parent))
continue;
parentData.add(parent.toDataTransferObject());
}
return parentData;
}
use of org.jbei.ice.lib.dto.entry.PartData 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.dto.entry.PartData in project ice by JBEI.
the class RemoteEntries method getPublicEntries.
public PartnerEntries getPublicEntries(long remoteId, int offset, int limit, String sort, boolean asc) {
if (!hasRemoteAccessEnabled())
return null;
RemotePartner partner = this.remotePartnerDAO.get(remoteId);
if (partner == null)
return null;
FolderDetails details;
try {
final String restPath = "rest/folders/public/entries";
HashMap<String, Object> queryParams = new HashMap<>();
queryParams.put("offset", offset);
queryParams.put("limit", limit);
queryParams.put("asc", asc);
queryParams.put("sort", sort);
details = this.remoteContact.getFolderEntries(partner.getUrl(), restPath, queryParams, partner.getApiKey());
if (details == null)
return null;
} catch (Exception e) {
Logger.error(e);
return null;
}
Results<PartData> results = new Results<>();
results.setData(details.getEntries());
results.setResultCount(details.getCount());
return new PartnerEntries(partner.toDataTransferObject(), results);
}
use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.
the class RemoteEntriesAsCSV method writeDataEntries.
protected void writeDataEntries(RemotePartner partner, List<PartData> entries, List<EntryField> 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 (EntryField 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 = SequenceController.dnaSequenceToSequence(featuredDNASequence);
GenbankFormatter genbankFormatter = new GenbankFormatter(name);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
genbankFormatter.format(sequence, byteStream);
ByteArrayWrapper wrapper = new ByteArrayWrapper(byteStream.toByteArray(), 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.dto.entry.PartData in project ice by JBEI.
the class WebEntries method getPart.
/**
* Checks the local database for the entry with id <code>recordId</code>
* If it exists locally and is public, it returns it. Otherwise it checks the
* other ICE instances that it partners with, in turn, to see if it exists on there
*
* @param recordId unique record identifier for the desired entry
* @return entry details if found, else null
* @throws PermissionException if the entry exists locally but is not a public entry
*/
public PartData getPart(String recordId) {
// check local first
Entry entry = this.entryDAO.getByRecordId(recordId);
if (entry != null && entry.getVisibility() != Visibility.REMOTE.getValue()) {
PermissionsController permissionsController = new PermissionsController();
if (permissionsController.isPubliclyVisible(entry))
return ModelToInfoFactory.getInfo(entry);
}
List<RemotePartner> partners = this.remotePartnerDAO.getRegistryPartners();
for (RemotePartner partner : partners) {
if (partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
continue;
PartData partData = this.remoteContact.getPublicEntry(partner.getUrl(), recordId, partner.getApiKey());
// if the part is just a remote then the main one is on some other ICE instance
if (partData == null || partData.getVisibility() == Visibility.REMOTE)
continue;
return partData;
}
return null;
}
Aggregations