mirror of
https://github.com/sismics/docs.git
synced 2024-11-21 21:47:57 +01:00
Search on shared status (server)
This commit is contained in:
parent
ea1e226b50
commit
c14797bd5a
@ -123,17 +123,9 @@ public class DocumentDao {
|
|||||||
Map<String, Object> parameterMap = new HashMap<String, Object>();
|
Map<String, Object> parameterMap = new HashMap<String, Object>();
|
||||||
List<String> criteriaList = new ArrayList<String>();
|
List<String> criteriaList = new ArrayList<String>();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("select d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3");
|
StringBuilder sb = new StringBuilder("select d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, s.SHA_ID_C is not null c4 ");
|
||||||
sb.append(" from T_DOCUMENT d ");
|
sb.append(" from T_DOCUMENT d ");
|
||||||
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
|
sb.append(" left join T_SHARE s on s.SHA_IDDOCUMENT_C = d.DOC_ID_C and s.SHA_DELETEDATE_D is null ");
|
||||||
int index = 0;
|
|
||||||
for (String tagId : criteria.getTagIdList()) {
|
|
||||||
sb.append(" left join T_DOCUMENT_TAG dt" + index + " on dt" + index + ".DOT_IDDOCUMENT_C = d.DOC_ID_C and dt" + index + ".DOT_IDTAG_C = :tagId" + index + " ");
|
|
||||||
criteriaList.add("dt" + index + ".DOT_ID_C is not null");
|
|
||||||
parameterMap.put("tagId" + index, tagId);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds search criteria
|
// Adds search criteria
|
||||||
if (criteria.getUserId() != null) {
|
if (criteria.getUserId() != null) {
|
||||||
@ -152,6 +144,18 @@ public class DocumentDao {
|
|||||||
criteriaList.add("d.DOC_CREATEDATE_D <= :createDateMax");
|
criteriaList.add("d.DOC_CREATEDATE_D <= :createDateMax");
|
||||||
parameterMap.put("createDateMax", criteria.getCreateDateMax());
|
parameterMap.put("createDateMax", criteria.getCreateDateMax());
|
||||||
}
|
}
|
||||||
|
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
|
||||||
|
int index = 0;
|
||||||
|
for (String tagId : criteria.getTagIdList()) {
|
||||||
|
sb.append(" left join T_DOCUMENT_TAG dt" + index + " on dt" + index + ".DOT_IDDOCUMENT_C = d.DOC_ID_C and dt" + index + ".DOT_IDTAG_C = :tagId" + index + " ");
|
||||||
|
criteriaList.add("dt" + index + ".DOT_ID_C is not null");
|
||||||
|
parameterMap.put("tagId" + index, tagId);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (criteria.getShared() != null && criteria.getShared()) {
|
||||||
|
criteriaList.add("s.SHA_ID_C is not null");
|
||||||
|
}
|
||||||
|
|
||||||
criteriaList.add("d.DOC_DELETEDATE_D is null");
|
criteriaList.add("d.DOC_DELETEDATE_D is null");
|
||||||
|
|
||||||
@ -173,6 +177,7 @@ public class DocumentDao {
|
|||||||
documentDto.setTitle((String) o[i++]);
|
documentDto.setTitle((String) o[i++]);
|
||||||
documentDto.setDescription((String) o[i++]);
|
documentDto.setDescription((String) o[i++]);
|
||||||
documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
|
documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
|
||||||
|
documentDto.setShared((Boolean) o[i++]);
|
||||||
documentDtoList.add(documentDto);
|
documentDtoList.add(documentDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,11 @@ public class DocumentCriteria {
|
|||||||
*/
|
*/
|
||||||
private List<String> tagIdList;
|
private List<String> tagIdList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared status.
|
||||||
|
*/
|
||||||
|
private Boolean shared;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter of userId.
|
* Getter of userId.
|
||||||
*
|
*
|
||||||
@ -124,4 +129,22 @@ public class DocumentCriteria {
|
|||||||
public void setTagIdList(List<String> tagIdList) {
|
public void setTagIdList(List<String> tagIdList) {
|
||||||
this.tagIdList = tagIdList;
|
this.tagIdList = tagIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of shared.
|
||||||
|
*
|
||||||
|
* @return the shared
|
||||||
|
*/
|
||||||
|
public Boolean getShared() {
|
||||||
|
return shared;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter of shared.
|
||||||
|
*
|
||||||
|
* @param shared shared
|
||||||
|
*/
|
||||||
|
public void setShared(Boolean shared) {
|
||||||
|
this.shared = shared;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,11 @@ public class DocumentDto {
|
|||||||
* Creation date.
|
* Creation date.
|
||||||
*/
|
*/
|
||||||
private Long createTimestamp;
|
private Long createTimestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared status.
|
||||||
|
*/
|
||||||
|
private Boolean shared;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter de id.
|
* Getter de id.
|
||||||
@ -100,4 +105,22 @@ public class DocumentDto {
|
|||||||
public void setCreateTimestamp(Long createTimestamp) {
|
public void setCreateTimestamp(Long createTimestamp) {
|
||||||
this.createTimestamp = createTimestamp;
|
this.createTimestamp = createTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of shared.
|
||||||
|
*
|
||||||
|
* @return the shared
|
||||||
|
*/
|
||||||
|
public Boolean getShared() {
|
||||||
|
return shared;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter of shared.
|
||||||
|
*
|
||||||
|
* @param shared shared
|
||||||
|
*/
|
||||||
|
public void setShared(Boolean shared) {
|
||||||
|
this.shared = shared;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
- Advanced search: shared documents (client/server)
|
- Advanced search: shared documents (client)
|
||||||
|
- Show shared status in documents list (client)
|
@ -129,7 +129,8 @@ public class DocumentResource extends BaseResource {
|
|||||||
@QueryParam("search") String search,
|
@QueryParam("search") String search,
|
||||||
@QueryParam("create_date_min") String createDateMinStr,
|
@QueryParam("create_date_min") String createDateMinStr,
|
||||||
@QueryParam("create_date_max") String createDateMaxStr,
|
@QueryParam("create_date_max") String createDateMaxStr,
|
||||||
@QueryParam("tags") List<String> tagIdList) throws JSONException {
|
@QueryParam("tags") List<String> tagIdList,
|
||||||
|
@QueryParam("shared") Boolean shared) throws JSONException {
|
||||||
if (!authenticate()) {
|
if (!authenticate()) {
|
||||||
throw new ForbiddenClientException();
|
throw new ForbiddenClientException();
|
||||||
}
|
}
|
||||||
@ -150,6 +151,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
documentCriteria.setCreateDateMin(createDateMin);
|
documentCriteria.setCreateDateMin(createDateMin);
|
||||||
documentCriteria.setCreateDateMax(createDateMax);
|
documentCriteria.setCreateDateMax(createDateMax);
|
||||||
documentCriteria.setTagIdList(tagIdList);
|
documentCriteria.setTagIdList(tagIdList);
|
||||||
|
documentCriteria.setShared(shared);
|
||||||
if (!Strings.isNullOrEmpty(search)) {
|
if (!Strings.isNullOrEmpty(search)) {
|
||||||
documentCriteria.setSearch(search);
|
documentCriteria.setSearch(search);
|
||||||
}
|
}
|
||||||
@ -161,6 +163,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
document.put("title", documentDto.getTitle());
|
document.put("title", documentDto.getTitle());
|
||||||
document.put("description", documentDto.getDescription());
|
document.put("description", documentDto.getDescription());
|
||||||
document.put("create_date", documentDto.getCreateTimestamp());
|
document.put("create_date", documentDto.getCreateTimestamp());
|
||||||
|
document.put("shared", documentDto.getShared());
|
||||||
|
|
||||||
// Get tags
|
// Get tags
|
||||||
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentDto.getId());
|
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentDto.getId());
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
var App = angular.module('docs',
|
var App = angular.module('docs',
|
||||||
// Dependencies
|
// Dependencies
|
||||||
['ui.state', 'ui.bootstrap', 'ui.route', 'ui.keypress', 'ui.validate',
|
['ui.state', 'ui.bootstrap', 'ui.keypress', 'ui.validate',
|
||||||
'ui.sortable', 'restangular', 'ngSanitize', 'ngMobile', 'colorpicker.module']
|
'ui.sortable', 'restangular', 'ngSanitize', 'ngMobile', 'colorpicker.module']
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuring modules.
|
* Configuring modules.
|
||||||
*/
|
*/
|
||||||
.config(function($stateProvider, $httpProvider, $routeProvider, RestangularProvider) {
|
.config(function($stateProvider, $httpProvider, RestangularProvider) {
|
||||||
// Configuring UI Router
|
// Configuring UI Router
|
||||||
$stateProvider
|
$stateProvider
|
||||||
.state('main', {
|
.state('main', {
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
*/
|
*/
|
||||||
var App = angular.module('share',
|
var App = angular.module('share',
|
||||||
// Dependencies
|
// Dependencies
|
||||||
['ui.state', 'ui.bootstrap', 'ui.route', 'restangular', 'ngSanitize', 'ngMobile']
|
['ui.state', 'ui.bootstrap', 'restangular', 'ngSanitize', 'ngMobile']
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuring modules.
|
* Configuring modules.
|
||||||
*/
|
*/
|
||||||
.config(function($stateProvider, $httpProvider, $routeProvider, RestangularProvider) {
|
.config(function($stateProvider, $httpProvider, RestangularProvider) {
|
||||||
// Configuring UI Router
|
// Configuring UI Router
|
||||||
$stateProvider
|
$stateProvider
|
||||||
.state('main', {
|
.state('main', {
|
||||||
|
83
docs-web/src/main/webapp/app/share/controller/FileView.js
Normal file
83
docs-web/src/main/webapp/app/share/controller/FileView.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File view controller.
|
||||||
|
*/
|
||||||
|
App.controller('FileView', function($dialog, $state, $stateParams) {
|
||||||
|
var dialog = $dialog.dialog({
|
||||||
|
keyboard: true,
|
||||||
|
templateUrl: 'partial/share/file.view.html',
|
||||||
|
controller: function($scope, $state, $stateParams, Restangular, dialog) {
|
||||||
|
// Load files
|
||||||
|
Restangular.one('file').getList('list', { id: $stateParams.documentId, share: $stateParams.shareId }).then(function(data) {
|
||||||
|
$scope.files = data.files;
|
||||||
|
|
||||||
|
// Search current file
|
||||||
|
_.each($scope.files, function(value) {
|
||||||
|
if (value.id == $stateParams.fileId) {
|
||||||
|
$scope.file = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigate to the next file.
|
||||||
|
*/
|
||||||
|
$scope.nextFile = function() {
|
||||||
|
_.each($scope.files, function(value, key) {
|
||||||
|
if (value.id == $stateParams.fileId) {
|
||||||
|
var next = $scope.files[key + 1];
|
||||||
|
if (next) {
|
||||||
|
dialog.close({});
|
||||||
|
$state.transitionTo('share.file', { documentId: $stateParams.documentId, shareId: $stateParams.shareId, fileId: next.id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigate to the previous file.
|
||||||
|
*/
|
||||||
|
$scope.previousFile = function() {
|
||||||
|
_.each($scope.files, function(value, key) {
|
||||||
|
if (value.id == $stateParams.fileId) {
|
||||||
|
var previous = $scope.files[key - 1];
|
||||||
|
if (previous) {
|
||||||
|
dialog.close({});
|
||||||
|
$state.transitionTo('share.file', { documentId: $stateParams.documentId, shareId: $stateParams.shareId, fileId: previous.id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the file in a new window.
|
||||||
|
*/
|
||||||
|
$scope.openFile = function() {
|
||||||
|
window.open('api/file/' + $stateParams.fileId + '/data?share=' + $stateParams.shareId);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the file preview.
|
||||||
|
*/
|
||||||
|
$scope.closeFile = function () {
|
||||||
|
dialog.close();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Close the dialog when the user exits this state
|
||||||
|
var off = $scope.$on('$stateChangeStart', function(event, toState){
|
||||||
|
if (dialog.isOpen()) {
|
||||||
|
dialog.close(toState.name == 'share.file' ? {} : null);
|
||||||
|
}
|
||||||
|
off();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Returns to share view on file close
|
||||||
|
dialog.open().then(function(result) {
|
||||||
|
if (result == null) {
|
||||||
|
$state.transitionTo('share', { documentId: $stateParams.documentId, shareId: $stateParams.shareId });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
21
docs-web/src/main/webapp/partial/share/file.view.html
Normal file
21
docs-web/src/main/webapp/partial/share/file.view.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<div class="text-center">
|
||||||
|
<div class="btn-group pull-left">
|
||||||
|
<button type="button" class="btn" ng-click="closeFile()"><span class="icon-remove"></span></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="btn-group">
|
||||||
|
<button type="button" class="btn" ng-click="previousFile()">Previous</button>
|
||||||
|
<button type="button" class="btn" ng-click="nextFile()">Next</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="btn-group pull-right">
|
||||||
|
<button type="button" class="btn" ng-click="openFile()"><span class="icon-share"></span></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<img ng-if="$stateParams.fileId && (file.mimetype == 'image/png' || file.mimetype == 'image/jpeg' || file.mimetype == 'image/gif')" ng-src="api/file/{{ $stateParams.fileId }}/data?share={{ $stateParams.shareId }}" />
|
||||||
|
|
||||||
|
<div class="text-center" ng-if="$stateParams.fileId && file.mimetype == 'application/pdf'">
|
||||||
|
<img ng-src="api/file/{{ $stateParams.fileId }}/data?thumbnail=true&share={{ $stateParams.shareId }}" />
|
||||||
|
</div>
|
@ -58,6 +58,15 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
String document1Id = json.optString("id");
|
String document1Id = json.optString("id");
|
||||||
Assert.assertNotNull(document1Id);
|
Assert.assertNotNull(document1Id);
|
||||||
|
|
||||||
|
// Share this document
|
||||||
|
WebResource fileShareResource = resource().path("/share");
|
||||||
|
fileShareResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
|
postParams = new MultivaluedMapImpl();
|
||||||
|
postParams.add("id", document1Id);
|
||||||
|
response = fileShareResource.put(ClientResponse.class, postParams);
|
||||||
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
|
json = response.getEntity(JSONObject.class);
|
||||||
|
|
||||||
// List all documents
|
// List all documents
|
||||||
documentResource = resource().path("/document/list");
|
documentResource = resource().path("/document/list");
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
@ -114,6 +123,19 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
Assert.assertTrue(documents.length() == 1);
|
Assert.assertTrue(documents.length() == 1);
|
||||||
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
|
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
|
||||||
|
|
||||||
|
// Search documents by shared status
|
||||||
|
documentResource = resource().path("/document/list");
|
||||||
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
|
getParams = new MultivaluedMapImpl();
|
||||||
|
getParams.putSingle("shared", true);
|
||||||
|
response = documentResource.queryParams(getParams).get(ClientResponse.class);
|
||||||
|
json = response.getEntity(JSONObject.class);
|
||||||
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
|
documents = json.getJSONArray("documents");
|
||||||
|
Assert.assertTrue(documents.length() == 1);
|
||||||
|
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
|
||||||
|
Assert.assertEquals(true, documents.getJSONObject(0).getBoolean("shared"));
|
||||||
|
|
||||||
// Search documents (nothing)
|
// Search documents (nothing)
|
||||||
documentResource = resource().path("/document/list");
|
documentResource = resource().path("/document/list");
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
|
@ -64,12 +64,12 @@ public class TestShareResource extends BaseJerseyTest {
|
|||||||
String file1Id = json.getString("id");
|
String file1Id = json.getString("id");
|
||||||
|
|
||||||
// Share this document
|
// Share this document
|
||||||
WebResource fileShareResource = resource().path("/share");
|
WebResource shareResource = resource().path("/share");
|
||||||
fileShareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
|
shareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
|
||||||
postParams = new MultivaluedMapImpl();
|
postParams = new MultivaluedMapImpl();
|
||||||
postParams.add("id", document1Id);
|
postParams.add("id", document1Id);
|
||||||
postParams.add("name", "4 All");
|
postParams.add("name", "4 All");
|
||||||
response = fileShareResource.put(ClientResponse.class, postParams);
|
response = shareResource.put(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);
|
||||||
String share1Id = json.getString("id");
|
String share1Id = json.getString("id");
|
||||||
@ -109,9 +109,9 @@ public class TestShareResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(163510, fileBytes.length);
|
Assert.assertEquals(163510, fileBytes.length);
|
||||||
|
|
||||||
// Deletes the share
|
// Deletes the share
|
||||||
fileShareResource = resource().path("/share/" + share1Id);
|
shareResource = resource().path("/share/" + share1Id);
|
||||||
fileShareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
|
shareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
|
||||||
response = fileShareResource.delete(ClientResponse.class);
|
response = shareResource.delete(ClientResponse.class);
|
||||||
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);
|
||||||
Assert.assertEquals("ok", json.getString("status"));
|
Assert.assertEquals("ok", json.getString("status"));
|
||||||
|
Loading…
Reference in New Issue
Block a user