Project

General

Profile

« Previous | Next » 

Revision 0eaa0762

Added by Patrick Plitzner about 5 years ago

ref #8011 Add service method to find term DTOs by label

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IDefinedTermDao.java
221 221
     */
222 222
    public Collection<TermDto> getKindOfsAsDto(TermDto parentTerm);
223 223

  
224
    public Collection<TermDto> findByTitleAsDto(String title);
225

  
224 226
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DefinedTermDaoImpl.java
696 696
        return list;
697 697
    }
698 698

  
699
    @Override
700
    public Collection<TermDto> findByTitleAsDto(String title) {
701
        String queryString = TermDto.getTermDtoSelect()
702
                + "where a.titleCache like :title";
703
        Query query =  getSession().createQuery(queryString);
704
        query.setParameter("title", "%"+title+"%");
705

  
706
        @SuppressWarnings("unchecked")
707
        List<Object[]> result = query.list();
708

  
709
        List<TermDto> list = TermDto.termDtoListFrom(result);
710
        return list;
711
    }
712

  
699 713
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermDto.java
41 41
    private String idInVocabulary = null;
42 42
    private Collection<TermDto> includes;
43 43
    private Collection<TermDto> generalizationOf;
44
    private Set<Representation> vocRepresentations = null;
45
    private String vocRepresentation_L10n = null;
46
    private String vocRepresentation_L10n_abbreviatedLabel = null;
44 47

  
45
    private TermDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid, UUID vocabularyUuid, Integer orderIndex, String idInVocabulary) {
48
    private TermDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid,
49
            UUID vocabularyUuid, Integer orderIndex, String idInVocabulary) {
50
        this(uuid, representations, partOfUuid, kindOfUuid, vocabularyUuid, orderIndex, idInVocabulary, null);
51
    }
52

  
53
    private TermDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid,
54
            UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, Set<Representation> vocRepresentations) {
46 55
        super(uuid, representations);
47 56
        this.partOfUuid = partOfUuid;
48 57
        this.kindOfUuid = kindOfUuid;
49 58
        this.vocabularyUuid = vocabularyUuid;
50 59
        this.orderIndex = orderIndex;
51 60
        this.idInVocabulary = idInVocabulary;
61
        this.vocRepresentations = vocRepresentations;
52 62
    }
53 63

  
54 64
    static public TermDto fromTerm(DefinedTermBase term) {
......
87 97
        return dto;
88 98
    }
89 99

  
100
    @Override
101
    public void localize(ITermRepresentation_L10n representation_L10n) {
102
        if(vocRepresentations!=null){
103
            representation_L10n.localize(vocRepresentations);
104
            if (representation_L10n.getLabel() != null) {
105
                setVocRepresentation_L10n(representation_L10n.getLabel());
106
            }
107
            if (representation_L10n.getAbbreviatedLabel() != null) {
108
                setVocRepresentation_L10n_abbreviatedLabel(representation_L10n.getAbbreviatedLabel());
109
            }
110
        }
111
        super.localize(representation_L10n);
112
    }
113

  
114
    public void setVocRepresentation_L10n(String vocRepresentation_L10n) {
115
        this.vocRepresentation_L10n = vocRepresentation_L10n;
116
    }
117

  
118
    public String getVocRepresentation_L10n() {
119
        return vocRepresentation_L10n;
120
    }
121

  
122
    public void setVocRepresentation_L10n_abbreviatedLabel(String vocRepresentation_L10n_abbreviatedLabel) {
123
        this.vocRepresentation_L10n_abbreviatedLabel = vocRepresentation_L10n_abbreviatedLabel;
124
    }
125

  
126
    public String getVocRepresentation_L10n_abbreviatedLabel() {
127
        return vocRepresentation_L10n_abbreviatedLabel;
128
    }
129

  
90 130
    public void setPartOfDto(TermDto partOfDto) {
91 131
        this.partOfDto = partOfDto;
92 132
    }
......
165 205

  
166 206
    public static String getTermDtoSelect(String fromTable){
167 207
        return ""
168
                + "select a.uuid, r, p.uuid, k.uuid, v.uuid, a.orderIndex, a.idInVocabulary "
208
                + "select a.uuid, r, p.uuid, k.uuid, v.uuid, a.orderIndex, a.idInVocabulary, voc_rep "
169 209
                + "from "+fromTable+" as a "
170 210
                + "LEFT JOIN a.partOf as p "
171 211
                + "LEFT JOIN a.kindOf as k "
172 212
                + "LEFT JOIN a.representations AS r "
173
                + "LEFT JOIN a.vocabulary as v ";
213
                + "LEFT JOIN a.vocabulary as v "
214
                + "LEFT JOIN v.representations as voc_rep ";
174 215
    }
175 216

  
176 217
    public static List<TermDto> termDtoListFrom(List<Object[]> results) {
......
187 228
                } else {
188 229
                    representations = (Set<Representation>)elements[1];
189 230
                }
190
                dtoMap.put(uuid, new TermDto(uuid, representations, (UUID)elements[2], (UUID)elements[3], (UUID)elements[4], (Integer)elements[5], (String)elements[6]));
231
                Set<Representation> vocRepresentations = new HashSet<>();
232
                if(elements[7] instanceof Representation) {
233
                    vocRepresentations = new HashSet<Representation>(7);
234
                    vocRepresentations.add((Representation)elements[7]);
235
                } else {
236
                    vocRepresentations = (Set<Representation>)elements[7];
237
                }
238
                dtoMap.put(uuid, new TermDto(uuid, representations, (UUID)elements[2], (UUID)elements[3], (UUID)elements[4], (Integer)elements[5], (String)elements[6], vocRepresentations));
191 239
            }
192 240
        }
193 241
        return new ArrayList<>(dtoMap.values());
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITermService.java
236 236
     */
237 237
    public TermDto addNewTerm(TermType termType, UUID parentUuid, boolean isKindOf);
238 238

  
239
    public Collection<TermDto> findByTitleAsDto(String title);
240

  
239 241
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermServiceImpl.java
571 571
        return TermDto.fromTerm(term, true);
572 572
    }
573 573

  
574
    @Override
575
    public Collection<TermDto> findByTitleAsDto(String title){
576
        return dao.findByTitleAsDto(title);
577
    }
578

  
574 579
    public enum TermMovePosition{
575 580
        BEFORE,
576 581
        AFTER,

Also available in: Unified diff