mirror of
https://github.com/sismics/docs.git
synced 2025-12-14 10:16:21 +00:00
Orphan files are linked to a specific user
This commit is contained in:
@@ -61,6 +61,21 @@ public class FileDao {
|
||||
return (File) q.getSingleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an active file.
|
||||
*
|
||||
* @param id File ID
|
||||
* @param userId User ID
|
||||
* @return Document
|
||||
*/
|
||||
public File getFile(String id, String userId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
Query q = em.createQuery("select f from File f where f.id = :id and f.userId = :userId and f.deleteDate is null");
|
||||
q.setParameter("id", id);
|
||||
q.setParameter("userId", userId);
|
||||
return (File) q.getSingleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a file.
|
||||
*
|
||||
@@ -117,16 +132,18 @@ public class FileDao {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get files by document ID.
|
||||
* Get files by document ID or all orphan files of an user.
|
||||
*
|
||||
* @parma userId User ID
|
||||
* @param documentId Document ID
|
||||
* @return List of files
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<File> getByDocumentId(String documentId) {
|
||||
public List<File> getByDocumentId(String userId, String documentId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
if (documentId == null) {
|
||||
Query q = em.createQuery("select f from File f where f.documentId is null and f.deleteDate is null order by f.createDate asc");
|
||||
Query q = em.createQuery("select f from File f where f.documentId is null and f.deleteDate is null and f.userId = :userId order by f.createDate asc");
|
||||
q.setParameter("userId", userId);
|
||||
return q.getResultList();
|
||||
}
|
||||
Query q = em.createQuery("select f from File f where f.documentId = :documentId and f.deleteDate is null order by f.order asc");
|
||||
|
||||
@@ -27,9 +27,15 @@ public class File {
|
||||
/**
|
||||
* Document ID.
|
||||
*/
|
||||
@Column(name = "FIL_IDDOC_C", nullable = false, length = 36)
|
||||
@Column(name = "FIL_IDDOC_C", length = 36)
|
||||
private String documentId;
|
||||
|
||||
/**
|
||||
* User ID.
|
||||
*/
|
||||
@Column(name = "FIL_IDUSER_C", length = 36)
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* MIME type.
|
||||
*/
|
||||
@@ -186,6 +192,24 @@ public class File {
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter of userId.
|
||||
*
|
||||
* @return the userId
|
||||
*/
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter of userId.
|
||||
*
|
||||
* @param userId userId
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
alter table T_FILE alter column FIL_IDDOC_C set null;
|
||||
alter table T_FILE add column FIL_IDUSER_C varchar(36);
|
||||
update T_CONFIG set CFG_VALUE_C='7' where CFG_ID_C='DB_VERSION';
|
||||
|
||||
Reference in New Issue
Block a user