From 870a44da0d520befbc41e007a63fa468487742f5 Mon Sep 17 00:00:00 2001 From: jendib Date: Thu, 22 Aug 2013 17:59:24 +0200 Subject: [PATCH] Return file count on GET /document/list --- .../sismics/docs/core/dao/jpa/DocumentDao.java | 4 +++- .../docs/core/dao/jpa/dto/DocumentDto.java | 18 ++++++++++++++++++ docs-parent/TODO | 2 +- .../docs/rest/resource/DocumentResource.java | 1 + .../webapp/app/docs/controller/Navigation.js | 3 ++- .../docs/rest/TestDocumentResource.java | 1 + 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java index 944592e1..53e6290e 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java @@ -145,7 +145,8 @@ public class DocumentDao { Map parameterMap = new HashMap(); List criteriaList = new ArrayList(); - StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, s.SHA_ID_C is not null c5 "); + StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, s.SHA_ID_C is not null c5, "); + sb.append(" (select count(f.FIL_ID_C) from T_FILE f where f.FIL_DELETEDATE_D is null and f.FIL_IDDOC_C = d.DOC_ID_C) c6 "); sb.append(" from T_DOCUMENT d "); sb.append(" left join T_SHARE s on s.SHA_IDDOCUMENT_C = d.DOC_ID_C and s.SHA_DELETEDATE_D is null "); @@ -211,6 +212,7 @@ public class DocumentDao { documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime()); documentDto.setLanguage((String) o[i++]); documentDto.setShared((Boolean) o[i++]); + documentDto.setFileCount(((Number) o[i++]).intValue()); documentDtoList.add(documentDto); } diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java index 289ff400..ae4e56e5 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java @@ -39,6 +39,8 @@ public class DocumentDto { */ private Boolean shared; + private Integer fileCount; + /** * Getter de id. * @@ -146,4 +148,20 @@ public class DocumentDto { public void setLanguage(String language) { this.language = language; } + + /** + * Getter of fileCount. + * @return fileCount + */ + public Integer getFileCount() { + return fileCount; + } + + /** + * Setter of fileCount. + * @param fileCount fileCount + */ + public void setFileCount(Integer fileCount) { + this.fileCount = fileCount; + } } diff --git a/docs-parent/TODO b/docs-parent/TODO index 06560279..a6640a3d 100644 --- a/docs-parent/TODO +++ b/docs-parent/TODO @@ -1 +1 @@ -- Show number of files on documents list (client/server) \ No newline at end of file +- Show number of files on documents list (client) \ No newline at end of file diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java index 4dce379e..8e09ae70 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java @@ -171,6 +171,7 @@ public class DocumentResource extends BaseResource { document.put("create_date", documentDto.getCreateTimestamp()); document.put("shared", documentDto.getShared()); document.put("language", documentDto.getLanguage()); + document.put("file_count", documentDto.getFileCount()); // Get tags List tagDtoList = tagDao.getByDocumentId(documentDto.getId()); diff --git a/docs-web/src/main/webapp/app/docs/controller/Navigation.js b/docs-web/src/main/webapp/app/docs/controller/Navigation.js index a6319db4..43858a9a 100644 --- a/docs-web/src/main/webapp/app/docs/controller/Navigation.js +++ b/docs-web/src/main/webapp/app/docs/controller/Navigation.js @@ -16,7 +16,8 @@ App.controller('Navigation', function($scope, $http, $state, $rootScope, User, R setInterval(function() { $scope.$apply(function() { Restangular.one('app/log').get({ - limit: 100, + // Error count will be wrong if there is more than 10 errors in 10 seconds + limit: 10, level: 'ERROR' }).then(function(data) { // Add new errors diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java index 8add0093..78ba8535 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java @@ -109,6 +109,7 @@ public class TestDocumentResource extends BaseJerseyTest { Assert.assertTrue(documents.length() == 1); Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id")); Assert.assertEquals("eng", documents.getJSONObject(0).getString("language")); + Assert.assertEquals(1, documents.getJSONObject(0).getInt("file_count")); Assert.assertEquals(1, tags.length()); Assert.assertEquals(tag1Id, tags.getJSONObject(0).getString("id")); Assert.assertEquals("SuperTag", tags.getJSONObject(0).getString("name"));