You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/06/02 17:15:47 UTC
[isis] branch master updated: ISIS-3068: if DomainObject's nature is no specified, consider what the BeanTypeClassifier has come up with
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new d4ebca07e9 ISIS-3068: if DomainObject's nature is no specified, consider what the BeanTypeClassifier has come up with
d4ebca07e9 is described below
commit d4ebca07e99e982157bc67be3d10b47632db1286
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jun 2 19:15:40 2022 +0200
ISIS-3068: if DomainObject's nature is no specified, consider what the
BeanTypeClassifier has come up with
---
.../ViewModelFacetForDomainObjectAnnotation.java | 21 ++++++++++++---
.../DomainModelTest_usingGoodDomain.java | 10 ++++++++
...roperViewModelInferredFromNotBeingAnEntity.java | 30 ++++++++++++++++++++++
.../ui/components/widgets/select2/Select2.java | 3 +--
4 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacetForDomainObjectAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacetForDomainObjectAnnotation.java
index a7ec19673c..d76807397e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacetForDomainObjectAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/viewmodel/ViewModelFacetForDomainObjectAnnotation.java
@@ -23,7 +23,9 @@ import java.util.Optional;
import org.apache.isis.applib.annotation.DomainObject;
import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.metamodel.BeanSort;
import org.apache.isis.applib.services.urlencoding.UrlEncodingService;
+import org.apache.isis.commons.internal.base._Casts;
import org.apache.isis.commons.internal.memento._Mementos;
import org.apache.isis.commons.internal.memento._Mementos.SerializingAdapter;
import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
@@ -49,17 +51,30 @@ extends ViewModelFacetAbstract {
.map(DomainObject::nature)
.map(nature -> {
switch (nature) {
- case NOT_SPECIFIED:
case BEAN:
case ENTITY:
case MIXIN:
- // not a recreatable object, so no facet
+ // not a ViewModel, so no ViewModelFacet
return null;
+ case NOT_SPECIFIED:
+
+ //[ISIS-3068] consider what the BeanTypeClassifier has come up with
+ final boolean isClassifiedAsViewModel =
+ _Casts.castTo(ObjectSpecification.class, holder)
+ .map(ObjectSpecification::getBeanSort)
+ .map(BeanSort::isViewModel)
+ .orElse(false);
+
+ if(!isClassifiedAsViewModel) {
+ // not a ViewModel, so no ViewModelFacet
+ return null;
+ }
+ // else fall through
case VIEW_MODEL:
return new ViewModelFacetForDomainObjectAnnotation(
holder, postConstructMethodCache);
}
- // shouldn't happen, the above switch should match all cases.
+ // shouldn't happen, the above switch should match all cases
throw new IllegalArgumentException("nature of '" + nature + "' not recognized");
})
.filter(Objects::nonNull);
diff --git a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
index 69057382ba..3b210ba05f 100644
--- a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
+++ b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
@@ -57,6 +57,7 @@ import org.apache.isis.core.metamodel.facets.members.publish.execution.Execution
import org.apache.isis.core.metamodel.facets.object.icon.IconFacet;
import org.apache.isis.core.metamodel.facets.object.introspection.IntrospectionPolicyFacet;
import org.apache.isis.core.metamodel.facets.object.title.TitleFacet;
+import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
import org.apache.isis.core.metamodel.facets.param.choices.ActionParameterChoicesFacet;
import org.apache.isis.core.metamodel.facets.param.choices.methodnum.ActionParameterChoicesFacetViaMethod;
import org.apache.isis.core.metamodel.facets.param.defaults.ActionParameterDefaultsFacet;
@@ -88,6 +89,7 @@ import org.apache.isis.testdomain.model.good.ProperMemberSupportDiscovery;
import org.apache.isis.testdomain.model.good.ProperObjectWithAlias;
import org.apache.isis.testdomain.model.good.ProperServiceWithAlias;
import org.apache.isis.testdomain.model.good.ProperServiceWithMixin;
+import org.apache.isis.testdomain.model.good.ProperViewModelInferredFromNotBeingAnEntity;
import org.apache.isis.testdomain.model.good.ViewModelWithAnnotationOptionalUsingPrivateSupport;
import org.apache.isis.testdomain.model.good.ViewModelWithEncapsulatedMembers;
import org.apache.isis.testdomain.util.interaction.DomainObjectTesterFactory;
@@ -409,6 +411,14 @@ class DomainModelTest_usingGoodDomain {
}
+ @Test
+ void domainObjects_ifNatureNotSpecified_shouldConsiderBeanTypeClassifier() {
+ val vmSpec = specificationLoader.specForTypeElseFail(ProperViewModelInferredFromNotBeingAnEntity.class);
+
+ assertEquals(BeanSort.VIEW_MODEL, vmSpec.getBeanSort());
+ assertNotNull(vmSpec.getFacet(ViewModelFacet.class));
+ }
+
@Test
void interfaces_shouldSupport_inheritedMembers() {
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperViewModelInferredFromNotBeingAnEntity.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperViewModelInferredFromNotBeingAnEntity.java
new file mode 100644
index 0000000000..1a6ff3dfec
--- /dev/null
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperViewModelInferredFromNotBeingAnEntity.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.testdomain.model.good;
+
+import javax.inject.Named;
+
+import org.apache.isis.applib.annotation.DomainObject;
+
+//[ISIS-3068] if nature is no specified, consider what the BeanTypeClassifier has come up with
+@Named("testdomain.ProperViewModelInferredFromNotBeingAnEntity")
+@DomainObject
+public class ProperViewModelInferredFromNotBeingAnEntity {
+
+}
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/select2/Select2.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/select2/Select2.java
index 0732242c87..ca3b361961 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/select2/Select2.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/select2/Select2.java
@@ -144,8 +144,7 @@ implements
}
public boolean isEmpty() {
- final ObjectMemento curr = this.memento();
- return curr == null;
+ return memento() == null;
}
public void clear() {