mirror of
https://github.com/sismics/docs.git
synced 2025-12-14 10:16:21 +00:00
#176: search by tags and all associated children
This commit is contained in:
@@ -2,6 +2,7 @@ package com.sismics.docs.core.dao.jpa;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sismics.docs.core.constant.AuditLogType;
|
||||
import com.sismics.docs.core.constant.PermType;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.DocumentCriteria;
|
||||
@@ -239,11 +240,14 @@ public class DocumentDao {
|
||||
}
|
||||
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
|
||||
int index = 0;
|
||||
List<String> tagCriteriaList = Lists.newArrayList();
|
||||
for (String tagId : criteria.getTagIdList()) {
|
||||
sb.append(String.format(" join T_DOCUMENT_TAG dt%d on dt%d.DOT_IDDOCUMENT_C = d.DOC_ID_C and dt%d.DOT_IDTAG_C = :tagId%d and dt%d.DOT_DELETEDATE_D is null ", index, index, index, index, index));
|
||||
sb.append(String.format("left join T_DOCUMENT_TAG dt%d on dt%d.DOT_IDDOCUMENT_C = d.DOC_ID_C and dt%d.DOT_IDTAG_C = :tagId%d and dt%d.DOT_DELETEDATE_D is null ", index, index, index, index, index));
|
||||
parameterMap.put("tagId" + index, tagId);
|
||||
tagCriteriaList.add(String.format("dt%d.DOT_ID_C is not null", index));
|
||||
index++;
|
||||
}
|
||||
criteriaList.add(Joiner.on(" OR ").join(tagCriteriaList));
|
||||
}
|
||||
if (criteria.getShared() != null && criteria.getShared()) {
|
||||
criteriaList.add("(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) > 0");
|
||||
|
||||
@@ -195,10 +195,6 @@ public class TagDao {
|
||||
criteriaList.add("t.TAG_NAME_C = :name");
|
||||
parameterMap.put("name", criteria.getName());
|
||||
}
|
||||
if (criteria.getNameLike() != null) {
|
||||
criteriaList.add("t.TAG_NAME_C like :nameLike");
|
||||
parameterMap.put("nameLike", criteria.getNameLike() + "%");
|
||||
}
|
||||
|
||||
criteriaList.add("t.TAG_DELETEDATE_D is null");
|
||||
|
||||
|
||||
@@ -68,13 +68,4 @@ public class TagCriteria {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getNameLike() {
|
||||
return nameLike;
|
||||
}
|
||||
|
||||
public TagCriteria setNameLike(String nameLike) {
|
||||
this.nameLike = nameLike;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.sismics.docs.core.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sismics.docs.core.dao.jpa.dto.TagDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tag utilities.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class TagUtil {
|
||||
/**
|
||||
* Recursively find children of a tags.
|
||||
*
|
||||
* @param parentTagDto Parent tag
|
||||
* @param allTagDtoList List of all tags
|
||||
* @return Children tags
|
||||
*/
|
||||
public static List<TagDto> findChildren(TagDto parentTagDto, List<TagDto> allTagDtoList) {
|
||||
List<TagDto> childrenTagDtoList = Lists.newArrayList();
|
||||
|
||||
for (TagDto tagDto : allTagDtoList) {
|
||||
if (parentTagDto.getId().equals(tagDto.getParentId())) {
|
||||
childrenTagDtoList.add(tagDto);
|
||||
childrenTagDtoList.addAll(findChildren(tagDto, allTagDtoList));
|
||||
}
|
||||
}
|
||||
|
||||
return childrenTagDtoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find tags by name (start with).
|
||||
*
|
||||
* @param name Name
|
||||
* @param allTagDtoList List of all tags
|
||||
* @return List of filtered tags
|
||||
*/
|
||||
public static List<TagDto> findByName(String name, List<TagDto> allTagDtoList) {
|
||||
List<TagDto> tagDtoList = Lists.newArrayList();
|
||||
if (name == null || name.isEmpty()) {
|
||||
return tagDtoList;
|
||||
}
|
||||
name = name.toLowerCase();
|
||||
for (TagDto tagDto : allTagDtoList) {
|
||||
if (tagDto.getName().toLowerCase().startsWith(name)) {
|
||||
tagDtoList.add(tagDto);
|
||||
}
|
||||
}
|
||||
return tagDtoList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user