1 |
367973e0
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
|
|
* European Distributed Institute of Taxonomy
|
4 |
|
|
* http://www.e-taxonomy.eu
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
76cfd0f6
|
Andreas Müller
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.term;
|
11 |
367973e0
|
Andreas Müller
|
|
12 |
fb707701
|
Andreas Müller
|
import java.util.ArrayList;
|
13 |
|
|
import java.util.Collection;
|
14 |
9298a53f
|
Patrick Plitzner
|
import java.util.Collections;
|
15 |
a1ab6a74
|
Patrick Plitzner
|
import java.util.HashMap;
|
16 |
367973e0
|
Andreas Müller
|
import java.util.HashSet;
|
17 |
|
|
import java.util.List;
|
18 |
|
|
import java.util.Map;
|
19 |
|
|
import java.util.Set;
|
20 |
|
|
import java.util.UUID;
|
21 |
|
|
|
22 |
|
|
import org.hibernate.Criteria;
|
23 |
|
|
import org.hibernate.Query;
|
24 |
1184c8e0
|
Patrick Plitzner
|
import org.hibernate.Session;
|
25 |
b6ea6bbc
|
Katja Luther
|
import org.hibernate.criterion.Disjunction;
|
26 |
af1131f2
|
Katja Luther
|
import org.hibernate.criterion.Order;
|
27 |
367973e0
|
Andreas Müller
|
import org.hibernate.criterion.Restrictions;
|
28 |
|
|
import org.hibernate.envers.query.AuditEntity;
|
29 |
|
|
import org.hibernate.envers.query.AuditQuery;
|
30 |
|
|
import org.springframework.stereotype.Repository;
|
31 |
|
|
|
32 |
1c39686b
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
33 |
|
|
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
|
34 |
|
|
import eu.etaxonomy.cdm.model.term.Representation;
|
35 |
|
|
import eu.etaxonomy.cdm.model.term.TermType;
|
36 |
|
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
37 |
367973e0
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.view.AuditEvent;
|
38 |
76cfd0f6
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase;
|
39 |
|
|
import eu.etaxonomy.cdm.persistence.dao.term.ITermVocabularyDao;
|
40 |
a1ab6a74
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
41 |
|
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
42 |
1184c8e0
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
43 |
367973e0
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* @author a.mueller
|
47 |
|
|
*
|
48 |
|
|
*/
|
49 |
|
|
@Repository
|
50 |
|
|
public class TermVocabularyDaoImpl extends IdentifiableDaoBase<TermVocabulary> implements
|
51 |
|
|
ITermVocabularyDao {
|
52 |
9f2a0391
|
Andreas Müller
|
|
53 |
367973e0
|
Andreas Müller
|
/**
|
54 |
|
|
* @param type
|
55 |
|
|
*/
|
56 |
|
|
public TermVocabularyDaoImpl() {
|
57 |
|
|
super(TermVocabulary.class);
|
58 |
|
|
indexedClasses = new Class[2];
|
59 |
|
|
indexedClasses[0] = TermVocabulary.class;
|
60 |
|
|
indexedClasses[1] = OrderedTermVocabulary.class;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
@Override
|
64 |
9a21de1f
|
Andreas Müller
|
public long countTerms(TermVocabulary termVocabulary) {
|
65 |
367973e0
|
Andreas Müller
|
AuditEvent auditEvent = getAuditEventFromContext();
|
66 |
|
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
67 |
|
|
Query query = getSession().createQuery("select count(term) from DefinedTermBase term where term.vocabulary = :vocabulary");
|
68 |
|
|
query.setParameter("vocabulary", termVocabulary);
|
69 |
|
|
|
70 |
9a21de1f
|
Andreas Müller
|
return (Long)query.uniqueResult();
|
71 |
367973e0
|
Andreas Müller
|
} else {
|
72 |
9a21de1f
|
Andreas Müller
|
AuditQuery query = makeAuditQuery(null, auditEvent);
|
73 |
3dd6c00e
|
Andreas Müller
|
query.addProjection(AuditEntity.id().count());
|
74 |
367973e0
|
Andreas Müller
|
query.add(AuditEntity.relatedId("vocabulary").eq(termVocabulary.getId()));
|
75 |
9a21de1f
|
Andreas Müller
|
return (Long)query.getSingleResult();
|
76 |
367973e0
|
Andreas Müller
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
@Override
|
80 |
|
|
public <T extends DefinedTermBase> List<T> getTerms(TermVocabulary<T> vocabulary,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,List<String> propertyPaths) {
|
81 |
|
|
AuditEvent auditEvent = getAuditEventFromContext();
|
82 |
|
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
83 |
9a21de1f
|
Andreas Müller
|
Criteria criteria = getCriteria(DefinedTermBase.class);
|
84 |
367973e0
|
Andreas Müller
|
criteria.createCriteria("vocabulary").add(Restrictions.idEq(vocabulary.getId()));
|
85 |
|
|
|
86 |
9a21de1f
|
Andreas Müller
|
addPageSizeAndNumber(criteria, pageSize, pageNumber);
|
87 |
367973e0
|
Andreas Müller
|
this.addOrder(criteria, orderHints);
|
88 |
9a21de1f
|
Andreas Müller
|
|
89 |
9f2a0391
|
Andreas Müller
|
@SuppressWarnings("unchecked")
|
90 |
|
|
List<T> result = criteria.list();
|
91 |
367973e0
|
Andreas Müller
|
defaultBeanInitializer.initializeAll(result, propertyPaths);
|
92 |
|
|
return result;
|
93 |
|
|
} else {
|
94 |
9a21de1f
|
Andreas Müller
|
AuditQuery query = makeAuditQuery(null, auditEvent);
|
95 |
367973e0
|
Andreas Müller
|
query.add(AuditEntity.relatedId("vocabulary").eq(vocabulary.getId()));
|
96 |
|
|
|
97 |
9a21de1f
|
Andreas Müller
|
addPageSizeAndNumber(query, pageSize, pageNumber);
|
98 |
367973e0
|
Andreas Müller
|
|
99 |
9f2a0391
|
Andreas Müller
|
@SuppressWarnings("unchecked")
|
100 |
|
|
List<T> result = query.getResultList();
|
101 |
367973e0
|
Andreas Müller
|
defaultBeanInitializer.initializeAll(result, propertyPaths);
|
102 |
|
|
return result;
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
9a21de1f
|
Andreas Müller
|
@Override
|
107 |
367973e0
|
Andreas Müller
|
public <T extends DefinedTermBase> TermVocabulary<T> findByUri(String termSourceUri, Class<T> clazz) {
|
108 |
|
|
AuditEvent auditEvent = getAuditEventFromContext();
|
109 |
|
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
110 |
9a21de1f
|
Andreas Müller
|
//TODO use clazz
|
111 |
367973e0
|
Andreas Müller
|
Query query = getSession().createQuery("select vocabulary from TermVocabulary vocabulary where vocabulary.termSourceUri= :termSourceUri");
|
112 |
|
|
query.setParameter("termSourceUri", termSourceUri);
|
113 |
|
|
|
114 |
9a21de1f
|
Andreas Müller
|
@SuppressWarnings("unchecked")
|
115 |
|
|
TermVocabulary<T> result = (TermVocabulary<T>)query.uniqueResult();
|
116 |
|
|
return result;
|
117 |
367973e0
|
Andreas Müller
|
} else {
|
118 |
9a21de1f
|
Andreas Müller
|
@SuppressWarnings("unchecked")
|
119 |
a1ab6a74
|
Patrick Plitzner
|
AuditQuery query = makeAuditQuery(clazz, auditEvent);
|
120 |
367973e0
|
Andreas Müller
|
query.add(AuditEntity.property("termSourceUri").eq(termSourceUri));
|
121 |
|
|
|
122 |
9a21de1f
|
Andreas Müller
|
@SuppressWarnings("unchecked")
|
123 |
|
|
TermVocabulary<T> result = (TermVocabulary<T>)query.getSingleResult();
|
124 |
|
|
return result;
|
125 |
367973e0
|
Andreas Müller
|
}
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
@Override
|
130 |
|
|
public <T extends DefinedTermBase> List<T> getTerms(TermVocabulary<T> termVocabulary, Integer pageSize, Integer pageNumber) {
|
131 |
|
|
return getTerms(termVocabulary, pageSize, pageNumber, null, null);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
@Override
|
136 |
fa74401f
|
Patrick Plitzner
|
public <T extends DefinedTermBase> List<TermVocabulary<T>> findByTermType(TermType termType, List<String> propertyPaths) {
|
137 |
367973e0
|
Andreas Müller
|
|
138 |
|
|
Criteria criteria = getSession().createCriteria(type);
|
139 |
|
|
criteria.add(Restrictions.eq("termType", termType));
|
140 |
f8234c13
|
Katja Luther
|
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
|
141 |
367973e0
|
Andreas Müller
|
//this.addOrder(criteria, orderHints);
|
142 |
|
|
|
143 |
9f2a0391
|
Andreas Müller
|
@SuppressWarnings("unchecked")
|
144 |
367973e0
|
Andreas Müller
|
List<TermVocabulary<T>> result = criteria.list();
|
145 |
fa74401f
|
Patrick Plitzner
|
defaultBeanInitializer.initializeAll(result, propertyPaths);
|
146 |
367973e0
|
Andreas Müller
|
return result;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
@Override
|
150 |
|
|
public List<TermVocabulary> listByTermType(TermType termType, boolean includeSubTypes, Integer limit, Integer start,List<OrderHint> orderHints, List<String> propertyPaths) {
|
151 |
|
|
checkNotInPriorView("TermVocabularyDao.listByTermType(TermType termType, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths)");
|
152 |
|
|
|
153 |
|
|
Set<TermType> allTermTypes = new HashSet<TermType>();
|
154 |
|
|
allTermTypes.add(termType);
|
155 |
|
|
if (includeSubTypes){
|
156 |
|
|
allTermTypes.addAll(termType.getGeneralizationOf(true));
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
Criteria criteria = getSession().createCriteria(type);
|
160 |
|
|
criteria.add(Restrictions.in("termType", allTermTypes));
|
161 |
|
|
|
162 |
|
|
if(limit != null) {
|
163 |
|
|
criteria.setMaxResults(limit);
|
164 |
|
|
if(start != null) {
|
165 |
|
|
criteria.setFirstResult(start);
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
this.addOrder(criteria, orderHints);
|
170 |
|
|
|
171 |
9f2a0391
|
Andreas Müller
|
@SuppressWarnings("unchecked")
|
172 |
367973e0
|
Andreas Müller
|
List<TermVocabulary> result = criteria.list();
|
173 |
|
|
defaultBeanInitializer.initializeAll(result, propertyPaths);
|
174 |
|
|
return result;
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
@Override
|
178 |
|
|
public void missingTermUuids(
|
179 |
|
|
Map<UUID, Set<UUID>> uuidsRequested,
|
180 |
|
|
Map<UUID, Set<UUID>> uuidMissingTermsRepsonse,
|
181 |
|
|
Map<UUID, TermVocabulary<?>> vocabularyResponse){
|
182 |
|
|
|
183 |
60e8c5d1
|
Andreas Müller
|
Set<UUID> missingTermCandidateUuids = new HashSet<>();
|
184 |
367973e0
|
Andreas Müller
|
|
185 |
|
|
for (Set<UUID> uuidsPerVocSet : uuidsRequested.values()){
|
186 |
|
|
missingTermCandidateUuids.addAll(uuidsPerVocSet);
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
//search persisted subset of required (usually all)
|
190 |
|
|
String hql = " SELECT terms.uuid " +
|
191 |
|
|
" FROM TermVocabulary voc join voc.terms terms " +
|
192 |
|
|
" WHERE terms.uuid IN (:uuids) " +
|
193 |
|
|
" ORDER BY voc.uuid ";
|
194 |
|
|
Query query = getSession().createQuery(hql);
|
195 |
fb707701
|
Andreas Müller
|
|
196 |
|
|
int splitSize = 2000;
|
197 |
|
|
List<Collection<UUID>> missingTermCandidates = splitCollection(missingTermCandidateUuids, splitSize);
|
198 |
|
|
List<UUID> persistedUuids = new ArrayList<>();
|
199 |
|
|
|
200 |
|
|
for (Collection<UUID> uuids : missingTermCandidates){
|
201 |
|
|
query.setParameterList("uuids", uuids);
|
202 |
|
|
@SuppressWarnings("unchecked")
|
203 |
|
|
List<UUID> list = query.list();
|
204 |
|
|
persistedUuids.addAll(list);
|
205 |
|
|
}
|
206 |
367973e0
|
Andreas Müller
|
|
207 |
|
|
|
208 |
|
|
//fully load and initialize vocabularies if required
|
209 |
|
|
if (vocabularyResponse != null){
|
210 |
|
|
String hql2 = " SELECT DISTINCT voc " +
|
211 |
|
|
" FROM TermVocabulary voc " +
|
212 |
|
|
" LEFT JOIN FETCH voc.terms terms " +
|
213 |
|
|
" LEFT JOIN FETCH terms.representations representations " +
|
214 |
|
|
" LEFT JOIN FETCH voc.representations vocReps " +
|
215 |
|
|
" WHERE terms.uuid IN (:termUuids) OR ( voc.uuid IN (:vocUuids) ) " + //was: AND voc.terms is empty, but did not load originally empty vocabularies with user defined terms added
|
216 |
|
|
// " WHERE voc.uuid IN (:vocUuids) AND voc.terms is empty " +
|
217 |
|
|
" ORDER BY voc.uuid ";
|
218 |
|
|
query = getSession().createQuery(hql2);
|
219 |
fb707701
|
Andreas Müller
|
query.setParameterList("termUuids", missingTermCandidateUuids);
|
220 |
|
|
query.setParameterList("vocUuids", uuidsRequested.keySet());
|
221 |
|
|
|
222 |
|
|
for (Collection<UUID> uuids : missingTermCandidates){
|
223 |
|
|
query.setParameterList("termUuids", uuids);
|
224 |
|
|
@SuppressWarnings("unchecked")
|
225 |
|
|
List<TermVocabulary<?>> o = query.list();
|
226 |
|
|
for (TermVocabulary<?> voc : o){
|
227 |
|
|
vocabularyResponse.put(voc.getUuid(), voc);
|
228 |
|
|
}
|
229 |
|
|
}
|
230 |
367973e0
|
Andreas Müller
|
}
|
231 |
|
|
|
232 |
|
|
//compute missing terms
|
233 |
|
|
if (missingTermCandidateUuids.size() == persistedUuids.size()){
|
234 |
|
|
missingTermCandidateUuids.clear();
|
235 |
|
|
}else{
|
236 |
|
|
missingTermCandidateUuids.removeAll(persistedUuids);
|
237 |
|
|
//add missing terms to response
|
238 |
|
|
for (UUID vocUUID : uuidsRequested.keySet()){
|
239 |
|
|
for (UUID termUuid : uuidsRequested.get(vocUUID)){
|
240 |
|
|
if (missingTermCandidateUuids.contains(termUuid)){
|
241 |
|
|
Set<UUID> r = uuidMissingTermsRepsonse.get(vocUUID);
|
242 |
|
|
if (r == null){
|
243 |
60e8c5d1
|
Andreas Müller
|
r = new HashSet<>();
|
244 |
367973e0
|
Andreas Müller
|
uuidMissingTermsRepsonse.put(vocUUID, r);
|
245 |
|
|
}
|
246 |
|
|
r.add(termUuid);
|
247 |
|
|
}
|
248 |
|
|
}
|
249 |
|
|
}
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
return;
|
253 |
|
|
}
|
254 |
9f2a0391
|
Andreas Müller
|
|
255 |
1933a33c
|
Patrick Plitzner
|
@Override
|
256 |
|
|
public Collection<TermDto> getTerms(List<UUID> vocabularyUuids) {
|
257 |
|
|
String queryString = TermDto.getTermDtoSelect()
|
258 |
|
|
+ "where v.uuid in :vocabularyUuids "
|
259 |
|
|
+ "order by a.titleCache";
|
260 |
|
|
Query query = getSession().createQuery(queryString);
|
261 |
|
|
query.setParameterList("vocabularyUuids", vocabularyUuids);
|
262 |
|
|
|
263 |
|
|
@SuppressWarnings("unchecked")
|
264 |
|
|
List<Object[]> result = query.list();
|
265 |
|
|
|
266 |
|
|
List<TermDto> list = TermDto.termDtoListFrom(result);
|
267 |
|
|
return list;
|
268 |
|
|
}
|
269 |
|
|
|
270 |
581deb02
|
Patrick Plitzner
|
@Override
|
271 |
|
|
public Collection<TermDto> getTerms(UUID vocabularyUuid) {
|
272 |
|
|
String queryString = TermDto.getTermDtoSelect()
|
273 |
|
|
+ "where v.uuid = :vocabularyUuid "
|
274 |
|
|
+ "order by a.titleCache";
|
275 |
|
|
Query query = getSession().createQuery(queryString);
|
276 |
|
|
query.setParameter("vocabularyUuid", vocabularyUuid);
|
277 |
|
|
|
278 |
|
|
@SuppressWarnings("unchecked")
|
279 |
|
|
List<Object[]> result = query.list();
|
280 |
|
|
|
281 |
|
|
List<TermDto> list = TermDto.termDtoListFrom(result);
|
282 |
|
|
return list;
|
283 |
|
|
}
|
284 |
|
|
|
285 |
a1ab6a74
|
Patrick Plitzner
|
@Override
|
286 |
|
|
public Collection<TermDto> getTopLevelTerms(UUID vocabularyUuid) {
|
287 |
|
|
String queryString = TermDto.getTermDtoSelect()
|
288 |
|
|
+ "where v.uuid = :vocabularyUuid "
|
289 |
|
|
+ "and a.partOf is null "
|
290 |
|
|
+ "and a.kindOf is null";
|
291 |
|
|
Query query = getSession().createQuery(queryString);
|
292 |
|
|
query.setParameter("vocabularyUuid", vocabularyUuid);
|
293 |
|
|
|
294 |
|
|
@SuppressWarnings("unchecked")
|
295 |
|
|
List<Object[]> result = query.list();
|
296 |
|
|
|
297 |
|
|
List<TermDto> list = TermDto.termDtoListFrom(result);
|
298 |
|
|
return list;
|
299 |
|
|
}
|
300 |
|
|
|
301 |
|
|
@Override
|
302 |
9298a53f
|
Patrick Plitzner
|
public List<TermVocabularyDto> findVocabularyDtoByTermTypes(Set<TermType> termTypes) {
|
303 |
e9a06541
|
pplitzner
|
return findVocabularyDtoByTermTypes(termTypes, true);
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
@Override
|
307 |
|
|
public List<TermVocabularyDto> findVocabularyDtoByTermTypes(Set<TermType> termTypes, boolean includeSubtypes) {
|
308 |
|
|
Set<TermType> termTypeWithSubType = new HashSet<>(termTypes);
|
309 |
|
|
if(includeSubtypes){
|
310 |
|
|
for (TermType termType : termTypes) {
|
311 |
|
|
termTypeWithSubType.addAll(termType.getGeneralizationOf(true));
|
312 |
|
|
}
|
313 |
|
|
}
|
314 |
a1ab6a74
|
Patrick Plitzner
|
String queryString = ""
|
315 |
9298a53f
|
Patrick Plitzner
|
+ "select v.uuid, v.termType, r "
|
316 |
a1ab6a74
|
Patrick Plitzner
|
+ "from TermVocabulary as v LEFT JOIN v.representations AS r "
|
317 |
9298a53f
|
Patrick Plitzner
|
+ "where v.termType in (:termTypes) "
|
318 |
a1ab6a74
|
Patrick Plitzner
|
;
|
319 |
|
|
Query query = getSession().createQuery(queryString);
|
320 |
e9a06541
|
pplitzner
|
query.setParameterList("termTypes", termTypeWithSubType);
|
321 |
a1ab6a74
|
Patrick Plitzner
|
|
322 |
|
|
@SuppressWarnings("unchecked")
|
323 |
|
|
List<Object[]> result = query.list();
|
324 |
|
|
|
325 |
|
|
Map<UUID, TermVocabularyDto> dtoMap = new HashMap<>(result.size());
|
326 |
|
|
for (Object[] elements : result) {
|
327 |
|
|
UUID uuid = (UUID)elements[0];
|
328 |
9298a53f
|
Patrick Plitzner
|
TermType termType = (TermType)elements[1];
|
329 |
a1ab6a74
|
Patrick Plitzner
|
if(dtoMap.containsKey(uuid)){
|
330 |
9298a53f
|
Patrick Plitzner
|
dtoMap.get(uuid).addRepresentation((Representation)elements[2]);
|
331 |
a1ab6a74
|
Patrick Plitzner
|
} else {
|
332 |
|
|
Set<Representation> representations = new HashSet<>();
|
333 |
9298a53f
|
Patrick Plitzner
|
if(elements[2] instanceof Representation) {
|
334 |
|
|
representations = new HashSet<Representation>();
|
335 |
|
|
representations.add((Representation)elements[2]);
|
336 |
a1ab6a74
|
Patrick Plitzner
|
} else {
|
337 |
9298a53f
|
Patrick Plitzner
|
representations = (Set<Representation>)elements[2];
|
338 |
a1ab6a74
|
Patrick Plitzner
|
}
|
339 |
9b4264ec
|
Patrick Plitzner
|
dtoMap.put(uuid, new TermVocabularyDto(uuid, representations, termType));
|
340 |
a1ab6a74
|
Patrick Plitzner
|
}
|
341 |
|
|
}
|
342 |
|
|
return new ArrayList<>(dtoMap.values());
|
343 |
|
|
}
|
344 |
|
|
|
345 |
9298a53f
|
Patrick Plitzner
|
@Override
|
346 |
|
|
public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType) {
|
347 |
|
|
return findVocabularyDtoByTermTypes(Collections.singleton(termType));
|
348 |
|
|
}
|
349 |
|
|
|
350 |
1184c8e0
|
Patrick Plitzner
|
@Override
|
351 |
|
|
public <S extends TermVocabulary> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, TermType termType,
|
352 |
|
|
Integer limit, String pattern) {
|
353 |
|
|
if(termType==null){
|
354 |
|
|
return getUuidAndTitleCache(clazz, limit, pattern);
|
355 |
|
|
}
|
356 |
|
|
Session session = getSession();
|
357 |
|
|
Query query = null;
|
358 |
|
|
if (pattern != null){
|
359 |
|
|
query = session.createQuery(
|
360 |
|
|
" SELECT uuid, id, titleCache "
|
361 |
|
|
+ " FROM " + clazz.getSimpleName()
|
362 |
|
|
+ " WHERE titleCache LIKE :pattern "
|
363 |
|
|
+ " AND termType = :termType");
|
364 |
|
|
pattern = pattern.replace("*", "%");
|
365 |
|
|
pattern = pattern.replace("?", "_");
|
366 |
|
|
pattern = pattern + "%";
|
367 |
|
|
query.setParameter("pattern", pattern);
|
368 |
|
|
} else {
|
369 |
|
|
query = session.createQuery(
|
370 |
|
|
" SELECT uuid, id, titleCache "
|
371 |
|
|
+ " FROM " + clazz.getSimpleName()
|
372 |
|
|
+ " WHERE termType = :termType");
|
373 |
|
|
}
|
374 |
|
|
query.setParameter("termType", termType);
|
375 |
|
|
if (limit != null){
|
376 |
|
|
query.setMaxResults(limit);
|
377 |
|
|
}
|
378 |
|
|
return getUuidAndTitleCache(query);
|
379 |
|
|
}
|
380 |
|
|
|
381 |
af1131f2
|
Katja Luther
|
@Override
|
382 |
|
|
public TermVocabularyDto findVocabularyDtoByUuid(UUID vocUuid) {
|
383 |
|
|
Session session = getSession();
|
384 |
|
|
Criteria crit = session.createCriteria(type);
|
385 |
|
|
crit.add(Restrictions.eq("uuid", vocUuid));
|
386 |
|
|
crit.addOrder(Order.desc("created"));
|
387 |
|
|
List<TermVocabulary> result = crit.list();
|
388 |
|
|
|
389 |
|
|
if (result.size() == 0){
|
390 |
|
|
return null;
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
TermVocabulary resultVoc = result.get(0);
|
394 |
|
|
TermVocabularyDto dto = new TermVocabularyDto(resultVoc.getUuid(), resultVoc.getRepresentations(), resultVoc.getTermType());
|
395 |
|
|
for (Object o: resultVoc.getTerms()){
|
396 |
|
|
DefinedTermBase term = (DefinedTermBase)o;
|
397 |
|
|
dto.addTerm(TermDto.fromTerm(term));
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
return dto;
|
401 |
|
|
}
|
402 |
|
|
|
403 |
b6ea6bbc
|
Katja Luther
|
@Override
|
404 |
|
|
public List<TermVocabularyDto> findVocabularyDtoByUuids(List<UUID> vocUuids) {
|
405 |
|
|
Session session = getSession();
|
406 |
|
|
Criteria crit = session.createCriteria(type);
|
407 |
|
|
Disjunction or = Restrictions.disjunction();
|
408 |
|
|
for (UUID uuid: vocUuids){
|
409 |
|
|
or.add(Restrictions.or(Restrictions.eq("uuid", uuid)));
|
410 |
|
|
}
|
411 |
|
|
crit.add(or);
|
412 |
|
|
crit.addOrder(Order.desc("created"));
|
413 |
|
|
List<TermVocabulary> result = crit.list();
|
414 |
|
|
|
415 |
|
|
if (result.size() == 0){
|
416 |
|
|
return null;
|
417 |
|
|
}
|
418 |
|
|
List<TermVocabularyDto> dtos = new ArrayList<>();
|
419 |
|
|
for (TermVocabulary voc: result){
|
420 |
|
|
TermVocabularyDto dto = new TermVocabularyDto(voc.getUuid(), voc.getRepresentations(), voc.getTermType());
|
421 |
|
|
for (Object o: voc.getTerms()){
|
422 |
|
|
DefinedTermBase term = (DefinedTermBase)o;
|
423 |
|
|
dto.addTerm(TermDto.fromTerm(term));
|
424 |
|
|
}
|
425 |
|
|
dtos.add(dto);
|
426 |
|
|
|
427 |
|
|
}
|
428 |
|
|
return dtos;
|
429 |
|
|
}
|
430 |
|
|
|
431 |
367973e0
|
Andreas Müller
|
}
|