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/08/29 12:26:25 UTC
[isis] branch master updated: ISIS-3167: adds new Specializations: MIXIN, OTHER
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 facbefa55a ISIS-3167: adds new Specializations: MIXIN, OTHER
facbefa55a is described below
commit facbefa55a3a4a514958da8e39bddcfd1d6e76d7
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Aug 29 14:26:18 2022 +0200
ISIS-3167: adds new Specializations: MIXIN, OTHER
- can always remove OTHER later if not needed
---
.../images/managed-object-diagram.drawio.svg | 2 +-
.../isis/core/metamodel/object/ManagedObject.java | 103 ++++++++++++++++++---
.../core/metamodel/object/_ManagedObjectEmpty.java | 4 +
.../core/metamodel/object/_ManagedObjectValue.java | 91 ++++++++++++++++++
.../JsonValueEncoderTest_asAdapter.java | 6 ++
5 files changed, 193 insertions(+), 13 deletions(-)
diff --git a/core/metamodel/src/main/adoc/modules/metamodel/images/managed-object-diagram.drawio.svg b/core/metamodel/src/main/adoc/modules/metamodel/images/managed-object-diagram.drawio.svg
index 99a095ef55..aa867c9885 100644
--- a/core/metamodel/src/main/adoc/modules/metamodel/images/managed-object-diagram.drawio.svg
+++ b/core/metamodel/src/main/adoc/modules/metamodel/images/managed-object-diagram.drawio.svg
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file with editors other than diagrams.net -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1416px" height="583px" viewBox="-0.5 -0.5 1416 583" content="<mxfile host="Electron" modified="2022-08-28T17:55:51.322Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.2.3 Chrome/102.0.5005.167 Electron/19.0.11 Safari/537.36" etag="Nx5jms2W9E4vG-314Awj" version="20.2.3" type="device&qu [...]
\ No newline at end of file
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1391px" height="591px" viewBox="-0.5 -0.5 1391 591" content="<mxfile host="Electron" modified="2022-08-29T12:18:11.004Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.2.3 Chrome/102.0.5005.167 Electron/19.0.11 Safari/537.36" etag="O_s-bwyPrjJCA4A3Hi-v" version="20.2.3" type="device&qu [...]
\ No newline at end of file
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java
index 41f3dadbba..dc2659ac09 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java
@@ -70,7 +70,7 @@ public interface ManagedObject extends HasMetaModelContext {
/**
* <h1>Contract</h1><ul>
- * <li>Specification (immutable, allowed to correspond to abstract type)</li>
+ * <li>Specification (immutable, allowed to correspond to abstract type)</li>
* <li>Bookmark (n/a)</li>
* <li>Pojo (null, immutable)</li>
* </ul>
@@ -79,7 +79,7 @@ public interface ManagedObject extends HasMetaModelContext {
/**
* <h1>Contract</h1><ul>
- * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
+ * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
* <li>Bookmark (immutable)</li>
* <li>Pojo (immutable)</li>
* </ul>
@@ -88,7 +88,7 @@ public interface ManagedObject extends HasMetaModelContext {
/**
* <h1>Contract</h1><ul>
- * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
+ * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
* <li>Bookmark (immutable)</li>
* <li>Pojo (immutable)</li>
* </ul>
@@ -97,7 +97,7 @@ public interface ManagedObject extends HasMetaModelContext {
/**
* <h1>Contract</h1><ul>
- * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
+ * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
* <li>Bookmark (refreshable, as VM state changes manifest in change of ID)</li>
* <li>Pojo (mutable, but immutable obj. ref.)</li>
* </ul>
@@ -106,7 +106,7 @@ public interface ManagedObject extends HasMetaModelContext {
/**
* <h1>Contract</h1><ul>
- * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
+ * <li>Specification (immutable, NOT allowed to correspond to abstract type)</li>
* <li>Bookmark (immutable, entity must be persistent, it must have an ID, fail otherwise)</li>
* <li>Pojo (refetchable)</li>
* </ul>
@@ -115,7 +115,25 @@ public interface ManagedObject extends HasMetaModelContext {
/**
* <h1>Contract</h1><ul>
- * <li>Element Specification (immutable, allowed to correspond to abstract type)</li>
+ * <li>Element Specification (immutable, NOT allowed to correspond to abstract type)</li>
+ * <li>Bookmark (n/a)</li>
+ * <li>Pojo (allowed stateful, immutable obj. ref)</li>
+ * </ul>
+ */
+ MIXIN(TypePolicy.EXACT_TYPE_REQUIRED, BookmarkPolicy.NO_BOOKMARK, PojoPolicy.STATEFUL),
+
+ /**
+ * <h1>Contract</h1><ul>
+ * <li>Element Specification (immutable, NOT allowed to correspond to abstract type)</li>
+ * <li>Bookmark (n/a)</li>
+ * <li>Pojo (allowed stateful, immutable obj. ref)</li>
+ * </ul>
+ */
+ OTHER(TypePolicy.EXACT_TYPE_REQUIRED, BookmarkPolicy.NO_BOOKMARK, PojoPolicy.STATEFUL),
+
+ /**
+ * <h1>Contract</h1><ul>
+ * <li>Element Specification (immutable, NOT allowed to correspond to abstract type)</li>
* <li>Bookmark (n/a)</li>
* <li>Pojo (unmod. Collection of pojos)</li>
* </ul>
@@ -227,6 +245,20 @@ public interface ManagedObject extends HasMetaModelContext {
* @see PojoPolicy#REFETCHABLE
*/
public boolean isEntity() { return this == ENTITY; }
+ /**
+ * MIXIN
+ * @see TypePolicy#EXACT_TYPE_REQUIRED
+ * @see BookmarkPolicy#NO_BOOKMARK
+ * @see PojoPolicy#STATEFUL
+ */
+ public boolean isMixin() { return this == MIXIN; }
+ /**
+ * OTHER
+ * @see TypePolicy#EXACT_TYPE_REQUIRED
+ * @see BookmarkPolicy#NO_BOOKMARK
+ * @see PojoPolicy#STATEFUL
+ */
+ public boolean isOther() { return this == OTHER; }
/**
* PACKED
* @see TypePolicy#ABSTRACT_TYPE_ALLOWED
@@ -259,6 +291,12 @@ public interface ManagedObject extends HasMetaModelContext {
if(spec.isEntity()) {
return ENTITY;
}
+ if(spec.isMixin()) {
+ return MIXIN;
+ }
+ if(!spec.isAbstract()) {
+ return OTHER;
+ }
log.warn("failed specialization attempt for {}", spec);
return UNSPECIFIED;
}
@@ -391,8 +429,11 @@ public interface ManagedObject extends HasMetaModelContext {
*/
static ManagedObject value(
final @NonNull ObjectSpecification spec,
- final @NonNull Object pojo) {
- return new _ManagedObjectWithEagerSpec(spec, pojo); //FIXME
+ final @Nullable Object pojo) {
+ return pojo != null
+ ? new _ManagedObjectWithEagerSpec(spec, pojo) //FIXME
+ //new _ManagedObjectValue(spec, pojo)
+ : empty(spec);
}
/**
* SERVICE
@@ -417,8 +458,10 @@ public interface ManagedObject extends HasMetaModelContext {
*/
static ManagedObject viewmodel(
final @NonNull ObjectSpecification spec,
- final @NonNull Object pojo) {
- return new _ManagedObjectWithEagerSpec(spec, pojo); //FIXME
+ final @Nullable Object pojo) {
+ return pojo != null
+ ? new _ManagedObjectWithEagerSpec(spec, pojo) //FIXME
+ : empty(spec);
}
/**
* ENTITY
@@ -430,8 +473,40 @@ public interface ManagedObject extends HasMetaModelContext {
*/
static ManagedObject entity(
final @NonNull ObjectSpecification spec,
- final @NonNull Object pojo) {
- return new _ManagedObjectWithEagerSpec(spec, pojo); //FIXME
+ final @Nullable Object pojo) {
+ return pojo != null
+ ? new _ManagedObjectWithEagerSpec(spec, pojo) //FIXME
+ : empty(spec);
+ }
+ /**
+ * MIXIN
+ * @param pojo
+ * @param spec
+ * @see ManagedObject.Specialization.TypePolicy#EXACT_TYPE_REQUIRED
+ * @see ManagedObject.Specialization.BookmarkPolicy#NO_BOOKMARK
+ * @see ManagedObject.Specialization.PojoPolicy#STATEFUL
+ */
+ static ManagedObject mixin(
+ final @NonNull ObjectSpecification spec,
+ final @Nullable Object pojo) {
+ return pojo != null
+ ? new _ManagedObjectWithEagerSpec(spec, pojo) //FIXME
+ : empty(spec);
+ }
+ /**
+ * OTHER
+ * @param pojo
+ * @param spec
+ * @see ManagedObject.Specialization.TypePolicy#EXACT_TYPE_REQUIRED
+ * @see ManagedObject.Specialization.BookmarkPolicy#NO_BOOKMARK
+ * @see ManagedObject.Specialization.PojoPolicy#STATEFUL
+ */
+ static ManagedObject other(
+ final @NonNull ObjectSpecification spec,
+ final @Nullable Object pojo) {
+ return pojo != null
+ ? new _ManagedObjectWithEagerSpec(spec, pojo) //FIXME
+ : empty(spec);
}
/**
* PACKED
@@ -476,6 +551,10 @@ public interface ManagedObject extends HasMetaModelContext {
return viewmodel(spec, pojo);
case ENTITY:
return entity(spec, pojo);
+ case MIXIN:
+ return mixin(spec, pojo);
+ case OTHER:
+ return other(spec, pojo);
// unreachable (in this context)
case EMPTY:
case PACKED:
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEmpty.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEmpty.java
index 00d32cd097..d40fe5abaf 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEmpty.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEmpty.java
@@ -26,6 +26,10 @@ import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import lombok.Getter;
+/**
+ * (package private) specialization corresponding to {@link Specialization#EMPTY}
+ * @see ManagedObject.Specialization#EMPTY
+ */
@Getter
final class _ManagedObjectEmpty
extends _ManagedObjectSpecified {
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectValue.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectValue.java
new file mode 100644
index 0000000000..bbc9ea9c63
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectValue.java
@@ -0,0 +1,91 @@
+/*
+ * 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.core.metamodel.object;
+
+import java.util.Optional;
+import java.util.function.Supplier;
+
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.commons.internal.assertions._Assert;
+import org.apache.isis.commons.internal.base._Casts;
+import org.apache.isis.commons.internal.base._Lazy;
+import org.apache.isis.core.metamodel.facets.object.value.ValueFacet;
+import org.apache.isis.core.metamodel.facets.object.value.ValueSerializer.Format;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.experimental.Accessors;
+
+/**
+ * (package private) specialization corresponding to {@link Specialization#VALUE}
+ * @see ManagedObject.Specialization#VALUE
+ */
+@Getter
+final class _ManagedObjectValue
+extends _ManagedObjectSpecified {
+
+ @Getter(onMethod_ = {@Override}) @Accessors(makeFinal = true)
+ private final @NonNull Object pojo;
+
+ protected final _Lazy<Optional<Bookmark>> bookmarkLazy =
+ _Lazy.threadSafe(()->Optional.of(createBookmark()));
+
+ _ManagedObjectValue(
+ final ObjectSpecification spec,
+ final Object pojo) {
+ super(ManagedObject.Specialization.VALUE, spec);
+ _Assert.assertTrue(spec.isValue());
+ _Assert.assertFalse(spec.isAbstract());
+ this.pojo = pojo;
+ }
+
+ @Override
+ public Optional<Bookmark> getBookmark() {
+ return bookmarkLazy.get();
+ }
+
+ @Override
+ public Optional<Bookmark> getBookmarkRefreshed() {
+ return getBookmark(); // no-op for values
+ }
+
+ @Override
+ public void refreshViewmodel(final Supplier<Bookmark> bookmarkSupplier) {
+ // no-op for values
+ }
+
+ @Override
+ public boolean isBookmarkMemoized() {
+ return bookmarkLazy.isMemoized();
+ }
+
+ // -- HELPER
+
+ private ValueFacet<?> valueFacet() {
+ return getSpecification().valueFacet().orElseThrow();
+ }
+
+ private Bookmark createBookmark() {
+ return Bookmark.forLogicalTypeAndIdentifier(
+ getSpecification().getLogicalType(),
+ valueFacet().toEncodedString(Format.JSON, _Casts.uncheckedCast(getPojo())));
+ }
+
+}
\ No newline at end of file
diff --git a/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java b/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
index 592aaa0e12..6606a23eab 100644
--- a/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
+++ b/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
@@ -386,6 +386,12 @@ public class JsonValueEncoderTest_asAdapter {
context.checking(new Expectations() {
{
+ allowing(mockObjectSpec).isValue();
+ will(returnValue(true));
+
+ allowing(mockObjectSpec).isAbstract();
+ will(returnValue(false));
+
allowing(mockObjectSpec).valueFacet();
will(returnValue(Optional.of(mockValueFacet)));