cleanup
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / VocabularyServiceImpl.java
index 0eabe8674c370eb72fc5c25f511b84ba829612c1..4e077885745c61ab5924d5b7f47fa2999f6e27ad 100644 (file)
@@ -6,12 +6,13 @@
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
-
 package eu.etaxonomy.cdm.api.service;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,11 +22,12 @@ import org.springframework.transaction.annotation.Transactional;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
+import eu.etaxonomy.cdm.model.common.CdmClass;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
 import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.cdm.model.term.TermVocabulary;
-import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
+import eu.etaxonomy.cdm.persistence.dao.term.ITermVocabularyDao;
 import eu.etaxonomy.cdm.persistence.dto.TermDto;
 import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
@@ -45,7 +47,6 @@ public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabular
                this.dao = dao;
        }
 
-
        @Override
        @Transactional(readOnly = false)
     public UpdateResult updateCaches(Class<? extends TermVocabulary> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TermVocabulary> cacheStrategy, IProgressMonitor monitor) {
@@ -55,7 +56,6 @@ public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabular
                return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
        }
 
-
     @Override
     public List<TermVocabulary> listByTermType(TermType termType, boolean includeSubTypes,
             Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
@@ -99,12 +99,29 @@ public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabular
     }
 
     @Override
-    public Collection<TermDto> getCompleteTermHierarchy(UUID vocabularyUuid) {
-        Collection<TermDto> topLevelTerms = dao.getTopLevelTerms(vocabularyUuid);
+    public Collection<TermDto> getTerms(UUID vocabularyUuid) {
+        return dao.getTerms(vocabularyUuid);
+    }
+
+    @Override
+    public Collection<TermDto> getTerms(List<UUID> vocabularyUuids) {
+        return dao.getTerms(vocabularyUuids);
+    }
+
+    @Override
+    public Collection<TermDto> getNamedAreaTerms(List<UUID> vocabularyUuids) {
+        return dao.getNamedAreaTerms(vocabularyUuids);
+    }
+
+    @Override
+    public List<TermDto> getCompleteTermHierarchy(TermVocabularyDto vocabularyDto) {
+        List<TermDto> topLevelTerms = dao.getTopLevelTerms(vocabularyDto.getUuid(), vocabularyDto.getTermType());
         for (TermDto termDto : topLevelTerms) {
+            termDto.setVocabularyDto(vocabularyDto);
             initializeIncludes(termDto);
             initializeGeneralizationOf(termDto);
         }
+
         return topLevelTerms;
     }
 
@@ -112,6 +129,7 @@ public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabular
         Collection<TermDto> generalizationOf = termService.getKindOfsAsDto(parentTerm);
         parentTerm.setGeneralizationOf(generalizationOf);
         generalizationOf.forEach(generalization->{
+            generalization.setVocabularyDto(parentTerm.getVocabularyDto());
             generalization.setKindOfDto(parentTerm);
             initializeGeneralizationOf(generalization);
         });
@@ -121,6 +139,7 @@ public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabular
         Collection<TermDto> includes = termService.getIncludesAsDto(parentTerm);
         parentTerm.setIncludes(includes);
         includes.forEach(include->{
+            include.setVocabularyDto(parentTerm.getVocabularyDto());
             initializeIncludes(include);
             include.setPartOfDto(parentTerm);
         });
@@ -128,13 +147,43 @@ public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabular
 
     @Override
     public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType) {
-        return dao.findVocabularyDtoByTermType(termType);
+        return findVocabularyDtoByTermTypes(Collections.singleton(termType), true);
+    }
+
+    @Override
+    public List<TermVocabularyDto> findVocabularyDtoByTermTypeAndPattern(String pattern, TermType termType) {
+        return dao.findVocabularyDtoByTermTypes(Collections.singleton(termType), pattern, true);
+    }
+
+    @Override
+    public List<TermVocabularyDto> findVocabularyDtoByTermTypes(Set<TermType> termTypes) {
+        return findVocabularyDtoByTermTypes(termTypes, true);
+    }
+
+    @Override
+    public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType, boolean includeSubtypes) {
+        return findVocabularyDtoByTermTypes(Collections.singleton(termType), includeSubtypes);
+    }
+
+    @Override
+    public List<TermVocabularyDto> findVocabularyDtoByTermTypes(Set<TermType> termTypes, boolean includeSubtypes) {
+        return dao.findVocabularyDtoByTermTypes(termTypes, includeSubtypes);
+    }
+
+    @Override
+    public List<TermVocabularyDto> findFeatureVocabularyDtoByTermTypes(Set<CdmClass> availableFor) {
+        return dao.findVocabularyDtoByAvailableFor(availableFor);
+    }
+
+    @Override
+    public TermVocabularyDto findVocabularyDtoByVocabularyUuid(UUID vocUuid) {
+        return dao.findVocabularyDtoByUuid(vocUuid);
     }
 
     @Transactional(readOnly = false)
     @Override
     public TermDto addNewTerm(TermType termType, UUID vocabularyUUID) {
-        DefinedTermBase term = termType.getEmptyDefinedTermBase();
+        DefinedTermBase<?> term = termType.getEmptyDefinedTermBase();
         termService.save(term);
         TermVocabulary vocabulary = dao.load(vocabularyUUID);
         vocabulary.addTerm(term);
@@ -147,4 +196,9 @@ public class VocabularyServiceImpl extends IdentifiableServiceBase<TermVocabular
             Integer limit, String pattern) {
         return dao.getUuidAndTitleCache(clazz, termType, limit, pattern);
     }
+
+    @Override
+    public List<TermVocabularyDto> findVocabularyDtoByVocabularyUuids(List<UUID> vocUuids) {
+        return dao.findVocabularyDtoByUuids(vocUuids);
+    }
 }