Search in sources :

Example 6 with Attachment

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

the class AttachmentController method delete.

public boolean delete(String userId, long partId, long attachmentId) {
    Attachment attachment = dao.get(attachmentId);
    if (attachment == null)
        return false;
    if (attachment.getEntry().getId() != partId)
        return false;
    entryAuthorization.expectWrite(userId, attachment.getEntry());
    String dataDir = Utils.getConfigValue(ConfigurationKey.DATA_DIRECTORY);
    File attachmentDir = Paths.get(dataDir, attachmentDirName).toFile();
    try {
        dao.delete(attachmentDir, attachment);
        return true;
    } catch (Exception e) {
        return false;
    }
}
Also used : Attachment(org.jbei.ice.storage.model.Attachment) File(java.io.File) PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 7 with Attachment

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

the class AttachmentDAO method getByFileId.

/**
     * Retrieves attachment referenced by a unique file identifier
     *
     * @param fileId unique file identifier
     * @return retrieved attachment; null if none is found or there is a problem retrieving
     * the attachment
     */
public Attachment getByFileId(String fileId) {
    try {
        CriteriaQuery<Attachment> query = getBuilder().createQuery(Attachment.class);
        Root<Attachment> from = query.from(Attachment.class);
        query.where(getBuilder().equal(from.get("fileId"), fileId));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException("Failed to retrieve attachment by fileId: " + fileId, e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Attachment(org.jbei.ice.storage.model.Attachment)

Aggregations

Attachment (org.jbei.ice.storage.model.Attachment)7 HibernateException (org.hibernate.HibernateException)3 DAOException (org.jbei.ice.storage.DAOException)3 File (java.io.File)2 PermissionException (org.jbei.ice.lib.access.PermissionException)1 Entry (org.jbei.ice.storage.model.Entry)1