This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v3
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/v3 by this push:
new 17d0c0074e3 CAUSEWAY-3966: fixes ApplicationFeatureViewModel
instantiation issue
17d0c0074e3 is described below
commit 17d0c0074e373e30f8d11e509321bfab95ae0131
Author: andi-huber <[email protected]>
AuthorDate: Tue Feb 10 12:14:02 2026 +0100
CAUSEWAY-3966: fixes ApplicationFeatureViewModel instantiation issue
Task-Url: https://issues.apache.org/jira/browse/CAUSEWAY-3966
---
.../appfeatui/ApplicationFeatureViewModel.java | 72 ++++++----------------
1 file changed, 19 insertions(+), 53 deletions(-)
diff --git
a/api/applib/src/main/java/org/apache/causeway/applib/services/appfeatui/ApplicationFeatureViewModel.java
b/api/applib/src/main/java/org/apache/causeway/applib/services/appfeatui/ApplicationFeatureViewModel.java
index 49e84685122..9bbdc071f4f 100644
---
a/api/applib/src/main/java/org/apache/causeway/applib/services/appfeatui/ApplicationFeatureViewModel.java
+++
b/api/applib/src/main/java/org/apache/causeway/applib/services/appfeatui/ApplicationFeatureViewModel.java
@@ -26,9 +26,6 @@
import java.util.Optional;
import java.util.function.Function;
-import jakarta.inject.Inject;
-import jakarta.inject.Named;
-
import org.apache.causeway.applib.CausewayModuleApplib;
import org.apache.causeway.applib.ViewModel;
import org.apache.causeway.applib.annotation.DomainObject;
@@ -45,18 +42,19 @@
import org.apache.causeway.applib.services.appfeat.ApplicationFeatureId;
import
org.apache.causeway.applib.services.appfeat.ApplicationFeatureRepository;
import org.apache.causeway.applib.services.appfeat.ApplicationFeatureSort;
-import org.apache.causeway.applib.services.bookmark.Bookmark;
import org.apache.causeway.applib.services.factory.FactoryService;
import org.apache.causeway.applib.util.Equality;
import org.apache.causeway.applib.util.Hashing;
import org.apache.causeway.applib.util.ObjectContracts;
import org.apache.causeway.applib.util.ToString;
-import org.apache.causeway.commons.internal.assertions._Assert;
import org.apache.causeway.commons.internal.base._Casts;
import org.apache.causeway.commons.internal.collections._Lists;
+import org.apache.causeway.commons.internal.exceptions._Exceptions;
+import org.jspecify.annotations.NonNull;
+import jakarta.inject.Inject;
+import jakarta.inject.Named;
import lombok.Getter;
-import org.jspecify.annotations.NonNull;
import lombok.Setter;
/**
@@ -83,48 +81,21 @@ public static ApplicationFeatureViewModel newViewModel(
final ApplicationFeatureId featureId,
final ApplicationFeatureRepository applicationFeatureRepository,
final FactoryService factoryService) {
- final Class<? extends ApplicationFeatureViewModel> vmClass =
- viewModelClassFor(featureId, applicationFeatureRepository);
- if(featureId.getSort().isNamespace()) {
- _Assert.assertEquals(vmClass, ApplicationNamespace.class);
- return factoryService.viewModel(new
ApplicationNamespace(featureId));
- }
-
- return factoryService.viewModel(vmClass,
- Bookmark.forLogicalTypeNameAndIdentifier(
- featureId.getLogicalTypeName(),
- featureId.asEncodedString()));
- }
-
- private static Class<? extends ApplicationFeatureViewModel>
viewModelClassFor(
- final ApplicationFeatureId featureId,
- final ApplicationFeatureRepository applicationFeatureRepository) {
- switch (featureId.getSort()) {
- case NAMESPACE:
- return ApplicationNamespace.class;
- case TYPE:
- return ApplicationType.class;
- case MEMBER:
-
- var memberSort =
-
Optional.ofNullable(applicationFeatureRepository.findFeature(featureId))
- .flatMap(ApplicationFeature::getMemberSort)
- .orElse(null);
-
- if(memberSort != null) {
- switch(memberSort) {
- case PROPERTY:
- return ApplicationTypeProperty.class;
- case COLLECTION:
- return ApplicationTypeCollection.class;
- case ACTION:
- return ApplicationTypeAction.class;
- }
- }
-
- }
- throw new IllegalArgumentException("could not determine feature type;
featureId = " + featureId);
+ return switch (featureId.getSort()) {
+ case NAMESPACE->factoryService.viewModel(new
ApplicationNamespace(featureId));
+ case TYPE->factoryService.viewModel(new
ApplicationType(featureId));
+ case MEMBER->
+
Optional.ofNullable(applicationFeatureRepository.findFeature(featureId))
+ .flatMap(ApplicationFeature::getMemberSort)
+ .map(memberSort->switch (memberSort) {
+ case PROPERTY -> factoryService.viewModel(new
ApplicationTypeProperty(featureId));
+ case COLLECTION -> factoryService.viewModel(new
ApplicationTypeCollection(featureId));
+ case ACTION -> factoryService.viewModel(new
ApplicationTypeAction(featureId));
+ })
+ .orElseThrow(()->_Exceptions
+ .illegalArgument("could not map feature-id '%s' to
a view-model", featureId));
+ };
}
public ApplicationFeatureViewModel() {
@@ -326,12 +297,7 @@ public ApplicationFeatureViewModel getParent() {
if (feature == null) {
return null;
}
- final Class<? extends ApplicationFeatureViewModel> cls =
- viewModelClassFor(parentId, featureRepository);
- return factory.viewModel(cls,
- Bookmark.forLogicalTypeNameAndIdentifier(
- ApplicationFeatureViewModel.LOGICAL_TYPE_NAME,
- parentId.asEncodedString()));
+ return newViewModel(parentId, featureRepository, factory);
}
// -- parentPackage (property, programmatic, for packages & classes only)