Skip to content

Commit

Permalink
2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dxa-team committed Sep 19, 2019
2 parents e98d55e + a3407c8 commit cff5393
Show file tree
Hide file tree
Showing 45 changed files with 700 additions and 330 deletions.
2 changes: 1 addition & 1 deletion dxa-dd4t-ms-provider/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>dxa-parent</artifactId>
<groupId>com.sdl.dxa</groupId>
<version>2.2.1-SNAPSHOT</version>
<version>2.2.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion dxa-framework/dxa-common-api/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.sdl.dxa</groupId>
<artifactId>dxa-framework</artifactId>
<version>2.2.1-SNAPSHOT</version>
<version>2.2.1</version>
</parent>

<artifactId>dxa-common-api</artifactId>
Expand Down
Expand Up @@ -91,6 +91,7 @@ public View resolveViewName(String viewName, Locale locale) throws Exception {
}

@Bean
@Profile("!dxa.docs.enabled")
public ViewResolver overrideDeviceContextualViewResolver() {
UrlBasedViewResolver viewResolver = new ContextualDeviceUrlBasedViewResolver();
viewResolver.setViewClass(OptionalJstlView.class);
Expand All @@ -101,6 +102,7 @@ public ViewResolver overrideDeviceContextualViewResolver() {
}

@Bean
@Profile("!dxa.docs.enabled")
public ViewResolver deviceContextualViewResolver() {
UrlBasedViewResolver viewResolver = new ContextualDeviceUrlBasedViewResolver();
viewResolver.setViewClass(OptionalJstlView.class);
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.sdl.webapp.common.api.content.LinkResolver;
import com.sdl.webapp.common.api.localization.Localization;
import lombok.*;
Expand All @@ -13,18 +14,14 @@
import org.jetbrains.annotations.Nullable;
import org.joda.time.DateTime;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.*;

import static org.apache.commons.lang3.StringUtils.isEmpty;

/**
* @dxa.publicApi
*/
@Data
@ToString(exclude = {"parent"})
@EqualsAndHashCode(callSuper = true, of = {"title", "originalTitle", "type", "publishedDate"})
@Slf4j
@NoArgsConstructor
Expand All @@ -42,7 +39,7 @@ public class SitemapItem extends AbstractEntityModel {

@JsonProperty("Items")
@JsonDeserialize(as = LinkedHashSet.class)
private Set<SitemapItem> items;
private LinkedHashSet<SitemapItem> items;

@JsonProperty("PublishedDate")
private DateTime publishedDate;
Expand Down Expand Up @@ -98,8 +95,12 @@ public Set<SitemapItem> getItems() {
*
* @param items items to set
*/
public void setItems(@Nullable Set<SitemapItem> items) {
this.items = wrapItems(items);
public void setItems(@Nullable Collection<SitemapItem> items) {
if (LinkedHashSet.class.isAssignableFrom(items.getClass())){
this.items = (LinkedHashSet) items;
} else {
this.items = new LinkedHashSet<>(items);
}
rebuildParentRelationships();
}

Expand Down Expand Up @@ -130,7 +131,7 @@ public boolean removeItem(SitemapItem item) {
}

@Contract("null -> !null; !null -> !null")
protected Set<SitemapItem> wrapItems(@Nullable Set<SitemapItem> items) {
protected LinkedHashSet<SitemapItem> wrapItems(@Nullable LinkedHashSet<SitemapItem> items) {
return items == null ? new LinkedHashSet<>() : items;
}

Expand Down Expand Up @@ -182,4 +183,18 @@ public SitemapItem getParent() {
}
return parent;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).omitNullValues()
.add("id", getId())
.add("title", title)
.add("url", url)
.add("type", type)
.add("items", items)
.add("publishedDate", publishedDate)
.add("visible", visible)
.add("originalTitle", originalTitle)
.toString();
}
}
Expand Up @@ -2,18 +2,15 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ComparisonChain;
import com.sdl.webapp.common.api.content.LinkResolver;
import com.sdl.webapp.common.api.localization.Localization;
import com.sdl.webapp.common.api.model.sorting.SortableSiteMap;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import org.springframework.util.comparator.NullSafeComparator;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
import java.util.LinkedHashSet;

/**
* Represents a special kind of {@link SitemapItem} which is used for Taxonomy Nodes.
Expand All @@ -24,11 +21,6 @@
@EqualsAndHashCode(callSuper = true)
public class TaxonomyNode extends SitemapItem {

private static final Comparator<SitemapItem> SITEMAP_SORT_BY_TITLE_AND_ID = new NullSafeComparator<>((o1, o2) -> ComparisonChain.start()
.compare(o1.getOriginalTitle(), o2.getOriginalTitle())
.compare(o1.getId(), o2.getId())
.result(), true);

@JsonProperty("Key")
private String key;

Expand All @@ -45,12 +37,8 @@ public class TaxonomyNode extends SitemapItem {
private int classifiedItemsCount;

@Override
protected Set<SitemapItem> wrapItems(@Nullable Set<SitemapItem> items) {
TreeSet<SitemapItem> treeSet = new TreeSet<>(SITEMAP_SORT_BY_TITLE_AND_ID);
if (items != null) {
treeSet.addAll(items);
}
return treeSet;
protected LinkedHashSet<SitemapItem> wrapItems(@Nullable LinkedHashSet<SitemapItem> items) {
return new LinkedHashSet<>(SortableSiteMap.sortItem(items, SortableSiteMap.SORT_BY_TITLE_AND_ID));
}

@Override
Expand Down
Expand Up @@ -36,6 +36,7 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "id", "name", "title", "url", "meta", "regions" })
@NoArgsConstructor
@lombok.ToString
public class DefaultPageModel extends AbstractViewModel implements PageModel {

private static final String XPM_PAGE_SETTINGS_MARKUP = "<!-- Page Settings: {\"PageID\":\"%s\",\"PageModified\":\"%s\",\"PageTemplateID\":\"%s\",\"PageTemplateModified\":\"%s\"} -->";
Expand Down Expand Up @@ -108,7 +109,7 @@ public void filterConditionalEntities(Collection<ConditionalEntityEvaluator> eva
try {
regionModel.filterConditionalEntities(evaluators);
} catch (ContentProviderException ex) {
exception.set(ex);
if (exception.get() == null) exception.set(ex);
}
});
if (exception.get() != null) throw exception.get();
Expand Down
Expand Up @@ -205,15 +205,15 @@ public void filterConditionalEntities(Collection<ConditionalEntityEvaluator> eva
try {
regionModel.filterConditionalEntities(evaluators);
} catch (ContentProviderException ex) {
exception.set(ex);
if (exception.get() == null) exception.set(ex);
}
});
if (exception.get() != null) throw exception.get();
entities.removeIf(entityModel -> !evaluators.stream().allMatch(evaluator -> {
try {
return evaluator.includeEntity(entityModel);
} catch (ContentProviderException ex) {
exception.set(ex);
if (exception.get() == null) exception.set(ex);
return true;
}
}));
Expand Down
@@ -0,0 +1,148 @@
package com.sdl.webapp.common.api.model.sorting;

import com.google.common.collect.ComparisonChain;
import com.sdl.dxa.api.datamodel.model.SitemapItemModelData;
import com.sdl.webapp.common.api.model.entity.SitemapItem;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.comparator.NullSafeComparator;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* A private class that contains the results of the regex so they only have to be done once for a whole sorting.
*/
public class SortableSiteMap {
private static final Pattern TAXONOMY_ID_PATTERN = Pattern.compile("^(\\w?)(\\d+)-(\\w?)(\\d+)$");

public static final Comparator<SortableSiteMap> SORT_BY_TITLE_AND_ID = new NullSafeComparator<>(new Comparator<SortableSiteMap>() {
@Override
public int compare(SortableSiteMap o1, SortableSiteMap o2) {
return ComparisonChain.start()
.compareTrueFirst(o1 != null, o2 != null)
.compare(o1.getOriginalTitle(), o2.getOriginalTitle())
.compare(o1.getId(), o2.getId())
.result();
}
}, true);

public static final Comparator<SortableSiteMap> SORT_BY_TAXONOMY_AND_KEYWORD = new NullSafeComparator<>(new Comparator<SortableSiteMap>() {
@Override
public int compare(SortableSiteMap o1, SortableSiteMap o2) {
return ComparisonChain.start()
.compareTrueFirst(o1 != null, o2 != null)
.compare(o1.getFirstChar(), o2.getFirstChar())
.compare(o1.getFirstNumber(), o2.getFirstNumber())
.compare(o1.getSecondChar(), o2.getSecondChar())
.compare(o1.getSecondNumber(), o2.getSecondNumber())
.result();
}
}, true);

private Integer firstNumber = Integer.MIN_VALUE;
private String firstChar = "";
private Integer secondNumber = Integer.MIN_VALUE;
private String secondChar = "";
private String originalTitle = "";
private String id = "";
private SitemapItem sitemapItem;
private SitemapItemModelData sitemapItemModelData;

public SortableSiteMap(SitemapItemModelData sitemapItemModelData) {
this.sitemapItemModelData = sitemapItemModelData;
if (sitemapItemModelData == null) {
return;
}
originalTitle = sitemapItemModelData.getOriginalTitle() == null ? "" : sitemapItemModelData.getOriginalTitle();
id = sitemapItemModelData.getId() == null ? "" : sitemapItemModelData.getId();
if (sitemapItemModelData.getId() == null) return;
Matcher matcher = TAXONOMY_ID_PATTERN.matcher(sitemapItemModelData.getId());
if (!matcher.matches()) {
return;
}
fillFromMatcher(matcher);
}

public SortableSiteMap(SitemapItem sitemapItem) {
this.sitemapItem = sitemapItem;
if (sitemapItem == null) {
return;
}
originalTitle = sitemapItem.getOriginalTitle() == null ? "" : sitemapItem.getOriginalTitle();
id = sitemapItem.getId() == null ? "" : sitemapItem.getId();
if (sitemapItem.getId() == null) return;
Matcher matcher = TAXONOMY_ID_PATTERN.matcher(sitemapItem.getId());
if (!matcher.matches()) {
return;
}
fillFromMatcher(matcher);
}

private void fillFromMatcher(Matcher matcher) {
String group2 = matcher.group(2);
String group4 = matcher.group(4);
if (StringUtils.isNotEmpty(group2)) {
this.firstNumber = Integer.parseInt(group2);
}
if (StringUtils.isNotEmpty(group4)) {
this.secondNumber = Integer.parseInt(group4);
}
this.firstChar = matcher.group(1);
this.secondChar = matcher.group(3);
}

public Integer getFirstNumber() {
return firstNumber;
}

public Integer getSecondNumber() {
return secondNumber;
}

public String getFirstChar() {
return firstChar;
}

public String getSecondChar() {
return secondChar;
}

public SitemapItem getSitemapItem() {
return sitemapItem;
}

public SitemapItemModelData getSitemapItemModelData() {
return sitemapItemModelData;
}

public String getOriginalTitle() {
return originalTitle;
}

public String getId() {
return id;
}

public static Collection<SitemapItem> sortItem(Collection<SitemapItem> entries, Comparator<SortableSiteMap> comparator) {
if (entries == null) return Collections.emptyList();
return entries
.stream()
.map(SortableSiteMap::new)
.sorted(comparator)
.map(SortableSiteMap::getSitemapItem).collect(Collectors.toList());
}

public static Collection<SitemapItemModelData> sortModelData(Collection<SitemapItemModelData> entries, Comparator<SortableSiteMap> comparator) {
if (entries == null) return Collections.emptyList();
return entries
.stream()
.map(SortableSiteMap::new)
.sorted(comparator)
.map(SortableSiteMap::getSitemapItemModelData).collect(Collectors.toList());
}

}
Expand Up @@ -40,8 +40,7 @@ public IgnoreByNameInRequestFilter(HttpServletRequest httpServletRequest) {
*/
public static void ignoreByName(ServletRequest request, String... properties) {
if (properties != null && properties.length != 0) {
String value = on(DELIMITER).skipNulls().join(
on(DELIMITER).join(properties), request.getAttribute(REQUEST_ATTRIBUTE));
String value = on(DELIMITER).skipNulls().join(on(DELIMITER).join(properties), request.getAttribute(REQUEST_ATTRIBUTE));

request.setAttribute(REQUEST_ATTRIBUTE, value);
log.trace("Set ignore properties in current request: {}", value);
Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.sdl.webapp.common.api.model.entity.RedirectEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -23,6 +24,7 @@
* @dxa.publicApi
*/
@Controller
@Profile("!dxa.docs.enabled")
@RequestMapping(INCLUDE_MAPPING + "/Entity")
public class EntityController extends BaseController {

Expand Down

0 comments on commit cff5393

Please sign in to comment.