Project

General

Profile

Revision 0ebf52c1

ID0ebf52c19b64308da0d26d9dedd6e3a1186888c4
Parent 2d4cb2bf
Child c643a8b9

Added by Patrick Plitzner over 1 year ago

ref #7875 Add service method to load complete term hierarchy

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermDto.java
9 9
package eu.etaxonomy.cdm.persistence.dto;
10 10

  
11 11
import java.io.Serializable;
12
import java.util.Collection;
12 13
import java.util.Set;
13 14
import java.util.UUID;
14 15

  
......
30 31
    private final Set<Representation> representations;
31 32
    private String representation_L10n = null;
32 33
    private String representation_L10n_abbreviatedLabel = null;
34
    private Collection<TermDto> includes;
33 35

  
34 36
    public TermDto(UUID uuid, Set<Representation> representations, Integer orderIndex) {
35 37
        this.representations = representations;
......
144 146
        this.orderIndex = orderIndex;
145 147
    }
146 148

  
149
    public Collection<TermDto> getIncludes() {
150
        return includes;
151
    }
152

  
153
    /**
154
     * @param includes the includes to set
155
     */
156
    public void setIncludes(Collection<TermDto> includes) {
157
        this.includes = includes;
158
    }
159

  
147 160
    @Override
148 161
    public int hashCode() {
149 162
        final int prime = 31;
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IVocabularyService.java
77 77
	 */
78 78
	public Collection<TermDto> getTopLevelTerms(int vocabularyId);
79 79

  
80
    public Collection<TermDto> getCompleteTermHierarchy(int vocabularyId);
81

  
80 82
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/VocabularyServiceImpl.java
34 34
@Transactional(readOnly = true)
35 35
public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabulary,ITermVocabularyDao>  implements IVocabularyService {
36 36

  
37
    @Autowired
38
    private ITermService termService;
39

  
37 40
	@Override
38 41
    @Autowired
39 42
	protected void setDao(ITermVocabularyDao dao) {
......
93 96
        return dao.getTopLevelTerms(vocabularyId);
94 97
    }
95 98

  
99
    @Override
100
    public Collection<TermDto> getCompleteTermHierarchy(int vocabularyId) {
101
        Collection<TermDto> topLevelTerms = dao.getTopLevelTerms(vocabularyId);
102
        for (TermDto termDto : topLevelTerms) {
103
            initializeIncludes(termDto);
104
        }
105
        return topLevelTerms;
106
    }
107

  
108
    private void initializeIncludes(TermDto parentTerm){
109
        Collection<TermDto> includes = termService.getIncludesAsUuidAndTitleCache(parentTerm);
110
        parentTerm.setIncludes(includes);
111
        includes.forEach(include->initializeIncludes(include));
112
    }
113

  
96 114
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)