Skip to content

Commit

Permalink
Move multiple series title check logic
Browse files Browse the repository at this point in the history
This moves the logic to check if the series list provider returns
multiple identical titles to the series list provider.

Furthermore, only if the id gets cut, the ellipsis is added.
  • Loading branch information
geichelberger committed Apr 24, 2024
1 parent de460f8 commit b2efbb5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -130,7 +131,7 @@ public Map<String, String> getList(String listName, ResourceListQuery query)
seriesQuery.sortByTitle(SortCriterion.Order.Ascending);
seriesQuery.sortByCreatedDateTime(SortCriterion.Order.Descending);
seriesQuery.sortByOrganizers(SortCriterion.Order.Ascending);
SearchResult searchResult = searchIndex.getByQuery(seriesQuery);
SearchResult<Series> searchResult = searchIndex.getByQuery(seriesQuery);
Calendar calendar = Calendar.getInstance();
for (SearchResultItem<Series> item : searchResult.getItems()) {
Series s = item.getSource();
Expand All @@ -149,6 +150,24 @@ public Map<String, String> getList(String listName, ResourceListQuery query)
sb.append(" (").append(StringUtils.join(extendedTitleData, ", ")).append(")");
}
result.put(s.getIdentifier(), sb.toString());
} else if (PROVIDER_PREFIX.equals(listName)) {
String newSeriesName = s.getTitle();
boolean isTitleRepeated = Arrays.stream(searchResult.getItems())
.anyMatch(series ->
!series.equals(item) && series.getSource().getTitle().equals(s.getTitle())
);
if (isTitleRepeated) {
//If a series name is repeated, will add the first 7 characters of the series ID to the display name on the
//admin-ui
if (s.getIdentifier().length() > 8) {
newSeriesName += " " + "(ID: " + s.getIdentifier().substring(0, 8) + "...)";
} else {
newSeriesName += " " + "(ID: " + s.getIdentifier() + ")";
}
logger.trace(String.format("Repeated series title \"%s\" found, changing to \"%s\" for admin-ui display",
s.getTitle(), newSeriesName));
}
result.put(s.getIdentifier(), newSeriesName);
} else {
result.put(s.getIdentifier(), s.getTitle());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -158,24 +157,6 @@ public Map<String, String> getList(String listName, ResourceListQuery query, boo
throws ListProviderException {
ResourceListProvider provider = getProvider(listName);
Map<String, String> list = provider.getList(listName, query);
if ("SERIES".equals(listName)) {
for (Map.Entry<String,String> entry : list.entrySet()) {
int repeated = Collections.frequency(list.values(), entry.getValue());
if (repeated > 1) {
String newSeriesName = null;
//If a series name is repeated, will add the first 7 characters of the series ID to the display name on the
//admin-ui
try {
newSeriesName = entry.getValue() + " " + "(ID: " + entry.getKey().substring(0, 7) + "...)";
} catch (StringIndexOutOfBoundsException e) {
newSeriesName = entry.getValue() + " " + "(ID: " + entry.getKey() + ")";
}
logger.debug(String.format("Repeated series title \"%s\" found, changing to \"%s\" for admin-ui display",
entry.getValue(), newSeriesName));
list.put(entry.getKey(), newSeriesName);
}
}
}
return inverseValueKey ? ListProviderUtil.invertMap(list) : list;
}

Expand Down

0 comments on commit b2efbb5

Please sign in to comment.