Skip to content

Commit

Permalink
Specify document search parameter as HTTP params (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Kirch authored Oct 19, 2023
1 parent f9b5a52 commit 04c43eb
Show file tree
Hide file tree
Showing 23 changed files with 1,086 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public DocumentDto getDocument(String id, PermType perm, List<String> targetIdLi
}

EntityManager em = ThreadLocalContext.get().getEntityManager();
StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C, d.DOC_TITLE_C, d.DOC_DESCRIPTION_C, d.DOC_SUBJECT_C, d.DOC_IDENTIFIER_C, d.DOC_PUBLISHER_C, d.DOC_FORMAT_C, d.DOC_SOURCE_C, d.DOC_TYPE_C, d.DOC_COVERAGE_C, d.DOC_RIGHTS_C, d.DOC_CREATEDATE_D, d.DOC_UPDATEDATE_D, d.DOC_LANGUAGE_C, ");
StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C, d.DOC_TITLE_C, d.DOC_DESCRIPTION_C, d.DOC_SUBJECT_C, d.DOC_IDENTIFIER_C, d.DOC_PUBLISHER_C, d.DOC_FORMAT_C, d.DOC_SOURCE_C, d.DOC_TYPE_C, d.DOC_COVERAGE_C, d.DOC_RIGHTS_C, d.DOC_CREATEDATE_D, d.DOC_UPDATEDATE_D, d.DOC_LANGUAGE_C, d.DOC_IDFILE_C,");
sb.append(" (select count(s.SHA_ID_C) from T_SHARE s, T_ACL ac where ac.ACL_SOURCEID_C = d.DOC_ID_C and ac.ACL_TARGETID_C = s.SHA_ID_C and ac.ACL_DELETEDATE_D is null and s.SHA_DELETEDATE_D is null) shareCount, ");
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) fileCount, ");
sb.append(" u.USE_USERNAME_C ");
Expand Down Expand Up @@ -121,6 +121,7 @@ public DocumentDto getDocument(String id, PermType perm, List<String> targetIdLi
documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
documentDto.setUpdateTimestamp(((Timestamp) o[i++]).getTime());
documentDto.setLanguage((String) o[i++]);
documentDto.setFileId((String) o[i++]);
documentDto.setShared(((Number) o[i++]).intValue() > 0);
documentDto.setFileCount(((Number) o[i++]).intValue());
documentDto.setCreator((String) o[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DocumentCriteria {
/**
* Search query.
*/
private String search;
private String simpleSearch;

/**
* Full content search query.
Expand Down Expand Up @@ -96,12 +96,12 @@ public void setTargetIdList(List<String> targetIdList) {
this.targetIdList = targetIdList;
}

public String getSearch() {
return search;
public String getSimpleSearch() {
return simpleSearch;
}

public void setSearch(String search) {
this.search = search;
public void setSimpleSearch(String search) {
this.simpleSearch = search;
}

public String getFullSearch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ public void findByCriteria(PaginatedList<DocumentDto> paginatedList, List<String
criteriaList.add("(a.ACL_ID_C is not null or a2.ACL_ID_C is not null)");
}
parameterMap.put("targetIdList", criteria.getTargetIdList());

if (!Strings.isNullOrEmpty(criteria.getSearch()) || !Strings.isNullOrEmpty(criteria.getFullSearch())) {
documentSearchMap = search(criteria.getSearch(), criteria.getFullSearch());
if (!Strings.isNullOrEmpty(criteria.getSimpleSearch()) || !Strings.isNullOrEmpty(criteria.getFullSearch())) {
documentSearchMap = search(criteria.getSimpleSearch(), criteria.getFullSearch());
if (documentSearchMap.isEmpty()) {
// If the search doesn't find any document, the request should return nothing
documentSearchMap.put(UUID.randomUUID().toString(), null);
Expand Down Expand Up @@ -413,14 +412,14 @@ private void suggestSearchTerms(String search, List<String> suggestionList) thro
/**
* Fulltext search in files and documents.
*
* @param searchQuery Search query on metadatas
* @param simpleSearchQuery Search query on metadatas
* @param fullSearchQuery Search query on all fields
* @return Map of document IDs as key and highlight as value
* @throws Exception e
*/
private Map<String, String> search(String searchQuery, String fullSearchQuery) throws Exception {
private Map<String, String> search(String simpleSearchQuery, String fullSearchQuery) throws Exception {
// The fulltext query searches in all fields
searchQuery = searchQuery + " " + fullSearchQuery;
String searchQuery = simpleSearchQuery + " " + fullSearchQuery;

// Build search query
Analyzer analyzer = new StandardAnalyzer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static <E> void executeCountQuery(PaginatedList<E> paginatedList, QueryP
}

/**
* Executes a query and returns the data of the currunt page.
* Executes a query and returns the data of the current page.
*
* @param paginatedList Paginated list object containing parameters, and into which results are added by side effects
* @param queryParam Query parameters
Expand All @@ -82,18 +82,6 @@ private static <E> List<Object[]> executeResultQuery(PaginatedList<E> paginatedL
q.setMaxResults(paginatedList.getLimit());
return q.getResultList();
}

/**
* Executes a paginated request with 2 native queries (one to count the number of results, and one to return the page).
*
* @param paginatedList Paginated list object containing parameters, and into which results are added by side effects
* @param queryParam Query parameters
* @return List of results
*/
public static <E> List<Object[]> executePaginatedQuery(PaginatedList<E> paginatedList, QueryParam queryParam) {
executeCountQuery(paginatedList, queryParam);
return executeResultQuery(paginatedList, queryParam);
}

/**
* Executes a paginated request with 2 native queries (one to count the number of results, and one to return the page).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public abstract class BaseTransactionalTest extends BaseTest {
@Before
public void setUp() throws Exception {
public void setUp() {
// Initialize the entity manager
EntityManager em = EMF.get().createEntityManager();
ThreadLocalContext context = ThreadLocalContext.get();
Expand All @@ -40,7 +40,8 @@ public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
public void tearDown() {
ThreadLocalContext.get().getEntityManager().getTransaction().rollback();
}

protected User createUser(String userName) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public abstract class BaseJerseyTest extends JerseyTest {
* Test mail server.
*/
private Wiser wiser;


public String adminToken() {
return clientUtil.login("admin", "admin", false);
}

@Override
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
return new ExternalTestContainerFactory();
Expand Down
Loading

0 comments on commit 04c43eb

Please sign in to comment.