Project

General

Profile

Revision 7e89fd99

ID7e89fd990b7d55e2ccd3e1afde7b7574c44bcf27
Parent c643a8b9
Child ab4b0d27

Added by Patrick Plitzner 7 months ago

ref #7887 Extract AbstractTermDto + add vocabulary dto service method

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/ITermVocabularyDao.java
20 20
import eu.etaxonomy.cdm.model.common.TermType;
21 21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22 22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
23 24
import eu.etaxonomy.cdm.persistence.query.OrderHint;
24 25

  
25 26

  
......
106 107

  
107 108
    /**
108 109
     * Loads all top level terms, i.e. terms that have no parent terms, for the given vocabulary
109
     * @param vocabularyId the id of the vocabulary
110
     * @param vocabularyUuid the id of the vocabulary
110 111
     * @return a collection of top level terms
111 112
     */
112
    public Collection<TermDto> getTopLevelTerms(int vocabularyId);
113
    public Collection<TermDto> getTopLevelTerms(UUID vocabularyUuid);
114

  
115
    /**
116
     * Returns term vocabularies that contain terms of a certain {@link TermType} e.g. Feature, Modifier, State.
117
     *
118
     * @param termType the {@link TermType} of the terms in the vocabulary and of the vocabulary
119
     * @return a list of term vocabularies
120
     */
121
    public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType);
113 122

  
114 123
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/TermVocabularyDaoImpl.java
33 33
import eu.etaxonomy.cdm.model.view.AuditEvent;
34 34
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
35 35
import eu.etaxonomy.cdm.persistence.dto.TermDto;
36
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
36 37
import eu.etaxonomy.cdm.persistence.query.OrderHint;
37 38

  
38 39
/**
......
246 247
	}
247 248

  
248 249
    @Override
249
    public Collection<TermDto> getTopLevelTerms(int vocabularyId) {
250
    public Collection<TermDto> getTopLevelTerms(UUID vocabularyUuid) {
250 251
        String queryString = ""
251 252
                + "select a.uuid, r, p.uuid, v.uuid, a.orderIndex "
252 253
                + "from DefinedTermBase as a LEFT JOIN a.partOf as p LEFT JOIN a.representations AS r LEFT JOIN a.vocabulary as v "
253
                + "where v.id = :vocabularyId "
254
                + "where v.uuid = :vocabularyUuid "
254 255
                + "and a.partOf is null "
255 256
                + "and a.kindOf is null";
256 257
        Query query =  getSession().createQuery(queryString);
257
        query.setParameter("vocabularyId", vocabularyId);
258
        query.setParameter("vocabularyUuid", vocabularyUuid);
258 259

  
259 260
        @SuppressWarnings("unchecked")
260 261
        List<Object[]> result = query.list();
......
278 279
        return new ArrayList<>(dtoMap.values());
279 280
    }
280 281

  
282
    @Override
283
    public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType) {
284
        String queryString = ""
285
                + "select v.uuid, r "
286
                + "from TermVocabulary as v LEFT JOIN v.representations AS r "
287
                + "where v.termType = :termType "
288
                ;
289
        Query query =  getSession().createQuery(queryString);
290
        query.setParameter("termType", termType);
291

  
292
        @SuppressWarnings("unchecked")
293
        List<Object[]> result = query.list();
294

  
295
        Map<UUID, TermVocabularyDto> dtoMap = new HashMap<>(result.size());
296
        for (Object[] elements : result) {
297
            UUID uuid = (UUID)elements[0];
298
            if(dtoMap.containsKey(uuid)){
299
                dtoMap.get(uuid).addRepresentation((Representation)elements[1]);
300
            } else {
301
                Set<Representation> representations;
302
                if(elements[1] instanceof Representation) {
303
                    representations = new HashSet<Representation>(1);
304
                    representations.add((Representation)elements[1]);
305
                } else {
306
                    representations = (Set<Representation>)elements[1];
307
                }
308
                dtoMap.put(uuid, new TermVocabularyDto(uuid, representations));
309
            }
310
        }
311
        return new ArrayList<>(dtoMap.values());
312
    }
313

  
281 314
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/AbstractTermDto.java
1
// $Id$
2
/**
3
* Copyright (C) 2018 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.persistence.dto;
11

  
12
import java.io.Serializable;
13
import java.net.URI;
14
import java.util.Set;
15
import java.util.UUID;
16

  
17
import eu.etaxonomy.cdm.model.common.Representation;
18
import eu.etaxonomy.cdm.model.common.TermType;
19

  
20
/**
21
 * @author pplitzner
22
 * @date 05.11.2018
23
 *
24
 */
25
public class AbstractTermDto implements Serializable {
26

  
27
    private static final long serialVersionUID = -7160319884811828125L;
28

  
29
    private final UUID uuid;
30
    private URI uri;
31
    private TermType termType;
32
    private final Set<Representation> representations;
33
    private String representation_L10n = null;
34
    private String representation_L10n_abbreviatedLabel = null;
35

  
36
    public AbstractTermDto(UUID uuid, Set<Representation> representations) {
37
        this.representations = representations;
38
        this.uuid = uuid;
39
    }
40

  
41
    /**
42
     *
43
     * @param representation_L10n a blank instance of ITermRepresentation_L10n
44
     *   created by the  default constructor
45
     */
46
    public void localize(ITermRepresentation_L10n representation_L10n) {
47

  
48
        representation_L10n.localize(representations);
49
        if (representation_L10n.getLabel() != null) {
50
            setRepresentation_L10n(representation_L10n.getLabel());
51
        }
52
        if (representation_L10n.getAbbreviatedLabel() != null) {
53
            setRepresentation_L10n_abbreviatedLabel(representation_L10n.getAbbreviatedLabel());
54
        }
55
    }
56

  
57
    public URI getUri() {
58
        return uri;
59
    }
60

  
61
    public void setUri(URI uri) {
62
        this.uri = uri;
63
    }
64

  
65
    public TermType getTermType() {
66
        return termType;
67
    }
68

  
69
    public void setTermType(TermType termType) {
70
        this.termType = termType;
71
    }
72

  
73
    public String getRepresentation_L10n() {
74
        return representation_L10n;
75
    }
76

  
77
    public void setRepresentation_L10n(String representation_L10n) {
78
        this.representation_L10n = representation_L10n;
79
    }
80

  
81
    public void addRepresentation(Representation representation) {
82
        representations.add(representation);
83

  
84
    }
85

  
86
    public String getRepresentation_L10n_abbreviatedLabel() {
87
        return representation_L10n_abbreviatedLabel;
88
    }
89

  
90
    public void setRepresentation_L10n_abbreviatedLabel(String representation_L10n_abbreviatedLabel) {
91
        this.representation_L10n_abbreviatedLabel = representation_L10n_abbreviatedLabel;
92
    }
93

  
94
    public UUID getUuid() {
95
        return uuid;
96
    }
97

  
98
    public Set<Representation> getRepresentations() {
99
        return representations;
100
    }
101

  
102
    @Override
103
    public int hashCode() {
104
        final int prime = 31;
105
        int result = 1;
106
        result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
107
        return result;
108
    }
109

  
110
    @Override
111
    public boolean equals(Object obj) {
112
        if (this == obj) {
113
            return true;
114
        }
115
        if (obj == null) {
116
            return false;
117
        }
118
        if (getClass() != obj.getClass()) {
119
            return false;
120
        }
121
        AbstractTermDto other = (AbstractTermDto) obj;
122
        if (uuid == null) {
123
            if (other.uuid != null) {
124
                return false;
125
            }
126
        } else if (!uuid.equals(other.uuid)) {
127
            return false;
128
        }
129
        return true;
130
    }
131

  
132
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermDto.java
21 21
 * @since Mar 25, 2015
22 22
 *
23 23
 */
24
public class TermDto implements Serializable{
24
public class TermDto extends AbstractTermDto implements Serializable{
25 25

  
26 26
    private static final long serialVersionUID = 5627308906985438034L;
27
    private final UUID uuid;
27

  
28 28
    private UUID partOfUuid = null;
29 29
    private UUID vocabularyUuid = null;
30 30
    private Integer orderIndex = null;
31
    private final Set<Representation> representations;
32
    private String representation_L10n = null;
33
    private String representation_L10n_abbreviatedLabel = null;
34 31
    private Collection<TermDto> includes;
35 32

  
36 33
    public TermDto(UUID uuid, Set<Representation> representations, Integer orderIndex) {
37
        this.representations = representations;
38
        this.uuid = uuid;
34
        super(uuid, representations);
39 35
        this.setOrderIndex(orderIndex);
40 36
    }
41 37

  
42 38
    public TermDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID vocabularyUuid, Integer orderIndex) {
43
        this.representations = representations;
44
        this.uuid = uuid;
39
        super(uuid, representations);
45 40
        this.partOfUuid = partOfUuid;
46 41
        this.vocabularyUuid = vocabularyUuid;
47 42
        this.orderIndex = orderIndex;
......
52 47
        return dto;
53 48
    }
54 49

  
55
    /**
56
     *
57
     * @param representation_L10n a blank instance of ITermRepresentation_L10n
58
     *   created by the  default constructor
59
     */
60
    public void localize(ITermRepresentation_L10n representation_L10n) {
61

  
62
        representation_L10n.localize(representations);
63
        if (representation_L10n.getLabel() != null) {
64
            setRepresentation_L10n(representation_L10n.getLabel());
65
        }
66
        if (representation_L10n.getAbbreviatedLabel() != null) {
67
            setRepresentation_L10n_abbreviatedLabel(representation_L10n.getAbbreviatedLabel());
68
        }
69
    }
70

  
71
    /**
72
     * @return the uuid
73
     */
74
    public UUID getUuid() {
75
        return uuid;
76
    }
77

  
78
    /**
79
     * @return the representation_L10n
80
     */
81
    public String getRepresentation_L10n() {
82
        return representation_L10n;
83
    }
84

  
85
    /**
86
     * @param representation_L10n the representation_L10n to set
87
     */
88
    public void setRepresentation_L10n(String representation_L10n) {
89
        this.representation_L10n = representation_L10n;
90
    }
91

  
92
    /**
93
     * @param representation_L10n_abbreviatedLabel the representation_L10n_abbreviatedLabel to set
94
     */
95
    public void setRepresentation_L10n_abbreviatedLabel(String representation_L10n_abbreviatedLabel) {
96
        this.representation_L10n_abbreviatedLabel = representation_L10n_abbreviatedLabel;
97
    }
98

  
99
    /**
100
     * @return the representation_L10n_abbreviatedLabel
101
     */
102
    public String getRepresentation_L10n_abbreviatedLabel() {
103
        return representation_L10n_abbreviatedLabel;
104
    }
105

  
106
    /**
107
     * @return the vocabularyUuid
108
     */
109 50
    public UUID getVocabularyUuid() {
110 51
        return vocabularyUuid;
111 52
    }
112 53

  
113
    /**
114
     * @param vocabularyUuid the vocabularyUuid to set
115
     */
116 54
    public void setVocabularyUuid(UUID vocabularyUuid) {
117 55
        this.vocabularyUuid = vocabularyUuid;
118 56
    }
119 57

  
120
    /**
121
     * @return the partOfUuid
122
     */
123 58
    public UUID getPartOfUuid() {
124 59
        return partOfUuid;
125 60
    }
126 61

  
127
    /**
128
     * @param representation
129
     */
130
    public void addRepresentation(Representation representation) {
131
        representations.add(representation);
132

  
133
    }
134

  
135
    /**
136
     * @return the orderIndex
137
     */
138 62
    public Integer getOrderIndex() {
139 63
        return orderIndex;
140 64
    }
141 65

  
142
    /**
143
     * @param orderIndex the orderIndex to set
144
     */
145 66
    public void setOrderIndex(Integer orderIndex) {
146 67
        this.orderIndex = orderIndex;
147 68
    }
......
150 71
        return includes;
151 72
    }
152 73

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

  
160
    @Override
161
    public int hashCode() {
162
        final int prime = 31;
163
        int result = 1;
164
        result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
165
        return result;
166
    }
167

  
168
    @Override
169
    public boolean equals(Object obj) {
170
        if (this == obj) {
171
            return true;
172
        }
173
        if (obj == null) {
174
            return false;
175
        }
176
        if (getClass() != obj.getClass()) {
177
            return false;
178
        }
179
        TermDto other = (TermDto) obj;
180
        if (uuid == null) {
181
            if (other.uuid != null) {
182
                return false;
183
            }
184
        } else if (!uuid.equals(other.uuid)) {
185
            return false;
186
        }
187
        return true;
188
    }
189

  
190 78
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermVocabularyDto.java
1
// $Id$
2
/**
3
* Copyright (C) 2018 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.persistence.dto;
11

  
12
import java.io.Serializable;
13
import java.util.HashSet;
14
import java.util.Set;
15
import java.util.UUID;
16

  
17
import eu.etaxonomy.cdm.model.common.Representation;
18

  
19
/**
20
 * @author pplitzner
21
 * @date 05.11.2018
22
 *
23
 */
24
public class TermVocabularyDto extends AbstractTermDto implements Serializable {
25

  
26
    private static final long serialVersionUID = 6053392236860675874L;
27

  
28
    private Set<TermDto> terms;
29

  
30
    public TermVocabularyDto(UUID uuid, Set<Representation> representations) {
31
        super(uuid, representations);
32
        terms = new HashSet<>();
33
    }
34

  
35
    public Set<TermDto> getTerms() {
36
        return terms;
37
    }
38

  
39
    public void addTerm(TermDto term){
40
        terms.add(term);
41
    }
42

  
43
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IVocabularyService.java
11 11

  
12 12
import java.util.Collection;
13 13
import java.util.List;
14
import java.util.UUID;
14 15

  
15 16
import eu.etaxonomy.cdm.api.service.pager.Pager;
16 17
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
......
18 19
import eu.etaxonomy.cdm.model.common.TermType;
19 20
import eu.etaxonomy.cdm.model.common.TermVocabulary;
20 21
import eu.etaxonomy.cdm.persistence.dto.TermDto;
22
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
21 23
import eu.etaxonomy.cdm.persistence.query.OrderHint;
22 24

  
23 25
public interface IVocabularyService extends IIdentifiableEntityService<TermVocabulary> {
......
72 74

  
73 75
	/**
74 76
	 * Loads all top level terms, i.e. terms that have no parent terms, for the given vocabulary
75
	 * @param vocabularyId the id of the vocabulary
77
	 * @param vocabularyUuid the uuid of the vocabulary
76 78
	 * @return a collection of top level terms
77 79
	 */
78
	public Collection<TermDto> getTopLevelTerms(int vocabularyId);
80
	public Collection<TermDto> getTopLevelTerms(UUID vocabularyUuid);
79 81

  
80 82
	/**
81 83
	 * Initializes the complete term hierarchy consisting of {@link TermDto}s
82 84
	 * for the given vocabulary
83
	 * @param vocabularyId the id of the {@link TermVocabulary}
85
	 * @param vocabularyUuid the UUID of the {@link TermVocabulary}
84 86
	 * @return a the top level elements for this vocabulary
85 87
	 */
86
    public Collection<TermDto> getCompleteTermHierarchy(int vocabularyId);
88

  
89
	public Collection<TermDto> getCompleteTermHierarchy(UUID vocabularyUuid);
90
    /**
91
     * Returns term vocabularies that contain terms of a certain {@link TermType} e.g. Feature, Modifier, State.
92
     *
93
     * @param termType the {@link TermType} of the terms in the vocabulary and of the vocabulary
94
     * @return a list of term vocabularies
95
     */
96
    public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType);
87 97

  
88 98
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/VocabularyServiceImpl.java
27 27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28 28
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
29 29
import eu.etaxonomy.cdm.persistence.dto.TermDto;
30
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
30 31
import eu.etaxonomy.cdm.persistence.query.OrderHint;
31 32
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
32 33

  
......
92 93

  
93 94

  
94 95
    @Override
95
    public Collection<TermDto> getTopLevelTerms(int vocabularyId) {
96
        return dao.getTopLevelTerms(vocabularyId);
96
    public Collection<TermDto> getTopLevelTerms(UUID vocabularyUuid) {
97
        return dao.getTopLevelTerms(vocabularyUuid);
97 98
    }
98 99

  
99 100
    @Override
100
    public Collection<TermDto> getCompleteTermHierarchy(int vocabularyId) {
101
        Collection<TermDto> topLevelTerms = dao.getTopLevelTerms(vocabularyId);
101
    public Collection<TermDto> getCompleteTermHierarchy(UUID vocabularyUuid) {
102
        Collection<TermDto> topLevelTerms = dao.getTopLevelTerms(vocabularyUuid);
102 103
        for (TermDto termDto : topLevelTerms) {
103 104
            initializeIncludes(termDto);
104 105
        }
......
111 112
        includes.forEach(include->initializeIncludes(include));
112 113
    }
113 114

  
115
    @Override
116
    public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType) {
117
        return dao.findVocabularyDtoByTermType(termType);
118
    }
119

  
114 120
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)