Search in sources :

Example 1 with PartData

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;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData)

Example 2 with PartData

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;
}
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 3 with PartData

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);
}
Also used : HashMap(java.util.HashMap) Results(org.jbei.ice.lib.dto.common.Results) RemotePartner(org.jbei.ice.storage.model.RemotePartner) PartData(org.jbei.ice.lib.dto.entry.PartData) PartnerEntries(org.jbei.ice.lib.dto.web.PartnerEntries) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 4 with PartData

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);
    }
}
Also used : GenbankFormatter(org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) PartData(org.jbei.ice.lib.dto.entry.PartData) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Date(java.util.Date) EntryField(org.jbei.ice.lib.dto.entry.EntryField)

Example 5 with PartData

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;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) RemotePartner(org.jbei.ice.storage.model.RemotePartner) PartData(org.jbei.ice.lib.dto.entry.PartData) PermissionsController(org.jbei.ice.lib.access.PermissionsController)

Aggregations

PartData (org.jbei.ice.lib.dto.entry.PartData)62 Entry (org.jbei.ice.storage.model.Entry)22 Account (org.jbei.ice.storage.model.Account)18 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 Results (org.jbei.ice.lib.dto.common.Results)5 EntryField (org.jbei.ice.lib.dto.entry.EntryField)4 Group (org.jbei.ice.storage.model.Group)4 Strain (org.jbei.ice.storage.model.Strain)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 PermissionException (org.jbei.ice.lib.access.PermissionException)3 SearchResult (org.jbei.ice.lib.dto.search.SearchResult)3 SearchResults (org.jbei.ice.lib.dto.search.SearchResults)3 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)3 GroupController (org.jbei.ice.lib.group.GroupController)3 EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)3 Plasmid (org.jbei.ice.storage.model.Plasmid)3 RemotePartner (org.jbei.ice.storage.model.RemotePartner)3