Major Update to cdmlib-3.3
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / VocabularyServiceImpl.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.api.service;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.UUID;
15
16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.stereotype.Service;
18 import org.springframework.transaction.annotation.Propagation;
19 import org.springframework.transaction.annotation.Transactional;
20
21 import eu.etaxonomy.cdm.api.service.pager.Pager;
22 import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
23 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
24 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25 import eu.etaxonomy.cdm.model.common.Language;
26 import eu.etaxonomy.cdm.model.common.TermType;
27 import eu.etaxonomy.cdm.model.common.TermVocabulary;
28 import eu.etaxonomy.cdm.model.common.VocabularyEnum;
29 import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
30 import eu.etaxonomy.cdm.persistence.query.OrderHint;
31 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
32
33 @Service
34 @Transactional(readOnly = true)
35 public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabulary,ITermVocabularyDao> implements IVocabularyService {
36
37 @Autowired
38 protected void setDao(ITermVocabularyDao dao) {
39 this.dao = dao;
40 }
41
42
43 /* (non-Javadoc)
44 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
45 */
46 @Override
47 @Transactional(readOnly = false)
48 public void updateTitleCache(Class<? extends TermVocabulary> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TermVocabulary> cacheStrategy, IProgressMonitor monitor) {
49 if (clazz == null){
50 clazz = TermVocabulary.class;
51 }
52 super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
53 }
54
55
56 public TermVocabulary<DefinedTermBase> getVocabulary(VocabularyEnum vocabularyType){
57 return dao.findByUuid(vocabularyType.getUuid());
58 }
59
60 /* (non-Javadoc)
61 * @see eu.etaxonomy.cdm.api.service.IVocabularyService#listByTermClass(java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
62 */
63 @Override
64 public <TERM extends DefinedTermBase> List<TermVocabulary<TERM>> listByTermClass(Class<TERM> clazz, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
65 boolean includeSubclasses = false;
66 boolean includeEmptyVocs = false;
67 return (List)listByTermClass(clazz, includeSubclasses, includeEmptyVocs, limit, start, orderHints, propertyPaths);
68 }
69
70 public <TERM extends DefinedTermBase> List<TermVocabulary<? extends TERM>> listByTermClass(Class<TERM> clazz, boolean includeSubclasses, boolean includeEmptyVocs, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
71 return dao.listByTermClass(clazz, includeSubclasses, includeEmptyVocs,limit, start, orderHints, propertyPaths);
72 }
73
74 public <T extends DefinedTermBase> List<TermVocabulary<T>> findByTermType(TermType termType) {
75 return dao.findByTermType(termType);
76 }
77 /**
78 * (non-Javadoc)
79 * @see eu.etaxonomy.cdm.api.service.ITermService#getLanguageVocabulary()
80 * FIXME candidate for harmonization
81 * is this the same as getVocabulary(VocabularyEnum.Language)
82 */
83 public TermVocabulary<Language> getLanguageVocabulary() {
84 String uuidString = "45ac7043-7f5e-4f37-92f2-3874aaaef2de";
85 UUID uuid = UUID.fromString(uuidString);
86 TermVocabulary<Language> languageVocabulary = (TermVocabulary)dao.findByUuid(uuid);
87 return languageVocabulary;
88 }
89
90 public Pager<DefinedTermBase> getTerms(TermVocabulary vocabulary, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
91 Integer numberOfResults = dao.countTerms(vocabulary);
92
93 List<DefinedTermBase> results = new ArrayList<DefinedTermBase>();
94 if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
95 results = dao.getTerms(vocabulary, pageSize, pageNumber,orderHints,propertyPaths);
96 }
97
98 return new DefaultPagerImpl<DefinedTermBase>(pageNumber, numberOfResults, pageSize, results);
99 }
100
101
102
103 }