mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
Search on tags (server)
This commit is contained in:
parent
990a1c3aa5
commit
4dc5cb12b3
@ -112,6 +112,9 @@ public class DocumentDao {
|
||||
|
||||
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");
|
||||
sb.append(" from T_DOCUMENT d ");
|
||||
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
|
||||
sb.append(" left join T_DOCUMENT_TAG dt on dt.DOT_IDDOCUMENT_C = d.DOC_ID_C ");
|
||||
}
|
||||
|
||||
// Adds search criteria
|
||||
List<String> criteriaList = new ArrayList<String>();
|
||||
@ -132,6 +135,10 @@ public class DocumentDao {
|
||||
criteriaList.add("d.DOC_CREATEDATE_D <= :createDateMax");
|
||||
parameterMap.put("createDateMax", criteria.getCreateDateMax());
|
||||
}
|
||||
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
|
||||
criteriaList.add("dt.DOT_IDTAG_C in :tagIdList");
|
||||
parameterMap.put("tagIdList", criteria.getTagIdList());
|
||||
}
|
||||
|
||||
criteriaList.add("d.DOC_DELETEDATE_D is null");
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.sismics.docs.core.dao.jpa.criteria;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -29,6 +30,11 @@ public class DocumentCriteria {
|
||||
*/
|
||||
private Date createDateMax;
|
||||
|
||||
/**
|
||||
* Tag IDs.
|
||||
*/
|
||||
private List<String> tagIdList;
|
||||
|
||||
/**
|
||||
* Getter of userId.
|
||||
*
|
||||
@ -100,4 +106,22 @@ public class DocumentCriteria {
|
||||
public void setCreateDateMax(Date createDateMax) {
|
||||
this.createDateMax = createDateMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter of tagIdList.
|
||||
*
|
||||
* @return the tagIdList
|
||||
*/
|
||||
public List<String> getTagIdList() {
|
||||
return tagIdList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter of tagIdList.
|
||||
*
|
||||
* @param tagIdList tagIdList
|
||||
*/
|
||||
public void setTagIdList(List<String> tagIdList) {
|
||||
this.tagIdList = tagIdList;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
|
||||
hibernate.connection.url=jdbc:hsqldb:mem:dùs
|
||||
hibernate.connection.url=jdbc:hsqldb:mem:docs
|
||||
hibernate.connection.username=sa
|
||||
hibernate.connection.password=
|
||||
hibernate.hbm2ddl.auto=none
|
||||
|
@ -1,3 +1,3 @@
|
||||
- Client/server side search on tags
|
||||
- Client side search on tags
|
||||
- Client/server side edition of existing tag names
|
||||
- Server side reordering files
|
@ -108,7 +108,8 @@ public class DocumentResource extends BaseResource {
|
||||
@QueryParam("asc") Boolean asc,
|
||||
@QueryParam("search") String search,
|
||||
@QueryParam("create_date_min") String createDateMinStr,
|
||||
@QueryParam("create_date_max") String createDateMaxStr) throws JSONException {
|
||||
@QueryParam("create_date_max") String createDateMaxStr,
|
||||
@QueryParam("tags[]") List<String> tagIdList) throws JSONException {
|
||||
if (!authenticate()) {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
@ -127,6 +128,7 @@ public class DocumentResource extends BaseResource {
|
||||
documentCriteria.setUserId(principal.getId());
|
||||
documentCriteria.setCreateDateMin(createDateMin);
|
||||
documentCriteria.setCreateDateMax(createDateMax);
|
||||
documentCriteria.setTagIdList(tagIdList);
|
||||
if (!Strings.isNullOrEmpty(search)) {
|
||||
documentCriteria.setSearch(search);
|
||||
}
|
||||
|
@ -98,6 +98,18 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
Assert.assertTrue(documents.length() == 1);
|
||||
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
|
||||
|
||||
// Search documents by tag
|
||||
documentResource = resource().path("/document/list");
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
getParams = new MultivaluedMapImpl();
|
||||
getParams.putSingle("tags[]", tag1Id);
|
||||
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"));
|
||||
|
||||
// Search documents (nothing)
|
||||
documentResource = resource().path("/document/list");
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
|
Loading…
Reference in New Issue
Block a user