minor
[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.model.common.DefinedTermBase;
24 import eu.etaxonomy.cdm.model.common.Language;
25 import eu.etaxonomy.cdm.model.common.TermVocabulary;
26 import eu.etaxonomy.cdm.model.common.VocabularyEnum;
27 import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
28 import eu.etaxonomy.cdm.persistence.query.OrderHint;
29
30 @Service
31 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
32 public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabulary,ITermVocabularyDao> implements IVocabularyService {
33
34 @Autowired
35 protected void setDao(ITermVocabularyDao dao) {
36 this.dao = dao;
37 }
38
39 /* (non-Javadoc)
40 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache()
41 */
42 @Override
43 public void updateTitleCache() {
44 Class<TermVocabulary> clazz = TermVocabulary.class;
45 super.updateTitleCache(clazz, null, null);
46 }
47
48 public TermVocabulary<DefinedTermBase> getVocabulary(VocabularyEnum vocabularyType){
49 return dao.findByUuid(vocabularyType.getUuid());
50 }
51
52 public <TERM extends DefinedTermBase> List<TermVocabulary<TERM>> listByTermClass(Class<TERM> clazz, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
53 return dao.listByTermClass(clazz, limit, start, orderHints, propertyPaths);
54 }
55
56 /**
57 * (non-Javadoc)
58 * @see eu.etaxonomy.cdm.api.service.ITermService#getLanguageVocabulary()
59 * FIXME candidate for harmonization
60 * is this the same as getVocabulary(VocabularyEnum.Language)
61 */
62 public TermVocabulary<Language> getLanguageVocabulary() {
63 String uuidString = "45ac7043-7f5e-4f37-92f2-3874aaaef2de";
64 UUID uuid = UUID.fromString(uuidString);
65 TermVocabulary<Language> languageVocabulary = (TermVocabulary)dao.findByUuid(uuid);
66 return languageVocabulary;
67 }
68
69 public Pager<DefinedTermBase> getTerms(TermVocabulary vocabulary, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
70 Integer numberOfResults = dao.countTerms(vocabulary);
71
72 List<DefinedTermBase> results = new ArrayList<DefinedTermBase>();
73 if(numberOfResults > 0) { // no point checking again
74 results = dao.getTerms(vocabulary, pageSize, pageNumber,orderHints,propertyPaths);
75 }
76
77 return new DefaultPagerImpl<DefinedTermBase>(pageNumber, numberOfResults, pageSize, results);
78 }
79
80 }