mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 22:07:56 +01:00
List orphan files
This commit is contained in:
parent
2347483676
commit
d0c259ead2
@ -125,6 +125,10 @@ public class FileDao {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<File> getByDocumentId(String documentId) {
|
public List<File> getByDocumentId(String documentId) {
|
||||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
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");
|
||||||
|
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");
|
Query q = em.createQuery("select f from File f where f.documentId = :documentId and f.deleteDate is null order by f.order asc");
|
||||||
q.setParameter("documentId", documentId);
|
q.setParameter("documentId", documentId);
|
||||||
return q.getResultList();
|
return q.getResultList();
|
||||||
|
@ -286,18 +286,22 @@ public class FileResource extends BaseResource {
|
|||||||
public Response list(
|
public Response list(
|
||||||
@QueryParam("id") String documentId,
|
@QueryParam("id") String documentId,
|
||||||
@QueryParam("share") String shareId) throws JSONException {
|
@QueryParam("share") String shareId) throws JSONException {
|
||||||
authenticate();
|
boolean authenticated = authenticate();
|
||||||
|
|
||||||
// Check document visibility
|
// Check document visibility
|
||||||
try {
|
if (documentId != null) {
|
||||||
DocumentDao documentDao = new DocumentDao();
|
try {
|
||||||
Document document = documentDao.getDocument(documentId);
|
DocumentDao documentDao = new DocumentDao();
|
||||||
ShareDao shareDao = new ShareDao();
|
Document document = documentDao.getDocument(documentId);
|
||||||
if (!shareDao.checkVisibility(document, principal.getId(), shareId)) {
|
ShareDao shareDao = new ShareDao();
|
||||||
throw new ForbiddenClientException();
|
if (!shareDao.checkVisibility(document, principal.getId(), shareId)) {
|
||||||
|
throw new ForbiddenClientException();
|
||||||
|
}
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
||||||
}
|
}
|
||||||
} catch (NoResultException e) {
|
} else if (!authenticated) {
|
||||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
throw new ForbiddenClientException();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDao fileDao = new FileDao();
|
FileDao fileDao = new FileDao();
|
||||||
|
@ -218,6 +218,16 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
JSONObject json = response.getEntity(JSONObject.class);
|
JSONObject json = response.getEntity(JSONObject.class);
|
||||||
String file1Id = json.getString("id");
|
String file1Id = json.getString("id");
|
||||||
|
|
||||||
|
// Get all orphan files
|
||||||
|
fileResource = resource().path("/file/list");
|
||||||
|
fileResource.addFilter(new CookieAuthenticationFilter(file2AuthenticationToken));
|
||||||
|
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
||||||
|
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
||||||
|
json = response.getEntity(JSONObject.class);
|
||||||
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
|
JSONArray files = json.getJSONArray("files");
|
||||||
|
Assert.assertEquals(1, files.length());
|
||||||
|
|
||||||
// Create a document
|
// Create a document
|
||||||
WebResource documentResource = resource().path("/document");
|
WebResource documentResource = resource().path("/document");
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(file2AuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(file2AuthenticationToken));
|
||||||
@ -242,12 +252,12 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
// Get all files from a document
|
// Get all files from a document
|
||||||
fileResource = resource().path("/file/list");
|
fileResource = resource().path("/file/list");
|
||||||
fileResource.addFilter(new CookieAuthenticationFilter(file2AuthenticationToken));
|
fileResource.addFilter(new CookieAuthenticationFilter(file2AuthenticationToken));
|
||||||
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
getParams = new MultivaluedMapImpl();
|
||||||
getParams.putSingle("id", document1Id);
|
getParams.putSingle("id", document1Id);
|
||||||
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
JSONArray files = json.getJSONArray("files");
|
files = json.getJSONArray("files");
|
||||||
Assert.assertEquals(1, files.length());
|
Assert.assertEquals(1, files.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user