Project

General

Profile

Revision 74bdd593

ID74bdd593c379ace6445bb500bf2d9c4a3fd7783c
Parent cfcf723b
Child 2d4cb2bf

Added by Patrick Plitzner about 2 years ago

ref #7875 Implement term service based on UuidAndTitleCache

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IDefinedTermDao.java
27 27
import eu.etaxonomy.cdm.model.location.NamedAreaType;
28 28
import eu.etaxonomy.cdm.model.media.Media;
29 29
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
30
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
30 31
import eu.etaxonomy.cdm.persistence.query.OrderHint;
31 32

  
32 33

  
......
205 206
     */
206 207
    public List<NamedArea> getUuidAndTitleCache(List<TermVocabulary> vocs, Integer limit,
207 208
            String pattern);
209

  
210
    /**
211
     * Returns the parent term of the given term
212
     * @param childTerm the child term
213
     * @return the parent term
214
     */
215
    public UuidAndTitleCache<DefinedTermBase> getParentUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> childTerm);
216

  
217
    /**
218
     * Returns all terms that are included in the given parent term resp. a part of the given term.
219
     * @param parentTerm the parent term
220
     * @return a collection of included terms
221
     */
222
    public Collection<UuidAndTitleCache<DefinedTermBase>> getIncludesAsUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> parentTerm);
223

  
224
    /**
225
     * Returns all terms that the given term is a generalization of resp. that are a kind of the given term
226
     * @param parentTerm the parent term
227
     * @return a collection of included terms
228
     */
229
    public Collection<UuidAndTitleCache<DefinedTermBase>> getKindOfsAsUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> parentTerm);
230

  
208 231
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/ITermVocabularyDao.java
10 10
package eu.etaxonomy.cdm.persistence.dao.common;
11 11

  
12 12

  
13
import java.util.Collection;
13 14
import java.util.List;
14 15
import java.util.Map;
15 16
import java.util.Set;
......
18 19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19 20
import eu.etaxonomy.cdm.model.common.TermType;
20 21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
21 23
import eu.etaxonomy.cdm.persistence.query.OrderHint;
22 24

  
23 25

  
......
102 104
			Map<UUID, Set<UUID>> uuidsRepsonse,
103 105
			Map<UUID, TermVocabulary<?>> vocabularyResponse);
104 106

  
107
    /**
108
     * Loads all top level terms, i.e. terms that have no parent terms, for the given vocabulary
109
     * @param vocabularyId the id of the vocabulary
110
     * @return a collection of top level terms
111
     */
112
    public Collection<UuidAndTitleCache<DefinedTermBase>> getTopLevelTerms(int vocabularyId);
113

  
105 114
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DefinedTermDaoImpl.java
63 63
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
64 64
import eu.etaxonomy.cdm.model.view.AuditEvent;
65 65
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
66
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
66 67
import eu.etaxonomy.cdm.persistence.query.MatchMode;
67 68
import eu.etaxonomy.cdm.persistence.query.OrderHint;
68 69

  
......
665 666
        return result;
666 667
    }
667 668

  
669
    @Override
670
    public UuidAndTitleCache<DefinedTermBase> getParentUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> childTerm) {
671
        String parentQueryString = ""
672
                + "select distinct t1.uuid, t1.id, t1.titleCache "
673
                + "from DefinedTermBase t1, DefinedTermBase t2 "
674
                + "where t1.id = t2.partOf.id "
675
                + "and t2.id = :childTerm";
676
        Query query =  getSession().createQuery(parentQueryString);
677
        query.setParameter("childTerm", childTerm.getId());
678
        List<UuidAndTitleCache<DefinedTermBase>> list = new ArrayList<>();
679

  
680
        @SuppressWarnings("unchecked")
681
        List<Object[]> result = query.list();
682

  
683
        if(result.size()==1){
684
            Object[] object = result.get(0);
685
            UUID uuid = (UUID) object[0];
686
            Integer id = (Integer) object[1];
687
            String titleCache = (String) object[2];
688
            return new UuidAndTitleCache<>(uuid,id, titleCache);
689
        }
690
        return null;
691
    }
692

  
693
    @Override
694
    public List<UuidAndTitleCache<DefinedTermBase>> getIncludesAsUuidAndTitleCache(
695
            UuidAndTitleCache<DefinedTermBase> parentTerm) {
696
        String queryString = ""
697
                + "select distinct t2.uuid, t2.id, t2.titleCache "
698
                + "from DefinedTermBase t1, DefinedTermBase t2 "
699
                + "where t2.partOf.id = :parentId";
700
        Query query =  getSession().createQuery(queryString);
701
        query.setParameter("parentId", parentTerm.getId());
702

  
703
        @SuppressWarnings("unchecked")
704
        List<Object[]> result = query.list();
705

  
706
        List<UuidAndTitleCache<DefinedTermBase>> list = generateUuidAndTitleCache(result);
707
        return list;
708
    }
709

  
710
    @Override
711
    public List<UuidAndTitleCache<DefinedTermBase>> getKindOfsAsUuidAndTitleCache(
712
            UuidAndTitleCache<DefinedTermBase> parentTerm) {
713
        String queryString = ""
714
                + "select distinct t2.uuid, t2.id, t2.titleCache "
715
                + "from DefinedTermBase t1, DefinedTermBase t2 "
716
                + "where t2.kindOf.id = :parentId";
717
        Query query =  getSession().createQuery(queryString);
718
        query.setParameter("parentId", parentTerm.getId());
719

  
720
        @SuppressWarnings("unchecked")
721
        List<Object[]> result = query.list();
722

  
723
        List<UuidAndTitleCache<DefinedTermBase>> list = generateUuidAndTitleCache(result);
724
        return list;
725
    }
726

  
727
    private List<UuidAndTitleCache<DefinedTermBase>> generateUuidAndTitleCache(List<Object[]> result){
728
        List<UuidAndTitleCache<DefinedTermBase>> list = new ArrayList<>();
729
        for(Object[] object : result){
730
            UUID uuid = (UUID) object[0];
731
            Integer id = (Integer) object[1];
732
            String titleCache = (String) object[2];
733
            if(titleCache!=null){
734
                list.add(new UuidAndTitleCache<>(uuid,id, titleCache));
735
            }
736
        }
737
        return list;
738
    }
739

  
668 740

  
669 741
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/TermVocabularyDaoImpl.java
30 30
import eu.etaxonomy.cdm.model.common.TermVocabulary;
31 31
import eu.etaxonomy.cdm.model.view.AuditEvent;
32 32
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
33
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
33 34
import eu.etaxonomy.cdm.persistence.query.OrderHint;
34 35

  
35 36
/**
......
106 107
	    	return result;
107 108
		} else {
108 109
			@SuppressWarnings("unchecked")
109
            AuditQuery query = makeAuditQuery((Class)clazz, auditEvent);
110
            AuditQuery query = makeAuditQuery(clazz, auditEvent);
110 111
			query.add(AuditEntity.property("termSourceUri").eq(termSourceUri));
111 112

  
112 113
			@SuppressWarnings("unchecked")
......
242 243
		return;
243 244
	}
244 245

  
246
    @Override
247
    public Collection<UuidAndTitleCache<DefinedTermBase>> getTopLevelTerms(int vocabularyId) {
248
        String queryString = ""
249
                + "select t.uuid, t.id, t.titleCache, t.partOf.id, t.kindOf.id "
250
                + "from TermVocabulary v, DefinedTermBase t "
251
                + "where v.id = :vocabularyId "
252
                + "and t.vocabulary.id = v.id "
253
                + "and t.partOf is null "
254
                + "and t.kindOf is null";
255
        Query query =  getSession().createQuery(queryString);
256
        query.setParameter("vocabularyId", vocabularyId);
257
        List<UuidAndTitleCache<DefinedTermBase>> list = new ArrayList<>();
258

  
259
        @SuppressWarnings("unchecked")
260
        List<Object[]> result = query.list();
261

  
262
        for(Object[] object : result){
263
            UUID uuid = (UUID) object[0];
264
            Integer id = (Integer) object[1];
265
            String taxonTitleCache = (String) object[2];
266
            String classificationTitleCache = (String) object[3];
267
            if(taxonTitleCache!=null){
268
                list.add(new UuidAndTitleCache<>(uuid,id, taxonTitleCache));
269
            }
270
            else{
271
                list.add(new UuidAndTitleCache<>(uuid,id, classificationTitleCache));
272
            }
273
        }
274
        return list;
275
    }
276

  
245 277
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITermService.java
192 192
     */
193 193
    List<UuidAndTitleCache<NamedArea>> getUuidAndTitleCache(List<TermVocabulary> vocs, Integer limit, String pattern,
194 194
            Language lang);
195

  
196
    /**
197
     * Returns the parent term of the given term
198
     * @param childTerm the child term
199
     * @return the parent term
200
     */
201
    public UuidAndTitleCache<DefinedTermBase> getParentUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> childTerm);
202

  
203
    /**
204
     * Returns all terms that are included in the given parent term resp. a part of the given term.
205
     * @param parentTerm the parent term
206
     * @return a collection of included terms
207
     */
208
    public Collection<UuidAndTitleCache<DefinedTermBase>> getIncludesAsUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> parentTerm);
209

  
210
    /**
211
     * Returns all terms that the given term is a generalization of resp. that are a kind of the given term
212
     * @param parentTerm the parent term
213
     * @return a collection of included terms
214
     */
215
    public Collection<UuidAndTitleCache<DefinedTermBase>> getKindOfsAsUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> parentTerm);
216

  
195 217
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IVocabularyService.java
9 9

  
10 10
package eu.etaxonomy.cdm.api.service;
11 11

  
12
import java.util.Collection;
12 13
import java.util.List;
13 14

  
14 15
import eu.etaxonomy.cdm.api.service.pager.Pager;
......
16 17
import eu.etaxonomy.cdm.model.common.Language;
17 18
import eu.etaxonomy.cdm.model.common.TermType;
18 19
import eu.etaxonomy.cdm.model.common.TermVocabulary;
20
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
19 21
import eu.etaxonomy.cdm.persistence.query.OrderHint;
20 22

  
21 23
public interface IVocabularyService extends IIdentifiableEntityService<TermVocabulary> {
......
68 70
	 */
69 71
	public <T extends DefinedTermBase> List<TermVocabulary<T>> findByTermType(TermType termType, List<String> propertyPaths);
70 72

  
73
	/**
74
	 * Loads all top level terms, i.e. terms that have no parent terms, for the given vocabulary
75
	 * @param vocabularyId the id of the vocabulary
76
	 * @return a collection of top level terms
77
	 */
78
	public Collection<UuidAndTitleCache<DefinedTermBase>> getTopLevelTerms(int vocabularyId);
79

  
71 80
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermServiceImpl.java
460 460
        return result;
461 461
    }
462 462

  
463
    @Override
464
    public UuidAndTitleCache<DefinedTermBase> getParentUuidAndTitleCache(UuidAndTitleCache<DefinedTermBase> childTerm) {
465
        return dao.getParentUuidAndTitleCache(childTerm);
466
    }
467

  
468
    @Override
469
    public Collection<UuidAndTitleCache<DefinedTermBase>> getIncludesAsUuidAndTitleCache(
470
            UuidAndTitleCache<DefinedTermBase> parentTerm) {
471
        return dao.getIncludesAsUuidAndTitleCache(parentTerm);
472
    }
473

  
474
    @Override
475
    public Collection<UuidAndTitleCache<DefinedTermBase>> getKindOfsAsUuidAndTitleCache(
476
            UuidAndTitleCache<DefinedTermBase> parentTerm) {
477
        return dao.getKindOfsAsUuidAndTitleCache(parentTerm);
478
    }
463 479

  
464 480
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/VocabularyServiceImpl.java
10 10
package eu.etaxonomy.cdm.api.service;
11 11

  
12 12
import java.util.ArrayList;
13
import java.util.Collection;
13 14
import java.util.List;
14 15
import java.util.UUID;
15 16

  
......
25 26
import eu.etaxonomy.cdm.model.common.TermType;
26 27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
27 28
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
29
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
28 30
import eu.etaxonomy.cdm.persistence.query.OrderHint;
29 31
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
30 32

  
......
85 87
		return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
86 88
	}
87 89

  
90

  
91
    @Override
92
    public Collection<UuidAndTitleCache<DefinedTermBase>> getTopLevelTerms(int vocabularyId) {
93
        return dao.getTopLevelTerms(vocabularyId);
94
    }
95

  
88 96
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)