Project

General

Profile

« Previous | Next » 

Revision c98bc251

Added by Andreas Müller over 6 years ago

ref #6258 add cascading for registration in TaxonName and TypeDesignationBase

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/media/MediaUtils.java
36 36
        // find best matching representations of each media
37 37
        SortedMap<Integer, MediaRepresentation> prefRepresentations
38 38
                = filterAndOrderMediaRepresentations(media.getRepresentations(), null, mimeTypes,
39
                        size, widthOrDuration, height);
39
                        size, widthOrDuration, height, false);
40 40
        try {
41 41
            // take first one and remove all other representations
42 42
            MediaRepresentation prefOne = prefRepresentations.get(prefRepresentations.firstKey());
......
107 107
        return mediaRepresentationPart;
108 108
    }
109 109

  
110
    /**
111
     * @see #findPreferredMedia(List, Class, String[], String[], Integer, Integer, Integer, boolean)
112
     */
113
    public static Map<Media, MediaRepresentation> findPreferredMedia(List<Media> mediaList,
114
            Class<? extends MediaRepresentationPart> representationPartType, String[] mimeTypes, String[] sizeTokens,
115
            Integer widthOrDuration, Integer height, Integer size
116
            ) {
117
        return findPreferredMedia(mediaList, representationPartType, mimeTypes, sizeTokens,
118
                widthOrDuration, height, size, false);
119
    }
120

  
110 121

  
111 122
    /**
112 123
     * Filters the given List of Media by the supplied filter parameters <code>representationPartType</code>,
......
125 136
     * @param widthOrDuration
126 137
     * @param height
127 138
     * @param size
139
     * @param onlyBestMatchIfFilterMatches if <code>true</code> and all required filter parameters
140
     *      (like size, width and height) are not <code>null</code> only the best matching representation is returned.
141
     *       Otherwise all representations are returned in sorted order.
128 142
     * @return
129 143
     */
130 144
    public static Map<Media, MediaRepresentation> findPreferredMedia(List<Media> mediaList,
131 145
            Class<? extends MediaRepresentationPart> representationPartType, String[] mimeTypes, String[] sizeTokens,
132
            Integer widthOrDuration, Integer height, Integer size) {
146
            Integer widthOrDuration, Integer height, Integer size,
147
            boolean onlyBestMatchIfFilterMatches) {
133 148

  
134 149
        if(mimeTypes != null) {
135 150
            for(int i=0; i<mimeTypes.length; i++){
......
171 186

  
172 187
                SortedMap<Integer, MediaRepresentation> prefRepresentations
173 188
                    = filterAndOrderMediaRepresentations(candidateRepresentations, representationPartType,
174
                            mimeTypes, size, widthOrDuration, height);
189
                            mimeTypes, size, widthOrDuration, height, false);
175 190
                try {
176 191
                    if(prefRepresentations.size() > 0){
177 192
                        // Media.representations is a set
......
242 257
    }
243 258

  
244 259
    */
260

  
245 261
    /**
262
     * @param mediaRepresentations
263
     * @param representationPartType
246 264
     * @param mimeTypeRegexes
247 265
     * @param size
248 266
     * @param widthOrDuration
249 267
     * @param height
268
     * @param onlyBestMatchIfFilterMatches if <code>true</code> and all required filter parameters
269
     *      (like size, width and height) are not <code>null</code> only the best matching representation is returned.
270
     *       Otherwise all representations are returned in sorted order.
250 271
     * @return
251
     *
252
     *
253 272
     */
254 273
    private static SortedMap<Integer, MediaRepresentation> filterAndOrderMediaRepresentations(
255 274
            Set<MediaRepresentation> mediaRepresentations,
256 275
            Class<? extends MediaRepresentationPart> representationPartType, String[] mimeTypeRegexes,
257
            Integer size, Integer widthOrDuration, Integer height) {
276
            Integer size, Integer widthOrDuration, Integer height, boolean onlyBestMatchIfFilterMatches) {
258 277

  
259 278
        SortedMap<Integer, MediaRepresentation> prefRepr = new TreeMap<>();
260 279

  
......
264 283
        height = (height == null ? new Integer(0) : height);
265 284
        mimeTypeRegexes = (mimeTypeRegexes == null ? new String[]{".*"} : mimeTypeRegexes);
266 285

  
286
        boolean filterMatches = true;
267 287
        for (String mimeTypeRegex : mimeTypeRegexes) {
268 288
            // getRepresentationByMimeType
269 289
            Pattern mimeTypePattern = Pattern.compile(mimeTypeRegex);
......
280 300

  
281 301
                int dwa = 0;
282 302

  
283

  
284 303
                //first the size is used for comparison
285 304
                for (MediaRepresentationPart part : representation.getParts()) {
286 305

  
......
296 315
                    logger.debug(part + " matches");
297 316
                    matchingParts.add(part);
298 317

  
318
                    boolean partFilterMatches = false;
319

  
299 320
                    if (part.getSize()!= null){
300 321
                        int sizeOfPart = part.getSize();
301 322
                        int distance = sizeOfPart - size;
......
303 324
                            distance *= -1;
304 325
                        }
305 326
                        dwa += distance;
327
                        if (size > 0){
328
                            partFilterMatches = true;
329
                        }
306 330
                    }
307 331

  
308 332
                    //if height and width/duration is defined, add this information, too
......
327 351
                        }
328 352
                        dwa += durationWidthWeight;
329 353

  
354
                    }else{
355
                        partFilterMatches = true;
330 356
                    }
357
                    filterMatches &= partFilterMatches;
331 358
                } // loop parts
332 359
                logger.debug("matchingParts.size():" + matchingParts.size());
333 360
                if(matchingParts.size() > 0 ){
......
343 370
            } // loop representations
344 371
        } // loop mime types
345 372
        logger.debug(prefRepr.size() + " preferred representations found");
346
        return prefRepr;
373

  
374
        if (onlyBestMatchIfFilterMatches && filterMatches){
375
            SortedMap<Integer, MediaRepresentation> result = new TreeMap<>();
376
            try {
377
                result.put(prefRepr.firstKey(), prefRepr.get(prefRepr.firstKey()));
378
                return result;
379
            } catch (Exception e) {
380
                return result;
381
            }
382
        }else{
383
            return prefRepr;
384
        }
347 385
    }
348 386
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonName.java
67 67
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
68 68
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
69 69
import eu.etaxonomy.cdm.model.common.CdmBase;
70
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
70 71
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
71 72
import eu.etaxonomy.cdm.model.common.IParsable;
72 73
import eu.etaxonomy.cdm.model.common.IRelated;
73 74
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
74 75
import eu.etaxonomy.cdm.model.common.RelationshipBase;
76
import eu.etaxonomy.cdm.model.common.TermType;
77
import eu.etaxonomy.cdm.model.common.TermVocabulary;
75 78
import eu.etaxonomy.cdm.model.description.IDescribable;
76 79
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
77 80
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
......
336 339
    @XmlIDREF
337 340
    @XmlSchemaType(name = "IDREF")
338 341
    @OneToMany(mappedBy="name", fetch= FetchType.LAZY)
342
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
339 343
    @NotNull
340 344
    @IndexedEmbedded(depth=1)
341 345
    private Set<Registration> registrations = new HashSet<>();
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TypeDesignationBase.java
99 99
    @XmlIDREF
100 100
    @XmlSchemaType(name = "IDREF")
101 101
    @ManyToMany(mappedBy="typeDesignations", fetch= FetchType.LAZY)
102
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
102 103
    @NotNull
103 104
    @IndexedEmbedded(depth=1)
104 105
    private Set<Registration> registrations = new HashSet<>();
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/name/TaxonNameDefaultCacheStrategy.java
484 484
        }else if (rank.isSupraGeneric()){
485 485
            tags = getGenusOrUninomialTaggedNameCache(nonViralName);
486 486
        }else{
487
            logger.warn("Name Strategy for Name (UUID: " + nonViralName.getUuid() +  ") not yet implemented");
487
            tags = getRanklessTaggedNameCache(nonViralName);
488
            logger.warn("Rank does not belong to a rank class: " + rank.getTitleCache() + ". Used rankless nameCache for name " + nonViralName.getUuid());
488 489
        }
489 490
        //TODO handle appended phrase here instead of different places, check first if this is true for all
490 491
        //cases

Also available in: Unified diff