Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SITES-17412: Log WARN when getting duplicate id from Magento GraphQL API #994

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@

import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient;
import com.adobe.cq.commerce.graphql.client.GraphqlResponse;
Expand All @@ -37,6 +41,8 @@

public abstract class AbstractCategoriesRetriever extends AbstractRetriever {

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCategoriesRetriever.class);

public static final String CATEGORY_IMAGE_FOLDER = "catalog/category/";

/**
Expand Down Expand Up @@ -195,5 +201,20 @@ protected void populate() {
} else {
categories = Collections.emptyList();
}
logDuplicateCategories();
}

private void logDuplicateCategories() {
if (categories == null) {
return;
}
Set<String> categoryIds = new HashSet<>();
for (CategoryTree category : categories) {
String uid = category.getUid().toString();
if (categoryIds.contains(uid)) {
LOGGER.warn("Duplicate category detected: {}", uid);
}
categoryIds.add(uid);
}
}
}