From a5af6a8c27f8d3d138249684ec4f33b75ec2d8b8 Mon Sep 17 00:00:00 2001 From: Teo Sarca Date: Wed, 3 May 2017 09:47:35 +0300 Subject: [PATCH] WebuiRelatedProcessDescriptor shall memorize the preconditionsResolutionSupplier https://github.com/metasfresh/metasfresh-webui-api/issues/330 --- .../WebuiRelatedProcessDescriptor.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/metas/ui/web/process/descriptor/WebuiRelatedProcessDescriptor.java b/src/main/java/de/metas/ui/web/process/descriptor/WebuiRelatedProcessDescriptor.java index 5b3b1550f..21cbefef8 100644 --- a/src/main/java/de/metas/ui/web/process/descriptor/WebuiRelatedProcessDescriptor.java +++ b/src/main/java/de/metas/ui/web/process/descriptor/WebuiRelatedProcessDescriptor.java @@ -4,6 +4,7 @@ import java.util.function.Supplier; import org.adempiere.util.Check; +import org.adempiere.util.lang.ExtendedMemorizingSupplier; import com.google.common.collect.ImmutableMap; @@ -43,7 +44,6 @@ * @author metas-dev * */ -@lombok.Builder public final class WebuiRelatedProcessDescriptor { public static final WebuiRelatedProcessDescriptor of( // @@ -55,7 +55,7 @@ public static final WebuiRelatedProcessDescriptor of( // Check.assumeNotNull(relatedProcessDescriptor, "Parameter relatedProcessDescriptor is not null"); Check.assumeNotNull(processDescriptor, "Parameter processDescriptor is not null"); Check.assume(relatedProcessDescriptor.getProcessId() == processDescriptor.getProcessId().getProcessIdAsInt(), "AD_Process_ID matching for {} and {}", relatedProcessDescriptor, processDescriptor); - + return builder() .processId(processDescriptor.getProcessId()) .processCaption(processDescriptor.getCaption()) @@ -77,9 +77,34 @@ public static final WebuiRelatedProcessDescriptor of( // private final boolean defaultQuickAction; @NonNull private final Supplier preconditionsResolutionSupplier; - + private final String debugProcessClassname; + @lombok.Builder + private WebuiRelatedProcessDescriptor( // + final ProcessId processId // + , final ITranslatableString processCaption // + , final ITranslatableString processDescription // + , final boolean quickAction // + , final boolean defaultQuickAction // + , @NonNull final Supplier preconditionsResolutionSupplier // + , final String debugProcessClassname // + ) + { + super(); + this.processId = processId; + this.processCaption = processCaption; + this.processDescription = processDescription; + this.quickAction = quickAction; + this.defaultQuickAction = defaultQuickAction; + + // Memorize the resolution supplier to make sure it's not invoked more than once because it might be an expensive operation. + // Also we assume this is a short living instance which was created right before checking + this.preconditionsResolutionSupplier = ExtendedMemorizingSupplier.of(preconditionsResolutionSupplier); + + this.debugProcessClassname = debugProcessClassname; + } + public ProcessId getProcessId() { return processId;