diff --git a/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/CollectionLoaderImpl.java b/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/CollectionLoaderImpl.java index 8472098b9a..208c699d94 100644 --- a/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/CollectionLoaderImpl.java +++ b/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/CollectionLoaderImpl.java @@ -114,7 +114,7 @@ protected boolean _load() { LoadContext loadContext = createLoadContext(); - if (!sendPreLoadEvent(loadContext)) { + if (sendPreLoadEvent(loadContext)) { return false; } @@ -192,8 +192,7 @@ public LoadContext createLoadContext() { * @return true if duplicate results are possible, false otherwise */ protected boolean canLeadToDuplicateResultsRecursive(Condition condition) { - if (condition instanceof LogicalCondition) { - LogicalCondition logicalCondition = (LogicalCondition) condition; + if (condition instanceof LogicalCondition logicalCondition) { for (Condition childCondition : logicalCondition.getConditions()) { boolean duplicatesPossible = canLeadToDuplicateResultsRecursive(childCondition); if (duplicatesPossible) { @@ -201,8 +200,7 @@ protected boolean canLeadToDuplicateResultsRecursive(Condition condition) { } } return false; - } else if (condition instanceof PropertyCondition) { - PropertyCondition propertyCondition = (PropertyCondition) condition; + } else if (condition instanceof PropertyCondition propertyCondition) { MetaPropertyPath mpp = container.getEntityMetaClass().getPropertyPath(propertyCondition.getProperty()); if (mpp == null) { return false; @@ -220,15 +218,13 @@ protected boolean canLeadToDuplicateResultsRecursive(Condition condition) { } } + @Nullable protected FetchPlan resolveFetchPlan() { - FetchPlan fp = this.fetchPlan; - if (fp == null && fetchPlanName != null) { - fp = fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName); - } - if (fp == null) { - fp = container.getFetchPlan(); - } - return fp; + if (this.fetchPlan != null) return this.fetchPlan; + + return fetchPlanName != null + ? fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName) + : container.getFetchPlan(); } protected boolean sendPreLoadEvent(LoadContext loadContext) { @@ -241,7 +237,7 @@ protected boolean sendPreLoadEvent(LoadContext loadContext) { DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this); stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.PRE_LOAD, info); - return !preLoadEvent.isLoadPrevented(); + return preLoadEvent.isLoadPrevented(); } protected void sendPostLoadEvent(List entities) { diff --git a/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/InstanceLoaderImpl.java b/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/InstanceLoaderImpl.java index 7e79c4394d..7c09fd79be 100644 --- a/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/InstanceLoaderImpl.java +++ b/jmix-flowui/flowui/src/main/java/io/jmix/flowui/model/impl/InstanceLoaderImpl.java @@ -98,50 +98,38 @@ public void load() { if (container == null) throw new IllegalStateException("container is null"); - E entity; - LoadContext loadContext = createLoadContext(); - if (!needLoad()) + if (sendPreLoadEvent(loadContext)) { return; + } - if (loadFromRepositoryDelegate == null && delegate == null) { - if (!sendPreLoadEvent(loadContext)) { - return; - } + E entity; - Timer.Sample sample = UiMonitoring.startTimerSample(meterRegistry); + Timer.Sample sample = UiMonitoring.startTimerSample(meterRegistry); + if (loadFromRepositoryDelegate != null) { + entity = loadFromRepositoryDelegate + .apply(entityId, resolveFetchPlan()) + .orElse(null); + } else if (delegate != null) { + entity = delegate.apply(loadContext); + } else { + if (skipLoading()) return; entity = dataManager.load(loadContext); + } - DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this); - UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.LOAD, info); + DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this); + UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.LOAD, info); - if (entity == null) { - throw new EntityAccessException(container.getEntityMetaClass(), entityId); - } - } else { - if (!sendPreLoadEvent(loadContext)) { + if (entity == null) { + if (loadFromRepositoryDelegate != null || delegate != null) { return; - } - - Timer.Sample sample = UiMonitoring.startTimerSample(meterRegistry); - - if (loadFromRepositoryDelegate != null) { - entity = loadFromRepositoryDelegate.apply(entityId, resolveFetchPlan()).orElse(null); } else { - entity = delegate.apply(createLoadContext()); - } - - DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this); - UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.LOAD, info); - - if (entity == null) { - return; + throw new EntityAccessException(container.getEntityMetaClass(), entityId); } } - if (dataContext != null) { entity = dataContext.merge(entity, new MergeOptions().setFresh(true)); } @@ -150,8 +138,8 @@ public void load() { sendPostLoadEvent(entity); } - protected boolean needLoad() { - return entityId != null || !Strings.isNullOrEmpty(query); + protected boolean skipLoading() { + return entityId == null & Strings.isNullOrEmpty(query); } /** @@ -162,7 +150,7 @@ protected boolean needLoad() { public LoadContext createLoadContext() { Class entityClass = container.getEntityMetaClass().getJavaClass(); - LoadContext loadContext = new LoadContext(metadata.getClass(entityClass)); + LoadContext loadContext = new LoadContext<>(metadata.getClass(entityClass)); if (entityId != null) { loadContext.setId(entityId); @@ -179,15 +167,13 @@ public LoadContext createLoadContext() { return loadContext; } + @Nullable protected FetchPlan resolveFetchPlan() { - FetchPlan fp = this.fetchPlan; - if (fp == null && fetchPlanName != null) { - fp = fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName); - } - if (fp == null) { - fp = container.getFetchPlan(); - } - return fp; + if (this.fetchPlan != null) return this.fetchPlan; + + return fetchPlanName != null + ? fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName) + : container.getFetchPlan(); } protected boolean sendPreLoadEvent(LoadContext loadContext) { @@ -200,7 +186,7 @@ protected boolean sendPreLoadEvent(LoadContext loadContext) { DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this); UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.PRE_LOAD, info); - return !preLoadEvent.isLoadPrevented(); + return preLoadEvent.isLoadPrevented(); } protected void sendPostLoadEvent(E entity) { diff --git a/jmix-flowui/flowui/src/test/java/component/image/view/JmixImageTestView.java b/jmix-flowui/flowui/src/test/java/component/image/view/JmixImageTestView.java index 5bf04a227e..98a62f8047 100644 --- a/jmix-flowui/flowui/src/test/java/component/image/view/JmixImageTestView.java +++ b/jmix-flowui/flowui/src/test/java/component/image/view/JmixImageTestView.java @@ -41,7 +41,7 @@ public class JmixImageTestView extends StandardView { @Subscribe public void onReady(ReadyEvent event) { DocumentAttachment attachment = metadata.create(DocumentAttachment.class); - attachment.setPreview(RandomUtils.nextBytes(1)); + attachment.setPreview(RandomUtils.secure().randomBytes(1)); documentAttachmentDc.setItem(attachment); } }