mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 22:07:56 +01:00
Order of files attached to document
This commit is contained in:
parent
6c976087de
commit
2347483676
@ -80,32 +80,12 @@ public class FileDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the content of a file.
|
* Update a file.
|
||||||
*
|
*
|
||||||
* @param file File to update
|
* @param file File to update
|
||||||
* @return Updated file
|
* @return Updated file
|
||||||
*/
|
*/
|
||||||
public File updateContent(File file) {
|
public File update(File file) {
|
||||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
|
||||||
|
|
||||||
// Get the file
|
|
||||||
Query q = em.createQuery("select f from File f where f.id = :id and f.deleteDate is null");
|
|
||||||
q.setParameter("id", file.getId());
|
|
||||||
File fileFromDb = (File) q.getSingleResult();
|
|
||||||
|
|
||||||
// Update the file
|
|
||||||
fileFromDb.setContent(file.getContent());
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the document of a file.
|
|
||||||
*
|
|
||||||
* @param file File to update
|
|
||||||
* @return Updated file
|
|
||||||
*/
|
|
||||||
public File updateDocument(File file) {
|
|
||||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||||
|
|
||||||
// Get the file
|
// Get the file
|
||||||
@ -115,6 +95,8 @@ public class FileDao {
|
|||||||
|
|
||||||
// Update the file
|
// Update the file
|
||||||
fileFromDb.setDocumentId(file.getDocumentId());
|
fileFromDb.setDocumentId(file.getDocumentId());
|
||||||
|
fileFromDb.setContent(file.getContent());
|
||||||
|
fileFromDb.setOrder(file.getOrder());
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ public class FileCreatedAsyncListener {
|
|||||||
final File file = fileCreatedAsyncEvent.getFile();
|
final File file = fileCreatedAsyncEvent.getFile();
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
final String content = FileUtil.extractContent(fileCreatedAsyncEvent.getDocument(), file, fileCreatedAsyncEvent.getInputStream());
|
final String content = FileUtil.extractContent(fileCreatedAsyncEvent.getDocument(), file, fileCreatedAsyncEvent.getInputStream());
|
||||||
|
fileCreatedAsyncEvent.getInputStream().close();
|
||||||
log.info(MessageFormat.format("File content extracted in {0}ms", System.currentTimeMillis() - startTime));
|
log.info(MessageFormat.format("File content extracted in {0}ms", System.currentTimeMillis() - startTime));
|
||||||
|
|
||||||
// Store the OCR-ization result in the database
|
// Store the OCR-ization result in the database
|
||||||
@ -48,7 +49,7 @@ public class FileCreatedAsyncListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
FileDao fileDao = new FileDao();
|
FileDao fileDao = new FileDao();
|
||||||
file.setContent(content);
|
file.setContent(content);
|
||||||
fileDao.updateContent(file);
|
fileDao.update(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -204,9 +204,9 @@ public class FileResource extends BaseResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the file
|
// Update the file
|
||||||
// TODO Reorder files to put the new one at the end
|
|
||||||
file.setDocumentId(documentId);
|
file.setDocumentId(documentId);
|
||||||
fileDao.updateDocument(file);
|
file.setOrder(fileDao.getByDocumentId(documentId).size());
|
||||||
|
fileDao.update(file);
|
||||||
|
|
||||||
// Raise a new file created event (it wasn't sent during file creation)
|
// Raise a new file created event (it wasn't sent during file creation)
|
||||||
try {
|
try {
|
||||||
|
@ -238,5 +238,16 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
response = documentResource.post(ClientResponse.class, postParams);
|
response = documentResource.post(ClientResponse.class, postParams);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
|
|
||||||
|
// Get all files from a document
|
||||||
|
fileResource = resource().path("/file/list");
|
||||||
|
fileResource.addFilter(new CookieAuthenticationFilter(file2AuthenticationToken));
|
||||||
|
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
||||||
|
getParams.putSingle("id", document1Id);
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user