Project

General

Profile

« Previous | Next » 

Revision 892efc69

Added by Andreas Kohlbecker almost 14 years ago

merging /branches/cdmlib/SPRINT-Chichorieae1/ to trunk

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptionServiceImpl.java
11 11
package eu.etaxonomy.cdm.api.service;
12 12

  
13 13
import java.util.ArrayList;
14
import java.util.Collection;
14 15
import java.util.List;
16
import java.util.Map;
15 17
import java.util.Set;
16 18
import java.util.UUID;
17 19

  
18 20
import org.apache.log4j.Logger;
19 21
import org.springframework.beans.factory.annotation.Autowired;
20 22
import org.springframework.stereotype.Service;
23
import org.springframework.transaction.annotation.Propagation;
21 24
import org.springframework.transaction.annotation.Transactional;
22 25

  
23 26
import eu.etaxonomy.cdm.api.service.pager.Pager;
24 27
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
28
import eu.etaxonomy.cdm.model.common.Annotation;
29
import eu.etaxonomy.cdm.model.common.MarkerType;
25 30
import eu.etaxonomy.cdm.model.common.TermVocabulary;
26 31
import eu.etaxonomy.cdm.model.description.DescriptionBase;
27 32
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
33
import eu.etaxonomy.cdm.model.description.Distribution;
28 34
import eu.etaxonomy.cdm.model.description.Feature;
29 35
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
30 36
import eu.etaxonomy.cdm.model.description.Scope;
31 37
import eu.etaxonomy.cdm.model.description.TaxonDescription;
32 38
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
33 39
import eu.etaxonomy.cdm.model.location.NamedArea;
40
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
34 41
import eu.etaxonomy.cdm.model.media.Media;
35 42
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
36 43
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
50 57
 * @version 1.0
51 58
 */
52 59
@Service
53
@Transactional(readOnly = true)
60
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
54 61
public class DescriptionServiceImpl extends IdentifiableServiceBase<DescriptionBase,IDescriptionDao> implements IDescriptionService {
55 62
 	
56 63
	private static final Logger logger = Logger.getLogger(DescriptionServiceImpl.class);
......
142 149
		}
143 150
		return results;
144 151
	}
152
	public Pager<Annotation> getDescriptionElementAnnotations(DescriptionElementBase annotatedObj, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
153
		Integer numberOfResults = descriptionElementDao.countAnnotations(annotatedObj, status);
154
		
155
		List<Annotation> results = new ArrayList<Annotation>();
156
		if(numberOfResults > 0) { // no point checking again
157
			results = descriptionElementDao.getAnnotations(annotatedObj, status, pageSize, pageNumber, orderHints, propertyPaths); 
158
		}
159
		
160
		return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
161
	}
162
	
163
	
145 164

  
146 165
	public Pager<Media> getMedia(DescriptionElementBase descriptionElement,	Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
147 166
        Integer numberOfResults = descriptionElementDao.countMedia(descriptionElement);
......
164 183
		
165 184
		return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);
166 185
	}
186
	
187
	public NamedAreaTree getOrderedDistributions(Set<TaxonDescription> taxonDescriptions, Set<NamedAreaLevel> omitLevels){
188
		List<NamedArea> areaList = new ArrayList<NamedArea>();
189
		NamedAreaTree tree = new NamedAreaTree();
190
		//getting all the areas
191
		for (TaxonDescription taxonDescription : taxonDescriptions) {
192
			taxonDescription = (TaxonDescription) dao.load(taxonDescription.getUuid());
193
			Set<DescriptionElementBase> elements = taxonDescription.getElements();
194
			for (DescriptionElementBase element : elements) {
195
				if(element.isInstanceOf(Distribution.class)){
196
					Distribution distribution = (Distribution) element;
197
					areaList.add(distribution.getArea());
198
				}
199
			}
200
		}
201
		//ordering the areas
202
		tree.merge(areaList, omitLevels);
203
		tree.sortChildren();
204
		return tree;	
205
	}
167 206

  
168 207
	public Pager<TaxonNameDescription> getTaxonNameDescriptions(TaxonNameBase name, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
169 208
        Integer numberOfResults = dao.countTaxonNameDescriptions(name);
......
238 277
     * FIXME Candidate for harmonization
239 278
     * descriptionElementService.save
240 279
     */
280
	@Transactional(readOnly = false)
241 281
	public UUID saveDescriptionElement(DescriptionElementBase descriptionElement) {
242 282
		return descriptionElementDao.save(descriptionElement);
243 283
	}
284
	
285
    /**
286
     * FIXME Candidate for harmonization
287
     * descriptionElementService.save
288
     */
289
	@Transactional(readOnly = false)
290
	public Map<UUID, DescriptionElementBase> saveDescriptionElement(Collection<DescriptionElementBase> descriptionElements) {
291
		return descriptionElementDao.saveAll(descriptionElements);
292
	}
244 293

  
245 294
    /**
246 295
     * FIXME Candidate for harmonization
......
253 302
	public TermVocabulary<Feature> getFeatureVocabulary(UUID uuid) {
254 303
		return (TermVocabulary)vocabularyDao.findByUuid(uuid);
255 304
	}
305

  
306
	public List<DescriptionElementBase> getDescriptionElementsForTaxon(
307
			Taxon taxon, Set<Feature> features,
308
			Class<? extends DescriptionElementBase> type, Integer pageSize,
309
			Integer pageNumber, List<String> propertyPaths) {
310
		 return dao.getDescriptionElementForTaxon(taxon, features, type, pageSize, pageNumber, propertyPaths);
311
	}
256 312
}

Also available in: Unified diff