Revision 76cfd0f6
Added by Andreas Müller about 5 years ago
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/EditGeoService.java | ||
---|---|---|
52 | 52 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
53 | 53 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
54 | 54 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
55 |
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao; |
|
56 |
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao; |
|
57 | 55 |
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao; |
58 | 56 |
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao; |
57 |
import eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao; |
|
58 |
import eu.etaxonomy.cdm.persistence.dao.term.ITermVocabularyDao; |
|
59 | 59 |
|
60 | 60 |
/** |
61 | 61 |
* @author a.kohlbecker |
... | ... | |
76 | 76 |
@Autowired |
77 | 77 |
private ITermVocabularyDao vocabDao; |
78 | 78 |
|
79 |
private IDefinedTermDao termDao; |
|
80 | 79 |
@Autowired |
81 |
public void setTermDao(IDefinedTermDao termDao) { |
|
82 |
this.termDao = termDao; |
|
83 |
EditGeoServiceUtilities.setTermDao(termDao); |
|
84 |
} |
|
80 |
private IDefinedTermDao termDao; |
|
85 | 81 |
|
86 | 82 |
@Autowired |
87 | 83 |
private IOccurrenceDao occurrenceDao; |
88 | 84 |
|
89 | 85 |
private Set<Feature> getDistributionFeatures() { |
90 |
Set<Feature> distributionFeature = new HashSet<Feature>();
|
|
86 |
Set<Feature> distributionFeature = new HashSet<>(); |
|
91 | 87 |
Feature feature = (Feature) termDao.findByUuid(Feature.DISTRIBUTION().getUuid()); |
92 | 88 |
distributionFeature.add(feature); |
93 | 89 |
return distributionFeature; |
... | ... | |
98 | 94 |
* @return |
99 | 95 |
*/ |
100 | 96 |
private Set<Distribution> getDistributionsOf(List<TaxonDescription> taxonDescriptions) { |
101 |
Set<Distribution> result = new HashSet<Distribution>();
|
|
97 |
Set<Distribution> result = new HashSet<>(); |
|
102 | 98 |
|
103 | 99 |
Set<Feature> features = getDistributionFeatures(); |
104 | 100 |
for (TaxonDescription taxonDescription : taxonDescriptions) { |
... | ... | |
187 | 183 |
Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors, |
188 | 184 |
List<Language> langs) { |
189 | 185 |
|
190 |
List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
|
|
186 |
List<TaxonDescription> taxonDescriptions = new ArrayList<>(); |
|
191 | 187 |
taxonDescriptions.add(taxonDescription); |
192 | 188 |
|
193 | 189 |
return getDistributionServiceRequestParameterString(taxonDescriptions, |
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/EditGeoServiceUtilities.java | ||
---|---|---|
52 | 52 |
import eu.etaxonomy.cdm.model.term.Representation; |
53 | 53 |
import eu.etaxonomy.cdm.model.term.TermType; |
54 | 54 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
55 |
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao; |
|
56 | 55 |
|
57 | 56 |
/** |
58 | 57 |
* Class implementing the business logic for creating the map service string for |
... | ... | |
68 | 67 |
|
69 | 68 |
private static final int INT_MAX_LENGTH = String.valueOf(Integer.MAX_VALUE).length(); |
70 | 69 |
|
71 |
private static IDefinedTermDao termDao; |
|
72 |
|
|
73 |
/** |
|
74 |
* @param termDao |
|
75 |
*/ |
|
76 |
public static void setTermDao(IDefinedTermDao termDao) { |
|
77 |
EditGeoServiceUtilities.termDao= termDao; |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 | 70 |
private static HashMap<SpecimenOrObservationType, Color> defaultSpecimenOrObservationTypeColors = null; |
82 | 71 |
|
83 | 72 |
private static HashMap<SpecimenOrObservationType, Color> getDefaultSpecimenOrObservationTypeColors() { |
cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/geo/EditGeoServiceTest.java | ||
---|---|---|
61 | 61 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
62 | 62 |
import eu.etaxonomy.cdm.model.term.TermType; |
63 | 63 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
64 |
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao; |
|
65 | 64 |
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest; |
66 | 65 |
|
67 | 66 |
/** |
... | ... | |
74 | 73 |
private static final String EDIT_MAPSERVICE_URI_STING = "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php"; |
75 | 74 |
private static URI editMapServiceUri; |
76 | 75 |
|
77 |
@SpringBeanByType |
|
78 |
private IDefinedTermDao termDao; |
|
79 |
|
|
80 | 76 |
@SpringBeanByType |
81 | 77 |
private ITermService termService; |
82 | 78 |
|
... | ... | |
98 | 94 |
*/ |
99 | 95 |
@Before |
100 | 96 |
public void setUp() throws Exception { |
101 |
EditGeoServiceUtilities.setTermDao(termDao); |
|
102 | 97 |
System.setProperty("ONLY-A-TEST", "TRUE"); // allows EditGeoServiceUtilities to skip some line of code |
103 | 98 |
editMapServiceUri = new URI(EDIT_MAPSERVICE_URI_STING); |
104 | 99 |
} |
... | ... | |
107 | 102 |
//******************************************** TESTS************** |
108 | 103 |
|
109 | 104 |
@Test |
110 |
public void testGetWebServiceUrlCountry() throws MalformedURLException, IOException {
|
|
111 |
Set<Distribution> distributions = new HashSet<Distribution>();
|
|
105 |
public void testGetWebServiceUrlCountry() { |
|
106 |
Set<Distribution> distributions = new HashSet<>(); |
|
112 | 107 |
Country germany = termService.findByIdInVocabulary("DEU", Country.uuidCountryVocabulary, Country.class); |
113 | 108 |
// germany = (Country)termService.find(665); |
114 | 109 |
// germany = (Country)termService.find(UUID.fromString("cbe7ce69-2952-4309-85dd-0d7d4a4830a1")); |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/PersistentTermInitializer.java | ||
---|---|---|
33 | 33 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
34 | 34 |
import eu.etaxonomy.cdm.model.term.VocabularyEnum; |
35 | 35 |
import eu.etaxonomy.cdm.model.term.init.TermLoader; |
36 |
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
|
|
36 |
import eu.etaxonomy.cdm.persistence.dao.term.ITermVocabularyDao;
|
|
37 | 37 |
|
38 | 38 |
/** |
39 | 39 |
* Spring bean class to initialize the {@link IVocabularyStore IVocabularyStore}. |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IDefinedTermDao.java | ||
---|---|---|
1 |
/** |
|
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 |
package eu.etaxonomy.cdm.persistence.dao.common; |
|
11 |
|
|
12 |
import java.net.URI; |
|
13 |
import java.util.Collection; |
|
14 |
import java.util.Enumeration; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Locale; |
|
17 |
import java.util.Set; |
|
18 |
import java.util.UUID; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.model.common.Language; |
|
21 |
import eu.etaxonomy.cdm.model.location.Country; |
|
22 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
23 |
import eu.etaxonomy.cdm.model.location.NamedAreaLevel; |
|
24 |
import eu.etaxonomy.cdm.model.location.NamedAreaType; |
|
25 |
import eu.etaxonomy.cdm.model.media.Media; |
|
26 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
27 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
28 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
29 |
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer; |
|
30 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
31 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
32 |
|
|
33 |
|
|
34 |
public interface IDefinedTermDao extends IIdentifiableDao<DefinedTermBase>, ITitledDao<DefinedTermBase>{ |
|
35 |
|
|
36 |
/** |
|
37 |
* @param iso639 a two or three letter language code according to iso639-1 or iso639-2 |
|
38 |
* @return the Language or null |
|
39 |
*/ |
|
40 |
//TODO refactor typo: |
|
41 |
public Language getLanguageByIso(String iso639); |
|
42 |
|
|
43 |
public List<Language> getLanguagesByIso(List<String> iso639List); |
|
44 |
|
|
45 |
public List<Language> getLanguagesByLocale(Enumeration<Locale> locales); |
|
46 |
|
|
47 |
/** |
|
48 |
* Returns the country with the isoCode iso639, works only with string length 2 or 3 |
|
49 |
* |
|
50 |
* @param iso639 the isoCode of the searched country |
|
51 |
* |
|
52 |
* @return country with isoCode iso639 |
|
53 |
*/ |
|
54 |
public Country getCountryByIso(String iso639); |
|
55 |
|
|
56 |
public <TYPE extends DefinedTermBase> List<TYPE> getDefinedTermByRepresentationText(String text, Class<TYPE> clazz ); |
|
57 |
|
|
58 |
public <TYPE extends DefinedTermBase> List<TYPE> getDefinedTermByRepresentationText(String text, Class<TYPE> clazz, Integer pageSize,Integer pageNumber); |
|
59 |
|
|
60 |
public long countDefinedTermByRepresentationText(String text, Class<? extends DefinedTermBase> clazz); |
|
61 |
|
|
62 |
public <TYPE extends DefinedTermBase> List<TYPE> getDefinedTermByRepresentationAbbrev(String text, Class<TYPE> clazz, Integer pageSize,Integer pageNumber); |
|
63 |
|
|
64 |
public long countDefinedTermByRepresentationAbbrev(String text, Class<? extends DefinedTermBase> clazz); |
|
65 |
|
|
66 |
|
|
67 |
/** |
|
68 |
* Returns a List of Media that represent a given DefinedTerm instance |
|
69 |
* |
|
70 |
* @param definedTerm the definedTerm represented by these media |
|
71 |
* @param pageSize The maximum number of media returned (can be null for all related media) |
|
72 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
|
73 |
* @return a List of media instances |
|
74 |
*/ |
|
75 |
public List<Media> getMedia(DefinedTermBase definedTerm, Integer pageSize, Integer pageNumber); |
|
76 |
|
|
77 |
/** |
|
78 |
* Returns a count of the Media that represent a given |
|
79 |
* DefinedTermBase instance |
|
80 |
* |
|
81 |
* @param definedTerm the definedTerm represented by these media |
|
82 |
* @return a count of Media entities |
|
83 |
*/ |
|
84 |
public long countMedia(DefinedTermBase definedTerm); |
|
85 |
|
|
86 |
/** |
|
87 |
* Returns a List of NamedArea instances (optionally filtered by type or level) |
|
88 |
* |
|
89 |
* @param level restrict the result set to named areas of a certain level (can be null) |
|
90 |
* @param type restrict the result set to named areas of a certain type (can be null) |
|
91 |
* @param pageSize The maximum number of namedAreas returned (can be null for all named areas) |
|
92 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
|
93 |
* @return a List of named areas |
|
94 |
*/ |
|
95 |
public List<NamedArea> list(NamedAreaLevel level, NamedAreaType type, Integer pageSize, Integer pageNumber); |
|
96 |
|
|
97 |
/** |
|
98 |
* @param level |
|
99 |
* @param type |
|
100 |
* @param pageSize |
|
101 |
* @param pageNumber |
|
102 |
* @param orderHints |
|
103 |
* @param propertyPaths |
|
104 |
* @return |
|
105 |
*/ |
|
106 |
public List<NamedArea> list(NamedAreaLevel level, NamedAreaType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths); |
|
107 |
|
|
108 |
|
|
109 |
/** |
|
110 |
* Returns a count of NamedArea instances (optionally filtered by type or level) |
|
111 |
* |
|
112 |
* @param level restrict the result set to named areas of a certain level (can be null) |
|
113 |
* @param type restrict the result set to named areas of a certain type (can be null) |
|
114 |
* @return a count of named areas |
|
115 |
*/ |
|
116 |
public long count(NamedAreaLevel level, NamedAreaType type); |
|
117 |
|
|
118 |
/** |
|
119 |
* Return a list of terms which are specializations of a given definedTerm |
|
120 |
* |
|
121 |
* @param definedTerm The term which is a generalization of the terms returned |
|
122 |
* @param pageSize The maximum number of terms returned (can be null for all specializations) |
|
123 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
|
124 |
* @return a List of DefinedTerms |
|
125 |
*/ |
|
126 |
public <T extends DefinedTermBase> List<T> getGeneralizationOf(T definedTerm, Integer pageSize, Integer pageNumber); |
|
127 |
|
|
128 |
/** |
|
129 |
* Return a count of terms which are specializations of a given definedTerm |
|
130 |
* |
|
131 |
* @param definedTerm The term which is a generalization of the terms returned |
|
132 |
* @return a count of DefinedTerms |
|
133 |
*/ |
|
134 |
public <T extends DefinedTermBase> long countGeneralizationOf(T definedTerm); |
|
135 |
|
|
136 |
/** |
|
137 |
* Return a List of distinct terms which include the terms supplied |
|
138 |
* |
|
139 |
* @param definedTerms the set of terms which are part of the terms of interest |
|
140 |
* @param pageSize The maximum number of terms returned (can be null for all terms) |
|
141 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
|
142 |
* @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)} |
|
143 |
* @return a List of DefinedTerms |
|
144 |
*/ |
|
145 |
public <T extends DefinedTermBase> List<T> getPartOf(Set<T> definedTerms, Integer pageSize, Integer pageNumber, List<String> propertyPaths); |
|
146 |
|
|
147 |
/** |
|
148 |
* Return a count of distinct terms which include the terms supplied |
|
149 |
* |
|
150 |
* @param definedTerms the set of terms which are part of the terms of interest |
|
151 |
* @return a count of DefinedTerms |
|
152 |
*/ |
|
153 |
public <T extends DefinedTermBase> long countPartOf(Set<T> definedTerms); |
|
154 |
|
|
155 |
/** |
|
156 |
* Return a List of terms which are part of the terms supplied |
|
157 |
* |
|
158 |
* @param definedTerms the collection of terms which include the terms of interest |
|
159 |
* @param pageSize The maximum number of terms returned (can be null for all terms) |
|
160 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
|
161 |
* @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)} |
|
162 |
* @return a List of DefinedTerms |
|
163 |
*/ |
|
164 |
public <T extends DefinedTermBase> List<T> getIncludes(Collection<T> definedTerms, Integer pageSize, Integer pageNumber, List<String> propertyPaths); |
|
165 |
|
|
166 |
/** |
|
167 |
* Return a count of terms which are part of the terms supplied |
|
168 |
* |
|
169 |
* @param definedTerms the set of terms which include the terms of interest |
|
170 |
* @return a count of DefinedTerms |
|
171 |
*/ |
|
172 |
public <T extends DefinedTermBase> long countIncludes(Collection<T> definedTerms); |
|
173 |
|
|
174 |
public DefinedTermBase findByUri(URI uri); |
|
175 |
|
|
176 |
/** |
|
177 |
* Retrieves all {@link DefinedTermBase}s with the given {@link TermType} |
|
178 |
* @param termType the term type to filter the terms |
|
179 |
* @param limit |
|
180 |
* @param start |
|
181 |
* @param orderHints |
|
182 |
* @param propertyPaths |
|
183 |
* @return a list containing the terms |
|
184 |
*/ |
|
185 |
public <T extends DefinedTermBase> List<T> listByTermType(TermType termType, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths); |
|
186 |
|
|
187 |
public <TERM extends DefinedTermBase> List<TERM> listByTermClass(Class<TERM> clazz, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths); |
|
188 |
|
|
189 |
/** |
|
190 |
* Returns a term or a list of terms depending of the label/id used in its vocabulary. |
|
191 |
* @param idInVoc |
|
192 |
* @param vocUuid |
|
193 |
* @param clazz |
|
194 |
* @param pageSize |
|
195 |
* @param pageNumber |
|
196 |
* @return |
|
197 |
*/ |
|
198 |
public <TERM extends DefinedTermBase> List<TERM> getDefinedTermByIdInVocabulary(String idInVoc, UUID vocUuid, Class<TERM> clazz, Integer pageSize, Integer pageNumber); |
|
199 |
|
|
200 |
/** |
|
201 |
* @param clazz |
|
202 |
* @param vocs |
|
203 |
* @param limit |
|
204 |
* @param pattern |
|
205 |
* @return |
|
206 |
*/ |
|
207 |
public List<NamedArea> getUuidAndTitleCache(List<TermVocabulary> vocs, Integer limit, |
|
208 |
String pattern); |
|
209 |
|
|
210 |
/** |
|
211 |
* Returns all terms that are included in the given parent term resp. a part of the given term. |
|
212 |
* @param parentTerm the parent term |
|
213 |
* @return a collection of included terms |
|
214 |
*/ |
|
215 |
public Collection<TermDto> getIncludesAsDto(TermDto parentTerm); |
|
216 |
|
|
217 |
/** |
|
218 |
* Returns all terms that the given term is a generalization of resp. that are a kind of the given term |
|
219 |
* @param parentTerm the parent term |
|
220 |
* @return a collection of included terms |
|
221 |
*/ |
|
222 |
public Collection<TermDto> getKindOfsAsDto(TermDto parentTerm); |
|
223 |
|
|
224 |
public Collection<TermDto> findByTitleAsDto(String title, TermType termType); |
|
225 |
|
|
226 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IOrderedTermVocabularyDao.java | ||
---|---|---|
1 |
/** |
|
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 |
package eu.etaxonomy.cdm.persistence.dao.common; |
|
11 |
|
|
12 |
import eu.etaxonomy.cdm.model.term.OrderedTermBase; |
|
13 |
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary; |
|
14 |
|
|
15 |
|
|
16 |
/** |
|
17 |
* @author a.mueller |
|
18 |
* |
|
19 |
*/ |
|
20 |
public interface IOrderedTermVocabularyDao extends ICdmEntityDao<OrderedTermVocabulary<OrderedTermBase<?>>> { |
|
21 |
|
|
22 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IRepresentationDao.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2009 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 |
package eu.etaxonomy.cdm.persistence.dao.common; |
|
11 |
|
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.model.term.Representation; |
|
15 |
|
|
16 |
public interface IRepresentationDao extends ILanguageStringBaseDao<Representation> { |
|
17 |
|
|
18 |
public List<Representation> getAllRepresentations(Integer limit, Integer start); |
|
19 |
|
|
20 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/ITermVocabularyDao.java | ||
---|---|---|
1 |
/** |
|
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 |
package eu.etaxonomy.cdm.persistence.dao.common; |
|
11 |
|
|
12 |
|
|
13 |
import java.util.Collection; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
import java.util.Set; |
|
17 |
import java.util.UUID; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
20 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
21 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
22 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
23 |
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto; |
|
24 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
25 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* @author a.mueller |
|
30 |
* |
|
31 |
*/ |
|
32 |
public interface ITermVocabularyDao extends IIdentifiableDao<TermVocabulary> { |
|
33 |
|
|
34 |
/** |
|
35 |
* Return a count of terms that belong to the termVocabulary supplied |
|
36 |
* |
|
37 |
* @param termVocabulary The term vocabulary which 'owns' the terms of interest |
|
38 |
* @return a count of terms |
|
39 |
*/ |
|
40 |
public long countTerms(TermVocabulary termVocabulary); |
|
41 |
|
|
42 |
/** |
|
43 |
* Return a List of terms that belong to the termVocabulary supplied |
|
44 |
* |
|
45 |
* @param termVocabulary The term vocabulary which 'owns' the terms of interest |
|
46 |
* @param pageSize The maximum number of terms returned (can be null for all terms) |
|
47 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
|
48 |
* @return a List of terms |
|
49 |
*/ |
|
50 |
public <T extends DefinedTermBase> List<T> getTerms(TermVocabulary<T> termVocabulary, Integer pageSize, Integer pageNumber); |
|
51 |
|
|
52 |
public <T extends DefinedTermBase> TermVocabulary<T> findByUri(String termSourceUri, Class<T> clazz); |
|
53 |
|
|
54 |
/** |
|
55 |
* Return a List of terms that belong to the termVocabulary supplied |
|
56 |
* |
|
57 |
* @param termVocabulary The term vocabulary which 'owns' the terms of interest |
|
58 |
* @param pageSize The maximum number of terms returned (can be null for all terms) |
|
59 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
|
60 |
* @param orderHints |
|
61 |
* Supports path like <code>orderHints.propertyNames</code> which |
|
62 |
* include *-to-one properties like createdBy.username or |
|
63 |
* authorTeam.persistentTitleCache |
|
64 |
* @param propertyPaths properties to be initialized |
|
65 |
* @return a List of terms |
|
66 |
*/ |
|
67 |
public <T extends DefinedTermBase> List<T> getTerms(TermVocabulary<T> vocabulary,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths); |
|
68 |
|
|
69 |
/** |
|
70 |
* Return a List of vocabularies that belong to the term type supplied |
|
71 |
* |
|
72 |
* @param termType The term type corresponding to the vocabularies of interest |
|
73 |
* @param propertyPaths |
|
74 |
* @return a List of vocabularies |
|
75 |
*/ |
|
76 |
public <T extends DefinedTermBase> List<TermVocabulary<T>> findByTermType(TermType termType, List<String> propertyPaths); |
|
77 |
|
|
78 |
|
|
79 |
/** |
|
80 |
* Returns term vocabularies that contain terms of a certain {@link TermType} e.g. Feature, Modifier, State. |
|
81 |
* |
|
82 |
* @param <TERMTYPE> |
|
83 |
* @param termType the {@link TermType} of the terms in the vocabulary and of the vocabulary |
|
84 |
* @param includeSubtypes if <code>true</code> all subtypes will be included for computation of the result |
|
85 |
* @param limit The maximum number of vocabularies returned (can be null for all vocabularies) |
|
86 |
* @param start The offset from the start of the result set (0 - based, can be null - equivalent of starting at the beginning of the recordset) |
|
87 |
* @param orderHints |
|
88 |
* Supports path like <code>orderHints.propertyNames</code> which |
|
89 |
* include *-to-one properties like createdBy.username or |
|
90 |
* authorTeam.persistentTitleCache |
|
91 |
* @param propertyPaths properties to be initialized |
|
92 |
* @return a list of term vocabularies |
|
93 |
*/ |
|
94 |
public List<TermVocabulary> listByTermType(TermType termType, boolean includeSubtypes, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths); |
|
95 |
|
|
96 |
/** |
|
97 |
* Fills the response map with those term uuids which do exist in the requested map |
|
98 |
* but not in the repository (missing terms). The map key is the vocabulary uuid in both cases. |
|
99 |
* If parameter vocabularyRepsonse is not <code>null</code> the vocabularies will be fully loaded |
|
100 |
* and returned within the map. The later is for using this method together with fast termloading. |
|
101 |
* @param uuidsRequested |
|
102 |
* @param uuidsRepsonse |
|
103 |
* @param vocabularyResponse |
|
104 |
*/ |
|
105 |
public void missingTermUuids(Map<UUID, Set<UUID>> uuidsRequested, |
|
106 |
Map<UUID, Set<UUID>> uuidsRepsonse, |
|
107 |
Map<UUID, TermVocabulary<?>> vocabularyResponse); |
|
108 |
|
|
109 |
/** |
|
110 |
* Loads all top level terms, i.e. terms that have no parent terms, for the given vocabulary |
|
111 |
* @param vocabularyUuid the id of the vocabulary |
|
112 |
* @return a collection of top level terms |
|
113 |
*/ |
|
114 |
public Collection<TermDto> getTopLevelTerms(UUID vocabularyUuid); |
|
115 |
|
|
116 |
/** |
|
117 |
* Returns term vocabularies that contain terms of a certain {@link TermType} e.g. Feature, Modifier, State. |
|
118 |
* |
|
119 |
* @param termType the {@link TermType} of the terms in the vocabulary and of the vocabulary |
|
120 |
* @return a list of term vocabularies |
|
121 |
*/ |
|
122 |
public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType); |
|
123 |
|
|
124 |
/** |
|
125 |
* |
|
126 |
* Like {@link #getUuidAndTitleCache(Class, Integer, String)} but filtering |
|
127 |
* the results by {@link TermType} of the vocabularies. |
|
128 |
* |
|
129 |
* |
|
130 |
* @param clazz |
|
131 |
* the (sub)class |
|
132 |
* @param termType |
|
133 |
* the {@link TermType} of the vocabularies to be retrieved |
|
134 |
* @param limit |
|
135 |
* max number of results |
|
136 |
* @param pattern |
|
137 |
* search pattern |
|
138 |
* @return a list of {@link UuidAndTitleCache} |
|
139 |
* |
|
140 |
* @see #getUuidAndTitleCache(Class, Integer, String)) |
|
141 |
*/ |
|
142 |
public <S extends TermVocabulary> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, TermType termType, |
|
143 |
Integer limit, String pattern); |
|
144 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DefinedTermDaoImpl.java | ||
---|---|---|
1 |
/** |
|
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 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.common; |
|
11 |
|
|
12 |
import java.net.URI; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.Collection; |
|
15 |
import java.util.Enumeration; |
|
16 |
import java.util.Iterator; |
|
17 |
import java.util.List; |
|
18 |
import java.util.Locale; |
|
19 |
import java.util.Set; |
|
20 |
import java.util.UUID; |
|
21 |
|
|
22 |
import org.apache.commons.lang.StringUtils; |
|
23 |
import org.apache.log4j.Logger; |
|
24 |
import org.hibernate.Criteria; |
|
25 |
import org.hibernate.Query; |
|
26 |
import org.hibernate.Session; |
|
27 |
import org.hibernate.criterion.Criterion; |
|
28 |
import org.hibernate.criterion.Projections; |
|
29 |
import org.hibernate.criterion.Restrictions; |
|
30 |
import org.hibernate.envers.query.AuditEntity; |
|
31 |
import org.hibernate.envers.query.AuditQuery; |
|
32 |
import org.springframework.stereotype.Repository; |
|
33 |
|
|
34 |
import eu.etaxonomy.cdm.model.common.AnnotationType; |
|
35 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
36 |
import eu.etaxonomy.cdm.model.common.ExtensionType; |
|
37 |
import eu.etaxonomy.cdm.model.common.Language; |
|
38 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
39 |
import eu.etaxonomy.cdm.model.description.MeasurementUnit; |
|
40 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
41 |
import eu.etaxonomy.cdm.model.description.State; |
|
42 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
|
43 |
import eu.etaxonomy.cdm.model.description.TextFormat; |
|
44 |
import eu.etaxonomy.cdm.model.location.Country; |
|
45 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
46 |
import eu.etaxonomy.cdm.model.location.NamedAreaLevel; |
|
47 |
import eu.etaxonomy.cdm.model.location.NamedAreaType; |
|
48 |
import eu.etaxonomy.cdm.model.location.ReferenceSystem; |
|
49 |
import eu.etaxonomy.cdm.model.media.Media; |
|
50 |
import eu.etaxonomy.cdm.model.media.RightsType; |
|
51 |
import eu.etaxonomy.cdm.model.name.HybridRelationshipType; |
|
52 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
53 |
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus; |
|
54 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; |
|
55 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
56 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus; |
|
57 |
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType; |
|
58 |
import eu.etaxonomy.cdm.model.taxon.SynonymType; |
|
59 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
|
60 |
import eu.etaxonomy.cdm.model.term.DefinedTerm; |
|
61 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
62 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
63 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
64 |
import eu.etaxonomy.cdm.model.view.AuditEvent; |
|
65 |
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao; |
|
66 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
67 |
import eu.etaxonomy.cdm.persistence.query.MatchMode; |
|
68 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
69 |
|
|
70 |
/** |
|
71 |
* @author a.kohlbecker |
|
72 |
* @since 29.05.2008 |
|
73 |
* @version 1.0 |
|
74 |
*/ |
|
75 |
@Repository |
|
76 |
public class DefinedTermDaoImpl extends IdentifiableDaoBase<DefinedTermBase> implements IDefinedTermDao{ |
|
77 |
private static final Logger logger = Logger.getLogger(DefinedTermDaoImpl.class); |
|
78 |
|
|
79 |
public DefinedTermDaoImpl() { |
|
80 |
super(DefinedTermBase.class); |
|
81 |
indexedClasses = new Class[25]; |
|
82 |
indexedClasses[0] = Rank.class; |
|
83 |
indexedClasses[1] = AnnotationType.class; |
|
84 |
indexedClasses[2] = ExtensionType.class; |
|
85 |
indexedClasses[3] = Language.class; |
|
86 |
indexedClasses[4] = MarkerType.class; |
|
87 |
indexedClasses[5] = MeasurementUnit.class; |
|
88 |
indexedClasses[6] = DefinedTerm.class; |
|
89 |
indexedClasses[7] = PresenceAbsenceTerm.class; |
|
90 |
indexedClasses[8] = State.class; |
|
91 |
indexedClasses[9] = StatisticalMeasure.class; |
|
92 |
indexedClasses[10] = TextFormat.class; |
|
93 |
indexedClasses[11] = DerivationEventType.class; |
|
94 |
indexedClasses[12] = NamedArea.class; |
|
95 |
indexedClasses[13] = NamedAreaLevel.class; |
|
96 |
indexedClasses[14] = NamedAreaType.class; |
|
97 |
indexedClasses[15] = ReferenceSystem.class; |
|
98 |
indexedClasses[16] = Country.class; |
|
99 |
indexedClasses[17] = RightsType.class; |
|
100 |
indexedClasses[18] = HybridRelationshipType.class; |
|
101 |
indexedClasses[19] = NameRelationshipType.class; |
|
102 |
indexedClasses[20] = NameTypeDesignationStatus.class; |
|
103 |
indexedClasses[21] = NomenclaturalStatusType.class; |
|
104 |
indexedClasses[22] = SpecimenTypeDesignationStatus.class; |
|
105 |
indexedClasses[23] = SynonymType.class; |
|
106 |
indexedClasses[24] = TaxonRelationshipType.class; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Searches by Label |
|
111 |
* @see eu.etaxonomy.cdm.persistence.dao.common.ITitledDao#findByTitle(java.lang.String) |
|
112 |
*/ |
|
113 |
@Override |
|
114 |
public List<DefinedTermBase> findByTitle(String queryString) { |
|
115 |
return findByTitle(queryString, null); |
|
116 |
} |
|
117 |
|
|
118 |
|
|
119 |
/** |
|
120 |
* Searches by Label |
|
121 |
* @see eu.etaxonomy.cdm.persistence.dao.common.ITitledDao#findByTitle(java.lang.String, eu.etaxonomy.cdm.model.common.CdmBase) |
|
122 |
*/ |
|
123 |
@Override |
|
124 |
public List<DefinedTermBase> findByTitle(String queryString, CdmBase sessionObject) { |
|
125 |
checkNotInPriorView("DefinedTermDaoImpl.findByTitle(String queryString, CdmBase sessionObject)"); |
|
126 |
Session session = getSession(); |
|
127 |
if ( sessionObject != null ) {//attache the object to the session, TODO needed? |
|
128 |
session.update(sessionObject); |
|
129 |
} |
|
130 |
Query query = session.createQuery("select term from DefinedTermBase term join fetch term.representations representation where representation.label = :label"); |
|
131 |
query.setParameter("label", queryString); |
|
132 |
return query.list(); |
|
133 |
|
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
public List<DefinedTermBase> findByTitleAndClass(String queryString, Class<DefinedTermBase> clazz) { |
|
138 |
checkNotInPriorView("DefinedTermDaoImpl.findByTitleAndClass(String queryString, Class<DefinedTermBase> clazz)"); |
|
139 |
Session session = getSession(); |
|
140 |
Criteria crit = session.createCriteria(clazz); |
|
141 |
crit.add(Restrictions.ilike("persistentTitleCache", queryString)); |
|
142 |
List<DefinedTermBase> results = crit.list(); |
|
143 |
return results; |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public List<DefinedTermBase> findByTitle(String queryString, MatchMode matchMode, int page, int pagesize, List<Criterion> criteria) { |
|
148 |
//FIXME is query parametrised? |
|
149 |
checkNotInPriorView("DefinedTermDaoImpl.findByTitle(String queryString, ITitledDao.MATCH_MODE matchMode, int page, int pagesize, List<Criterion> criteria)"); |
|
150 |
Criteria crit = getSession().createCriteria(type); |
|
151 |
crit.add(Restrictions.ilike("titleCache", matchMode.queryStringFrom(queryString))); |
|
152 |
crit.setMaxResults(pagesize); |
|
153 |
int firstItem = (page - 1) * pagesize + 1; |
|
154 |
crit.setFirstResult(firstItem); |
|
155 |
List<DefinedTermBase> results = crit.list(); |
|
156 |
return results; |
|
157 |
} |
|
158 |
|
|
159 |
|
|
160 |
@Override |
|
161 |
public Country getCountryByIso(String iso3166) { |
|
162 |
// If iso639 = "" query returns non-unique result. We prevent this here: |
|
163 |
if (StringUtils.isBlank(iso3166) || iso3166.length()<2 || iso3166.length()>3) { return null; } |
|
164 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
165 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
166 |
Query query = getSession().createQuery("from Country where iso3166_A2 = :isoCode OR idInVocabulary = :isoCode"); |
|
167 |
query.setParameter("isoCode", iso3166); |
|
168 |
return (Country) query.uniqueResult(); |
|
169 |
} else { |
|
170 |
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(Country.class,auditEvent.getRevisionNumber()); |
|
171 |
query.add(AuditEntity.property("iso3166_A2").eq(iso3166)); |
|
172 |
query.add(AuditEntity.property("idInVocabulary").eq(iso3166)); |
|
173 |
return (Country) query.getSingleResult(); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public <T extends DefinedTermBase> List<T> getDefinedTermByRepresentationText(String text, Class<T> clazz ) { |
|
179 |
return getDefinedTermByRepresentationText(text,clazz,null,null); |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public <T extends DefinedTermBase> List<T> getDefinedTermByRepresentationText(String text, Class<T> clazz, Integer pageSize,Integer pageNumber) { |
|
184 |
checkNotInPriorView("DefinedTermDaoImpl.getDefinedTermByRepresentationText(String text, Class<T> clazz, Integer pageSize,Integer pageNumber)"); |
|
185 |
|
|
186 |
Criteria criteria = getCriteria(clazz); |
|
187 |
|
|
188 |
criteria.createAlias("representations", "r").add(Restrictions.like("r.text", text)); |
|
189 |
|
|
190 |
addPageSizeAndNumber(criteria, pageSize, pageNumber); |
|
191 |
|
|
192 |
@SuppressWarnings("unchecked") |
|
193 |
List<T> result = criteria.list(); |
|
194 |
return result; |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public long countDefinedTermByRepresentationText(String text, Class<? extends DefinedTermBase> clazz) { |
|
199 |
checkNotInPriorView("DefinedTermDaoImpl.countDefinedTermByRepresentationText(String text, Class<? extends DefinedTermBase> clazz)"); |
|
200 |
Criteria criteria = getCriteria(clazz); |
|
201 |
|
|
202 |
criteria.createAlias("representations", "r").add(Restrictions.like("r.text", text)); |
|
203 |
|
|
204 |
criteria.setProjection(Projections.rowCount()); |
|
205 |
|
|
206 |
return (Long)criteria.uniqueResult(); |
|
207 |
} |
|
208 |
|
|
209 |
@Override |
|
210 |
public <T extends DefinedTermBase> List<T> getDefinedTermByIdInVocabulary(String label, UUID vocUuid, Class<T> clazz, Integer pageSize, Integer pageNumber) { |
|
211 |
checkNotInPriorView("DefinedTermDaoImpl.getDefinedTermByIdInVocabulary(String label, UUID vocUuid, Class<T> clazz, Integer pageSize, Integer pageNumber)"); |
|
212 |
|
|
213 |
Criteria criteria = getCriteria(clazz); |
|
214 |
|
|
215 |
criteria.createAlias("vocabulary", "voc") |
|
216 |
.add(Restrictions.like("voc.uuid", vocUuid)) |
|
217 |
.add(Restrictions.like("idInVocabulary", label, org.hibernate.criterion.MatchMode.EXACT)); |
|
218 |
|
|
219 |
addPageSizeAndNumber(criteria, pageSize, pageNumber); |
|
220 |
|
|
221 |
@SuppressWarnings("unchecked") |
|
222 |
List<T> result = criteria.list(); |
|
223 |
return result; |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public <T extends DefinedTermBase> List<T> getDefinedTermByRepresentationAbbrev(String text, Class<T> clazz, Integer pageSize,Integer pageNumber) { |
|
228 |
checkNotInPriorView("DefinedTermDaoImpl.getDefinedTermByRepresentationAbbrev(String abbrev, Class<T> clazz, Integer pageSize,Integer pageNumber)"); |
|
229 |
|
|
230 |
Criteria criteria = getCriteria(clazz); |
|
231 |
|
|
232 |
criteria.createAlias("representations", "r").add(Restrictions.like("r.abbreviatedLabel", text)); |
|
233 |
|
|
234 |
addPageSizeAndNumber(criteria, pageSize, pageNumber); |
|
235 |
|
|
236 |
@SuppressWarnings("unchecked") |
|
237 |
List<T> result = criteria.list(); |
|
238 |
return result; |
|
239 |
} |
|
240 |
|
|
241 |
@Override |
|
242 |
public long countDefinedTermByRepresentationAbbrev(String text, Class<? extends DefinedTermBase> clazz) { |
|
243 |
checkNotInPriorView("DefinedTermDaoImpl.countDefinedTermByRepresentationAbbrev(String abbrev, Class<? extends DefinedTermBase> clazz)"); |
|
244 |
Criteria criteria = getCriteria(clazz); |
|
245 |
|
|
246 |
criteria.createAlias("representations", "r").add(Restrictions.like("r.abbreviatedLabel", text)); |
|
247 |
criteria.setProjection(Projections.rowCount()); |
|
248 |
|
|
249 |
return (Long)criteria.uniqueResult(); |
|
250 |
} |
|
251 |
|
|
252 |
@Override |
|
253 |
public Language getLanguageByIso(String iso639) { |
|
254 |
if (iso639.length() < 2 || iso639.length() > 3) { |
|
255 |
logger.warn("Invalid length " + iso639.length() + " of ISO code. Length must be 2 or 3."); |
|
256 |
return null; |
|
257 |
} |
|
258 |
boolean isIso639_1 = iso639.length() == 2; |
|
259 |
|
|
260 |
String queryStr; |
|
261 |
if (isIso639_1){ |
|
262 |
queryStr = "from Language where iso639_1 = :isoCode"; |
|
263 |
}else{ |
|
264 |
queryStr = "from Language where idInVocabulary = :isoCode and vocabulary.uuid = :vocUuid"; |
|
265 |
} |
|
266 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
267 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
268 |
Query query = getSession().createQuery(queryStr); |
|
269 |
query.setParameter("isoCode", iso639); |
|
270 |
if (! isIso639_1){ |
|
271 |
query.setParameter("vocUuid", Language.uuidLanguageVocabulary); |
|
272 |
} |
|
273 |
return (Language) query.uniqueResult(); |
|
274 |
} else { |
|
275 |
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(Language.class,auditEvent.getRevisionNumber()); |
|
276 |
if (isIso639_1){ |
|
277 |
query.add(AuditEntity.property("iso639_1").eq(iso639)); |
|
278 |
}else{ |
|
279 |
query.add(AuditEntity.property("iso639_2").eq(iso639)); |
|
280 |
query.add(AuditEntity.property("vocabulary.uuid").eq(Language.uuidLanguageVocabulary)); |
|
281 |
} |
|
282 |
|
|
283 |
return (Language)query.getSingleResult(); |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* FIXME this will result in a query per language - could you, given that iso codes |
|
289 |
* are unique, use from Language where iso639_1 in (:isoCode) or iso639_2 in (:isoCode) |
|
290 |
*/ |
|
291 |
@Override |
|
292 |
public List<Language> getLanguagesByIso(List<String> iso639List) { |
|
293 |
List<Language> languages = new ArrayList<Language>(iso639List.size()); |
|
294 |
for (String iso639 : iso639List) { |
|
295 |
languages.add(getLanguageByIso(iso639)); |
|
296 |
} |
|
297 |
return languages; |
|
298 |
} |
|
299 |
|
|
300 |
@Override |
|
301 |
public List<Language> getLanguagesByLocale(Enumeration<Locale> locales) { |
|
302 |
List<Language> languages = new ArrayList<Language>(); |
|
303 |
while(locales.hasMoreElements()) { |
|
304 |
Locale locale = locales.nextElement(); |
|
305 |
languages.add(getLanguageByIso(locale.getLanguage())); |
|
306 |
} |
|
307 |
return languages; |
|
308 |
} |
|
309 |
|
|
310 |
@Override |
|
311 |
public long count(NamedAreaLevel level, NamedAreaType type) { |
|
312 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
313 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
314 |
Criteria criteria = getCriteria(NamedArea.class); |
|
315 |
|
|
316 |
if(level != null) { |
|
317 |
criteria.add(Restrictions.eq("level",level)); |
|
318 |
} |
|
319 |
|
|
320 |
if(type != null) { |
|
321 |
criteria.add(Restrictions.eq("type", type)); |
|
322 |
} |
|
323 |
|
|
324 |
criteria.setProjection(Projections.rowCount()); |
|
325 |
|
|
326 |
return (Long)criteria.uniqueResult(); |
|
327 |
} else { |
|
328 |
AuditQuery query = makeAuditQuery(NamedArea.class, auditEvent); |
|
329 |
|
|
330 |
if(level != null) { |
|
331 |
query.add(AuditEntity.relatedId("level").eq(level.getId())); |
|
332 |
} |
|
333 |
|
|
334 |
if(type != null) { |
|
335 |
query.add(AuditEntity.relatedId("type").eq(type.getId())); |
|
336 |
} |
|
337 |
query.addProjection(AuditEntity.id().count()); |
|
338 |
return (Long)query.getSingleResult(); |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
@Override |
|
343 |
public long countMedia(DefinedTermBase definedTerm) { |
|
344 |
checkNotInPriorView("DefinedTermDaoImpl.countMedia(DefinedTermBase definedTerm)"); |
|
345 |
Query query = getSession().createQuery("select count(media) from DefinedTermBase definedTerm join definedTerm.media media where definedTerm = :definedTerm"); |
|
346 |
query.setParameter("definedTerm", definedTerm); |
|
347 |
|
|
348 |
return (Long)query.uniqueResult(); |
|
349 |
} |
|
350 |
|
|
351 |
@Override |
|
352 |
public List<Media> getMedia(DefinedTermBase definedTerm, Integer pageSize, Integer pageNumber) { |
|
353 |
checkNotInPriorView("DefinedTermDaoImpl.getMedia(DefinedTermBase definedTerm, Integer pageSize, Integer pageNumber)"); |
|
354 |
Query query = getSession().createQuery("select media from DefinedTermBase definedTerm join definedTerm.media media where definedTerm = :definedTerm"); |
|
355 |
query.setParameter("definedTerm", definedTerm); |
|
356 |
|
|
357 |
addPageSizeAndNumber(query, pageSize, pageNumber); |
|
358 |
|
|
359 |
@SuppressWarnings("unchecked") |
|
360 |
List<Media> result = query.list(); |
|
361 |
return result; |
|
362 |
} |
|
363 |
|
|
364 |
@Override |
|
365 |
public List<NamedArea> list(NamedAreaLevel level, NamedAreaType type, Integer pageSize, Integer pageNumber) { |
|
366 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
367 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
368 |
Criteria criteria = getCriteria(NamedArea.class); |
|
369 |
|
|
370 |
if(level != null) { |
|
371 |
criteria.add(Restrictions.eq("level",level)); |
|
372 |
} |
|
373 |
|
|
374 |
if(type != null) { |
|
375 |
criteria.add(Restrictions.eq("type", type)); |
|
376 |
} |
|
377 |
|
|
378 |
addPageSizeAndNumber(criteria, pageSize, pageNumber); |
|
379 |
|
|
380 |
@SuppressWarnings("unchecked") |
|
381 |
List<NamedArea> result = criteria.list(); |
|
382 |
return result; |
|
383 |
} else { |
|
384 |
AuditQuery query = makeAuditQuery(NamedArea.class, auditEvent); |
|
385 |
|
|
386 |
if(level != null) { |
|
387 |
query.add(AuditEntity.relatedId("level").eq(level.getId())); |
|
388 |
} |
|
389 |
|
|
390 |
if(type != null) { |
|
391 |
query.add(AuditEntity.relatedId("type").eq(type.getId())); |
|
392 |
} |
|
393 |
|
|
394 |
@SuppressWarnings("unchecked") |
|
395 |
List<NamedArea> result = query.getResultList(); |
|
396 |
return result; |
|
397 |
} |
|
398 |
} |
|
399 |
|
|
400 |
@Override |
|
401 |
public List<NamedArea> list(NamedAreaLevel level, NamedAreaType type, Integer pageSize, Integer pageNumber, |
|
402 |
List<OrderHint> orderHints, List<String> propertyPaths) { |
|
403 |
|
|
404 |
List<NamedArea> result; |
|
405 |
|
|
406 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
407 |
if (auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
408 |
Criteria criteria = getCriteria(NamedArea.class); |
|
409 |
|
|
410 |
if (level != null) { |
|
411 |
criteria.add(Restrictions.eq("level", level)); |
|
412 |
} |
|
413 |
if (type != null) { |
|
414 |
criteria.add(Restrictions.eq("type", type)); |
|
415 |
} |
|
416 |
addOrder(criteria,orderHints); |
|
417 |
addPageSizeAndNumber(criteria, pageSize, pageNumber); |
|
418 |
|
|
419 |
result = criteria.list(); |
|
420 |
|
|
421 |
} else { |
|
422 |
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(NamedArea.class, |
|
423 |
auditEvent.getRevisionNumber()); |
|
424 |
if (level != null) { |
|
425 |
query.add(AuditEntity.relatedId("level").eq(level.getId())); |
|
426 |
} |
|
427 |
if (type != null) { |
|
428 |
query.add(AuditEntity.relatedId("type").eq(type.getId())); |
|
429 |
} |
|
430 |
result = query.getResultList(); |
|
431 |
} |
|
432 |
|
|
433 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
|
434 |
|
|
435 |
return result; |
|
436 |
} |
|
437 |
|
|
438 |
|
|
439 |
@Override |
|
440 |
public <T extends DefinedTermBase> long countGeneralizationOf(T kindOf) { |
|
441 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
442 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
443 |
Query query = getSession().createQuery("select count(term) from DefinedTermBase term where term.kindOf = :kindOf"); |
|
444 |
query.setParameter("kindOf", kindOf); |
|
445 |
return (Long)query.uniqueResult(); |
|
446 |
} else { |
|
447 |
AuditQuery query = makeAuditQuery(DefinedTermBase.class,auditEvent); |
|
448 |
query.add(AuditEntity.relatedId("kindOf").eq(kindOf.getId())); |
|
449 |
query.addProjection(AuditEntity.id().count()); |
|
450 |
return (Long)query.getSingleResult(); |
|
451 |
} |
|
452 |
} |
|
453 |
|
|
454 |
@Override |
|
455 |
public <T extends DefinedTermBase> long countIncludes(Collection<T> partOf) { |
|
456 |
if (partOf == null || partOf.isEmpty()){ |
|
457 |
return 0; |
|
458 |
} |
|
459 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
460 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
461 |
Query query = getSession().createQuery("select count(term) from DefinedTermBase term where term.partOf in (:partOf)"); |
|
462 |
query.setParameterList("partOf", partOf); |
|
463 |
return (Long)query.uniqueResult(); |
|
464 |
} else { |
|
465 |
long count = 0; |
|
466 |
for(T t : partOf) { |
|
467 |
AuditQuery query = makeAuditQuery(DefinedTermBase.class, auditEvent); |
|
468 |
query.add(AuditEntity.relatedId("partOf").eq(t.getId())); |
|
469 |
query.addProjection(AuditEntity.id().count()); |
|
470 |
count += (Long)query.getSingleResult(); |
|
471 |
} |
|
472 |
return count; |
|
473 |
} |
|
474 |
} |
|
475 |
|
|
476 |
@Override |
|
477 |
public <T extends DefinedTermBase> List<T> getGeneralizationOf(T kindOf, Integer pageSize, Integer pageNumber) { |
|
478 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
479 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
480 |
Query query = getSession().createQuery("select term from DefinedTermBase term where term.kindOf = :kindOf"); |
|
481 |
query.setParameter("kindOf", kindOf); |
|
482 |
|
|
483 |
addPageSizeAndNumber(query, pageSize, pageNumber); |
|
484 |
|
|
485 |
@SuppressWarnings("unchecked") |
|
486 |
List<T> result = query.list(); |
|
487 |
return result; |
|
488 |
} else { |
|
489 |
AuditQuery query = makeAuditQuery(DefinedTermBase.class, auditEvent); |
|
490 |
query.add(AuditEntity.relatedId("kindOf").eq(kindOf.getId())); |
|
491 |
|
|
492 |
addPageSizeAndNumber(query, pageSize, pageNumber); |
|
493 |
|
|
494 |
@SuppressWarnings("unchecked") |
|
495 |
List<T> result = query.getResultList(); |
|
496 |
return result; |
|
497 |
} |
|
498 |
} |
|
499 |
|
|
500 |
@Override |
|
501 |
public <T extends DefinedTermBase> List<T> getIncludes(Collection<T> partOf, Integer pageSize, Integer pageNumber, List<String> propertyPaths) { |
|
502 |
if (partOf == null || partOf.isEmpty()){ |
|
503 |
return new ArrayList<>(); |
|
504 |
} |
|
505 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
506 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
507 |
Query query = getSession().createQuery("select term from DefinedTermBase term where term.partOf in (:partOf)"); |
|
508 |
query.setParameterList("partOf", partOf); |
|
509 |
|
|
510 |
addPageSizeAndNumber(query, pageSize, pageNumber); |
|
511 |
|
|
512 |
@SuppressWarnings("unchecked") |
|
513 |
List<T> results = query.list(); |
|
514 |
defaultBeanInitializer.initializeAll(results, propertyPaths); |
|
515 |
return results; |
|
516 |
} else { |
|
517 |
List<T> result = new ArrayList<T>(); |
|
518 |
for(T t : partOf) { |
|
519 |
AuditQuery query = makeAuditQuery(DefinedTermBase.class, auditEvent); |
|
520 |
query.add(AuditEntity.relatedId("partOf").eq(t.getId())); |
|
521 |
addPageSizeAndNumber(query, pageSize, pageNumber); |
|
522 |
|
|
523 |
result.addAll(query.getResultList()); |
|
524 |
} |
|
525 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
|
526 |
return result; |
|
527 |
} |
|
528 |
} |
|
529 |
|
|
530 |
@Override |
|
531 |
public <T extends DefinedTermBase> long countPartOf(Set<T> definedTerms) { |
|
532 |
checkNotInPriorView("DefinedTermDaoImpl.countPartOf(Set<T> definedTerms)"); |
|
533 |
Query query = getSession().createQuery("select count(distinct definedTerm) from DefinedTermBase definedTerm join definedTerm.includes included where included in (:definedTerms)"); |
|
534 |
query.setParameterList("definedTerms", definedTerms); |
|
535 |
return (Long)query.uniqueResult(); |
|
536 |
} |
|
537 |
|
|
538 |
@Override |
|
539 |
public <T extends DefinedTermBase> List<T> getPartOf(Set<T> definedTerms, Integer pageSize, Integer pageNumber, List<String> propertyPaths) { |
|
540 |
checkNotInPriorView("DefinedTermDaoImpl.getPartOf(Set<T> definedTerms, Integer pageSize, Integer pageNumber)"); |
|
541 |
Query query = getSession().createQuery("select distinct definedTerm from DefinedTermBase definedTerm join definedTerm.includes included where included in (:definedTerms)"); |
|
542 |
query.setParameterList("definedTerms", definedTerms); |
|
543 |
|
|
544 |
addPageSizeAndNumber(query, pageSize, pageNumber); |
|
545 |
|
|
546 |
@SuppressWarnings("unchecked") |
|
547 |
List<T> r = query.list(); |
|
548 |
/** |
|
549 |
* For some weird reason, hibernate returns proxies (extending the superclass), not the actual class on this, |
|
550 |
* despite querying the damn database and returning the discriminator along with the rest of the object properties! |
|
551 |
* |
|
552 |
* Probably a bug in hibernate, but we'll manually deproxy for now since the objects are initialized anyway, the |
|
553 |
* performance implications are small (we're swapping one array of references for another, not hitting the db or |
|
554 |
* cache). |
|
555 |
*/ |
|
556 |
List<T> results = new ArrayList<>(); |
|
557 |
if(!definedTerms.isEmpty()) { |
|
558 |
for(T t : r) { |
|
559 |
T deproxied = CdmBase.deproxy(t); |
|
560 |
results.add(deproxied); |
|
561 |
} |
|
562 |
defaultBeanInitializer.initializeAll(results, propertyPaths); |
|
563 |
} |
|
564 |
return results; |
|
565 |
} |
|
566 |
|
|
567 |
@Override |
|
568 |
public DefinedTermBase findByUri(URI uri) { |
|
569 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
570 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
571 |
Query query = getSession().createQuery("select term from DefinedTermBase term where term.uri = :uri"); |
|
572 |
query.setParameter("uri", uri); |
|
573 |
return (DefinedTermBase<?>)query.uniqueResult(); |
|
574 |
} else { |
|
575 |
AuditQuery query = makeAuditQuery(DefinedTermBase.class, auditEvent); |
|
576 |
query.add(AuditEntity.property("uri").eq(uri)); |
|
577 |
return (DefinedTermBase<?>)query.getSingleResult(); |
|
578 |
} |
|
579 |
} |
|
580 |
|
|
581 |
@Override |
|
582 |
public <T extends DefinedTermBase> List<T> listByTermType(TermType termType, Integer limit, Integer start, |
|
583 |
List<OrderHint> orderHints, List<String> propertyPaths) { |
|
584 |
Query query = getSession().createQuery("SELECT term FROM DefinedTermBase term WHERE term.termType = :termType"); |
|
585 |
query.setParameter("termType", termType); |
|
586 |
|
|
587 |
@SuppressWarnings("unchecked") |
|
588 |
List<T> result = query.list(); |
|
589 |
|
|
590 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
|
591 |
return result; |
|
592 |
} |
|
593 |
|
|
594 |
@Override |
|
595 |
public <TERM extends DefinedTermBase> List<TERM> listByTermClass(Class<TERM> clazz, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
596 |
// checkNotInPriorView("DefinedTermDaoImpl.listByTermClass(Class<TERM> clazz, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths)"); |
|
597 |
|
|
598 |
Query query = getSession().createQuery("FROM " + clazz.getSimpleName()); |
|
599 |
|
|
600 |
@SuppressWarnings("unchecked") |
|
601 |
List<TERM> result = query.list(); |
|
602 |
|
|
603 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
|
604 |
|
|
605 |
return result; |
|
606 |
} |
|
607 |
|
|
608 |
@Override |
|
609 |
public <S extends DefinedTermBase> List<S> list(Class<S> type, Integer limit, Integer start, |
|
610 |
List<OrderHint> orderHints, List<String> propertyPath) { |
|
611 |
|
|
612 |
return deduplicateResult(super.list(type, limit, start, orderHints, propertyPath)); |
|
613 |
} |
|
614 |
|
|
615 |
/** |
|
616 |
* Workaround for http://dev.e-taxonomy.eu/trac/ticket/5871 and #5945 |
|
617 |
* Terms with multiple representations return identical duplicates |
|
618 |
* due to eager representation loading. We expect these duplicates to appear |
|
619 |
* in line wo we only compare one term with its predecessor. If it already |
|
620 |
* exists we remove it from the result. |
|
621 |
* @param orginals |
|
622 |
* @return |
|
623 |
*/ |
|
624 |
private <S extends DefinedTermBase<?>> List<S> deduplicateResult(List<S> orginals) { |
|
625 |
List<S> result = new ArrayList<>(); |
|
626 |
Iterator<S> it = orginals.iterator(); |
|
627 |
S last = null; |
|
628 |
while (it.hasNext()){ |
|
629 |
S a = it.next(); |
|
630 |
if (a != last){ |
|
631 |
if (!result.contains(a)){ |
|
632 |
result.add(a); |
|
633 |
} |
|
634 |
} |
|
635 |
last = a; |
|
636 |
} |
|
637 |
return result; |
|
638 |
} |
|
639 |
|
|
640 |
|
|
641 |
@Override |
|
642 |
public List<NamedArea> getUuidAndTitleCache(List<TermVocabulary> vocs, Integer limit, String pattern){ |
|
643 |
Session session = getSession(); |
|
644 |
Query query = null; |
|
645 |
if (pattern != null){ |
|
646 |
if (vocs != null && !vocs.isEmpty()){ |
|
647 |
query = session.createQuery("from NamedArea where titleCache like :pattern and vocabulary in :vocs"); |
|
648 |
query.setParameterList("vocs", vocs); |
|
649 |
}else{ |
|
650 |
query = session.createQuery("from NamedArea where titleCache like :pattern "); |
|
651 |
} |
|
652 |
pattern = pattern.replace("*", "%"); |
|
653 |
pattern = pattern.replace("?", "_"); |
|
654 |
pattern = pattern + "%"; |
|
655 |
query.setParameter("pattern", pattern); |
|
656 |
|
|
657 |
} else { |
|
658 |
query = session.createQuery("FROM NamedArea WHERE vocabulary IN :vocs"); |
|
659 |
query.setParameterList("vocs", vocs); |
|
660 |
} |
|
661 |
if (limit != null){ |
|
662 |
query.setMaxResults(limit); |
|
663 |
} |
|
664 |
@SuppressWarnings("unchecked") |
|
665 |
List<NamedArea> result = query.list(); |
|
666 |
return result; |
|
667 |
} |
|
668 |
|
|
669 |
@Override |
|
670 |
public Collection<TermDto> getIncludesAsDto( |
|
671 |
TermDto parentTerm) { |
|
672 |
String queryString = TermDto.getTermDtoSelect() |
|
673 |
+ "where a.partOf.uuid = :parentUuid"; |
|
674 |
Query query = getSession().createQuery(queryString); |
|
675 |
query.setParameter("parentUuid", parentTerm.getUuid()); |
|
676 |
|
|
677 |
@SuppressWarnings("unchecked") |
|
678 |
List<Object[]> result = query.list(); |
|
679 |
|
|
680 |
List<TermDto> list = TermDto.termDtoListFrom(result); |
|
681 |
return list; |
|
682 |
} |
|
683 |
|
|
684 |
@Override |
|
685 |
public Collection<TermDto> getKindOfsAsDto( |
|
686 |
TermDto parentTerm) { |
|
687 |
String queryString = TermDto.getTermDtoSelect() |
|
688 |
+ "where a.kindOf.uuid = :parentUuid"; |
|
689 |
Query query = getSession().createQuery(queryString); |
|
690 |
query.setParameter("parentUuid", parentTerm.getUuid()); |
|
691 |
|
|
692 |
@SuppressWarnings("unchecked") |
|
693 |
List<Object[]> result = query.list(); |
|
694 |
|
|
695 |
List<TermDto> list = TermDto.termDtoListFrom(result); |
|
696 |
return list; |
|
697 |
} |
|
698 |
|
|
699 |
@Override |
|
700 |
public Collection<TermDto> findByTitleAsDto(String title, TermType termType) { |
|
701 |
String queryString = TermDto.getTermDtoSelect() |
|
702 |
+ " where a.titleCache like :title " |
|
703 |
+ (termType!=null?" and a.termType = :termType ":""); |
|
704 |
Query query = getSession().createQuery(queryString); |
|
705 |
query.setParameter("title", "%"+title+"%"); |
|
706 |
if(termType!=null){ |
|
707 |
query.setParameter("termType", termType); |
|
708 |
} |
|
709 |
|
|
710 |
@SuppressWarnings("unchecked") |
|
711 |
List<Object[]> result = query.list(); |
|
712 |
|
|
713 |
List<TermDto> list = TermDto.termDtoListFrom(result); |
|
714 |
return list; |
|
715 |
} |
|
716 |
|
|
717 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/OrderedTermVocabularyDaoImpl.java | ||
---|---|---|
1 |
/** |
|
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 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.common; |
|
11 |
|
|
12 |
import org.springframework.stereotype.Repository; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.model.term.OrderedTermBase; |
|
15 |
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary; |
|
16 |
import eu.etaxonomy.cdm.persistence.dao.common.IOrderedTermVocabularyDao; |
|
17 |
|
|
18 |
/** |
|
19 |
* @author a.mueller |
|
20 |
* TODO this dao is maybe only a work around for an ClassCastException error thrown when |
|
21 |
* OrderedTermVocabulary<Rank> rankVocabulary = (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(rankUuid); |
|
22 |
* is called in NameServiceImpl.getRankVocabulary(). |
|
23 |
* If data exist in the database, it returns a TermVocabulary$CGLIB class created by hibernate |
|
24 |
*/ |
|
25 |
@Repository |
|
26 |
public class OrderedTermVocabularyDaoImpl extends CdmEntityDaoBase<OrderedTermVocabulary<OrderedTermBase<?>>> implements |
|
27 |
IOrderedTermVocabularyDao { |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* @param type |
|
32 |
*/ |
|
33 |
public OrderedTermVocabularyDaoImpl() { |
|
34 |
super((Class)OrderedTermVocabulary.class); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/RepresentationDaoImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2008 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
*/ |
|
6 |
|
|
7 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.common; |
|
8 |
|
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
import org.apache.log4j.Logger; |
|
12 |
import org.hibernate.Criteria; |
|
13 |
import org.springframework.stereotype.Repository; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.model.term.Representation; |
|
16 |
import eu.etaxonomy.cdm.persistence.dao.common.IRepresentationDao; |
|
17 |
|
|
18 |
/** |
|
19 |
* @author a.babadshanjan |
|
20 |
* @since 10.09.2008 |
|
21 |
*/ |
|
22 |
@Repository |
|
23 |
public class RepresentationDaoImpl |
|
24 |
extends LanguageStringBaseDaoImpl<Representation> implements IRepresentationDao { |
|
25 |
@SuppressWarnings("unused") |
|
26 |
private static final Logger logger = Logger.getLogger(RepresentationDaoImpl.class); |
|
27 |
|
|
28 |
public RepresentationDaoImpl() { |
|
29 |
super(Representation.class); |
|
30 |
} |
|
31 |
|
|
32 |
public List<Representation> getAllRepresentations(Integer limit, Integer start) { |
|
33 |
Criteria crit = getSession().createCriteria(Representation.class); |
|
34 |
List<Representation> results = crit.list(); |
|
35 |
return results; |
|
36 |
} |
|
37 |
} |
|
38 |
|
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/TermVocabularyDaoImpl.java | ||
---|---|---|
1 |
/** |
|
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 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.common; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.Collection; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.HashSet; |
|
16 |
import java.util.List; |
|
17 |
import java.util.Map; |
|
18 |
import java.util.Set; |
|
19 |
import java.util.UUID; |
|
20 |
|
|
21 |
import org.hibernate.Criteria; |
|
22 |
import org.hibernate.Query; |
|
23 |
import org.hibernate.Session; |
|
24 |
import org.hibernate.criterion.Restrictions; |
|
25 |
import org.hibernate.envers.query.AuditEntity; |
|
26 |
import org.hibernate.envers.query.AuditQuery; |
|
27 |
import org.springframework.stereotype.Repository; |
|
28 |
|
|
29 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
30 |
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary; |
|
31 |
import eu.etaxonomy.cdm.model.term.Representation; |
|
32 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
33 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
34 |
import eu.etaxonomy.cdm.model.view.AuditEvent; |
|
35 |
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao; |
|
36 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
37 |
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto; |
|
38 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
39 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
40 |
|
|
41 |
/** |
|
42 |
* @author a.mueller |
|
43 |
* |
|
44 |
*/ |
|
45 |
@Repository |
|
46 |
public class TermVocabularyDaoImpl extends IdentifiableDaoBase<TermVocabulary> implements |
|
47 |
ITermVocabularyDao { |
|
48 |
|
|
49 |
/** |
|
50 |
* @param type |
|
51 |
*/ |
|
52 |
public TermVocabularyDaoImpl() { |
|
53 |
super(TermVocabulary.class); |
|
54 |
indexedClasses = new Class[2]; |
|
55 |
indexedClasses[0] = TermVocabulary.class; |
|
56 |
indexedClasses[1] = OrderedTermVocabulary.class; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public long countTerms(TermVocabulary termVocabulary) { |
|
61 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
62 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
63 |
Query query = getSession().createQuery("select count(term) from DefinedTermBase term where term.vocabulary = :vocabulary"); |
|
64 |
query.setParameter("vocabulary", termVocabulary); |
|
65 |
|
|
66 |
return (Long)query.uniqueResult(); |
|
67 |
} else { |
|
68 |
AuditQuery query = makeAuditQuery(null, auditEvent); |
|
69 |
query.addProjection(AuditEntity.id().count()); |
|
70 |
query.add(AuditEntity.relatedId("vocabulary").eq(termVocabulary.getId())); |
|
71 |
return (Long)query.getSingleResult(); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public <T extends DefinedTermBase> List<T> getTerms(TermVocabulary<T> vocabulary,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,List<String> propertyPaths) { |
|
77 |
AuditEvent auditEvent = getAuditEventFromContext(); |
|
78 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) { |
|
79 |
Criteria criteria = getCriteria(DefinedTermBase.class); |
|
80 |
criteria.createCriteria("vocabulary").add(Restrictions.idEq(vocabulary.getId())); |
|
81 |
|
|
82 |
addPageSizeAndNumber(criteria, pageSize, pageNumber); |
|
83 |
this.addOrder(criteria, orderHints); |
|
84 |
|
|
85 |
@SuppressWarnings("unchecked") |
|
86 |
List<T> result = criteria.list(); |
|
87 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
|
88 |
return result; |
|
89 |
} else { |
|
90 |
AuditQuery query = makeAuditQuery(null, auditEvent); |
|
91 |
query.add(AuditEntity.relatedId("vocabulary").eq(vocabulary.getId())); |
|
92 |
|
|
93 |
addPageSizeAndNumber(query, pageSize, pageNumber); |
|
94 |
|
|
95 |
@SuppressWarnings("unchecked") |
|
96 |
List<T> result = query.getResultList(); |
|
97 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
|
98 |
return result; |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public <T extends DefinedTermBase> TermVocabulary<T> findByUri(String termSourceUri, Class<T> clazz) { |
Also available in: Unified diff
ref #8162 move term related classes from persistence(.dao.)common to .term