mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 17:56:20 +00:00
File sharing (in progress)
This commit is contained in:
@@ -56,12 +56,12 @@ public class FileDao {
|
||||
public void delete(String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
// Get the document
|
||||
// Get the file
|
||||
Query q = em.createQuery("select f from File f where f.id = :id and f.deleteDate is null");
|
||||
q.setParameter("id", id);
|
||||
File fileDb = (File) q.getSingleResult();
|
||||
|
||||
// Delete the document
|
||||
// Delete the file
|
||||
Date dateNow = new Date();
|
||||
fileDb.setDeleteDate(dateNow);
|
||||
}
|
||||
@@ -69,8 +69,8 @@ public class FileDao {
|
||||
/**
|
||||
* Gets a file by its ID.
|
||||
*
|
||||
* @param id Document ID
|
||||
* @return Document
|
||||
* @param id File ID
|
||||
* @return File
|
||||
*/
|
||||
public File getById(String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.sismics.docs.core.dao.jpa;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import com.sismics.docs.core.model.jpa.FileShare;
|
||||
import com.sismics.util.context.ThreadLocalContext;
|
||||
|
||||
/**
|
||||
* File share DAO.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class FileShareDao {
|
||||
/**
|
||||
* Creates a new file share.
|
||||
*
|
||||
* @param fileShare File share
|
||||
* @return New ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public String create(FileShare fileShare) {
|
||||
// Create the UUID
|
||||
fileShare.setId(UUID.randomUUID().toString());
|
||||
|
||||
// Create the file
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
fileShare.setCreateDate(new Date());
|
||||
em.persist(fileShare);
|
||||
|
||||
return fileShare.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an active file share.
|
||||
*
|
||||
* @param id File ID
|
||||
* @return Document
|
||||
*/
|
||||
public FileShare getFileShare(String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
Query q = em.createQuery("select fs from FileShare fs where fs.id = :id and fs.deleteDate is null");
|
||||
q.setParameter("id", id);
|
||||
return (FileShare) q.getSingleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a file share.
|
||||
*
|
||||
* @param id File ID
|
||||
*/
|
||||
public void delete(String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
// Get the document
|
||||
Query q = em.createQuery("select fs from FileShare fs where fs.id = :id and fs.deleteDate is null");
|
||||
q.setParameter("id", id);
|
||||
FileShare fileShareDb = (FileShare) q.getSingleResult();
|
||||
|
||||
// Delete the document
|
||||
Date dateNow = new Date();
|
||||
fileShareDb.setDeleteDate(dateNow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a file share by its ID.
|
||||
*
|
||||
* @param id Document ID
|
||||
* @return Document
|
||||
*/
|
||||
public FileShare getById(String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
try {
|
||||
return em.find(FileShare.class, id);
|
||||
} catch (NoResultException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file shares by file ID.
|
||||
*
|
||||
* @param fileId File ID
|
||||
* @return List of file shares
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<FileShare> getByFileId(String fileId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
Query q = em.createQuery("select fs from FileShare fs where fs.fileId = :fileId and fs.deleteDate is null");
|
||||
q.setParameter("fileId", fileId);
|
||||
return q.getResultList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user