Search in sources :

Example 1 with Entry

use of org.jbei.ice.storage.model.Entry in project ice by JBEI.

the class EntryLinks method removeLink.

/**
     * Removes link specified entry id based on the specified type
     *
     * @param partToRemove unique identifier for part to remove
     * @param linkType     type of relationship that exists
     * @return true, if entry is removed successfully.
     */
public boolean removeLink(long partToRemove, LinkType linkType) {
    entryAuthorization.expectWrite(userId, entry);
    Entry linkedEntry = entryDAO.get(partToRemove);
    switch(linkType) {
        case PARENT:
            return linkedEntry.getLinkedEntries().remove(entry) && entryDAO.update(linkedEntry) != null;
        case CHILD:
        default:
            return entry.getLinkedEntries().remove(linkedEntry) && entryDAO.update(entry) != null;
    }
}
Also used : Entry(org.jbei.ice.storage.model.Entry)

Example 2 with Entry

use of org.jbei.ice.storage.model.Entry 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 3 with Entry

use of org.jbei.ice.storage.model.Entry in project ice by JBEI.

the class EntryPermissionTask method execute.

@Override
public void execute() {
    // check if user has write privileges on entries
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    List<Group> accountGroups = new GroupController().getAllGroups(account);
    boolean checkIndividual = false;
    if (account.getType() != AccountType.ADMIN && !permissionDAO.canWrite(account, accountGroups, entries)) {
        checkIndividual = true;
    }
    EntryDAO entryDAO = DAOFactory.getEntryDAO();
    EntryAuthorization entryAuthorization = new EntryAuthorization();
    for (long entryId : entries) {
        Entry entry = entryDAO.get(entryId);
        if (entry == null)
            continue;
        // check permission on individual entries
        if (checkIndividual && !entryAuthorization.canWrite(userId, entry)) {
            continue;
        }
        // add or remove permissions
        if (this.isAdd) {
            addPermissions(entry);
        } else {
            removePermissions(entry);
        }
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Example 4 with Entry

use of org.jbei.ice.storage.model.Entry in project ice by JBEI.

the class EntryLinks method addLink.

/**
     * Adds a link for the specified entry (or creates a new entry) of the type specified
     *
     * @param partData data for entry to be linked. If the id does not point to an existing entry, a new one will be
     *                 created and linked to this entry
     * @param type     type of link to create. If <code>CHILD</code> (default) is specified, then the entry in the parameter
     *                 is added as a child in the hierarchy; if <code>PARENT</code> is specified, then the entry is
     *                 add as a parent in the hierarchy.
     * @return true, if the two entries are successfully linked. false, if the specified hierarchy is not compatible
     * with the types of the link specified e.g. an plasmid cannot be added as a <code>PARENT</code> of a strain
     * @throws org.jbei.ice.lib.access.PermissionException if the user does not have write permissions
     *                                                     on at least one of the entries being linked
     */
public boolean addLink(PartData partData, LinkType type) {
    long linkId = partData.getId();
    Entry linkedEntry = this.entryDAO.get(linkId);
    if (linkedEntry == null) {
        // todo : create a new entry
        Logger.error("Could not retrieve entry for linking: " + linkId);
        return false;
    }
    if (linkedEntry.getId() == this.entry.getId())
        throw new IllegalArgumentException("Cannot link and entry to itself");
    // should have write permissions on the main entry but only read on the entry being linked
    entryAuthorization.expectRead(userId, linkedEntry);
    entryAuthorization.expectWrite(userId, entry);
    // add as parent
    switch(type) {
        case PARENT:
            return addParentEntry(linkedEntry);
        // add as child. default behavior
        case CHILD:
        default:
            return addChildEntry(linkedEntry);
    }
}
Also used : Entry(org.jbei.ice.storage.model.Entry)

Example 5 with Entry

use of org.jbei.ice.storage.model.Entry in project ice by JBEI.

the class FileResource method getSBOLVisual.

@GET
@Produces("image/png")
@Path("sbolVisual/{rid}")
public Response getSBOLVisual(@PathParam("rid") String recordId) {
    final String tmpDir = Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY);
    final Entry entry = DAOFactory.getEntryDAO().getByRecordId(recordId);
    final Sequence sequence = entry.getSequence();
    final String hash = sequence.getFwdHash();
    final File png = Paths.get(tmpDir, hash + ".png").toFile();
    if (png.exists()) {
        return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
    }
    final URI uri = PigeonSBOLv.generatePigeonVisual(sequence);
    if (uri != null) {
        try (final InputStream in = uri.toURL().openStream();
            final OutputStream out = new FileOutputStream(png)) {
            ByteStreams.copy(in, out);
        } catch (IOException e) {
            Logger.error(e);
            return respond(false);
        }
        return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
    }
    return respond(false);
}
Also used : Entry(org.jbei.ice.storage.model.Entry) RemoteSequence(org.jbei.ice.lib.net.RemoteSequence) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) Sequence(org.jbei.ice.storage.model.Sequence) TraceSequence(org.jbei.ice.storage.model.TraceSequence) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) URI(java.net.URI)

Aggregations

Entry (org.jbei.ice.storage.model.Entry)64 PartData (org.jbei.ice.lib.dto.entry.PartData)22 Account (org.jbei.ice.storage.model.Account)21 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)15 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)8 DAOException (org.jbei.ice.storage.DAOException)6 Group (org.jbei.ice.storage.model.Group)6 Parameter (org.jbei.ice.storage.model.Parameter)6 Part (org.jbei.ice.storage.model.Part)6 IOException (java.io.IOException)5 HibernateException (org.hibernate.HibernateException)5 GroupController (org.jbei.ice.lib.group.GroupController)5 EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)5 BulkUpload (org.jbei.ice.storage.model.BulkUpload)5 Folder (org.jbei.ice.storage.model.Folder)5 Sequence (org.jbei.ice.storage.model.Sequence)4 HashSet (java.util.HashSet)3 Session (org.hibernate.Session)3 FullTextQuery (org.hibernate.search.FullTextQuery)3