use of org.jbei.ice.storage.model.Attachment in project ice by JBEI.
the class AttachmentDAO method getByEntry.
/**
* Retrieve all {@link Attachment}s associated with the given {@link Entry}.
*
* @param entry Entry whose attachments are desired
* @return ArrayList of Attachments.
* @throws DAOException
*/
public List<Attachment> getByEntry(Entry entry) {
try {
CriteriaQuery<Attachment> query = getBuilder().createQuery(Attachment.class);
Root<Attachment> from = query.from(Attachment.class);
query.where(getBuilder().equal(from.get("entry"), entry));
query.orderBy(getBuilder().desc(from.get("id")));
return currentSession().createQuery(query).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to retrieve attachment by entry: " + entry.getId(), e);
}
}
use of org.jbei.ice.storage.model.Attachment in project ice by JBEI.
the class AttachmentDAO method hasAttachment.
public boolean hasAttachment(Entry entry) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Attachment> from = query.from(Attachment.class);
query.select(getBuilder().countDistinct(from.get("id"))).where(getBuilder().equal(from.get("entry"), entry));
return currentSession().createQuery(query).uniqueResult() > 0;
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to retrieve attachment by entry: " + entry.getId(), e);
}
}
use of org.jbei.ice.storage.model.Attachment in project ice by JBEI.
the class AttachmentController method getAttachmentByFileId.
/**
* Retrieves a previously uploaded attachment to an entry by it's unique file identifier
* This file identifier is assigned on upload
*
* @return Attachment file if one is found with the identifier, null otherwise (including if the user making
* the request does not have read permissions on the entry that this attachment is associated with)
*/
public File getAttachmentByFileId(String userId, String fileId) {
Attachment attachment = dao.getByFileId(fileId);
if (attachment == null)
return null;
entryAuthorization.expectRead(userId, attachment.getEntry());
String dataDir = Utils.getConfigValue(ConfigurationKey.DATA_DIRECTORY);
File attachmentDir = Paths.get(dataDir, attachmentDirName).toFile();
return dao.getFile(attachmentDir, attachment);
}
use of org.jbei.ice.storage.model.Attachment in project ice by JBEI.
the class AttachmentController method getFileName.
public String getFileName(String userId, String fileId) {
Attachment attachment = dao.getByFileId(fileId);
if (attachment == null)
return null;
entryAuthorization.expectRead(userId, attachment.getEntry());
return dao.getByFileId(fileId).getFileName();
}
use of org.jbei.ice.storage.model.Attachment in project ice by JBEI.
the class AttachmentController method addAttachmentToEntry.
public AttachmentInfo addAttachmentToEntry(String userId, long partId, AttachmentInfo info) {
Entry entry = entryDAO.get(partId);
entryAuthorization.expectRead(userId, entry);
// todo : make sure file at /fileId exists
Attachment attachment = new Attachment();
attachment.setEntry(entry);
if (StringUtils.isEmpty(info.getDescription()))
attachment.setDescription("");
else
attachment.setDescription(info.getDescription());
attachment.setFileName(info.getFilename());
attachment.setFileId(info.getFileId());
// tODO : information about who added the file
return dao.create(attachment).toDataTransferObject();
}
Aggregations