Search on shared status (server)

This commit is contained in:
jendib 2013-08-15 18:33:58 +02:00
parent ea1e226b50
commit c14797bd5a
11 changed files with 203 additions and 22 deletions

View File

@ -123,17 +123,9 @@ public class DocumentDao {
Map<String, Object> parameterMap = new HashMap<String, Object>();
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 ");
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++;
}
}
sb.append(" left join T_SHARE s on s.SHA_IDDOCUMENT_C = d.DOC_ID_C and s.SHA_DELETEDATE_D is null ");
// Adds search criteria
if (criteria.getUserId() != null) {
@ -152,6 +144,18 @@ public class DocumentDao {
criteriaList.add("d.DOC_CREATEDATE_D <= :createDateMax");
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");
@ -173,6 +177,7 @@ public class DocumentDao {
documentDto.setTitle((String) o[i++]);
documentDto.setDescription((String) o[i++]);
documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
documentDto.setShared((Boolean) o[i++]);
documentDtoList.add(documentDto);
}

View File

@ -35,6 +35,11 @@ public class DocumentCriteria {
*/
private List<String> tagIdList;
/**
* Shared status.
*/
private Boolean shared;
/**
* Getter of userId.
*
@ -124,4 +129,22 @@ public class DocumentCriteria {
public void setTagIdList(List<String> 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;
}
}

View File

@ -28,6 +28,11 @@ public class DocumentDto {
* Creation date.
*/
private Long createTimestamp;
/**
* Shared status.
*/
private Boolean shared;
/**
* Getter de id.
@ -100,4 +105,22 @@ public class DocumentDto {
public void setCreateTimestamp(Long 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;
}
}

View File

@ -1 +1,2 @@
- Advanced search: shared documents (client/server)
- Advanced search: shared documents (client)
- Show shared status in documents list (client)

View File

@ -129,7 +129,8 @@ public class DocumentResource extends BaseResource {
@QueryParam("search") String search,
@QueryParam("create_date_min") String createDateMinStr,
@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()) {
throw new ForbiddenClientException();
}
@ -150,6 +151,7 @@ public class DocumentResource extends BaseResource {
documentCriteria.setCreateDateMin(createDateMin);
documentCriteria.setCreateDateMax(createDateMax);
documentCriteria.setTagIdList(tagIdList);
documentCriteria.setShared(shared);
if (!Strings.isNullOrEmpty(search)) {
documentCriteria.setSearch(search);
}
@ -161,6 +163,7 @@ public class DocumentResource extends BaseResource {
document.put("title", documentDto.getTitle());
document.put("description", documentDto.getDescription());
document.put("create_date", documentDto.getCreateTimestamp());
document.put("shared", documentDto.getShared());
// Get tags
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentDto.getId());

View File

@ -5,14 +5,14 @@
*/
var App = angular.module('docs',
// 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']
)
/**
* Configuring modules.
*/
.config(function($stateProvider, $httpProvider, $routeProvider, RestangularProvider) {
.config(function($stateProvider, $httpProvider, RestangularProvider) {
// Configuring UI Router
$stateProvider
.state('main', {

View File

@ -5,13 +5,13 @@
*/
var App = angular.module('share',
// Dependencies
['ui.state', 'ui.bootstrap', 'ui.route', 'restangular', 'ngSanitize', 'ngMobile']
['ui.state', 'ui.bootstrap', 'restangular', 'ngSanitize', 'ngMobile']
)
/**
* Configuring modules.
*/
.config(function($stateProvider, $httpProvider, $routeProvider, RestangularProvider) {
.config(function($stateProvider, $httpProvider, RestangularProvider) {
// Configuring UI Router
$stateProvider
.state('main', {

View 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 });
}
});
});

View 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>

View File

@ -58,6 +58,15 @@ public class TestDocumentResource extends BaseJerseyTest {
String document1Id = json.optString("id");
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
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
@ -114,6 +123,19 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertTrue(documents.length() == 1);
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)
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));

View File

@ -64,12 +64,12 @@ public class TestShareResource extends BaseJerseyTest {
String file1Id = json.getString("id");
// Share this document
WebResource fileShareResource = resource().path("/share");
fileShareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
WebResource shareResource = resource().path("/share");
shareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
postParams = new MultivaluedMapImpl();
postParams.add("id", document1Id);
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()));
json = response.getEntity(JSONObject.class);
String share1Id = json.getString("id");
@ -109,9 +109,9 @@ public class TestShareResource extends BaseJerseyTest {
Assert.assertEquals(163510, fileBytes.length);
// Deletes the share
fileShareResource = resource().path("/share/" + share1Id);
fileShareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
response = fileShareResource.delete(ClientResponse.class);
shareResource = resource().path("/share/" + share1Id);
shareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
response = shareResource.delete(ClientResponse.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.getEntity(JSONObject.class);
Assert.assertEquals("ok", json.getString("status"));