Project

General

Profile

Revision 8b2071a3

ID8b2071a31e20f57d4438ac80907b0103354af0b3
Parent f9e8f532
Child 4aa385eb

Added by Patrick Plitzner over 1 year ago

ref #8283 Add media uuids to term dto

  • fix HQL response handling for left outer joins

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermDto.java
18 18
import java.util.Set;
19 19
import java.util.UUID;
20 20

  
21
import eu.etaxonomy.cdm.model.media.Media;
21 22
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
22 23
import eu.etaxonomy.cdm.model.term.OrderedTermBase;
23 24
import eu.etaxonomy.cdm.model.term.Representation;
......
46 47
    private Set<Representation> vocRepresentations = null;
47 48
    private String vocRepresentation_L10n = null;
48 49
    private String vocRepresentation_L10n_abbreviatedLabel = null;
50
    private Collection<UUID> media = null;
49 51

  
50 52
    private TermDto(UUID uuid, Set<Representation> representations, TermType termType, UUID partOfUuid, UUID kindOfUuid,
51 53
            UUID vocabularyUuid, Integer orderIndex, String idInVocabulary) {
......
99 101
            }
100 102
        }
101 103
        dto.setVocabularyDto(new TermVocabularyDto(vocabulary.getUuid(), vocabulary.getRepresentations(), term.getTermType()));
104
        if(term.getMedia()!=null){
105
            Collection<UUID> mediaUuids = new HashSet<>();
106
            Set<Media> media = term.getMedia();
107
            for (Media medium : media) {
108
                mediaUuids.add(medium.getUuid());
109
            }
110
            dto.setMedia(mediaUuids);
111
        }
102 112
        return dto;
103 113
    }
104 114

  
......
132 142
        return vocRepresentation_L10n_abbreviatedLabel;
133 143
    }
134 144

  
145
    private void addVocRepresentation(Representation vocRepresentation){
146
        this.vocRepresentations.add(vocRepresentation);
147
    }
148

  
135 149
    public void setPartOfDto(TermDto partOfDto) {
136 150
        this.partOfDto = partOfDto;
137 151
    }
......
208 222
        return getTermDtoSelect("DefinedTermBase");
209 223
    }
210 224

  
225
    public Collection<UUID> getMedia() {
226
        return media;
227
    }
228

  
229
    public void setMedia(Collection<UUID> media) {
230
        this.media = media;
231
    }
232

  
233
    private void addMedia(UUID mediaUuid){
234
        this.media.add(mediaUuid);
235
    }
236

  
211 237
    public static String getTermDtoSelect(String fromTable){
212 238
        return ""
213 239
                + "select a.uuid, "
......
219 245
                + "a.idInVocabulary, "
220 246
                + "voc_rep,  "
221 247
                + "a.termType,  "
222
                + "a.uri  "
248
                + "a.uri,  "
249
                + "m  "
223 250
                + "from "+fromTable+" as a "
224 251
                + "LEFT JOIN a.partOf as p "
225 252
                + "LEFT JOIN a.kindOf as k "
253
                + "LEFT JOIN a.media as m "
226 254
                + "LEFT JOIN a.representations AS r "
227 255
                + "LEFT JOIN a.vocabulary as v "
228
                + "LEFT JOIN v.representations as voc_rep ";
256
                + "LEFT JOIN v.representations as voc_rep "
257
                ;
229 258
    }
230 259

  
231 260
    public static List<TermDto> termDtoListFrom(List<Object[]> results) {
232 261
        List<TermDto> dtos = new ArrayList<>(); // list to ensure order
233
        Map<UUID, TermDto> dtoMap = new HashMap<>(results.size()); // map to handle multiple representations
262
        // map to handle multiple representations/media/vocRepresentation because of LEFT JOIN
263
        Map<UUID, TermDto> dtoMap = new HashMap<>(results.size());
234 264
        for (Object[] elements : results) {
235 265
            UUID uuid = (UUID)elements[0];
236 266
            if(dtoMap.containsKey(uuid)){
237 267
                dtoMap.get(uuid).addRepresentation((Representation)elements[1]);
268
                dtoMap.get(uuid).addVocRepresentation((Representation)elements[7]);
269
                dtoMap.get(uuid).addMedia(((Media) elements[10]).getUuid());
238 270
            } else {
239 271
                Set<Representation> representations = new HashSet<>();
240 272
                if(elements[1] instanceof Representation) {
......
243 275
                } else {
244 276
                    representations = (Set<Representation>)elements[1];
245 277
                }
278
                Set<UUID> mediaUuids = new HashSet<>();
279
                if(elements[10] instanceof Media) {
280
                    mediaUuids.add(((Media) elements[10]).getUuid());
281
                } else if(elements[10] instanceof Collection){
282
                    Set<Media> media = (Set<Media>)elements[10];
283
                    media.forEach(m->mediaUuids.add(m.getUuid()));
284
                }
246 285
                Set<Representation> vocRepresentations = new HashSet<>();
247 286
                if(elements[7] instanceof Representation) {
248 287
                    vocRepresentations = new HashSet<Representation>(7);
......
261 300
                        (String)elements[6],
262 301
                        vocRepresentations);
263 302
                termDto.setUri((URI)elements[9]);
303
                termDto.setMedia(mediaUuids);
264 304

  
265 305
                dtoMap.put(uuid, termDto);
266 306
                dtos.add(termDto);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)