Closes #66: Search by creator

This commit is contained in:
jendib 2016-02-15 23:09:45 +01:00
parent d8d01b077d
commit ef3a592807
6 changed files with 32 additions and 90 deletions

View File

@ -259,6 +259,10 @@ public class DocumentDao {
criteriaList.add("d.DOC_LANGUAGE_C = :language"); criteriaList.add("d.DOC_LANGUAGE_C = :language");
parameterMap.put("language", criteria.getLanguage()); parameterMap.put("language", criteria.getLanguage());
} }
if (criteria.getCreatorId() != null) {
criteriaList.add("d.DOC_IDUSER_C = :creatorId");
parameterMap.put("creatorId", criteria.getCreatorId());
}
criteriaList.add("d.DOC_DELETEDATE_D is null"); criteriaList.add("d.DOC_DELETEDATE_D is null");

View File

@ -51,146 +51,79 @@ public class DocumentCriteria {
private String language; private String language;
/** /**
* Getter of userId. * Creator ID.
*
* @return userId
*/ */
private String creatorId;
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
/**
* Setter of userId.
*
* @param userId userId
*/
public void setUserId(String userId) { public void setUserId(String userId) {
this.userId = userId; this.userId = userId;
} }
/**
* Getter of search.
*
* @return the search
*/
public String getSearch() { public String getSearch() {
return search; return search;
} }
/**
* Setter of search.
*
* @param search search
*/
public void setSearch(String search) { public void setSearch(String search) {
this.search = search; this.search = search;
} }
/**
* Getter of fullSearch.
*
* @return the fullSearch
*/
public String getFullSearch() { public String getFullSearch() {
return fullSearch; return fullSearch;
} }
/**
* Setter of fullSearch.
*
* @param fullSearch fullSearch
*/
public void setFullSearch(String fullSearch) { public void setFullSearch(String fullSearch) {
this.fullSearch = fullSearch; this.fullSearch = fullSearch;
} }
/**
* Getter of createDateMin.
*
* @return the createDateMin
*/
public Date getCreateDateMin() { public Date getCreateDateMin() {
return createDateMin; return createDateMin;
} }
/**
* Setter of createDateMin.
*
* @param createDateMin createDateMin
*/
public void setCreateDateMin(Date createDateMin) { public void setCreateDateMin(Date createDateMin) {
this.createDateMin = createDateMin; this.createDateMin = createDateMin;
} }
/**
* Getter of createDateMax.
*
* @return the createDateMax
*/
public Date getCreateDateMax() { public Date getCreateDateMax() {
return createDateMax; return createDateMax;
} }
/**
* Setter of createDateMax.
*
* @param createDateMax createDateMax
*/
public void setCreateDateMax(Date createDateMax) { public void setCreateDateMax(Date createDateMax) {
this.createDateMax = createDateMax; this.createDateMax = createDateMax;
} }
/**
* Getter of tagIdList.
*
* @return the tagIdList
*/
public List<String> getTagIdList() { public List<String> getTagIdList() {
return tagIdList; return tagIdList;
} }
/**
* Setter of tagIdList.
*
* @param tagIdList tagIdList
*/
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() { public Boolean getShared() {
return shared; return shared;
} }
/**
* Setter of shared.
*
* @param shared shared
*/
public void setShared(Boolean shared) { public void setShared(Boolean shared) {
this.shared = shared; this.shared = shared;
} }
/**
* Getter of language.
*
* @return the language
*/
public String getLanguage() { public String getLanguage() {
return language; return language;
} }
/**
* Setter of language.
*
* @param language language
*/
public void setLanguage(String language) { public void setLanguage(String language) {
this.language = language; this.language = language;
} }
public String getCreatorId() {
return creatorId;
}
public void setCreatorId(String creatorId) {
this.creatorId = creatorId;
}
} }

View File

@ -13,20 +13,10 @@ public class UserCriteria {
*/ */
private String search; private String search;
/**
* Getter of search.
*
* @return the search
*/
public String getSearch() { public String getSearch() {
return search; return search;
} }
/**
* Setter of search.
*
* @param search search
*/
public UserCriteria setSearch(String search) { public UserCriteria setSearch(String search) {
this.search = search; this.search = search;
return this; return this;

View File

@ -295,6 +295,7 @@ public class DocumentResource extends BaseResource {
} }
TagDao tagDao = new TagDao(); TagDao tagDao = new TagDao();
UserDao userDao = new UserDao();
DateTimeParser[] parsers = { DateTimeParser[] parsers = {
DateTimeFormat.forPattern("yyyy").getParser(), DateTimeFormat.forPattern("yyyy").getParser(),
DateTimeFormat.forPattern("yyyy-MM").getParser(), DateTimeFormat.forPattern("yyyy-MM").getParser(),
@ -370,6 +371,16 @@ public class DocumentResource extends BaseResource {
if (Constants.SUPPORTED_LANGUAGES.contains(params[1])) { if (Constants.SUPPORTED_LANGUAGES.contains(params[1])) {
documentCriteria.setLanguage(params[1]); documentCriteria.setLanguage(params[1]);
} }
} else if (params[0].equals("by")) {
// New creator criteria
User user = userDao.getActiveByUsername(params[1]);
if (user == null) {
// This user doesn't exists, return nothing
documentCriteria.setCreatorId(UUID.randomUUID().toString());
} else {
// This user exists, search its documents
documentCriteria.setCreatorId(user.getId());
}
} else if (params[0].equals("full")) { } else if (params[0].equals("full")) {
// New full content search criteria // New full content search criteria
fullQuery.add(params[1]); fullQuery.add(params[1]);

View File

@ -26,7 +26,8 @@
tag:car<br/> tag:car<br/>
full:led<br/> full:led<br/>
shared:yes<br/> shared:yes<br/>
lang:fra"></span> lang:fra<br/>
by:user1"></span>
</span> </span>
<input type="search" class="form-control" placeholder="Search" ng-model="search" /> <input type="search" class="form-control" placeholder="Search" ng-model="search" />
<span class="input-group-addon"> <span class="input-group-addon">

View File

@ -55,7 +55,7 @@ public class TestDocumentResource extends BaseJerseyTest {
String tag1Id = json.getString("id"); String tag1Id = json.getString("id");
Assert.assertNotNull(tag1Id); Assert.assertNotNull(tag1Id);
// Create a document // Create a document with document1
long create1Date = new Date().getTime(); long create1Date = new Date().getTime();
json = target().path("/document").request() json = target().path("/document").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
@ -176,6 +176,9 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertEquals(1, searchDocuments("software", document1Token)); Assert.assertEquals(1, searchDocuments("software", document1Token));
Assert.assertEquals(1, searchDocuments("greenland", document1Token)); Assert.assertEquals(1, searchDocuments("greenland", document1Token));
Assert.assertEquals(1, searchDocuments("public domain", document1Token)); Assert.assertEquals(1, searchDocuments("public domain", document1Token));
Assert.assertEquals(0, searchDocuments("by:document3", document1Token));
Assert.assertEquals(1, searchDocuments("by:document1", document1Token));
Assert.assertEquals(0, searchDocuments("by:nobody", document1Token));
Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy").print(new Date().getTime()), document1Token)); Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy").print(new Date().getTime()), document1Token));
Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy-MM").print(new Date().getTime()), document1Token)); Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy-MM").print(new Date().getTime()), document1Token));
Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy-MM-dd").print(new Date().getTime()), document1Token)); Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy-MM-dd").print(new Date().getTime()), document1Token));