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