Revision f22bf4ad
Added by Andreas Kohlbecker over 8 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/utility/DescriptionUtility.java | ||
---|---|---|
74 | 74 |
* @param distributions |
75 | 75 |
* the distributions to filter |
76 | 76 |
* @param hiddenAreaMarkerTypes |
77 |
* distributions where the area has a {@link Marker} with one of the specified {@link MarkerType}s will be skipped |
|
77 |
* distributions where the area has a {@link Marker} with one of the specified {@link MarkerType}s will |
|
78 |
* be skipped or acts as fall back area. For more details see <b>Marked area filter</b> above. |
|
78 | 79 |
* @param preferComputed |
79 | 80 |
* Computed distributions for the same area will be preferred over edited distributions. |
80 | 81 |
* <b>This parameter should always be set to <code>true</code>.</b> |
... | ... | |
110 | 111 |
if(hiddenAreaMarkerTypes != null && !hiddenAreaMarkerTypes.isEmpty()) { |
111 | 112 |
Set<NamedArea> areasHiddenByMarker = new HashSet<NamedArea>(); |
112 | 113 |
for(NamedArea area : filteredDistributions.keySet()) { |
113 |
for(MarkerType markerType : hiddenAreaMarkerTypes){ |
|
114 |
if(area.hasMarker(markerType, true)){ |
|
115 |
boolean showAsFallbackArea = false; |
|
116 |
// if at least one sub area is not hidden by a marker |
|
117 |
// this area is a fall back area for this sub area |
|
118 |
for(NamedArea subArea : area.getIncludes()) { |
|
119 |
if (!areasHiddenByMarker.contains(subArea) && subArea.hasMarker(markerType, true)) { |
|
120 |
// TODO here we would need to check for all hiddenAreaMarkerTypes! |
|
121 |
if(filteredDistributions.containsKey(subArea)) { |
|
122 |
areasHiddenByMarker.add(subArea); |
|
123 |
} |
|
114 |
if(checkAreaMarkedHidden(hiddenAreaMarkerTypes, area)) { |
|
115 |
boolean showAsFallbackArea = false; |
|
116 |
// if at least one sub area is not hidden by a marker |
|
117 |
// this area is a fall back area for this sub area |
|
118 |
for(NamedArea subArea : area.getIncludes()) { |
|
119 |
if (!areasHiddenByMarker.contains(subArea) && checkAreaMarkedHidden(hiddenAreaMarkerTypes, subArea)) { |
|
120 |
if(filteredDistributions.containsKey(subArea)) { |
|
121 |
areasHiddenByMarker.add(subArea); |
|
124 | 122 |
} |
125 |
// if this subarea is not marked to be hidden |
|
126 |
// the parent area must be visible if there is no |
|
127 |
// data for the subarea |
|
128 |
boolean subAreaVisible = filteredDistributions.containsKey(subArea) && !areasHiddenByMarker.contains(subArea); |
|
129 |
showAsFallbackArea = !subAreaVisible || showAsFallbackArea; |
|
130 |
} |
|
131 |
if (!showAsFallbackArea) { |
|
132 |
// this area does not need to be shown as |
|
133 |
// fallback for another area |
|
134 |
// so it will be hidden. |
|
135 |
areasHiddenByMarker.add(area); |
|
136 | 123 |
} |
124 |
// if this subarea is not marked to be hidden |
|
125 |
// the parent area must be visible if there is no |
|
126 |
// data for the subarea |
|
127 |
boolean subAreaVisible = filteredDistributions.containsKey(subArea) && !areasHiddenByMarker.contains(subArea); |
|
128 |
showAsFallbackArea = !subAreaVisible || showAsFallbackArea; |
|
129 |
} |
|
130 |
if (!showAsFallbackArea) { |
|
131 |
// this area does not need to be shown as |
|
132 |
// fallback for another area |
|
133 |
// so it will be hidden. |
|
134 |
areasHiddenByMarker.add(area); |
|
137 | 135 |
} |
138 | 136 |
} |
139 | 137 |
} |
... | ... | |
222 | 220 |
return valuesOfAllInnerSets(filteredDistributions.values()); |
223 | 221 |
} |
224 | 222 |
|
223 |
/** |
|
224 |
* @param hiddenAreaMarkerTypes |
|
225 |
* @param area |
|
226 |
* @param isMarkedHidden |
|
227 |
* @return |
|
228 |
*/ |
|
229 |
public static boolean checkAreaMarkedHidden(Set<MarkerType> hiddenAreaMarkerTypes, NamedArea area) { |
|
230 |
if(hiddenAreaMarkerTypes != null) { |
|
231 |
for(MarkerType markerType : hiddenAreaMarkerTypes){ |
|
232 |
if(area.hasMarker(markerType, true)){ |
|
233 |
return true; |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
return false; |
|
238 |
} |
|
239 |
|
|
225 | 240 |
/** |
226 | 241 |
* Orders the given Distribution elements in a hierarchical structure. |
227 | 242 |
* This method will not filter out any of the Distribution elements. |
228 | 243 |
* @param termDao |
229 | 244 |
* @param omitLevels |
245 |
* @param hiddenAreaMarkerTypes |
|
246 |
* Areas not associated to a Distribution in the {@code distList} are detected as fall back area |
|
247 |
* if they are having a {@link Marker} with one of the specified {@link MarkerType}s. Areas identified as such |
|
248 |
* are omitted from the hierarchy and the sub areas are moving one level up. |
|
249 |
* For more details on fall back areas see <b>Marked area filter</b> of |
|
250 |
* {@link DescriptionUtility#filterDistributions(Collection, Set, boolean, boolean, boolean)}. |
|
230 | 251 |
* @param distList |
231 | 252 |
* @return |
232 | 253 |
*/ |
233 |
public static DistributionTree orderDistributions(IDefinedTermDao termDao, Set<NamedAreaLevel> omitLevels, Collection<Distribution> distributions) { |
|
254 |
public static DistributionTree orderDistributions(IDefinedTermDao termDao, Set<NamedAreaLevel> omitLevels, Collection<Distribution> distributions, |
|
255 |
Set<MarkerType> hiddenAreaMarkerTypes) { |
|
234 | 256 |
|
235 | 257 |
DistributionTree tree = new DistributionTree(termDao); |
236 | 258 |
|
237 | 259 |
if (logger.isDebugEnabled()){logger.debug("order tree ...");} |
238 | 260 |
//order by areas |
239 |
tree.orderAsTree(distributions, omitLevels); |
|
261 |
tree.orderAsTree(distributions, omitLevels, hiddenAreaMarkerTypes);
|
|
240 | 262 |
tree.recursiveSortChildrenByLabel(); // FIXME respect current locale for sorting |
241 | 263 |
if (logger.isDebugEnabled()){logger.debug("create tree - DONE");} |
242 | 264 |
return tree; |
Also available in: Unified diff
#5112 - hiding fall back areas from the hierachchic distribution representation