Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion api/src/org/labkey/api/products/ProductRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.products;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -219,7 +220,9 @@ public String getPrimaryProductIdForContainer(@NotNull Container container)
public ProductMenuProvider getPrimaryProductMenuForContainer(@NotNull Container container)
{
List<String> productIds = getProductIdsForContainer(container);
_logger.debug("Product Ids in container '{}' of type '{}' are {}", container.getPath(), container.getFolderType().getName(), StringUtils.join(productIds));
List<ProductMenuProvider> providers = getRegisteredProducts().stream().filter(provider -> productIds.contains(provider.getProductId())).toList();
_logger.debug("Menu providers: {}", providers.stream().map(ProductMenuProvider::getProductId).collect(Collectors.toList()));
if (providers.isEmpty())
return null;

Expand All @@ -229,16 +232,27 @@ public ProductMenuProvider getPrimaryProductMenuForContainer(@NotNull Container
// see if there's a provider that matches the folder type (need to check this first so if LabKey LIMS or LKB is the configured product you can still show LKSM folders)
Optional<ProductMenuProvider> optionalProvider = providers.stream().filter(provider -> provider.getFolderTypeName() != null && provider.getFolderTypeName().equals(container.getFolderType().getName())).findFirst();
if (optionalProvider.isPresent())
{
_logger.debug("Found product menu provider for folder type '{}'", container.getFolderType().getName());
return optionalProvider.get();
}

List<String> orderedProducts = getProducts(true, false).stream().filter(Product::isEnabled).map(Product::getProductGroupId).toList();
ProductMenuProvider highestProvider = providers.stream().min(Comparator.comparing(provider -> orderedProducts.indexOf(provider.getProductId()))).orElse(null);
_logger.debug("Products are {}", _products.keySet());
_logger.debug("Ordered products are {}", orderedProducts);
ProductMenuProvider highestProvider = providers.stream()
.min(Comparator.comparing(provider -> orderedProducts.indexOf(provider.getProductId()))).orElse(null);
_logger.debug("Highest product menu provider: {}", highestProvider.getProductId());
// then see if there's a provider that matches the configured product
Product product = new ProductConfiguration().getCurrentProduct();
if (product == null)
{
_logger.debug("Using highest product menu provider.");
return highestProvider;
}

optionalProvider = providers.stream().filter(provider -> provider.getProductId().equals(product.getProductGroupId())).findFirst();
_logger.debug("Product from product group: {}", optionalProvider.isPresent() ? optionalProvider.get() : "null");
// if neither of those is true (when can this happen?), use the highest provider
return optionalProvider.orElseGet(() -> highestProvider);
}
Expand Down
4 changes: 4 additions & 0 deletions api/src/org/labkey/api/settings/ProductConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package org.labkey.api.settings;

import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.module.ModuleLoader;
import org.labkey.api.products.Product;
import org.labkey.api.products.ProductRegistry;
import org.labkey.api.util.logging.LogHelper;

import java.util.Collection;

public class ProductConfiguration extends AbstractWriteableSettingsGroup implements StartupProperty
{
public static final String SCOPE_PRODUCT_CONFIGURATION = "ProductConfiguration";
public static final String PROPERTY_NAME = "productKey";
private static final Logger _logger = LogHelper.getLogger(ProductConfiguration.class, "Product Configuration properties");

@Override
protected String getGroupName()
Expand Down Expand Up @@ -54,6 +57,7 @@ public String getCurrentProductKey()
public Product getCurrentProduct()
{
String productKey = getCurrentProductKey();
_logger.debug("Current product key: {}", productKey);
if (productKey == null)
return null;
return ProductRegistry.getProduct(productKey);
Expand Down
Loading