1 |
1 |
/**
|
2 |
2 |
* Copyright (C) 2007 EDIT
|
3 |
|
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy
|
4 |
4 |
* http://www.e-taxonomy.eu
|
5 |
|
*
|
|
5 |
*
|
6 |
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7 |
7 |
* See LICENSE.TXT at the top of this package for the full license terms.
|
8 |
8 |
*/
|
... | ... | |
46 |
46 |
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
47 |
47 |
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
48 |
48 |
|
49 |
|
@Repository
|
|
49 |
@Repository
|
50 |
50 |
@Qualifier("descriptionDaoImpl")
|
51 |
51 |
public class DescriptionDaoImpl extends IdentifiableDaoBase<DescriptionBase> implements IDescriptionDao{
|
52 |
52 |
|
53 |
|
@SuppressWarnings("unused")
|
54 |
|
private static final Logger logger = Logger.getLogger(DescriptionDaoImpl.class);
|
55 |
|
|
56 |
|
public DescriptionDaoImpl() {
|
57 |
|
super(DescriptionBase.class);
|
58 |
|
indexedClasses = new Class[3];
|
59 |
|
indexedClasses[0] = TaxonDescription.class;
|
60 |
|
indexedClasses[1] = TaxonNameDescription.class;
|
61 |
|
indexedClasses[2] = SpecimenDescription.class;
|
62 |
|
}
|
63 |
|
|
64 |
|
public int countDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status) {
|
65 |
|
checkNotInPriorView("DescriptionDaoImpl.countDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status)");
|
66 |
|
Query query = null;
|
67 |
|
|
68 |
|
if(status == null) {
|
69 |
|
query = getSession().createQuery("select count(distinct description) from TaxonDescription description left join description.descriptionElements element join element.area area where area in (:namedAreas)");
|
70 |
|
} else {
|
71 |
|
query = getSession().createQuery("select count(distinct description) from TaxonDescription description left join description.descriptionElements element join element.area area join element.status status where area in (:namedAreas) and status = :status");
|
72 |
|
query.setParameter("status", status);
|
73 |
|
}
|
74 |
|
query.setParameterList("namedAreas", namedAreas);
|
75 |
|
|
76 |
|
return ((Long)query.uniqueResult()).intValue();
|
77 |
|
}
|
78 |
|
|
79 |
|
public int countDescriptionElements(DescriptionBase description, Set<Feature> features, Class<? extends DescriptionElementBase> clazz) {
|
80 |
|
AuditEvent auditEvent = getAuditEventFromContext();
|
81 |
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
82 |
|
Criteria criteria = null;
|
83 |
|
if(clazz == null) {
|
84 |
|
criteria = getSession().createCriteria(DescriptionElementBase.class);
|
85 |
|
} else {
|
86 |
|
criteria = getSession().createCriteria(clazz);
|
87 |
|
}
|
88 |
|
|
89 |
|
if(description != null) {
|
90 |
|
criteria.add(Restrictions.eq("inDescription", description));
|
91 |
|
}
|
92 |
|
|
93 |
|
if(features != null && !features.isEmpty()) {
|
94 |
|
criteria.add(Restrictions.in("feature", features));
|
95 |
|
}
|
96 |
|
|
97 |
|
criteria.setProjection(Projections.rowCount());
|
98 |
|
|
99 |
|
return (Integer)criteria.uniqueResult();
|
100 |
|
} else {
|
101 |
|
if(features != null && !features.isEmpty()) {
|
102 |
|
Integer count = 0;
|
103 |
|
for(Feature f : features) {
|
104 |
|
AuditQuery query = null;
|
105 |
|
if(clazz == null) {
|
106 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
107 |
|
} else {
|
108 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
109 |
|
}
|
110 |
|
|
111 |
|
if(description != null) {
|
112 |
|
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
113 |
|
}
|
114 |
|
|
115 |
|
query.add(AuditEntity.relatedId("feature").eq(f.getId()));
|
116 |
|
query.addProjection(AuditEntity.id().count("id"));
|
117 |
|
count += ((Long)query.getSingleResult()).intValue();
|
118 |
|
}
|
119 |
|
|
120 |
|
return count;
|
121 |
|
} else {
|
122 |
|
AuditQuery query = null;
|
123 |
|
if(clazz == null) {
|
124 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
125 |
|
} else {
|
126 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
127 |
|
}
|
128 |
|
|
129 |
|
if(description != null) {
|
130 |
|
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
131 |
|
}
|
132 |
|
query.addProjection(AuditEntity.id().count("id"));
|
133 |
|
return ((Long)query.getSingleResult()).intValue();
|
134 |
|
}
|
135 |
|
}
|
136 |
|
}
|
137 |
|
|
138 |
|
public int countDescriptions(Class<? extends DescriptionBase> clazz, Boolean hasImages, Boolean hasText, Set<Feature> features) {
|
139 |
|
checkNotInPriorView("DescriptionDaoImpl.countDescriptions(Class<TYPE> type, Boolean hasImages, Boolean hasText, Set<Feature> features)");
|
140 |
|
Criteria inner = null;
|
141 |
|
|
142 |
|
if(clazz == null) {
|
143 |
|
inner = getSession().createCriteria(type);
|
144 |
|
} else {
|
145 |
|
inner = getSession().createCriteria(clazz);
|
146 |
|
}
|
147 |
|
|
148 |
|
Criteria elementsCriteria = inner.createCriteria("descriptionElements");
|
149 |
|
if(hasText != null) {
|
150 |
|
if(hasText) {
|
151 |
|
elementsCriteria.add(Restrictions.isNotEmpty("multilanguageText"));
|
152 |
|
} else {
|
153 |
|
elementsCriteria.add(Restrictions.isEmpty("multilanguageText"));
|
154 |
|
}
|
155 |
|
}
|
156 |
|
|
157 |
|
if(hasImages != null) {
|
158 |
|
if(hasImages) {
|
159 |
|
elementsCriteria.add(Restrictions.isNotEmpty("media"));
|
160 |
|
} else {
|
161 |
|
elementsCriteria.add(Restrictions.isEmpty("media"));
|
162 |
|
}
|
163 |
|
}
|
164 |
|
|
165 |
|
if(features != null && !features.isEmpty()) {
|
166 |
|
elementsCriteria.add(Restrictions.in("feature", features));
|
167 |
|
}
|
168 |
|
|
169 |
|
inner.setProjection(Projections.countDistinct("id"));
|
170 |
|
|
171 |
|
return (Integer) inner.uniqueResult();
|
172 |
|
}
|
173 |
|
|
174 |
|
public int countTaxonDescriptions(Taxon taxon, Set<Scope> scopes,Set<NamedArea> geographicalScopes, Set<MarkerType> markerTypes) {
|
175 |
|
AuditEvent auditEvent = getAuditEventFromContext();
|
176 |
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
177 |
|
Criteria criteria = getSession().createCriteria(TaxonDescription.class);
|
178 |
|
|
179 |
|
if(taxon != null) {
|
180 |
|
criteria.add(Restrictions.eq("taxon", taxon));
|
181 |
|
}
|
182 |
|
|
183 |
|
if(scopes != null && !scopes.isEmpty()) {
|
184 |
|
Set<Integer> scopeIds = new HashSet<Integer>();
|
185 |
|
for(Scope s : scopes) {
|
186 |
|
scopeIds.add(s.getId());
|
187 |
|
}
|
188 |
|
criteria.createCriteria("scopes").add(Restrictions.in("id", scopeIds));
|
189 |
|
}
|
190 |
|
|
191 |
|
if(geographicalScopes != null && !geographicalScopes.isEmpty()) {
|
192 |
|
Set<Integer> geoScopeIds = new HashSet<Integer>();
|
193 |
|
for(NamedArea n : geographicalScopes) {
|
194 |
|
geoScopeIds.add(n.getId());
|
195 |
|
}
|
196 |
|
criteria.createCriteria("geoScopes").add(Restrictions.in("id", geoScopeIds));
|
197 |
|
}
|
198 |
|
|
199 |
|
|
200 |
|
addMarkerTypesCriterion(markerTypes, criteria);
|
201 |
|
|
202 |
|
|
203 |
|
criteria.setProjection(Projections.rowCount());
|
204 |
|
|
205 |
|
return (Integer)criteria.uniqueResult();
|
206 |
|
} else {
|
207 |
|
if((scopes == null || scopes.isEmpty())&& (geographicalScopes == null || geographicalScopes.isEmpty()) && (markerTypes == null || markerTypes.isEmpty())) {
|
208 |
|
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(TaxonDescription.class,auditEvent.getRevisionNumber());
|
209 |
|
if(taxon != null) {
|
210 |
|
query.add(AuditEntity.relatedId("taxon").eq(taxon.getId()));
|
211 |
|
}
|
212 |
|
|
213 |
|
query.addProjection(AuditEntity.id().count("id"));
|
214 |
|
|
215 |
|
return ((Long)query.getSingleResult()).intValue();
|
216 |
|
} else {
|
217 |
|
throw new OperationNotSupportedInPriorViewException("countTaxonDescriptions(Taxon taxon, Set<Scope> scopes,Set<NamedArea> geographicalScopes)");
|
218 |
|
}
|
219 |
|
}
|
220 |
|
}
|
221 |
|
|
222 |
|
/**
|
223 |
|
* @param markerTypes
|
224 |
|
* @param criteria
|
225 |
|
*
|
226 |
|
*/
|
227 |
|
//TODO move to AnnotatableEntityDao(?)
|
228 |
|
private void addMarkerTypesCriterion(Set<MarkerType> markerTypes,
|
229 |
|
Criteria criteria) {
|
230 |
|
if(markerTypes != null && !markerTypes.isEmpty()) {
|
231 |
|
Set<Integer> markerTypeIds = new HashSet<Integer>();
|
232 |
|
for(MarkerType markerType : markerTypes) {
|
233 |
|
markerTypeIds.add(markerType.getId());
|
234 |
|
}
|
235 |
|
criteria.createCriteria("markers").add(Restrictions.eq("flag", true))
|
236 |
|
.createAlias("markerType", "mt")
|
237 |
|
.add(Restrictions.in("mt.id", markerTypeIds));
|
238 |
|
}
|
239 |
|
}
|
240 |
|
|
241 |
|
public List<DescriptionElementBase> getDescriptionElements(DescriptionBase description, Set<Feature> features,Class<? extends DescriptionElementBase> clazz, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
242 |
|
|
243 |
|
AuditEvent auditEvent = getAuditEventFromContext();
|
244 |
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
|
53 |
@SuppressWarnings("unused")
|
|
54 |
private static final Logger logger = Logger.getLogger(DescriptionDaoImpl.class);
|
|
55 |
|
|
56 |
public DescriptionDaoImpl() {
|
|
57 |
super(DescriptionBase.class);
|
|
58 |
indexedClasses = new Class[3];
|
|
59 |
indexedClasses[0] = TaxonDescription.class;
|
|
60 |
indexedClasses[1] = TaxonNameDescription.class;
|
|
61 |
indexedClasses[2] = SpecimenDescription.class;
|
|
62 |
}
|
|
63 |
|
|
64 |
public int countDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status) {
|
|
65 |
checkNotInPriorView("DescriptionDaoImpl.countDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status)");
|
|
66 |
Query query = null;
|
|
67 |
|
|
68 |
if(status == null) {
|
|
69 |
query = getSession().createQuery("select count(distinct description) from TaxonDescription description left join description.descriptionElements element join element.area area where area in (:namedAreas)");
|
|
70 |
} else {
|
|
71 |
query = getSession().createQuery("select count(distinct description) from TaxonDescription description left join description.descriptionElements element join element.area area join element.status status where area in (:namedAreas) and status = :status");
|
|
72 |
query.setParameter("status", status);
|
|
73 |
}
|
|
74 |
query.setParameterList("namedAreas", namedAreas);
|
|
75 |
|
|
76 |
return ((Long)query.uniqueResult()).intValue();
|
|
77 |
}
|
|
78 |
|
|
79 |
public int countDescriptionElements(DescriptionBase description, Set<Feature> features, Class<? extends DescriptionElementBase> clazz) {
|
|
80 |
AuditEvent auditEvent = getAuditEventFromContext();
|
|
81 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
|
82 |
Criteria criteria = null;
|
|
83 |
if(clazz == null) {
|
|
84 |
criteria = getSession().createCriteria(DescriptionElementBase.class);
|
|
85 |
} else {
|
|
86 |
criteria = getSession().createCriteria(clazz);
|
|
87 |
}
|
|
88 |
|
|
89 |
if(description != null) {
|
|
90 |
criteria.add(Restrictions.eq("inDescription", description));
|
|
91 |
}
|
|
92 |
|
|
93 |
if(features != null && !features.isEmpty()) {
|
|
94 |
criteria.add(Restrictions.in("feature", features));
|
|
95 |
}
|
|
96 |
|
|
97 |
criteria.setProjection(Projections.rowCount());
|
|
98 |
|
|
99 |
return (Integer)criteria.uniqueResult();
|
|
100 |
} else {
|
|
101 |
if(features != null && !features.isEmpty()) {
|
|
102 |
Integer count = 0;
|
|
103 |
for(Feature f : features) {
|
|
104 |
AuditQuery query = null;
|
|
105 |
if(clazz == null) {
|
|
106 |
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
|
107 |
} else {
|
|
108 |
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
|
109 |
}
|
|
110 |
|
|
111 |
if(description != null) {
|
|
112 |
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
|
113 |
}
|
|
114 |
|
|
115 |
query.add(AuditEntity.relatedId("feature").eq(f.getId()));
|
|
116 |
query.addProjection(AuditEntity.id().count("id"));
|
|
117 |
count += ((Long)query.getSingleResult()).intValue();
|
|
118 |
}
|
|
119 |
|
|
120 |
return count;
|
|
121 |
} else {
|
|
122 |
AuditQuery query = null;
|
|
123 |
if(clazz == null) {
|
|
124 |
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
|
125 |
} else {
|
|
126 |
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
|
127 |
}
|
|
128 |
|
|
129 |
if(description != null) {
|
|
130 |
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
|
131 |
}
|
|
132 |
query.addProjection(AuditEntity.id().count("id"));
|
|
133 |
return ((Long)query.getSingleResult()).intValue();
|
|
134 |
}
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
public int countDescriptions(Class<? extends DescriptionBase> clazz, Boolean hasImages, Boolean hasText, Set<Feature> features) {
|
|
139 |
checkNotInPriorView("DescriptionDaoImpl.countDescriptions(Class<TYPE> type, Boolean hasImages, Boolean hasText, Set<Feature> features)");
|
|
140 |
Criteria inner = null;
|
|
141 |
|
|
142 |
if(clazz == null) {
|
|
143 |
inner = getSession().createCriteria(type);
|
|
144 |
} else {
|
|
145 |
inner = getSession().createCriteria(clazz);
|
|
146 |
}
|
|
147 |
|
|
148 |
Criteria elementsCriteria = inner.createCriteria("descriptionElements");
|
|
149 |
if(hasText != null) {
|
|
150 |
if(hasText) {
|
|
151 |
elementsCriteria.add(Restrictions.isNotEmpty("multilanguageText"));
|
|
152 |
} else {
|
|
153 |
elementsCriteria.add(Restrictions.isEmpty("multilanguageText"));
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
if(hasImages != null) {
|
|
158 |
if(hasImages) {
|
|
159 |
elementsCriteria.add(Restrictions.isNotEmpty("media"));
|
|
160 |
} else {
|
|
161 |
elementsCriteria.add(Restrictions.isEmpty("media"));
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
if(features != null && !features.isEmpty()) {
|
|
166 |
elementsCriteria.add(Restrictions.in("feature", features));
|
|
167 |
}
|
|
168 |
|
|
169 |
inner.setProjection(Projections.countDistinct("id"));
|
|
170 |
|
|
171 |
return (Integer) inner.uniqueResult();
|
|
172 |
}
|
|
173 |
|
|
174 |
public int countTaxonDescriptions(Taxon taxon, Set<Scope> scopes,Set<NamedArea> geographicalScopes, Set<MarkerType> markerTypes) {
|
|
175 |
AuditEvent auditEvent = getAuditEventFromContext();
|
|
176 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
|
177 |
Criteria criteria = getSession().createCriteria(TaxonDescription.class);
|
|
178 |
|
|
179 |
if(taxon != null) {
|
|
180 |
criteria.add(Restrictions.eq("taxon", taxon));
|
|
181 |
}
|
|
182 |
|
|
183 |
if(scopes != null && !scopes.isEmpty()) {
|
|
184 |
Set<Integer> scopeIds = new HashSet<Integer>();
|
|
185 |
for(Scope s : scopes) {
|
|
186 |
scopeIds.add(s.getId());
|
|
187 |
}
|
|
188 |
criteria.createCriteria("scopes").add(Restrictions.in("id", scopeIds));
|
|
189 |
}
|
|
190 |
|
|
191 |
if(geographicalScopes != null && !geographicalScopes.isEmpty()) {
|
|
192 |
Set<Integer> geoScopeIds = new HashSet<Integer>();
|
|
193 |
for(NamedArea n : geographicalScopes) {
|
|
194 |
geoScopeIds.add(n.getId());
|
|
195 |
}
|
|
196 |
criteria.createCriteria("geoScopes").add(Restrictions.in("id", geoScopeIds));
|
|
197 |
}
|
|
198 |
|
|
199 |
|
|
200 |
addMarkerTypesCriterion(markerTypes, criteria);
|
|
201 |
|
|
202 |
|
|
203 |
criteria.setProjection(Projections.rowCount());
|
|
204 |
|
|
205 |
return (Integer)criteria.uniqueResult();
|
|
206 |
} else {
|
|
207 |
if((scopes == null || scopes.isEmpty())&& (geographicalScopes == null || geographicalScopes.isEmpty()) && (markerTypes == null || markerTypes.isEmpty())) {
|
|
208 |
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(TaxonDescription.class,auditEvent.getRevisionNumber());
|
|
209 |
if(taxon != null) {
|
|
210 |
query.add(AuditEntity.relatedId("taxon").eq(taxon.getId()));
|
|
211 |
}
|
|
212 |
|
|
213 |
query.addProjection(AuditEntity.id().count("id"));
|
|
214 |
|
|
215 |
return ((Long)query.getSingleResult()).intValue();
|
|
216 |
} else {
|
|
217 |
throw new OperationNotSupportedInPriorViewException("countTaxonDescriptions(Taxon taxon, Set<Scope> scopes,Set<NamedArea> geographicalScopes)");
|
|
218 |
}
|
|
219 |
}
|
|
220 |
}
|
|
221 |
|
|
222 |
/**
|
|
223 |
* @param markerTypes
|
|
224 |
* @param criteria
|
|
225 |
*
|
|
226 |
*/
|
|
227 |
//TODO move to AnnotatableEntityDao(?)
|
|
228 |
private void addMarkerTypesCriterion(Set<MarkerType> markerTypes,
|
|
229 |
Criteria criteria) {
|
|
230 |
|
|
231 |
if(markerTypes != null && !markerTypes.isEmpty()) {
|
|
232 |
Set<Integer> markerTypeIds = new HashSet<Integer>();
|
|
233 |
for(MarkerType markerType : markerTypes) {
|
|
234 |
markerTypeIds.add(markerType.getId());
|
|
235 |
}
|
|
236 |
criteria.createCriteria("markers").add(Restrictions.eq("flag", true))
|
|
237 |
.createAlias("markerType", "mt")
|
|
238 |
.add(Restrictions.in("mt.id", markerTypeIds));
|
|
239 |
}
|
|
240 |
}
|
|
241 |
|
|
242 |
public List<DescriptionElementBase> getDescriptionElements(DescriptionBase description, Set<Feature> features,Class<? extends DescriptionElementBase> clazz, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
|
243 |
|
|
244 |
AuditEvent auditEvent = getAuditEventFromContext();
|
|
245 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
245 |
246 |
Criteria criteria = null;
|
246 |
247 |
if(clazz == null) {
|
247 |
|
criteria = getSession().createCriteria(DescriptionElementBase.class);
|
|
248 |
criteria = getSession().createCriteria(DescriptionElementBase.class);
|
248 |
249 |
} else {
|
249 |
|
criteria = getSession().createCriteria(clazz);
|
|
250 |
criteria = getSession().createCriteria(clazz);
|
250 |
251 |
}
|
251 |
|
|
|
252 |
|
252 |
253 |
if(description != null) {
|
253 |
|
criteria.add(Restrictions.eq("inDescription", description));
|
254 |
|
}
|
255 |
|
|
256 |
|
if(features != null && !features.isEmpty()) {
|
257 |
|
criteria.add(Restrictions.in("feature", features));
|
258 |
|
}
|
259 |
|
|
260 |
|
if(pageSize != null) {
|
261 |
|
criteria.setMaxResults(pageSize);
|
262 |
|
if(pageNumber != null) {
|
263 |
|
criteria.setFirstResult(pageNumber * pageSize);
|
264 |
|
}
|
265 |
|
}
|
266 |
|
|
267 |
|
List<DescriptionElementBase> results = (List<DescriptionElementBase>)criteria.list();
|
268 |
|
|
269 |
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
270 |
|
|
271 |
|
return results;
|
272 |
|
} else {
|
273 |
|
List<DescriptionElementBase> result = new ArrayList<DescriptionElementBase>();
|
274 |
|
if(features != null && !features.isEmpty()) {
|
275 |
|
|
276 |
|
for(Feature f : features) {
|
277 |
|
AuditQuery query = null;
|
278 |
|
if(clazz == null) {
|
279 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
280 |
|
} else {
|
281 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
282 |
|
}
|
283 |
|
|
284 |
|
if(description != null) {
|
285 |
|
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
286 |
|
}
|
287 |
|
|
288 |
|
query.add(AuditEntity.relatedId("feature").eq(f.getId()));
|
289 |
|
result.addAll((List<DescriptionElementBase>)query.getResultList());
|
290 |
|
}
|
291 |
|
} else {
|
292 |
|
AuditQuery query = null;
|
293 |
|
if(clazz == null) {
|
294 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
295 |
|
} else {
|
296 |
|
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
297 |
|
}
|
298 |
|
|
299 |
|
if(description != null) {
|
300 |
|
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
301 |
|
}
|
302 |
|
|
303 |
|
result = query.getResultList();
|
304 |
|
}
|
305 |
|
|
306 |
|
defaultBeanInitializer.initializeAll(result, propertyPaths);
|
307 |
|
|
308 |
|
return result;
|
309 |
|
}
|
310 |
|
}
|
311 |
|
|
312 |
|
public List<TaxonDescription> getTaxonDescriptions(Taxon taxon, Set<Scope> scopes, Set<NamedArea> geographicalScopes, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
313 |
|
AuditEvent auditEvent = getAuditEventFromContext();
|
314 |
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
315 |
|
Criteria criteria = getSession().createCriteria(TaxonDescription.class);
|
316 |
|
|
317 |
|
if(taxon != null) {
|
318 |
|
criteria.add(Restrictions.eq("taxon", taxon));
|
319 |
|
}
|
320 |
|
|
321 |
|
if(scopes != null && !scopes.isEmpty()) {
|
322 |
|
Set<Integer> scopeIds = new HashSet<Integer>();
|
323 |
|
for(Scope s : scopes) {
|
324 |
|
scopeIds.add(s.getId());
|
325 |
|
}
|
326 |
|
criteria.createCriteria("scopes").add(Restrictions.in("id", scopeIds));
|
327 |
|
}
|
328 |
|
|
329 |
|
if(geographicalScopes != null && !geographicalScopes.isEmpty()) {
|
330 |
|
Set<Integer> geoScopeIds = new HashSet<Integer>();
|
331 |
|
for(NamedArea n : geographicalScopes) {
|
332 |
|
geoScopeIds.add(n.getId());
|
333 |
|
}
|
334 |
|
criteria.createCriteria("geoScopes").add(Restrictions.in("id", geoScopeIds));
|
335 |
|
}
|
336 |
|
|
337 |
|
addMarkerTypesCriterion(markerTypes, criteria);
|
338 |
|
|
339 |
|
if(pageSize != null) {
|
340 |
|
criteria.setMaxResults(pageSize);
|
341 |
|
if(pageNumber != null) {
|
342 |
|
criteria.setFirstResult(pageNumber * pageSize);
|
343 |
|
}
|
344 |
|
}
|
345 |
|
|
346 |
|
List<TaxonDescription> results = (List<TaxonDescription>)criteria.list();
|
347 |
|
|
348 |
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
349 |
|
|
350 |
|
return results;
|
351 |
|
} else {
|
352 |
|
if((scopes == null || scopes.isEmpty())&& (geographicalScopes == null || geographicalScopes.isEmpty())&& (markerTypes == null || markerTypes.isEmpty())) {
|
353 |
|
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(TaxonDescription.class,auditEvent.getRevisionNumber());
|
354 |
|
if(taxon != null) {
|
355 |
|
query.add(AuditEntity.relatedId("taxon").eq(taxon.getId()));
|
356 |
|
}
|
357 |
|
|
358 |
|
if(pageSize != null) {
|
359 |
|
query.setMaxResults(pageSize);
|
360 |
|
if(pageNumber != null) {
|
361 |
|
query.setFirstResult(pageNumber * pageSize);
|
362 |
|
} else {
|
363 |
|
query.setFirstResult(0);
|
364 |
|
}
|
365 |
|
}
|
366 |
|
|
367 |
|
List<TaxonDescription> results = (List<TaxonDescription>)query.getResultList();
|
368 |
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
369 |
|
return results;
|
370 |
|
} else {
|
371 |
|
throw new OperationNotSupportedInPriorViewException("countTaxonDescriptions(Taxon taxon, Set<Scope> scopes,Set<NamedArea> geographicalScopes)");
|
372 |
|
}
|
373 |
|
}
|
374 |
|
}
|
375 |
|
|
|
254 |
criteria.add(Restrictions.eq("inDescription", description));
|
|
255 |
}
|
|
256 |
|
|
257 |
if(features != null && !features.isEmpty()) {
|
|
258 |
criteria.add(Restrictions.in("feature", features));
|
|
259 |
}
|
|
260 |
|
|
261 |
if(pageSize != null) {
|
|
262 |
criteria.setMaxResults(pageSize);
|
|
263 |
if(pageNumber != null) {
|
|
264 |
criteria.setFirstResult(pageNumber * pageSize);
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
List<DescriptionElementBase> results = (List<DescriptionElementBase>)criteria.list();
|
|
269 |
|
|
270 |
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
|
271 |
|
|
272 |
return results;
|
|
273 |
} else {
|
|
274 |
List<DescriptionElementBase> result = new ArrayList<DescriptionElementBase>();
|
|
275 |
if(features != null && !features.isEmpty()) {
|
|
276 |
|
|
277 |
for(Feature f : features) {
|
|
278 |
AuditQuery query = null;
|
|
279 |
if(clazz == null) {
|
|
280 |
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
|
281 |
} else {
|
|
282 |
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
|
283 |
}
|
|
284 |
|
|
285 |
if(description != null) {
|
|
286 |
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
|
287 |
}
|
|
288 |
|
|
289 |
query.add(AuditEntity.relatedId("feature").eq(f.getId()));
|
|
290 |
result.addAll((List<DescriptionElementBase>)query.getResultList());
|
|
291 |
}
|
|
292 |
} else {
|
|
293 |
AuditQuery query = null;
|
|
294 |
if(clazz == null) {
|
|
295 |
query = getAuditReader().createQuery().forEntitiesAtRevision(DescriptionElementBase.class,auditEvent.getRevisionNumber());
|
|
296 |
} else {
|
|
297 |
query = getAuditReader().createQuery().forEntitiesAtRevision(clazz,auditEvent.getRevisionNumber());
|
|
298 |
}
|
|
299 |
|
|
300 |
if(description != null) {
|
|
301 |
query.add(AuditEntity.relatedId("inDescription").eq(description.getId()));
|
|
302 |
}
|
|
303 |
|
|
304 |
result = query.getResultList();
|
|
305 |
}
|
|
306 |
|
|
307 |
defaultBeanInitializer.initializeAll(result, propertyPaths);
|
|
308 |
|
|
309 |
return result;
|
|
310 |
}
|
|
311 |
}
|
|
312 |
|
|
313 |
public List<TaxonDescription> listTaxonDescriptions(Taxon taxon, Set<Scope> scopes, Set<NamedArea> geographicalScopes, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
|
314 |
AuditEvent auditEvent = getAuditEventFromContext();
|
|
315 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
|
316 |
Criteria criteria = getSession().createCriteria(TaxonDescription.class);
|
|
317 |
|
|
318 |
if(taxon != null) {
|
|
319 |
criteria.add(Restrictions.eq("taxon", taxon));
|
|
320 |
}
|
|
321 |
|
|
322 |
if(scopes != null && !scopes.isEmpty()) {
|
|
323 |
Set<Integer> scopeIds = new HashSet<Integer>();
|
|
324 |
for(Scope s : scopes) {
|
|
325 |
scopeIds.add(s.getId());
|
|
326 |
}
|
|
327 |
criteria.createCriteria("scopes").add(Restrictions.in("id", scopeIds));
|
|
328 |
}
|
|
329 |
|
|
330 |
if(geographicalScopes != null && !geographicalScopes.isEmpty()) {
|
|
331 |
Set<Integer> geoScopeIds = new HashSet<Integer>();
|
|
332 |
for(NamedArea n : geographicalScopes) {
|
|
333 |
geoScopeIds.add(n.getId());
|
|
334 |
}
|
|
335 |
criteria.createCriteria("geoScopes").add(Restrictions.in("id", geoScopeIds));
|
|
336 |
}
|
|
337 |
|
|
338 |
addMarkerTypesCriterion(markerTypes, criteria);
|
|
339 |
|
|
340 |
if(pageSize != null) {
|
|
341 |
criteria.setMaxResults(pageSize);
|
|
342 |
if(pageNumber != null) {
|
|
343 |
criteria.setFirstResult(pageNumber * pageSize);
|
|
344 |
}
|
|
345 |
}
|
|
346 |
|
|
347 |
List<TaxonDescription> results = (List<TaxonDescription>)criteria.list();
|
|
348 |
|
|
349 |
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
|
350 |
|
|
351 |
return results;
|
|
352 |
} else {
|
|
353 |
if((scopes == null || scopes.isEmpty())&& (geographicalScopes == null || geographicalScopes.isEmpty())&& (markerTypes == null || markerTypes.isEmpty())) {
|
|
354 |
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(TaxonDescription.class,auditEvent.getRevisionNumber());
|
|
355 |
if(taxon != null) {
|
|
356 |
query.add(AuditEntity.relatedId("taxon").eq(taxon.getId()));
|
|
357 |
}
|
|
358 |
|
|
359 |
if(pageSize != null) {
|
|
360 |
query.setMaxResults(pageSize);
|
|
361 |
if(pageNumber != null) {
|
|
362 |
query.setFirstResult(pageNumber * pageSize);
|
|
363 |
} else {
|
|
364 |
query.setFirstResult(0);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
List<TaxonDescription> results = (List<TaxonDescription>)query.getResultList();
|
|
369 |
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
|
370 |
return results;
|
|
371 |
} else {
|
|
372 |
throw new OperationNotSupportedInPriorViewException("countTaxonDescriptions(Taxon taxon, Set<Scope> scopes,Set<NamedArea> geographicalScopes)");
|
|
373 |
}
|
|
374 |
}
|
|
375 |
}
|
|
376 |
|
376 |
377 |
public List<TaxonNameDescription> getTaxonNameDescriptions(TaxonNameBase name, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
377 |
378 |
AuditEvent auditEvent = getAuditEventFromContext();
|
378 |
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
379 |
|
Criteria criteria = getSession().createCriteria(TaxonNameDescription.class);
|
380 |
|
|
381 |
|
if(name != null) {
|
382 |
|
criteria.add(Restrictions.eq("taxonName", name));
|
383 |
|
}
|
384 |
|
|
385 |
|
if(pageSize != null) {
|
386 |
|
criteria.setMaxResults(pageSize);
|
387 |
|
if(pageNumber != null) {
|
388 |
|
criteria.setFirstResult(pageNumber * pageSize);
|
389 |
|
}
|
390 |
|
}
|
391 |
|
|
392 |
|
List<TaxonNameDescription> results = (List<TaxonNameDescription>)criteria.list();
|
393 |
|
|
394 |
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
395 |
|
|
396 |
|
return results;
|
397 |
|
} else {
|
398 |
|
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(TaxonNameDescription.class,auditEvent.getRevisionNumber());
|
399 |
|
|
400 |
|
if(name != null) {
|
401 |
|
query.add(AuditEntity.relatedId("taxonName").eq(name.getId()));
|
402 |
|
}
|
403 |
|
|
404 |
|
if(pageSize != null) {
|
405 |
|
query.setMaxResults(pageSize);
|
406 |
|
if(pageNumber != null) {
|
407 |
|
query.setFirstResult(pageNumber * pageSize);
|
408 |
|
}
|
409 |
|
}
|
410 |
|
|
411 |
|
List<TaxonNameDescription> results = (List<TaxonNameDescription>)query.getResultList();
|
412 |
|
|
413 |
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
414 |
|
|
415 |
|
return results;
|
416 |
|
}
|
417 |
|
|
|
379 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
|
380 |
Criteria criteria = getSession().createCriteria(TaxonNameDescription.class);
|
|
381 |
|
|
382 |
if(name != null) {
|
|
383 |
criteria.add(Restrictions.eq("taxonName", name));
|
|
384 |
}
|
|
385 |
|
|
386 |
if(pageSize != null) {
|
|
387 |
criteria.setMaxResults(pageSize);
|
|
388 |
if(pageNumber != null) {
|
|
389 |
criteria.setFirstResult(pageNumber * pageSize);
|
|
390 |
}
|
|
391 |
}
|
|
392 |
|
|
393 |
List<TaxonNameDescription> results = (List<TaxonNameDescription>)criteria.list();
|
|
394 |
|
|
395 |
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
|
396 |
|
|
397 |
return results;
|
|
398 |
} else {
|
|
399 |
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(TaxonNameDescription.class,auditEvent.getRevisionNumber());
|
|
400 |
|
|
401 |
if(name != null) {
|
|
402 |
query.add(AuditEntity.relatedId("taxonName").eq(name.getId()));
|
|
403 |
}
|
|
404 |
|
|
405 |
if(pageSize != null) {
|
|
406 |
query.setMaxResults(pageSize);
|
|
407 |
if(pageNumber != null) {
|
|
408 |
query.setFirstResult(pageNumber * pageSize);
|
|
409 |
}
|
|
410 |
}
|
|
411 |
|
|
412 |
List<TaxonNameDescription> results = (List<TaxonNameDescription>)query.getResultList();
|
|
413 |
|
|
414 |
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
|
415 |
|
|
416 |
return results;
|
|
417 |
}
|
|
418 |
|
418 |
419 |
}
|
419 |
|
|
420 |
|
public int countTaxonNameDescriptions(TaxonNameBase name) {
|
421 |
|
AuditEvent auditEvent = getAuditEventFromContext();
|
422 |
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
423 |
|
Criteria criteria = getSession().createCriteria(TaxonNameDescription.class);
|
424 |
|
|
425 |
|
if(name != null) {
|
426 |
|
criteria.add(Restrictions.eq("taxonName", name));
|
427 |
|
}
|
428 |
|
|
429 |
|
criteria.setProjection(Projections.rowCount());
|
430 |
|
|
431 |
|
return (Integer)criteria.uniqueResult();
|
432 |
|
} else {
|
|
420 |
|
|
421 |
public int countTaxonNameDescriptions(TaxonNameBase name) {
|
|
422 |
AuditEvent auditEvent = getAuditEventFromContext();
|
|
423 |
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
|
424 |
Criteria criteria = getSession().createCriteria(TaxonNameDescription.class);
|
|
425 |
|
|
426 |
if(name != null) {
|
|
427 |
criteria.add(Restrictions.eq("taxonName", name));
|
|
428 |
}
|
|
429 |
|
|
430 |
criteria.setProjection(Projections.rowCount());
|
|
431 |
|
|
432 |
return (Integer)criteria.uniqueResult();
|
|
433 |
} else {
|
433 |
434 |
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(TaxonNameDescription.class,auditEvent.getRevisionNumber());
|
434 |
|
|
435 |
|
if(name != null) {
|
436 |
|
query.add(AuditEntity.relatedId("taxonName").eq(name.getId()));
|
437 |
|
}
|
438 |
|
|
439 |
|
query.addProjection(AuditEntity.id().count("id"));
|
440 |
|
return ((Long)query.getSingleResult()).intValue();
|
441 |
|
}
|
442 |
|
}
|
443 |
|
|
444 |
|
/**
|
445 |
|
* Should use a DetachedCriteria & subquery, but HHH-158 prevents this, for now.
|
446 |
|
*
|
447 |
|
* e.g. DetachedCriteria inner = DestachedCriteria.forClass(type);
|
448 |
|
*
|
449 |
|
* outer.add(Subqueries.propertyIn("id", inner));
|
450 |
|
*/
|
451 |
|
public List<DescriptionBase> listDescriptions(Class<? extends DescriptionBase> clazz, Boolean hasImages, Boolean hasText, Set<Feature> features, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
452 |
|
checkNotInPriorView("DescriptionDaoImpl.listDescriptions(Class<TYPE> type, Boolean hasImages, Boolean hasText, Set<Feature> features, Integer pageSize, Integer pageNumber)");
|
453 |
|
Criteria inner = null;
|
454 |
|
|
455 |
|
if(clazz == null) {
|
456 |
|
inner = getSession().createCriteria(type);
|
457 |
|
} else {
|
458 |
|
inner = getSession().createCriteria(clazz);
|
459 |
|
}
|
460 |
|
|
461 |
|
Criteria elementsCriteria = inner.createCriteria("descriptionElements");
|
462 |
|
if(hasText != null) {
|
463 |
|
if(hasText) {
|
464 |
|
elementsCriteria.add(Restrictions.isNotEmpty("multilanguageText"));
|
465 |
|
} else {
|
466 |
|
elementsCriteria.add(Restrictions.isEmpty("multilanguageText"));
|
467 |
|
}
|
468 |
|
}
|
469 |
|
|
470 |
|
if(hasImages != null) {
|
471 |
|
if(hasImages) {
|
472 |
|
elementsCriteria.add(Restrictions.isNotEmpty("media"));
|
473 |
|
} else {
|
474 |
|
elementsCriteria.add(Restrictions.isEmpty("media"));
|
475 |
|
}
|
476 |
|
}
|
477 |
|
|
478 |
|
if(features != null && !features.isEmpty()) {
|
479 |
|
elementsCriteria.add(Restrictions.in("feature", features));
|
480 |
|
}
|
481 |
|
|
482 |
|
inner.setProjection(Projections.distinct(Projections.id()));
|
483 |
|
|
484 |
|
List<Object> intermediateResult = (List<Object>)inner.list();
|
485 |
|
|
486 |
|
if(intermediateResult.isEmpty()) {
|
487 |
|
return new ArrayList<DescriptionBase>();
|
488 |
|
}
|
489 |
|
|
490 |
|
Integer[] resultIds = new Integer[intermediateResult.size()];
|
491 |
|
for(int i = 0; i < resultIds.length; i++) {
|
492 |
|
resultIds[i] = (Integer)intermediateResult.get(i);
|
493 |
|
}
|
494 |
|
|
495 |
|
Criteria outer = null;
|
496 |
|
|
497 |
|
if(clazz == null) {
|
498 |
|
outer = getSession().createCriteria(type);
|
499 |
|
} else {
|
500 |
|
outer = getSession().createCriteria(clazz);
|
501 |
|
}
|
502 |
|
|
503 |
|
outer.add(Restrictions.in("id", resultIds));
|
504 |
|
addOrder(outer, orderHints);
|
505 |
|
|
506 |
|
if(pageSize != null) {
|
507 |
|
outer.setMaxResults(pageSize);
|
508 |
|
if(pageNumber != null) {
|
509 |
|
outer.setFirstResult(pageNumber * pageSize);
|
510 |
|
}
|
511 |
|
}
|
512 |
|
|
513 |
|
List<DescriptionBase> results = (List<DescriptionBase>)outer.list();
|
514 |
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
515 |
|
return results;
|
516 |
|
}
|
517 |
|
|
518 |
|
public List<TaxonDescription> searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
519 |
|
checkNotInPriorView("DescriptionDaoImpl.searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)");
|
520 |
|
|
|
435 |
|
|
436 |
if(name != null) {
|
|
437 |
query.add(AuditEntity.relatedId("taxonName").eq(name.getId()));
|
|
438 |
}
|
|
439 |
|
|
440 |
query.addProjection(AuditEntity.id().count("id"));
|
|
441 |
return ((Long)query.getSingleResult()).intValue();
|
|
442 |
}
|
|
443 |
}
|
|
444 |
|
|
445 |
/**
|
|
446 |
* Should use a DetachedCriteria & subquery, but HHH-158 prevents this, for now.
|
|
447 |
*
|
|
448 |
* e.g. DetachedCriteria inner = DestachedCriteria.forClass(type);
|
|
449 |
*
|
|
450 |
* outer.add(Subqueries.propertyIn("id", inner));
|
|
451 |
*/
|
|
452 |
public List<DescriptionBase> listDescriptions(Class<? extends DescriptionBase> clazz, Boolean hasImages, Boolean hasText, Set<Feature> features, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
|
453 |
checkNotInPriorView("DescriptionDaoImpl.listDescriptions(Class<TYPE> type, Boolean hasImages, Boolean hasText, Set<Feature> features, Integer pageSize, Integer pageNumber)");
|
|
454 |
Criteria inner = null;
|
|
455 |
|
|
456 |
if(clazz == null) {
|
|
457 |
inner = getSession().createCriteria(type);
|
|
458 |
} else {
|
|
459 |
inner = getSession().createCriteria(clazz);
|
|
460 |
}
|
|
461 |
|
|
462 |
Criteria elementsCriteria = inner.createCriteria("descriptionElements");
|
|
463 |
if(hasText != null) {
|
|
464 |
if(hasText) {
|
|
465 |
elementsCriteria.add(Restrictions.isNotEmpty("multilanguageText"));
|
|
466 |
} else {
|
|
467 |
elementsCriteria.add(Restrictions.isEmpty("multilanguageText"));
|
|
468 |
}
|
|
469 |
}
|
|
470 |
|
|
471 |
if(hasImages != null) {
|
|
472 |
if(hasImages) {
|
|
473 |
elementsCriteria.add(Restrictions.isNotEmpty("media"));
|
|
474 |
} else {
|
|
475 |
elementsCriteria.add(Restrictions.isEmpty("media"));
|
|
476 |
}
|
|
477 |
}
|
|
478 |
|
|
479 |
if(features != null && !features.isEmpty()) {
|
|
480 |
elementsCriteria.add(Restrictions.in("feature", features));
|
|
481 |
}
|
|
482 |
|
|
483 |
inner.setProjection(Projections.distinct(Projections.id()));
|
|
484 |
|
|
485 |
List<Object> intermediateResult = (List<Object>)inner.list();
|
|
486 |
|
|
487 |
if(intermediateResult.isEmpty()) {
|
|
488 |
return new ArrayList<DescriptionBase>();
|
|
489 |
}
|
|
490 |
|
|
491 |
Integer[] resultIds = new Integer[intermediateResult.size()];
|
|
492 |
for(int i = 0; i < resultIds.length; i++) {
|
|
493 |
resultIds[i] = (Integer)intermediateResult.get(i);
|
|
494 |
}
|
|
495 |
|
|
496 |
Criteria outer = null;
|
|
497 |
|
|
498 |
if(clazz == null) {
|
|
499 |
outer = getSession().createCriteria(type);
|
|
500 |
} else {
|
|
501 |
outer = getSession().createCriteria(clazz);
|
|
502 |
}
|
|
503 |
|
|
504 |
outer.add(Restrictions.in("id", resultIds));
|
|
505 |
addOrder(outer, orderHints);
|
|
506 |
|
|
507 |
if(pageSize != null) {
|
|
508 |
outer.setMaxResults(pageSize);
|
|
509 |
if(pageNumber != null) {
|
|
510 |
outer.setFirstResult(pageNumber * pageSize);
|
|
511 |
}
|
|
512 |
}
|
|
513 |
|
|
514 |
List<DescriptionBase> results = (List<DescriptionBase>)outer.list();
|
|
515 |
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
|
516 |
return results;
|
|
517 |
}
|
|
518 |
|
|
519 |
public List<TaxonDescription> searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
|
520 |
checkNotInPriorView("DescriptionDaoImpl.searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)");
|
|
521 |
|
521 |
522 |
Criteria criteria = getSession().createCriteria(TaxonDescription.class);
|
522 |
523 |
Criteria elements = criteria.createCriteria("descriptionElements", "descriptionElement", Criteria.LEFT_JOIN);
|
523 |
|
elements.add(Restrictions.in("area", namedAreas.toArray()));
|
524 |
|
|
525 |
|
if(status != null) {
|
526 |
|
elements.add(Restrictions.eq("status", status));
|
527 |
|
}
|
528 |
|
|
529 |
|
ProjectionList projectionList = Projections.projectionList().add(Projections.id());
|
530 |
|
|
531 |
|
if(orderHints != null && !orderHints.isEmpty()) {
|
532 |
|
for(OrderHint orderHint : orderHints) {
|
533 |
|
projectionList = projectionList.add(Projections.property(orderHint.getPropertyName()));
|
534 |
|
}
|
535 |
|
}
|
536 |
|
|
537 |
|
criteria.setProjection(Projections.distinct(projectionList));
|
538 |
|
|
539 |
|
if(pageSize != null) {
|
540 |
|
criteria.setMaxResults(pageSize);
|
541 |
|
if(pageNumber != null) {
|
542 |
|
criteria.setFirstResult(pageNumber * pageSize);
|
543 |
|
}
|
544 |
|
}
|
545 |
|
|
546 |
|
addOrder(criteria,orderHints);
|
547 |
|
|
548 |
|
List<Object> intermediateResult = (List<Object>)criteria.list();
|
549 |
|
|
550 |
|
if(intermediateResult.isEmpty())
|
551 |
|
return new ArrayList<TaxonDescription>();
|
552 |
|
|
553 |
|
Integer[] resultIds = new Integer[intermediateResult.size()];
|
554 |
|
for(int i = 0; i < resultIds.length; i++) {
|
555 |
|
if(orderHints == null || orderHints.isEmpty()) {
|
556 |
|
resultIds[i] = (Integer)intermediateResult.get(i);
|
557 |
|
} else {
|
558 |
|
resultIds[i] = (Integer)((Object[])intermediateResult.get(i))[0];
|
559 |
|
}
|
560 |
|
}
|
561 |
|
|
562 |
|
criteria = getSession().createCriteria(TaxonDescription.class);
|
563 |
|
criteria.add(Restrictions.in("id", resultIds));
|
564 |
|
addOrder(criteria,orderHints);
|
565 |
|
|
566 |
|
List<TaxonDescription> results = (List<TaxonDescription>)criteria.list();
|
567 |
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
568 |
|
return results;
|
569 |
|
}
|
570 |
|
|
571 |
|
public List<CommonTaxonName> searchDescriptionByCommonName(String queryString, MatchMode matchMode, Integer pageSize, Integer pageNumber) {
|
572 |
|
|
573 |
|
Criteria crit = getSession().createCriteria(CommonTaxonName.class);
|
574 |
|
if (matchMode == MatchMode.EXACT) {
|
575 |
|
crit.add(Restrictions.eq("name", matchMode.queryStringFrom(queryString)));
|
576 |
|
} else {
|
577 |
|
crit.add(Restrictions.ilike("name", matchMode.queryStringFrom(queryString)));
|
578 |
|
}
|
579 |
|
|
580 |
|
if(pageSize != null) {
|
581 |
|
crit.setMaxResults(pageSize);
|
582 |
|
if(pageNumber != null) {
|
583 |
|
crit.setFirstResult(pageNumber * pageSize);
|
584 |
|
}
|
585 |
|
}
|
586 |
|
List<CommonTaxonName> results = (List<CommonTaxonName>)crit.list();
|
587 |
|
return results;
|
588 |
|
}
|
589 |
|
|
590 |
|
public Integer countDescriptionByCommonName(String queryString, MatchMode matchMode) {
|
591 |
|
//TODO inprove performance
|
592 |
|
List<CommonTaxonName> results = searchDescriptionByCommonName(queryString, matchMode, null, null);
|
593 |
|
return results.size();
|
594 |
|
}
|
595 |
|
|
596 |
|
@Override
|
597 |
|
public DescriptionBase find(LSID lsid) {
|
598 |
|
DescriptionBase descriptionBase = super.find(lsid);
|
599 |
|
if(descriptionBase != null) {
|
600 |
|
List<String> propertyPaths = new ArrayList<String>();
|
601 |
|
propertyPaths.add("createdBy");
|
602 |
|
propertyPaths.add("updatedBy");
|
603 |
|
propertyPaths.add("taxon");
|
604 |
|
propertyPaths.add("taxonName");
|
605 |
|
propertyPaths.add("descriptionElements");
|
606 |
|
propertyPaths.add("descriptionElements.createdBy");
|
607 |
|
propertyPaths.add("descriptionElements.updatedBy");
|
608 |
|
propertyPaths.add("descriptionElements.feature");
|
609 |
|
propertyPaths.add("descriptionElements.multilanguageText");
|
610 |
|
propertyPaths.add("descriptionElements.multilanguageText.language");
|
611 |
|
propertyPaths.add("descriptionElements.area");
|
612 |
|
propertyPaths.add("descriptionElements.status");
|
613 |
|
propertyPaths.add("descriptionElements.modifyingText");
|
614 |
|
propertyPaths.add("descriptionElementsmodifyingText.language");
|
615 |
|
propertyPaths.add("descriptionElements.modifiers");
|
616 |
|
|
617 |
|
defaultBeanInitializer.initialize(descriptionBase, propertyPaths);
|
618 |
|
}
|
619 |
|
return descriptionBase;
|
620 |
|
}
|
harmonizing method names