>
+implements
+ HidingInteractionAdvisor,
+ DisablingInteractionAdvisor,
+ ValidatingInteractionAdvisor {
+
+ // -- FACET TYPE
+
+ private static Class extends Facet> type() {
+ return ActionDomainEventFacet.class;
+ }
+
+ // -- FACTORIES
+
+ /**
+ * For regular (non mixed-in) members only.
+ *
+ * @return empty, if event is not post-able
+ */
+ public static Optional createRegular(
+ final @NonNull Optional actionIfAny,
+ final @NonNull ObjectSpecification typeSpec,
+ final @NonNull FacetHolder facetHolder){
+
+ val actionDomainEventFacet =
+ actionIfAny
+ .map(Action::domainEvent)
+ .filter(domainEvent -> domainEvent != ActionDomainEvent.Default.class)
+ .map(domainEvent ->
+ new ActionDomainEventFacet(
+ defaultFromDomainObjectIfRequired(typeSpec, domainEvent), EventTypeOrigin.ANNOTATED_MEMBER, facetHolder))
+ .orElse(
+ new ActionDomainEventFacet(
+ defaultFromDomainObjectIfRequired(typeSpec, ActionDomainEvent.Default.class), EventTypeOrigin.DEFAULT, facetHolder)
+ );
+
+ return EventUtil.eventTypeIsPostable(
+ actionDomainEventFacet.getEventType(),
+ ActionDomainEvent.Noop.class,
+ ActionDomainEvent.Default.class,
+ facetHolder.getConfiguration().getApplib().getAnnotation().getAction().getDomainEvent().isPostForDefault())
+ ? Optional.of(actionDomainEventFacet)
+ : Optional.empty();
+ }
+
+ /**
+ * For mixed-in members.
+ */
+ public static Optional createMixedIn(
+ final @NonNull ObjectSpecification mixeeSpecification,
+ final @NonNull ObjectActionMixedIn mixedInAction) {
+
+
+ val facetedMethod = mixedInAction.getFacetedMethod();
+ final Method method = facetedMethod.getMethod().asMethodElseFail(); // no-arg method, should have a regular facade
+
+ //TODO[CAUSEWAY-3409] what if the @Action annotation is not on the method but on the (mixin) type
+ final Action actionAnnot =
+ _Annotations.synthesize(method, Action.class)
+ .orElse(null);
+
+ if(actionAnnot != null) {
+ final Class extends ActionDomainEvent>> actionDomainEventType =
+ defaultFromDomainObjectIfRequired(
+ mixeeSpecification, actionAnnot.domainEvent());
+
+ return Optional.of(
+ new ActionDomainEventFacet(
+ actionDomainEventType, EventTypeOrigin.ANNOTATED_MEMBER, mixedInAction));
+ }
+
+ return Optional.empty();
+
+ }
+
+ // -- CONSTRUCTION
+
+ private final TranslationService translationService;
+ private final TranslationContext translationContext;
+ private final DomainEventHelper domainEventHelper;
+
+ protected ActionDomainEventFacet(
+ final Class extends ActionDomainEvent>> eventType,
+ final EventTypeOrigin eventTypeOrigin,
+ final FacetHolder holder) {
+
+ super(type(), eventType, eventTypeOrigin, holder);
+
+ this.translationService = getTranslationService();
+ this.translationContext = holder.getTranslationContext();
+
+ domainEventHelper = DomainEventHelper.ofServiceRegistry(getServiceRegistry());
+ }
+
+ @Override
+ public void initWithMixee(final ObjectSpecification mixeeSpec) {
+ if(!getEventTypeOrigin().isDefault()) return; // skip if already set explicitly
+ mixeeSpec
+ .lookupFacet(ActionDomainEventDefaultFacetForDomainObjectAnnotation.class)
+ .ifPresent(facetOnMixee->
+ super.updateEventType(facetOnMixee.getEventType(), EventTypeOrigin.ANNOTATED_OBJECT));
+ }
+
+ @Override
+ public String hides(final VisibilityContext ic) {
+
+ final ActionDomainEvent> event =
+ domainEventHelper.postEventForAction(
+ AbstractDomainEvent.Phase.HIDE,
+ getEventType(),
+ actionFrom(ic), getFacetHolder(),
+ ic.getHead(),
+ // corresponds to programming model 'hidePlaceOrder()',
+ // which does no longer consider args
+ Can.empty(),
+ // result pojo n/a
+ null);
+ if (event != null && event.isHidden()) {
+ return "Hidden by subscriber";
+ }
+ return null;
+ }
+
+ @Override
+ public Optional disables(final UsabilityContext ic) {
+
+ final ActionDomainEvent> event =
+ domainEventHelper.postEventForAction(
+ AbstractDomainEvent.Phase.DISABLE,
+ getEventType(),
+ actionFrom(ic), getFacetHolder(),
+ ic.getHead(),
+ // corresponds to programming model 'disablePlaceOrder()',
+ // which does no longer consider args
+ Can.empty(),
+ // result pojo n/a
+ null);
+ if (event != null && event.isDisabled()) {
+ final TranslatableString reasonTranslatable = event.getDisabledReasonTranslatable();
+ final String reasonString = reasonTranslatable != null
+ ? reasonTranslatable.translate(translationService, translationContext)
+ : event.getDisabledReason();
+
+ if(reasonString!=null) {
+ return VetoReason.explicit(reasonString).toOptional();
+ }
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public String invalidates(final ValidityContext ic) {
+
+ _Assert.assertTrue(ic instanceof ActionValidityContext, ()->
+ String.format("expecting an action context but got %s", ic.getIdentifier()));
+
+ final ActionValidityContext aic = (ActionValidityContext) ic;
+ final ActionDomainEvent> event =
+ domainEventHelper.postEventForAction(
+ AbstractDomainEvent.Phase.VALIDATE,
+ getEventType(),
+ actionFrom(ic), getFacetHolder(),
+ ic.getHead(), aic.getArgs(),
+ null);
+ if (event != null && event.isInvalid()) {
+ final TranslatableString reasonTranslatable = event.getInvalidityReasonTranslatable();
+ if(reasonTranslatable != null) {
+ return reasonTranslatable.translate(translationService, translationContext);
+ }
+ return event.getInvalidityReason();
+ }
+
+ return null;
+ }
+
+ // -- HELPER
+
+ private static ObjectAction actionFrom(final InteractionContext ic) {
+ if(!(ic instanceof ActionInteractionContext)) {
+ throw new IllegalStateException(
+ "Expecting ic to be of type ActionInteractionContext, instead was: " + ic);
+ }
+ return ((ActionInteractionContext) ic).getObjectAction();
+ }
+
+ private static Class extends ActionDomainEvent>> defaultFromDomainObjectIfRequired(
+ final ObjectSpecification typeSpec,
+ final Class extends ActionDomainEvent>> actionDomainEventType) {
+
+ if (actionDomainEventType == ActionDomainEvent.Default.class) {
+ val typeFromDomainObject =
+ typeSpec.getFacet(ActionDomainEventDefaultFacetForDomainObjectAnnotation.class);
+ if (typeFromDomainObject != null) {
+ return typeFromDomainObject.getEventType();
+ }
+ }
+ return actionDomainEventType;
+ }
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetAbstract.java
deleted file mode 100644
index eb3e5a8ff05..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetAbstract.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.actions.action.invocation;
-
-import java.util.Optional;
-
-import org.apache.causeway.applib.events.domain.AbstractDomainEvent;
-import org.apache.causeway.applib.events.domain.ActionDomainEvent;
-import org.apache.causeway.applib.services.i18n.TranslatableString;
-import org.apache.causeway.applib.services.i18n.TranslationContext;
-import org.apache.causeway.applib.services.i18n.TranslationService;
-import org.apache.causeway.commons.collections.Can;
-import org.apache.causeway.commons.internal.assertions._Assert;
-import org.apache.causeway.core.metamodel.consent.Consent.VetoReason;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.DomainEventHelper;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacetAbstract;
-import org.apache.causeway.core.metamodel.interactions.ActionInteractionContext;
-import org.apache.causeway.core.metamodel.interactions.ActionValidityContext;
-import org.apache.causeway.core.metamodel.interactions.InteractionContext;
-import org.apache.causeway.core.metamodel.interactions.UsabilityContext;
-import org.apache.causeway.core.metamodel.interactions.ValidityContext;
-import org.apache.causeway.core.metamodel.interactions.VisibilityContext;
-import org.apache.causeway.core.metamodel.spec.feature.ObjectAction;
-
-import lombok.Getter;
-import lombok.Setter;
-
-public abstract class ActionDomainEventFacetAbstract
-extends SingleClassValueFacetAbstract
-implements ActionDomainEventFacet {
-
- @Getter @Setter private Class extends ActionDomainEvent>> eventType;
- private final TranslationService translationService;
- private final TranslationContext translationContext;
- private final DomainEventHelper domainEventHelper;
-
- public ActionDomainEventFacetAbstract(
- final Class extends ActionDomainEvent>> eventType,
- final FacetHolder holder) {
-
- super(ActionDomainEventFacet.class, holder, eventType);
- setEventType(eventType);
-
- this.translationService = getTranslationService();
- this.translationContext = holder.getTranslationContext();
-
- domainEventHelper = DomainEventHelper.ofServiceRegistry(getServiceRegistry());
- }
-
- @Override
- public Class> value() {
- return eventType;
- }
-
- @Override
- public String hides(final VisibilityContext ic) {
-
- final ActionDomainEvent> event =
- domainEventHelper.postEventForAction(
- AbstractDomainEvent.Phase.HIDE,
- getEventType(),
- actionFrom(ic), getFacetHolder(),
- ic.getHead(),
- // corresponds to programming model 'hidePlaceOrder()',
- // which does no longer consider args
- Can.empty(),
- // result pojo n/a
- null);
- if (event != null && event.isHidden()) {
- return "Hidden by subscriber";
- }
- return null;
- }
-
- @Override
- public Optional disables(final UsabilityContext ic) {
-
- final ActionDomainEvent> event =
- domainEventHelper.postEventForAction(
- AbstractDomainEvent.Phase.DISABLE,
- getEventType(),
- actionFrom(ic), getFacetHolder(),
- ic.getHead(),
- // corresponds to programming model 'disablePlaceOrder()',
- // which does no longer consider args
- Can.empty(),
- // result pojo n/a
- null);
- if (event != null && event.isDisabled()) {
- final TranslatableString reasonTranslatable = event.getDisabledReasonTranslatable();
- final String reasonString = reasonTranslatable != null
- ? reasonTranslatable.translate(translationService, translationContext)
- : event.getDisabledReason();
-
- if(reasonString!=null) {
- return VetoReason.explicit(reasonString).toOptional();
- }
- }
- return Optional.empty();
- }
-
- @Override
- public String invalidates(final ValidityContext ic) {
-
- _Assert.assertTrue(ic instanceof ActionValidityContext, ()->
- String.format("expecting an action context but got %s", ic.getIdentifier()));
-
- final ActionValidityContext aic = (ActionValidityContext) ic;
- final ActionDomainEvent> event =
- domainEventHelper.postEventForAction(
- AbstractDomainEvent.Phase.VALIDATE,
- getEventType(),
- actionFrom(ic), getFacetHolder(),
- ic.getHead(), aic.getArgs(),
- null);
- if (event != null && event.isInvalid()) {
- final TranslatableString reasonTranslatable = event.getInvalidityReasonTranslatable();
- if(reasonTranslatable != null) {
- return reasonTranslatable.translate(translationService, translationContext);
- }
- return event.getInvalidityReason();
- }
-
- return null;
- }
-
- // -- HELPER
-
- private static ObjectAction actionFrom(final InteractionContext ic) {
- if(!(ic instanceof ActionInteractionContext)) {
- throw new IllegalStateException(
- "Expecting ic to be of type ActionInteractionContext, instead was: " + ic);
- }
- return ((ActionInteractionContext) ic).getObjectAction();
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetDefault.java
deleted file mode 100644
index 311f7c3a4ff..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetDefault.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.actions.action.invocation;
-
-import org.apache.causeway.applib.events.domain.ActionDomainEvent;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-
-public class ActionDomainEventFacetDefault extends ActionDomainEventFacetAbstract {
-
- public ActionDomainEventFacetDefault(
- final Class extends ActionDomainEvent>> eventType, final FacetHolder holder) {
- super(eventType, holder);
- }
-
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetForActionAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetForActionAnnotation.java
deleted file mode 100644
index 6c70005485e..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionDomainEventFacetForActionAnnotation.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.actions.action.invocation;
-
-import org.apache.causeway.applib.events.domain.ActionDomainEvent;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-
-public class ActionDomainEventFacetForActionAnnotation extends ActionDomainEventFacetAbstract {
-
- public ActionDomainEventFacetForActionAnnotation(
- final Class extends ActionDomainEvent>> eventType, final FacetHolder holder) {
- super(eventType, holder);
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetAbstract.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetAbstract.java
index eb188b7b373..d85051424e1 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetAbstract.java
@@ -18,20 +18,46 @@
*/
package org.apache.causeway.core.metamodel.facets.actions.action.invocation;
+import java.util.function.BiConsumer;
+
+import org.apache.causeway.applib.events.domain.ActionDomainEvent;
import org.apache.causeway.core.metamodel.facetapi.Facet;
-import org.apache.causeway.core.metamodel.facetapi.FacetAbstract;
import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
+import org.apache.causeway.core.metamodel.facets.ImperativeFacet;
+
+import lombok.NonNull;
public abstract class ActionInvocationFacetAbstract
-extends FacetAbstract
-implements ActionInvocationFacet {
+extends DomainEventFacetAbstract>
+implements ActionInvocationFacet, ImperativeFacet {
private static final Class extends Facet> type() {
return ActionInvocationFacet.class;
}
- public ActionInvocationFacetAbstract(final FacetHolder holder) {
- super(type(), holder);
+ protected ActionInvocationFacetAbstract(
+ final Class extends ActionDomainEvent>> eventType,
+ final EventTypeOrigin eventTypeOrigin,
+ final FacetHolder holder) {
+ super(type(), eventType, eventTypeOrigin, holder);
+ }
+
+ @Override
+ public void visitAttributes(final BiConsumer visitor) {
+ super.visitAttributes(visitor);
+ ImperativeFacet.visitAttributes(this, visitor);
+ visitor.accept("declaringType", getDeclaringType());
+ visitor.accept("returnType", getReturnType());
+ //visitor.accept("eventType", getEventType()); done already in super
+ //visitor.accept("eventTypeOrigin", getEventTypeOrigin()); done already in super
+ }
+
+ @Override
+ public boolean semanticEquals(final @NonNull Facet other) {
+ return other instanceof ActionInvocationFacetAbstract
+ ? this.getEventType() == ((ActionInvocationFacetAbstract)other).getEventType()
+ : false;
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEvent.java
similarity index 92%
rename from core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java
rename to core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEvent.java
index 2fa08e526dc..780ccbc3157 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEvent.java
@@ -36,7 +36,9 @@
import org.apache.causeway.core.metamodel.commons.CanonicalInvoker;
import org.apache.causeway.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.causeway.core.metamodel.execution.InteractionInternal;
+import org.apache.causeway.core.metamodel.facetapi.Facet;
import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
import org.apache.causeway.core.metamodel.facets.DomainEventHelper;
import org.apache.causeway.core.metamodel.facets.ImperativeFacet;
import org.apache.causeway.core.metamodel.facets.actions.semantics.ActionSemanticsFacet;
@@ -54,26 +56,24 @@
import lombok.SneakyThrows;
import lombok.val;
-public abstract class ActionInvocationFacetForDomainEventAbstract
-extends ActionInvocationFacetAbstract
-implements ImperativeFacet {
+public class ActionInvocationFacetForDomainEvent
+extends ActionInvocationFacetAbstract {
- @Getter private final Class extends ActionDomainEvent>> eventType;
@Getter(onMethod_ = {@Override}) private final @NonNull Can methods;
- @Getter(onMethod = @__(@Override)) private final ObjectSpecification declaringType;
- @Getter(onMethod = @__(@Override)) private final ObjectSpecification returnType;
+ @Getter(onMethod_ = {@Override}) private final ObjectSpecification declaringType;
+ @Getter(onMethod_ = {@Override}) private final ObjectSpecification returnType;
private final ServiceRegistry serviceRegistry;
private final DomainEventHelper domainEventHelper;
- public ActionInvocationFacetForDomainEventAbstract(
+ public ActionInvocationFacetForDomainEvent(
final Class extends ActionDomainEvent>> eventType,
+ final EventTypeOrigin eventTypeOrigin,
final MethodFacade method,
final ObjectSpecification declaringType,
final ObjectSpecification returnType,
final FacetHolder holder) {
- super(holder);
- this.eventType = eventType;
+ super(eventType, eventTypeOrigin, holder);
this.methods = ImperativeFacet.singleMethod(method);
this.declaringType = declaringType;
this.returnType = returnType;
@@ -106,15 +106,6 @@ public ManagedObject invoke(
.getValue().orElse(null);
}
- @Override
- public void visitAttributes(final BiConsumer visitor) {
- super.visitAttributes(visitor);
- ImperativeFacet.visitAttributes(this, visitor);
- visitor.accept("declaringType", declaringType);
- visitor.accept("returnType", returnType);
- visitor.accept("eventType", eventType);
- }
-
// -- HELPER
private ManagedObject doInvoke(
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventFromActionAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventFromActionAnnotation.java
deleted file mode 100644
index bfd6385159b..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventFromActionAnnotation.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.actions.action.invocation;
-
-import org.apache.causeway.applib.events.domain.ActionDomainEvent;
-import org.apache.causeway.commons.internal.reflection._MethodFacades.MethodFacade;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
-
-public class ActionInvocationFacetForDomainEventFromActionAnnotation
-extends ActionInvocationFacetForDomainEventAbstract {
-
- public ActionInvocationFacetForDomainEventFromActionAnnotation(
- final Class extends ActionDomainEvent>> eventType,
- final MethodFacade method,
- final ObjectSpecification onType,
- final ObjectSpecification returnType,
- final FacetHolder holder) {
-
- super(eventType, method, onType, returnType, holder);
- }
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventFromDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventFromDefault.java
deleted file mode 100644
index 0a0c0d6e2f2..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventFromDefault.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.actions.action.invocation;
-
-import org.apache.causeway.applib.events.domain.ActionDomainEvent;
-import org.apache.causeway.commons.internal.reflection._MethodFacades.MethodFacade;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
-
-public class ActionInvocationFacetForDomainEventFromDefault
-extends ActionInvocationFacetForDomainEventAbstract {
-
- public ActionInvocationFacetForDomainEventFromDefault(
- final Class extends ActionDomainEvent>> eventType,
- final MethodFacade method,
- final ObjectSpecification onType,
- final ObjectSpecification returnType,
- final FacetHolder holder) {
-
- super(eventType, method, onType, returnType, holder);
- }
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java
index b4225d010f1..2b19c3c89aa 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/CollectionAnnotationFacetFactory.java
@@ -24,7 +24,6 @@
import org.apache.causeway.applib.annotation.Collection;
import org.apache.causeway.applib.annotation.SemanticsOf;
-import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
import org.apache.causeway.core.config.progmodel.ProgrammingModelConstants;
import org.apache.causeway.core.metamodel.context.MetaModelContext;
import org.apache.causeway.core.metamodel.facetapi.FeatureType;
@@ -34,15 +33,10 @@
import org.apache.causeway.core.metamodel.facets.actions.contributing.ContributingFacetAbstract;
import org.apache.causeway.core.metamodel.facets.actions.semantics.ActionSemanticsFacetAbstract;
import org.apache.causeway.core.metamodel.facets.collections.collection.hidden.HiddenFacetForCollectionAnnotation;
-import org.apache.causeway.core.metamodel.facets.collections.collection.modify.CollectionDomainEventFacetAbstract;
-import org.apache.causeway.core.metamodel.facets.collections.collection.modify.CollectionDomainEventFacetDefault;
-import org.apache.causeway.core.metamodel.facets.collections.collection.modify.CollectionDomainEventFacetForCollectionAnnotation;
+import org.apache.causeway.core.metamodel.facets.collections.collection.modify.CollectionDomainEventFacet;
import org.apache.causeway.core.metamodel.facets.collections.collection.typeof.TypeOfFacetForCollectionAnnotation;
-import org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents.CollectionDomainEventDefaultFacetForDomainObjectAnnotation;
import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
import org.apache.causeway.core.metamodel.specloader.validator.MetaModelValidatorForAmbiguousMixinAnnotations;
-import org.apache.causeway.core.metamodel.util.EventUtil;
import lombok.val;
@@ -107,45 +101,11 @@ void processModify(final ProcessMethodContext processMethodContext, final Option
//
// search for @Collection(domainEvent=...)
- val collectionDomainEventFacet = collectionIfAny
- .map(Collection::domainEvent)
- .filter(domainEvent -> domainEvent != CollectionDomainEvent.Default.class)
- .map(domainEvent ->
- (CollectionDomainEventFacetAbstract)
- new CollectionDomainEventFacetForCollectionAnnotation(
- defaultFromDomainObjectIfRequired(typeSpec, domainEvent), holder))
- .orElse(
- new CollectionDomainEventFacetDefault(
- defaultFromDomainObjectIfRequired(typeSpec, CollectionDomainEvent.Default.class), holder));
- if(!CollectionDomainEvent.Noop.class.isAssignableFrom(collectionDomainEventFacet.getEventType())) {
- addFacet(collectionDomainEventFacet);
- }
-
- if(EventUtil.eventTypeIsPostable(
- collectionDomainEventFacet.getEventType(),
- CollectionDomainEvent.Noop.class,
- CollectionDomainEvent.Default.class,
- getConfiguration().getApplib().getAnnotation().getCollection().getDomainEvent().isPostForDefault()
- )) {
- addFacet(collectionDomainEventFacet);
- }
-
- }
-
- public static Class extends CollectionDomainEvent,?>> defaultFromDomainObjectIfRequired(
- final ObjectSpecification typeSpec,
- final Class extends CollectionDomainEvent,?>> collectionDomainEventType) {
- if (collectionDomainEventType == CollectionDomainEvent.Default.class) {
- final CollectionDomainEventDefaultFacetForDomainObjectAnnotation typeFromDomainObject =
- typeSpec.getFacet(CollectionDomainEventDefaultFacetForDomainObjectAnnotation.class);
- if (typeFromDomainObject != null) {
- return typeFromDomainObject.getEventType();
- }
- }
- return collectionDomainEventType;
+ addFacetIfPresent(
+ CollectionDomainEventFacet
+ .createRegular(collectionIfAny, typeSpec, getterFacet, holder));
}
-
void processHidden(final ProcessMethodContext processMethodContext, final Optional collectionIfAny) {
val holder = processMethodContext.getFacetHolder();
@@ -180,5 +140,4 @@ void processTypeOf(final ProcessMethodContext processMethodContext, final Option
});
}
-
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacet.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacet.java
index 68871f9fc02..41c1069f296 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacet.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacet.java
@@ -18,14 +18,149 @@
*/
package org.apache.causeway.core.metamodel.facets.collections.collection.modify;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacet;
+import java.lang.reflect.Method;
+import java.util.Optional;
+
+import org.apache.causeway.applib.annotation.Collection;
+import org.apache.causeway.applib.events.domain.AbstractDomainEvent;
+import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
+import org.apache.causeway.commons.internal.base._Casts;
+import org.apache.causeway.commons.internal.reflection._Annotations;
+import org.apache.causeway.core.metamodel.facetapi.Facet;
+import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
+import org.apache.causeway.core.metamodel.facets.DomainEventHelper;
+import org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents.CollectionDomainEventDefaultFacetForDomainObjectAnnotation;
+import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
import org.apache.causeway.core.metamodel.interactions.HidingInteractionAdvisor;
+import org.apache.causeway.core.metamodel.interactions.VisibilityContext;
+import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
+import org.apache.causeway.core.metamodel.specloader.specimpl.OneToManyAssociationMixedIn;
+import org.apache.causeway.core.metamodel.util.EventUtil;
-/**
- * Corresponds to @Collection(domainEvent=...) annotation in the Causeway programming model.
- */
-public interface CollectionDomainEventFacet
-extends SingleClassValueFacet, HidingInteractionAdvisor {
+import lombok.NonNull;
+import lombok.val;
-}
+public class CollectionDomainEventFacet
+extends DomainEventFacetAbstract>
+implements HidingInteractionAdvisor {
+
+ // -- FACET TYPE
+
+ private static Class extends Facet> type() {
+ return CollectionDomainEventFacet.class;
+ }
+
+ // -- FACTORIES
+
+ /**
+ * For regular (non mixed-in) members only.
+ *
+ * @return empty, if event is not post-able
+ */
+ public static Optional createRegular(
+ final Optional collectionIfAny,
+ final ObjectSpecification typeSpec,
+ final PropertyOrCollectionAccessorFacet getterFacet,
+ final FacetHolder facetHolder) {
+
+ val collectionDomainEventFacet = collectionIfAny
+ .map(Collection::domainEvent)
+ .filter(domainEvent -> domainEvent != CollectionDomainEvent.Default.class)
+ .map(domainEvent ->
+ new CollectionDomainEventFacet(
+ defaultFromDomainObjectIfRequired(typeSpec, domainEvent),
+ EventTypeOrigin.ANNOTATED_MEMBER, facetHolder))
+ .orElse(
+ new CollectionDomainEventFacet(
+ defaultFromDomainObjectIfRequired(typeSpec, CollectionDomainEvent.Default.class),
+ EventTypeOrigin.DEFAULT, facetHolder));
+
+ return EventUtil.eventTypeIsPostable(
+ collectionDomainEventFacet.getEventType(),
+ CollectionDomainEvent.Noop.class,
+ CollectionDomainEvent.Default.class,
+ facetHolder.getConfiguration().getApplib().getAnnotation().getCollection().getDomainEvent().isPostForDefault())
+ ? Optional.of(collectionDomainEventFacet)
+ : Optional.empty();
+ }
+
+ /**
+ * For mixed-in members.
+ */
+ public static Optional createMixedIn(
+ final @NonNull ObjectSpecification mixeeSpecification,
+ final @NonNull OneToManyAssociationMixedIn mixedInCollection) {
+
+ val facetedMethod = mixedInCollection.getFacetedMethod();
+ final Method method = facetedMethod.getMethod().asMethodElseFail(); // no-arg method, should have a regular facade
+
+ //TODO[CAUSEWAY-3409] what if the @Collection annotation is not on the method but on the (mixin) type
+ final Collection collectionAnnot =
+ _Annotations.synthesize(method, Collection.class)
+ .orElse(null);
+ if(collectionAnnot != null) {
+ final Class extends CollectionDomainEvent, ?>> collectionDomainEventType =
+ defaultFromDomainObjectIfRequired(
+ mixeeSpecification, collectionAnnot.domainEvent());
+ return Optional.of(
+ new CollectionDomainEventFacet(
+ collectionDomainEventType, EventTypeOrigin.ANNOTATED_MEMBER, mixedInCollection));
+ }
+ return Optional.empty();
+ }
+
+ // -- CONSTRUCTION
+
+ private final DomainEventHelper domainEventHelper;
+
+ protected CollectionDomainEventFacet(
+ final Class extends CollectionDomainEvent, ?>> eventType,
+ final EventTypeOrigin eventTypeOrigin,
+ final FacetHolder holder) {
+ super(type(), eventType, eventTypeOrigin, holder);
+ domainEventHelper = DomainEventHelper.ofServiceRegistry(getServiceRegistry());
+ }
+
+ @Override
+ public void initWithMixee(final ObjectSpecification mixeeSpec) {
+ if(!getEventTypeOrigin().isDefault()) return; // skip if already set explicitly
+ mixeeSpec
+ .lookupFacet(CollectionDomainEventDefaultFacetForDomainObjectAnnotation.class)
+ .ifPresent(facetOnMixee->
+ super.updateEventType(facetOnMixee.getEventType(), EventTypeOrigin.ANNOTATED_OBJECT));
+ }
+
+ @Override
+ public String hides(final VisibilityContext ic) {
+
+ final CollectionDomainEvent, ?> event =
+ domainEventHelper.postEventForCollection(
+ AbstractDomainEvent.Phase.HIDE,
+ _Casts.uncheckedCast(getEventType()),
+ getFacetHolder(), ic.getHead()
+ );
+ if (event != null && event.isHidden()) {
+ return "Hidden by subscriber";
+ }
+ return null;
+ }
+
+ // -- HELPER
+
+ private static Class extends CollectionDomainEvent,?>> defaultFromDomainObjectIfRequired(
+ final ObjectSpecification typeSpec,
+ final Class extends CollectionDomainEvent,?>> collectionDomainEventType) {
+ if (collectionDomainEventType == CollectionDomainEvent.Default.class) {
+ final CollectionDomainEventDefaultFacetForDomainObjectAnnotation typeFromDomainObject =
+ typeSpec.getFacet(CollectionDomainEventDefaultFacetForDomainObjectAnnotation.class);
+ if (typeFromDomainObject != null) {
+ return typeFromDomainObject.getEventType();
+ }
+ }
+ return collectionDomainEventType;
+ }
+
+
+}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
deleted file mode 100644
index 573034371f3..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.collections.collection.modify;
-
-import org.apache.causeway.applib.events.domain.AbstractDomainEvent;
-import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
-import org.apache.causeway.commons.internal.base._Casts;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.DomainEventHelper;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacetAbstract;
-import org.apache.causeway.core.metamodel.interactions.VisibilityContext;
-
-public abstract class CollectionDomainEventFacetAbstract
- extends SingleClassValueFacetAbstract
- implements CollectionDomainEventFacet {
-
- private final DomainEventHelper domainEventHelper;
-
- public CollectionDomainEventFacetAbstract(
- final Class extends CollectionDomainEvent, ?>> eventType,
- final FacetHolder holder) {
-
- super(CollectionDomainEventFacet.class, holder, eventType);
- this.eventType = eventType;
-
- domainEventHelper = DomainEventHelper.ofServiceRegistry(getServiceRegistry());
- }
-
- private Class extends CollectionDomainEvent, ?>> eventType;
-
- @Override
- public Class> value() {
- return eventType;
- }
-
- public Class extends CollectionDomainEvent> getEventType() {
- return _Casts.uncheckedCast(eventType);
- }
-
- public void setEventType(final Class extends CollectionDomainEvent, ?>> eventType) {
- this.eventType = eventType;
- }
-
- @Override
- public String hides(final VisibilityContext ic) {
-
- final CollectionDomainEvent, ?> event =
- domainEventHelper.postEventForCollection(
- AbstractDomainEvent.Phase.HIDE,
- getEventType(),
- getFacetHolder(), ic.getHead()
- );
- if (event != null && event.isHidden()) {
- return "Hidden by subscriber";
- }
- return null;
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetDefault.java
deleted file mode 100644
index bc63fb0e1e3..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetDefault.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.collections.collection.modify;
-
-import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-
-public class CollectionDomainEventFacetDefault extends CollectionDomainEventFacetAbstract {
-
- public CollectionDomainEventFacetDefault(
- final Class extends CollectionDomainEvent, ?>> eventType, final FacetHolder holder) {
- super(eventType, holder);
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetForCollectionAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetForCollectionAnnotation.java
deleted file mode 100644
index c3c5309a84a..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetForCollectionAnnotation.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.collections.collection.modify;
-
-import org.apache.causeway.applib.annotation.Collection;
-import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
-import org.apache.causeway.applib.services.inject.ServiceInjector;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.specloader.SpecificationLoader;
-
-public class CollectionDomainEventFacetForCollectionAnnotation extends CollectionDomainEventFacetAbstract {
-
- static CollectionDomainEventFacet create(
- final Collection collection,
- final ServiceInjector servicesInjector,
- final SpecificationLoader specificationLoader,
- final FacetHolder holder) {
- Class extends CollectionDomainEvent, ?>> collectionInteractionEventType = collection.domainEvent();
- return new CollectionDomainEventFacetForCollectionAnnotation(
- collectionInteractionEventType, holder);
- }
-
- public CollectionDomainEventFacetForCollectionAnnotation(
- final Class extends CollectionDomainEvent, ?>> eventType, final FacetHolder holder) {
- super(eventType, holder);
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
index e63564c2dce..5f87c62213a 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
@@ -34,9 +34,6 @@
import org.apache.causeway.applib.annotation.Nature;
import org.apache.causeway.applib.annotation.Property;
import org.apache.causeway.applib.annotation.Value;
-import org.apache.causeway.applib.events.domain.ActionDomainEvent;
-import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
import org.apache.causeway.applib.events.lifecycle.ObjectCreatedEvent;
import org.apache.causeway.applib.events.lifecycle.ObjectLoadedEvent;
import org.apache.causeway.applib.events.lifecycle.ObjectPersistedEvent;
@@ -528,9 +525,8 @@ private void processDomainEventAction(
domainObjectIfAny
.map(DomainObject::actionDomainEvent)
- .filter(domainEvent -> domainEvent != ActionDomainEvent.Default.class)
- .map(domainEvent -> new ActionDomainEventDefaultFacetForDomainObjectAnnotation(
- holder, domainEvent))
+ .flatMap(domainEvent -> ActionDomainEventDefaultFacetForDomainObjectAnnotation
+ .create(domainEvent, holder))
.ifPresent(super::addFacet);
}
@@ -541,9 +537,8 @@ private void processDomainEventProperty(
domainObjectIfAny
.map(DomainObject::propertyDomainEvent)
- .filter(domainEvent -> domainEvent != PropertyDomainEvent.Default.class)
- .map(domainEvent -> new PropertyDomainEventDefaultFacetForDomainObjectAnnotation(
- holder, domainEvent))
+ .flatMap(domainEvent -> PropertyDomainEventDefaultFacetForDomainObjectAnnotation
+ .create(domainEvent, holder))
.ifPresent(super::addFacet);
}
@@ -553,9 +548,8 @@ private void processDomainEventCollection(
domainObjectIfAny
.map(DomainObject::collectionDomainEvent)
- .filter(domainEvent -> domainEvent != CollectionDomainEvent.Default.class)
- .map(domainEvent -> new CollectionDomainEventDefaultFacetForDomainObjectAnnotation(
- holder, domainEvent))
+ .flatMap(domainEvent -> CollectionDomainEventDefaultFacetForDomainObjectAnnotation
+ .create(domainEvent, holder))
.ifPresent(super::addFacet);
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/ActionDomainEventDefaultFacetForDomainObjectAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/ActionDomainEventDefaultFacetForDomainObjectAnnotation.java
index 0abd2ee326d..6f5108d6b63 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/ActionDomainEventDefaultFacetForDomainObjectAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/ActionDomainEventDefaultFacetForDomainObjectAnnotation.java
@@ -18,10 +18,12 @@
*/
package org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents;
+import java.util.Optional;
+
import org.apache.causeway.applib.events.domain.ActionDomainEvent;
import org.apache.causeway.core.metamodel.facetapi.Facet;
import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacetAbstract;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
import org.apache.causeway.core.metamodel.facets.actions.action.invocation.ActionDomainEventFacet;
/**
@@ -29,23 +31,24 @@
* for any actions as a fallback/default.
*/
public class ActionDomainEventDefaultFacetForDomainObjectAnnotation
-extends SingleClassValueFacetAbstract {
-
+extends DomainEventFacetAbstract> {
- private final Class extends ActionDomainEvent>> eventType;
- public Class extends ActionDomainEvent>> getEventType() {
- return eventType;
+ public static Optional create(
+ final Class extends ActionDomainEvent>> domainEvent,
+ final FacetHolder holder) {
+ return domainEvent != ActionDomainEvent.Default.class
+ ? Optional.of(new ActionDomainEventDefaultFacetForDomainObjectAnnotation(domainEvent, holder))
+ : Optional.empty();
}
private static Class extends Facet> type() {
return ActionDomainEventDefaultFacetForDomainObjectAnnotation.class;
}
- public ActionDomainEventDefaultFacetForDomainObjectAnnotation(
- final FacetHolder holder,
- final Class extends ActionDomainEvent>> value) {
- super(type(), holder, value);
- this.eventType = value;
+ private ActionDomainEventDefaultFacetForDomainObjectAnnotation(
+ final Class extends ActionDomainEvent>> value,
+ final FacetHolder holder) {
+ super(type(), value, EventTypeOrigin.ANNOTATED_OBJECT, holder);
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/CollectionDomainEventDefaultFacetForDomainObjectAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/CollectionDomainEventDefaultFacetForDomainObjectAnnotation.java
index 97516bdb6e0..89dd9292a8f 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/CollectionDomainEventDefaultFacetForDomainObjectAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/CollectionDomainEventDefaultFacetForDomainObjectAnnotation.java
@@ -18,10 +18,12 @@
*/
package org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents;
+import java.util.Optional;
+
import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
import org.apache.causeway.core.metamodel.facetapi.Facet;
import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacetAbstract;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
import org.apache.causeway.core.metamodel.facets.actions.action.invocation.ActionDomainEventFacet;
/**
@@ -29,22 +31,24 @@
* for any actions as a fallback/default.
*/
public class CollectionDomainEventDefaultFacetForDomainObjectAnnotation
-extends SingleClassValueFacetAbstract {
+extends DomainEventFacetAbstract> {
- private final Class extends CollectionDomainEvent, ?>> eventType;
- public Class extends CollectionDomainEvent, ?>> getEventType() {
- return eventType;
+ public static Optional create(
+ final Class extends CollectionDomainEvent,?>> domainEvent,
+ final FacetHolder holder) {
+ return domainEvent != CollectionDomainEvent.Default.class
+ ? Optional.of(new CollectionDomainEventDefaultFacetForDomainObjectAnnotation(domainEvent, holder))
+ : Optional.empty();
}
private static Class extends Facet> type() {
return CollectionDomainEventDefaultFacetForDomainObjectAnnotation.class;
}
- public CollectionDomainEventDefaultFacetForDomainObjectAnnotation(
- final FacetHolder holder,
- final Class extends CollectionDomainEvent,?>> value) {
- super(type(), holder, value);
- this.eventType = value;
+ private CollectionDomainEventDefaultFacetForDomainObjectAnnotation(
+ final Class extends CollectionDomainEvent, ?>> value,
+ final FacetHolder holder) {
+ super(type(), value, EventTypeOrigin.ANNOTATED_OBJECT, holder);
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/PropertyDomainEventDefaultFacetForDomainObjectAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/PropertyDomainEventDefaultFacetForDomainObjectAnnotation.java
index 8b8a7ae038a..3827e1f7a9d 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/PropertyDomainEventDefaultFacetForDomainObjectAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/object/domainobject/domainevents/PropertyDomainEventDefaultFacetForDomainObjectAnnotation.java
@@ -18,10 +18,12 @@
*/
package org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents;
+import java.util.Optional;
+
import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
import org.apache.causeway.core.metamodel.facetapi.Facet;
import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacetAbstract;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
import org.apache.causeway.core.metamodel.facets.actions.action.invocation.ActionDomainEventFacet;
/**
@@ -29,22 +31,24 @@
* for any actions as a fallback/default.
*/
public class PropertyDomainEventDefaultFacetForDomainObjectAnnotation
-extends SingleClassValueFacetAbstract {
+extends DomainEventFacetAbstract> {
- private final Class extends PropertyDomainEvent, ?>> eventType;
- public Class extends PropertyDomainEvent, ?>> getEventType() {
- return eventType;
+ public static Optional create(
+ final Class extends PropertyDomainEvent,?>> domainEvent,
+ final FacetHolder holder) {
+ return domainEvent != PropertyDomainEvent.Default.class
+ ? Optional.of(new PropertyDomainEventDefaultFacetForDomainObjectAnnotation(domainEvent, holder))
+ : Optional.empty();
}
private static Class extends Facet> type() {
return PropertyDomainEventDefaultFacetForDomainObjectAnnotation.class;
}
- public PropertyDomainEventDefaultFacetForDomainObjectAnnotation(
- final FacetHolder holder,
- final Class extends PropertyDomainEvent,?>> value) {
- super(type(), holder, value);
- this.eventType = value;
+ private PropertyDomainEventDefaultFacetForDomainObjectAnnotation(
+ final Class extends PropertyDomainEvent,?>> value,
+ final FacetHolder holder) {
+ super(type(), value, EventTypeOrigin.ANNOTATED_OBJECT, holder);
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java
index 5a6d9930fc3..2455af6334d 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/PropertyAnnotationFacetFactory.java
@@ -25,7 +25,6 @@
import org.apache.causeway.applib.annotation.Property;
import org.apache.causeway.applib.annotation.SemanticsOf;
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
import org.apache.causeway.applib.mixins.system.HasInteractionId;
import org.apache.causeway.core.metamodel.context.MetaModelContext;
import org.apache.causeway.core.metamodel.facetapi.FeatureType;
@@ -35,7 +34,6 @@
import org.apache.causeway.core.metamodel.facets.actions.semantics.ActionSemanticsFacetAbstract;
import org.apache.causeway.core.metamodel.facets.members.publish.command.CommandPublishingFacetForPropertyAnnotation;
import org.apache.causeway.core.metamodel.facets.members.publish.execution.ExecutionPublishingPropertyFacetForPropertyAnnotation;
-import org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents.PropertyDomainEventDefaultFacetForDomainObjectAnnotation;
import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
import org.apache.causeway.core.metamodel.facets.properties.projection.ProjectingFacetFromPropertyAnnotation;
import org.apache.causeway.core.metamodel.facets.properties.property.disabled.DisabledFacetForPropertyAnnotation;
@@ -45,23 +43,17 @@
import org.apache.causeway.core.metamodel.facets.properties.property.mandatory.MandatoryFacetForPropertyAnnotation;
import org.apache.causeway.core.metamodel.facets.properties.property.mandatory.MandatoryFacetInvertedByNullableAnnotationOnProperty;
import org.apache.causeway.core.metamodel.facets.properties.property.maxlength.MaxLengthFacetForPropertyAnnotation;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyClearFacetForDomainEventFromDefault;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyClearFacetForDomainEventFromPropertyAnnotation;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyDomainEventFacetAbstract;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyDomainEventFacetDefault;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyDomainEventFacetForPropertyAnnotation;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertySetterFacetForDomainEventFromDefault;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertySetterFacetForDomainEventFromPropertyAnnotation;
+import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyClearFacetForDomainEvent;
+import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyDomainEventFacet;
+import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertySetterFacetForDomainEvent;
import org.apache.causeway.core.metamodel.facets.properties.property.mustsatisfy.MustSatisfySpecificationFacetForPropertyAnnotation;
import org.apache.causeway.core.metamodel.facets.properties.property.regex.RegExFacetForPatternAnnotationOnProperty;
import org.apache.causeway.core.metamodel.facets.properties.property.regex.RegExFacetForPropertyAnnotation;
import org.apache.causeway.core.metamodel.facets.properties.property.snapshot.SnapshotExcludeFacetForPropertyAnnotation;
import org.apache.causeway.core.metamodel.facets.properties.update.clear.PropertyClearFacet;
import org.apache.causeway.core.metamodel.facets.properties.update.modify.PropertySetterFacet;
-import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
import org.apache.causeway.core.metamodel.specloader.validator.MetaModelValidatorForAmbiguousMixinAnnotations;
import org.apache.causeway.core.metamodel.specloader.validator.MetaModelValidatorForConflictingOptionality;
-import org.apache.causeway.core.metamodel.util.EventUtil;
import lombok.val;
@@ -136,76 +128,35 @@ void processModify(final ProcessMethodContext processMethodContext, final Option
//
// search for @Property(domainEvent=...), else use default event type
- val propertyDomainEventFacet = propertyIfAny
- .map(Property::domainEvent)
- .filter(domainEvent -> domainEvent != PropertyDomainEvent.Default.class)
- .map(domainEvent -> (PropertyDomainEventFacetAbstract) new PropertyDomainEventFacetForPropertyAnnotation(
- defaultFromDomainObjectIfRequired(typeSpec, domainEvent), getterFacet, holder))
- .orElse(new PropertyDomainEventFacetDefault(
- defaultFromDomainObjectIfRequired(typeSpec, PropertyDomainEvent.Default.class), getterFacet,
- holder));
-
- if(EventUtil.eventTypeIsPostable(
- propertyDomainEventFacet.getEventType(),
- PropertyDomainEvent.Noop.class,
- PropertyDomainEvent.Default.class,
- getConfiguration().getApplib().getAnnotation().getProperty().getDomainEvent().isPostForDefault()
- )) {
- addFacet(propertyDomainEventFacet);
- }
-
-
- //
- // if the property is mutable, then replace the current setter and clear facets with equivalents that
- // emit the appropriate domain event and then delegate onto the underlying
- //
+ PropertyDomainEventFacet
+ .createRegular(propertyIfAny, typeSpec, getterFacet, holder)
+ .ifPresent(propertyDomainEventFacet->{
- final PropertySetterFacet setterFacet = holder.getFacet(PropertySetterFacet.class);
- if(setterFacet != null) {
- // the current setter facet will end up as the underlying facet
- final PropertySetterFacet replacementFacet;
-
- if(propertyDomainEventFacet instanceof PropertyDomainEventFacetForPropertyAnnotation) {
- replacementFacet = new PropertySetterFacetForDomainEventFromPropertyAnnotation(
- propertyDomainEventFacet.getEventType(), getterFacet, setterFacet, propertyDomainEventFacet, holder);
- } else
- // default
- {
- replacementFacet = new PropertySetterFacetForDomainEventFromDefault(
- propertyDomainEventFacet.getEventType(), getterFacet, setterFacet, propertyDomainEventFacet, holder);
- }
- addFacet(replacementFacet);
- }
-
- final PropertyClearFacet clearFacet = holder.getFacet(PropertyClearFacet.class);
- if(clearFacet != null) {
- // the current clear facet will end up as the underlying facet
- final PropertyClearFacet replacementFacet;
-
- if(propertyDomainEventFacet instanceof PropertyDomainEventFacetForPropertyAnnotation) {
- replacementFacet = new PropertyClearFacetForDomainEventFromPropertyAnnotation(
- propertyDomainEventFacet.getEventType(), getterFacet, clearFacet, propertyDomainEventFacet, holder);
- } else
- // default
- {
- replacementFacet = new PropertyClearFacetForDomainEventFromDefault(
- propertyDomainEventFacet.getEventType(), getterFacet, clearFacet, propertyDomainEventFacet, holder);
- }
- addFacet(replacementFacet);
- }
- }
+ addFacet(propertyDomainEventFacet);
- public static Class extends PropertyDomainEvent,?>> defaultFromDomainObjectIfRequired(
- final ObjectSpecification typeSpec,
- final Class extends PropertyDomainEvent,?>> propertyDomainEventType) {
- if (propertyDomainEventType == PropertyDomainEvent.Default.class) {
- final PropertyDomainEventDefaultFacetForDomainObjectAnnotation typeFromDomainObject =
- typeSpec.getFacet(PropertyDomainEventDefaultFacetForDomainObjectAnnotation.class);
- if (typeFromDomainObject != null) {
- return typeFromDomainObject.getEventType();
- }
- }
- return propertyDomainEventType;
+ var eventType = propertyDomainEventFacet.getEventType();
+ var eventTypeOrigin = propertyDomainEventFacet.getEventTypeOrigin();
+
+ //
+ // if the property is mutable, then replace the current setter and clear facets with equivalents that
+ // emit the appropriate domain event and then delegate onto the underlying
+ //
+
+ holder.lookupFacet(PropertySetterFacet.class)
+ .ifPresent(setterFacet->
+ //TODO[CAUSEWAY-3409] we don't install those for the mixin case
+ // the current setter facet will end up as the underlying facet
+ addFacet(new PropertySetterFacetForDomainEvent(
+ eventType, eventTypeOrigin, getterFacet, setterFacet, holder)));
+
+
+ holder.lookupFacet(PropertyClearFacet.class)
+ .ifPresent(clearFacet->
+ //TODO[CAUSEWAY-3409] we don't install those for the mixin case
+ // the current clear facet will end up as the underlying facet
+ addFacet(new PropertyClearFacetForDomainEvent(
+ eventType, eventTypeOrigin, getterFacet, clearFacet, holder)));
+ });
}
void processHidden(final ProcessMethodContext processMethodContext, final Optional propertyIfAny) {
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEventFromDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEvent.java
similarity index 74%
rename from core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEventFromDefault.java
rename to core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEvent.java
index 4d011ed387a..025f328b6fd 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEventFromDefault.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEvent.java
@@ -23,18 +23,17 @@
import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
import org.apache.causeway.core.metamodel.facets.properties.update.clear.PropertyClearFacet;
-public class PropertyClearFacetForDomainEventFromDefault
+public class PropertyClearFacetForDomainEvent
extends PropertySetterOrClearFacetForDomainEventAbstract
implements PropertyClearFacet {
-
- public PropertyClearFacetForDomainEventFromDefault(
+ public PropertyClearFacetForDomainEvent(
final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacet,
- final PropertyClearFacet clearFacet,
- final PropertyDomainEventFacetAbstract propertyInteractionFacet,
- final FacetHolder holder) {
+ final EventTypeOrigin eventTypeOrigin,
+ final PropertyOrCollectionAccessorFacet getterFacet,
+ final PropertyClearFacet clearFacet,
+ final FacetHolder holder) {
- super(PropertyClearFacet.class, eventType, getterFacet, null, clearFacet, propertyInteractionFacet, holder);
+ super(PropertyClearFacet.class, eventType, eventTypeOrigin, getterFacet, null, clearFacet, holder);
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEventFromPropertyAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEventFromPropertyAnnotation.java
deleted file mode 100644
index 57890d7765b..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyClearFacetForDomainEventFromPropertyAnnotation.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.properties.property.modify;
-
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.causeway.core.metamodel.facets.properties.update.clear.PropertyClearFacet;
-
-public class PropertyClearFacetForDomainEventFromPropertyAnnotation
-extends PropertySetterOrClearFacetForDomainEventAbstract
-implements PropertyClearFacet {
-
-
- public PropertyClearFacetForDomainEventFromPropertyAnnotation(
- final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacet,
- final PropertyClearFacet clearFacet,
- final PropertyDomainEventFacetAbstract propertyInteractionFacet,
- final FacetHolder holder) {
-
- super(PropertyClearFacet.class, eventType, getterFacet, null, clearFacet, propertyInteractionFacet, holder);
- }
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacet.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacet.java
index 35755e3b4f7..564d5f005c6 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacet.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacet.java
@@ -18,15 +18,241 @@
*/
package org.apache.causeway.core.metamodel.facets.properties.property.modify;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacet;
+import java.lang.reflect.Method;
+import java.util.Optional;
+import java.util.function.BiConsumer;
+
+import org.apache.causeway.applib.annotation.Property;
+import org.apache.causeway.applib.events.domain.AbstractDomainEvent;
+import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
+import org.apache.causeway.applib.services.i18n.TranslatableString;
+import org.apache.causeway.applib.services.i18n.TranslationContext;
+import org.apache.causeway.applib.services.i18n.TranslationService;
+import org.apache.causeway.commons.internal.base._Casts;
+import org.apache.causeway.commons.internal.reflection._Annotations;
+import org.apache.causeway.core.metamodel.consent.Consent.VetoReason;
+import org.apache.causeway.core.metamodel.facetapi.Facet;
+import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
+import org.apache.causeway.core.metamodel.facets.DomainEventHelper;
+import org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents.PropertyDomainEventDefaultFacetForDomainObjectAnnotation;
+import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
import org.apache.causeway.core.metamodel.interactions.DisablingInteractionAdvisor;
import org.apache.causeway.core.metamodel.interactions.HidingInteractionAdvisor;
+import org.apache.causeway.core.metamodel.interactions.ProposedHolder;
+import org.apache.causeway.core.metamodel.interactions.UsabilityContext;
import org.apache.causeway.core.metamodel.interactions.ValidatingInteractionAdvisor;
+import org.apache.causeway.core.metamodel.interactions.ValidityContext;
+import org.apache.causeway.core.metamodel.interactions.VisibilityContext;
+import org.apache.causeway.core.metamodel.object.ManagedObject;
+import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
+import org.apache.causeway.core.metamodel.specloader.specimpl.OneToOneAssociationMixedIn;
+import org.apache.causeway.core.metamodel.util.EventUtil;
-/**
- * Corresponds to @Property(domainEvent=...) annotation in the Causeway programming model.
- */
-public interface PropertyDomainEventFacet
-extends SingleClassValueFacet, HidingInteractionAdvisor, DisablingInteractionAdvisor, ValidatingInteractionAdvisor {
+import lombok.NonNull;
+import lombok.val;
+
+public class PropertyDomainEventFacet
+extends DomainEventFacetAbstract>
+implements
+ HidingInteractionAdvisor,
+ DisablingInteractionAdvisor,
+ ValidatingInteractionAdvisor {
+
+ // -- FACET TYPE
+
+ private static Class extends Facet> type() {
+ return PropertyDomainEventFacet.class;
+ }
+
+ // -- FACTORIES
+
+ /**
+ * For regular (non mixed-in) members only.
+ *
+ * @return empty, if event is not post-able
+ */
+ public static Optional createRegular(
+ final @NonNull Optional propertyIfAny,
+ final @NonNull ObjectSpecification typeSpec,
+ final @NonNull PropertyOrCollectionAccessorFacet getterFacet,
+ final @NonNull FacetHolder facetHolder) {
+
+ val propertyDomainEventFacet = propertyIfAny
+ .map(Property::domainEvent)
+ .filter(domainEvent -> domainEvent != PropertyDomainEvent.Default.class)
+ .map(domainEvent -> new PropertyDomainEventFacet(
+ defaultFromDomainObjectIfRequired(typeSpec, domainEvent),
+ EventTypeOrigin.ANNOTATED_MEMBER, getterFacet, facetHolder))
+ .orElse(new PropertyDomainEventFacet(
+ defaultFromDomainObjectIfRequired(typeSpec, PropertyDomainEvent.Default.class),
+ EventTypeOrigin.DEFAULT, getterFacet, facetHolder));
+
+ return EventUtil.eventTypeIsPostable(
+ propertyDomainEventFacet.getEventType(),
+ PropertyDomainEvent.Noop.class,
+ PropertyDomainEvent.Default.class,
+ facetHolder.getConfiguration().getApplib().getAnnotation().getProperty().getDomainEvent().isPostForDefault())
+ ? Optional.of(propertyDomainEventFacet)
+ : Optional.empty();
+ }
+
+ /**
+ * For mixed-in members.
+ */
+ public static Optional createMixedIn(
+ final @NonNull ObjectSpecification mixeeSpecification,
+ final @NonNull OneToOneAssociationMixedIn mixedInProperty) {
+
+ val facetedMethod = mixedInProperty.getFacetedMethod();
+ final Method method = facetedMethod.getMethod().asMethodElseFail(); // no-arg method, should have a regular facade
+
+ //TODO[CAUSEWAY-3409] what if the @Property annotation is not on the method but on the (mixin) type
+ final Property propertyAnnot =
+ _Annotations.synthesize(method, Property.class)
+ .orElse(null);
+
+ if(propertyAnnot != null) {
+ final Class extends PropertyDomainEvent, ?>> propertyDomainEventType =
+ defaultFromDomainObjectIfRequired(
+ mixeeSpecification, propertyAnnot.domainEvent());
+ val getterFacet = (PropertyOrCollectionAccessorFacet)null;
+
+ return Optional.of(
+ new PropertyDomainEventFacet(
+ propertyDomainEventType, EventTypeOrigin.ANNOTATED_MEMBER, getterFacet, mixedInProperty));
+ }
+
+ return Optional.empty();
+ }
+
+ // -- CONSTRUCTION
+
+ private final DomainEventHelper domainEventHelper;
+
+ private final PropertyOrCollectionAccessorFacet getterFacetIfAny;
+ private final TranslationService translationService;
+ private final TranslationContext translationContext;
+
+ /**
+ * @param getterFacetIfAny - will be null if this is for a mixin {@link OneToOneAssociationMixedIn}.
+ */
+ protected PropertyDomainEventFacet(
+ final Class extends PropertyDomainEvent, ?>> eventType,
+ final EventTypeOrigin eventTypeOrigin,
+ final PropertyOrCollectionAccessorFacet getterFacetIfAny,
+ final FacetHolder holder) {
+
+ super(type(), eventType, eventTypeOrigin, holder);
+ this.getterFacetIfAny = getterFacetIfAny;
+
+ this.translationService = getTranslationService();
+ this.translationContext = holder.getTranslationContext();
+
+ domainEventHelper = DomainEventHelper.ofServiceRegistry(getServiceRegistry());
+ }
+
+ @Override
+ public void initWithMixee(final ObjectSpecification mixeeSpec) {
+ if(!getEventTypeOrigin().isDefault()) return; // skip if already set explicitly
+ mixeeSpec
+ .lookupFacet(PropertyDomainEventDefaultFacetForDomainObjectAnnotation.class)
+ .ifPresent(facetOnMixee->
+ super.updateEventType(facetOnMixee.getEventType(), EventTypeOrigin.ANNOTATED_OBJECT));
+ }
+
+ @Override
+ public String hides(final VisibilityContext ic) {
+
+ final PropertyDomainEvent, ?> event =
+ domainEventHelper.postEventForProperty(
+ AbstractDomainEvent.Phase.HIDE,
+ _Casts.uncheckedCast(getEventType()), null,
+ getFacetHolder(), ic.getHead(),
+ null, null);
+ if (event != null && event.isHidden()) {
+ return "Hidden by subscriber";
+ }
+ return null;
+ }
+
+ @Override
+ public Optional disables(final UsabilityContext ic) {
+
+ final PropertyDomainEvent, ?> event =
+ domainEventHelper.postEventForProperty(
+ AbstractDomainEvent.Phase.DISABLE,
+ _Casts.uncheckedCast(getEventType()), null,
+ getFacetHolder(), ic.getHead(),
+ null, null);
+ if (event != null
+ && event.isDisabled()) {
+
+ final TranslatableString reasonTranslatable = event.getDisabledReasonTranslatable();
+ final String reasonString = reasonTranslatable != null
+ ? reasonTranslatable.translate(translationService, translationContext)
+ : event.getDisabledReason();
+
+ return Optional.ofNullable(reasonString)
+ .map(VetoReason::explicit);
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public String invalidates(final ValidityContext ic) {
+
+ if(getterFacetIfAny == null) {
+ return null;
+ }
+
+ // if this is a mixin, then this ain't true.
+ if(!(ic instanceof ProposedHolder)) {
+ return null;
+ }
+ final ProposedHolder ph = (ProposedHolder) ic;
+
+ final Object oldValue = getterFacetIfAny.getProperty(ic.getTarget(), ic.getInitiatedBy());
+ final ManagedObject proposedAdapter = ph.getProposed();
+ final Object proposedValue = proposedAdapter != null ? proposedAdapter.getPojo() : null;
+
+ final PropertyDomainEvent, ?> event =
+ domainEventHelper.postEventForProperty(
+ AbstractDomainEvent.Phase.VALIDATE,
+ _Casts.uncheckedCast(getEventType()), null,
+ getFacetHolder(), ic.getHead(),
+ oldValue, proposedValue);
+ if (event != null && event.isInvalid()) {
+ final TranslatableString reasonTranslatable = event.getInvalidityReasonTranslatable();
+ if(reasonTranslatable != null) {
+ return reasonTranslatable.translate(translationService, translationContext);
+ }
+ return event.getInvalidityReason();
+ }
+
+ return null;
+ }
+
+
+ @Override
+ public void visitAttributes(final BiConsumer visitor) {
+ super.visitAttributes(visitor);
+ visitor.accept("getterFacet", getterFacetIfAny);
+ }
+
+ // -- HELPER
+
+ private static Class extends PropertyDomainEvent,?>> defaultFromDomainObjectIfRequired(
+ final ObjectSpecification typeSpec,
+ final Class extends PropertyDomainEvent,?>> propertyDomainEventType) {
+ if (propertyDomainEventType == PropertyDomainEvent.Default.class) {
+ final PropertyDomainEventDefaultFacetForDomainObjectAnnotation typeFromDomainObject =
+ typeSpec.getFacet(PropertyDomainEventDefaultFacetForDomainObjectAnnotation.class);
+ if (typeFromDomainObject != null) {
+ return typeFromDomainObject.getEventType();
+ }
+ }
+ return propertyDomainEventType;
+ }
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetAbstract.java
deleted file mode 100644
index 614a515af75..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetAbstract.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.properties.property.modify;
-
-import java.util.Optional;
-import java.util.function.BiConsumer;
-
-import org.apache.causeway.applib.annotation.DomainObject;
-import org.apache.causeway.applib.events.domain.AbstractDomainEvent;
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
-import org.apache.causeway.applib.services.i18n.TranslatableString;
-import org.apache.causeway.applib.services.i18n.TranslationContext;
-import org.apache.causeway.applib.services.i18n.TranslationService;
-import org.apache.causeway.commons.internal.base._Casts;
-import org.apache.causeway.core.metamodel.consent.Consent.VetoReason;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.DomainEventHelper;
-import org.apache.causeway.core.metamodel.facets.SingleClassValueFacetAbstract;
-import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.causeway.core.metamodel.interactions.ProposedHolder;
-import org.apache.causeway.core.metamodel.interactions.UsabilityContext;
-import org.apache.causeway.core.metamodel.interactions.ValidityContext;
-import org.apache.causeway.core.metamodel.interactions.VisibilityContext;
-import org.apache.causeway.core.metamodel.object.ManagedObject;
-import org.apache.causeway.core.metamodel.specloader.specimpl.OneToOneAssociationMixedIn;
-
-public abstract class PropertyDomainEventFacetAbstract
-extends SingleClassValueFacetAbstract implements PropertyDomainEventFacet {
-
- private final DomainEventHelper domainEventHelper;
-
- private final PropertyOrCollectionAccessorFacet getterFacetIfAny;
- private final TranslationService translationService;
- private final TranslationContext translationContext;
-
- /**
- * @param getterFacetIfAny - will be null if this is for a mixin {@link OneToOneAssociationMixedIn}.
- */
- public PropertyDomainEventFacetAbstract(
- final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacetIfAny,
- final FacetHolder holder ) {
-
- super(PropertyDomainEventFacet.class, holder, eventType);
- this.eventType = eventType;
- this.getterFacetIfAny = getterFacetIfAny;
-
- this.translationService = getTranslationService();
- this.translationContext = holder.getTranslationContext();
-
- domainEventHelper = DomainEventHelper.ofServiceRegistry(getServiceRegistry());
- }
-
- private Class extends PropertyDomainEvent, ?>> eventType;
-
- @Override
- public Class> value() {
- return eventType;
- }
-
- public Class extends PropertyDomainEvent> getEventType() {
- return _Casts.uncheckedCast(eventType);
- }
-
- /**
- * Can be overwritten if this facet is on a mixin where the subject (mixedInType) is annotated with
- * {@link DomainObject#propertyDomainEvent()}.
- */
- public void setEventType(final Class extends PropertyDomainEvent, ?>> eventType) {
- this.eventType = eventType;
- }
-
- @Override
- public String hides(final VisibilityContext ic) {
-
- final PropertyDomainEvent, ?> event =
- domainEventHelper.postEventForProperty(
- AbstractDomainEvent.Phase.HIDE,
- getEventType(), null,
- getFacetHolder(), ic.getHead(),
- null, null);
- if (event != null && event.isHidden()) {
- return "Hidden by subscriber";
- }
- return null;
- }
-
- @Override
- public Optional disables(final UsabilityContext ic) {
-
- final PropertyDomainEvent, ?> event =
- domainEventHelper.postEventForProperty(
- AbstractDomainEvent.Phase.DISABLE,
- getEventType(), null,
- getFacetHolder(), ic.getHead(),
- null, null);
- if (event != null
- && event.isDisabled()) {
-
- final TranslatableString reasonTranslatable = event.getDisabledReasonTranslatable();
- final String reasonString = reasonTranslatable != null
- ? reasonTranslatable.translate(translationService, translationContext)
- : event.getDisabledReason();
-
- return Optional.ofNullable(reasonString)
- .map(VetoReason::explicit);
- }
- return Optional.empty();
- }
-
- @Override
- public String invalidates(final ValidityContext ic) {
-
- if(getterFacetIfAny == null) {
- return null;
- }
-
- // if this is a mixin, then this ain't true.
- if(!(ic instanceof ProposedHolder)) {
- return null;
- }
- final ProposedHolder ph = (ProposedHolder) ic;
-
- final Object oldValue = getterFacetIfAny.getProperty(ic.getTarget(), ic.getInitiatedBy());
- final ManagedObject proposedAdapter = ph.getProposed();
- final Object proposedValue = proposedAdapter != null ? proposedAdapter.getPojo() : null;
-
- final PropertyDomainEvent, ?> event =
- domainEventHelper.postEventForProperty(
- AbstractDomainEvent.Phase.VALIDATE,
- getEventType(), null,
- getFacetHolder(), ic.getHead(),
- oldValue, proposedValue);
- if (event != null && event.isInvalid()) {
- final TranslatableString reasonTranslatable = event.getInvalidityReasonTranslatable();
- if(reasonTranslatable != null) {
- return reasonTranslatable.translate(translationService, translationContext);
- }
- return event.getInvalidityReason();
- }
-
- return null;
- }
-
-
- @Override
- public void visitAttributes(final BiConsumer visitor) {
- super.visitAttributes(visitor);
- visitor.accept("getterFacet", getterFacetIfAny);
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetDefault.java
deleted file mode 100644
index 345f66ed08e..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetDefault.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.properties.property.modify;
-
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.causeway.core.metamodel.specloader.specimpl.OneToOneAssociationMixedIn;
-
-public class PropertyDomainEventFacetDefault extends PropertyDomainEventFacetAbstract {
-
- /**
- * @param getterFacetIfAny - will be null if this is for a mixin {@link OneToOneAssociationMixedIn}.
- */
- public PropertyDomainEventFacetDefault(
- final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacetIfAny,
- final FacetHolder holder) {
-
- super(eventType, getterFacetIfAny, holder);
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetForPropertyAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetForPropertyAnnotation.java
deleted file mode 100644
index 1979de2be9f..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertyDomainEventFacetForPropertyAnnotation.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.properties.property.modify;
-
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.causeway.core.metamodel.specloader.specimpl.OneToOneAssociationMixedIn;
-
-public class PropertyDomainEventFacetForPropertyAnnotation extends PropertyDomainEventFacetAbstract {
-
- /**
- * @param getterFacetIfAny - will be null if this is for a mixin {@link OneToOneAssociationMixedIn}.
- */
- public PropertyDomainEventFacetForPropertyAnnotation(
- final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacetIfAny,
- final FacetHolder holder) {
- super(eventType, getterFacetIfAny, holder);
- }
-
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEventFromDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEvent.java
similarity index 73%
rename from core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEventFromDefault.java
rename to core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEvent.java
index 5aea1911ea0..ade1fa2df24 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEventFromDefault.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEvent.java
@@ -23,19 +23,18 @@
import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
import org.apache.causeway.core.metamodel.facets.properties.update.modify.PropertySetterFacet;
-public class PropertySetterFacetForDomainEventFromDefault
+public class PropertySetterFacetForDomainEvent
extends PropertySetterOrClearFacetForDomainEventAbstract
implements PropertySetterFacet {
-
- public PropertySetterFacetForDomainEventFromDefault(
+ public PropertySetterFacetForDomainEvent(
final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacet,
- final PropertySetterFacet setterFacet,
- final PropertyDomainEventFacetAbstract propertyInteractionFacet,
- final FacetHolder holder) {
+ final EventTypeOrigin eventTypeOrigin,
+ final PropertyOrCollectionAccessorFacet getterFacet,
+ final PropertySetterFacet setterFacet,
+ final FacetHolder holder) {
- super(PropertySetterFacet.class, eventType, getterFacet, setterFacet, null, propertyInteractionFacet, holder);
+ super(PropertySetterFacet.class, eventType, eventTypeOrigin, getterFacet, setterFacet, null, holder);
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEventFromPropertyAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEventFromPropertyAnnotation.java
deleted file mode 100644
index 4103cecf755..00000000000
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterFacetForDomainEventFromPropertyAnnotation.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets.properties.property.modify;
-
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.causeway.core.metamodel.facets.properties.update.modify.PropertySetterFacet;
-
-public class PropertySetterFacetForDomainEventFromPropertyAnnotation
-extends PropertySetterOrClearFacetForDomainEventAbstract
-implements PropertySetterFacet {
-
-
- public PropertySetterFacetForDomainEventFromPropertyAnnotation(
- final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacet,
- final PropertySetterFacet setterFacet,
- final PropertyDomainEventFacetAbstract propertyInteractionFacet,
- final FacetHolder holder) {
-
- super(PropertySetterFacet.class, eventType, getterFacet, setterFacet, null, propertyInteractionFacet, holder);
- }
-}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterOrClearFacetForDomainEventAbstract.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterOrClearFacetForDomainEventAbstract.java
index f57830b7e5d..2306ba8e274 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterOrClearFacetForDomainEventAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/properties/property/modify/PropertySetterOrClearFacetForDomainEventAbstract.java
@@ -28,8 +28,8 @@
import org.apache.causeway.core.metamodel.execution.InteractionInternal;
import org.apache.causeway.core.metamodel.facetapi.Facet;
import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
+import org.apache.causeway.core.metamodel.facets.DomainEventFacetAbstract;
import org.apache.causeway.core.metamodel.facets.DomainEventHelper;
-import org.apache.causeway.core.metamodel.facets.SingleValueFacetAbstract;
import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
import org.apache.causeway.core.metamodel.facets.properties.update.clear.PropertyClearFacet;
import org.apache.causeway.core.metamodel.facets.properties.update.clear.PropertyClearingAccessor;
@@ -48,7 +48,7 @@
import lombok.val;
public abstract class PropertySetterOrClearFacetForDomainEventAbstract
-extends SingleValueFacetAbstract>>
+extends DomainEventFacetAbstract>
implements
PropertyClearingAccessor,
PropertySettingAccessor {
@@ -62,13 +62,13 @@ public abstract class PropertySetterOrClearFacetForDomainEventAbstract
protected PropertySetterOrClearFacetForDomainEventAbstract(
final Class extends Facet> facetType,
final Class extends PropertyDomainEvent, ?>> eventType,
- final PropertyOrCollectionAccessorFacet getterFacet,
- final PropertySetterFacet setterFacet,
- final PropertyClearFacet clearFacet,
- final PropertyDomainEventFacetAbstract propertyDomainEventFacet,
- final FacetHolder holder) {
+ final EventTypeOrigin eventTypeOrigin,
+ final PropertyOrCollectionAccessorFacet getterFacet,
+ final PropertySetterFacet setterFacet,
+ final PropertyClearFacet clearFacet,
+ final FacetHolder holder) {
- super(facetType, eventType, holder);
+ super(facetType, eventType, eventTypeOrigin, holder);
this.getterFacet = getterFacet;
this.setterFacet = setterFacet;
this.clearFacet = clearFacet;
@@ -199,7 +199,7 @@ public Object execute(final PropertyEdit currentExecution) {
val propertyDomainEvent =
domainEventHelper.postEventForProperty(
AbstractDomainEvent.Phase.EXECUTING,
- PropertySetterOrClearFacetForDomainEventAbstract.this.getEventType(), null,
+ uncheckedCast(PropertySetterOrClearFacetForDomainEventAbstract.this.getEventType()), null,
PropertySetterOrClearFacetForDomainEventAbstract.this.getFacetHolder(), head,
oldValuePojo, newValuePojo);
@@ -225,7 +225,8 @@ public Object execute(final PropertyEdit currentExecution) {
// ... post the executed event
domainEventHelper.postEventForProperty(
AbstractDomainEvent.Phase.EXECUTED,
- PropertySetterOrClearFacetForDomainEventAbstract.this.getEventType(), uncheckedCast(propertyDomainEvent),
+ uncheckedCast(PropertySetterOrClearFacetForDomainEventAbstract.this.getEventType()),
+ uncheckedCast(propertyDomainEvent),
PropertySetterOrClearFacetForDomainEventAbstract.this.getFacetHolder(), head,
oldValuePojo, actualNewValue);
}
@@ -279,10 +280,6 @@ private ManagedObject doSetOrClearProperty(
);
}
- public Class extends PropertyDomainEvent> getEventType() {
- return uncheckedCast(value());
- }
-
private InteractionDtoFactory getInteractionDtoServiceInternal() {
return getServiceRegistry().lookupServiceElseFail(InteractionDtoFactory.class);
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/InteractionHead.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/InteractionHead.java
index a1af639dc67..2586c896c92 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/InteractionHead.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/InteractionHead.java
@@ -63,9 +63,9 @@ public static InteractionHead mixin(final @NonNull ManagedObject owner, final @N
/**
* as used by the domain event subsystem
- * @return optionally the owner, based on whether the target is a mixin
+ * @return optionally the owner (mixee), based on whether the target is a mixin
*/
- public Optional getMixedIn() {
+ public Optional getMixee() {
return Objects.equals(getOwner(), getTarget())
? Optional.empty()
: Optional.of(getOwner());
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/members/TweakDomainEventsForMixinPostProcessor.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/members/TweakDomainEventsForMixinPostProcessor.java
index d6913e8154e..d9d4fcaae55 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/members/TweakDomainEventsForMixinPostProcessor.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/members/TweakDomainEventsForMixinPostProcessor.java
@@ -18,39 +18,18 @@
*/
package org.apache.causeway.core.metamodel.postprocessors.members;
-import java.lang.reflect.Method;
-
import javax.inject.Inject;
-import org.apache.causeway.applib.annotation.Collection;
-import org.apache.causeway.applib.annotation.Property;
-import org.apache.causeway.applib.events.domain.ActionDomainEvent;
-import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
-import org.apache.causeway.applib.events.domain.PropertyDomainEvent;
-import org.apache.causeway.commons.internal.reflection._Annotations;
import org.apache.causeway.core.metamodel.context.MetaModelContext;
import org.apache.causeway.core.metamodel.facetapi.FacetUtil;
-import org.apache.causeway.core.metamodel.facets.FacetedMethod;
import org.apache.causeway.core.metamodel.facets.actions.action.invocation.ActionDomainEventFacet;
-import org.apache.causeway.core.metamodel.facets.actions.action.invocation.ActionDomainEventFacetAbstract;
-import org.apache.causeway.core.metamodel.facets.collections.collection.CollectionAnnotationFacetFactory;
import org.apache.causeway.core.metamodel.facets.collections.collection.modify.CollectionDomainEventFacet;
-import org.apache.causeway.core.metamodel.facets.collections.collection.modify.CollectionDomainEventFacetAbstract;
-import org.apache.causeway.core.metamodel.facets.collections.collection.modify.CollectionDomainEventFacetForCollectionAnnotation;
-import org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents.ActionDomainEventDefaultFacetForDomainObjectAnnotation;
-import org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents.CollectionDomainEventDefaultFacetForDomainObjectAnnotation;
-import org.apache.causeway.core.metamodel.facets.object.domainobject.domainevents.PropertyDomainEventDefaultFacetForDomainObjectAnnotation;
-import org.apache.causeway.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.causeway.core.metamodel.facets.properties.property.PropertyAnnotationFacetFactory;
import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyDomainEventFacet;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyDomainEventFacetAbstract;
-import org.apache.causeway.core.metamodel.facets.properties.property.modify.PropertyDomainEventFacetForPropertyAnnotation;
import org.apache.causeway.core.metamodel.postprocessors.ObjectSpecificationPostProcessorAbstract;
import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
import org.apache.causeway.core.metamodel.spec.feature.ObjectAction;
import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.causeway.core.metamodel.specloader.specimpl.ObjectActionMixedIn;
import org.apache.causeway.core.metamodel.specloader.specimpl.OneToManyAssociationMixedIn;
import org.apache.causeway.core.metamodel.specloader.specimpl.OneToOneAssociationMixedIn;
@@ -64,106 +43,47 @@ public TweakDomainEventsForMixinPostProcessor(final MetaModelContext metaModelCo
@Override
public void postProcessAction(final ObjectSpecification objectSpecification, final ObjectAction objectAction) {
-
- if(objectAction instanceof ObjectActionMixedIn) {
- // unlike collection and property mixins, there is no need to create the DomainEventFacet, it will
- // have been created in the ActionAnnotationFacetFactory
- final ActionDomainEventDefaultFacetForDomainObjectAnnotation actionDomainEventDefaultFacet =
- objectSpecification.getFacet(ActionDomainEventDefaultFacetForDomainObjectAnnotation.class);
-
- if(actionDomainEventDefaultFacet != null) {
- final ObjectActionMixedIn actionMixedIn = (ObjectActionMixedIn) objectAction;
- final ActionDomainEventFacet actionFacet = actionMixedIn.getFacet(ActionDomainEventFacet.class);
- if (actionFacet instanceof ActionDomainEventFacetAbstract) {
- final ActionDomainEventFacetAbstract facetAbstract = (ActionDomainEventFacetAbstract) actionFacet;
- if (facetAbstract.getEventType() == ActionDomainEvent.Default.class) {
- final ActionDomainEventFacetAbstract existing = (ActionDomainEventFacetAbstract) actionFacet;
- existing.setEventType(actionDomainEventDefaultFacet.getEventType());
- }
- }
- }
+ if(objectAction.isMixedIn()) {
+
+ //TODO[CAUSEWAY-3409] yet already created in ActionAnnotationFacetFactory
+ //FacetUtil.addFacetIfPresent(
+ //ActionDomainEventFacet.createMixedIn(objectSpecification, (ObjectActionMixedIn)objectAction));
+ //TODO[CAUSEWAY-3409] even when this lookup returns empty, we still might need an event-type holding facet
+ objectAction
+ .lookupFacet(ActionDomainEventFacet.class)
+ .ifPresent(actionDomainEventFacet->
+ actionDomainEventFacet.initWithMixee(objectSpecification));
}
}
@Override
public void postProcessProperty(final ObjectSpecification objectSpecification, final OneToOneAssociation property) {
- if(property instanceof OneToOneAssociationMixedIn) {
- final OneToOneAssociationMixedIn propertyMixin = (OneToOneAssociationMixedIn) property;
- final FacetedMethod facetedMethod = propertyMixin.getFacetedMethod();
- final Method method = facetedMethod.getMethod().asMethodElseFail(); // no-arg method, should have a regular facade
-
- {
- // this is basically a subset of the code that is in CollectionAnnotationFacetFactory,
- // ignoring stuff which is deprecated for Causeway v2
+ if(property.isMixedIn()) {
- final Property propertyAnnot =
- _Annotations.synthesize(method, Property.class)
- .orElse(null);
-
- if(propertyAnnot != null) {
- final Class extends PropertyDomainEvent, ?>> propertyDomainEventType =
- PropertyAnnotationFacetFactory.defaultFromDomainObjectIfRequired(
- objectSpecification, propertyAnnot.domainEvent());
- final PropertyOrCollectionAccessorFacet getterFacetIfAny = null;
- FacetUtil.addFacet(
- new PropertyDomainEventFacetForPropertyAnnotation(
- propertyDomainEventType, getterFacetIfAny, property));
- }
- }
- final PropertyDomainEventDefaultFacetForDomainObjectAnnotation propertyDomainEventDefaultFacet =
- objectSpecification.getFacet(PropertyDomainEventDefaultFacetForDomainObjectAnnotation.class);
- if(propertyDomainEventDefaultFacet != null) {
- final PropertyDomainEventFacet propertyFacet = property.getFacet(PropertyDomainEventFacet.class);
- if (propertyFacet instanceof PropertyDomainEventFacetAbstract) {
- final PropertyDomainEventFacetAbstract facetAbstract = (PropertyDomainEventFacetAbstract) propertyFacet;
- if (facetAbstract.getEventType() == PropertyDomainEvent.Default.class) {
- final PropertyDomainEventFacetAbstract existing = (PropertyDomainEventFacetAbstract) propertyFacet;
- existing.setEventType(propertyDomainEventDefaultFacet.getEventType());
- }
- }
- }
+ FacetUtil.addFacetIfPresent(
+ PropertyDomainEventFacet.createMixedIn(objectSpecification, (OneToOneAssociationMixedIn)property));
+//TODO[CAUSEWAY-3409] even when this lookup returns empty, we still might need an event-type holding facet
+ property
+ .lookupFacet(PropertyDomainEventFacet.class)
+ .ifPresent(propertyDomainEventFacet->
+ propertyDomainEventFacet.initWithMixee(objectSpecification));
}
}
@Override
public void postProcessCollection(final ObjectSpecification objectSpecification, final OneToManyAssociation collection) {
- if(collection instanceof OneToManyAssociationMixedIn) {
- final OneToManyAssociationMixedIn collectionMixin = (OneToManyAssociationMixedIn) collection;
- final FacetedMethod facetedMethod = collectionMixin.getFacetedMethod();
- final Method method = facetedMethod.getMethod().asMethodElseFail(); // no-arg method, should have a regular facade
-
- {
- // this is basically a subset of the code that is in CollectionAnnotationFacetFactory,
- // ignoring stuff which is deprecated for Causeway v2
-
- final Collection collectionAnnot =
- _Annotations.synthesize(method, Collection.class)
- .orElse(null);
+ if(collection.isMixedIn()) {
- if(collectionAnnot != null) {
- final Class extends CollectionDomainEvent, ?>> collectionDomainEventType =
- CollectionAnnotationFacetFactory.defaultFromDomainObjectIfRequired(
- objectSpecification, collectionAnnot.domainEvent());
- FacetUtil.addFacet(
- new CollectionDomainEventFacetForCollectionAnnotation(
- collectionDomainEventType, collection));
- }
+ FacetUtil.addFacetIfPresent(
+ CollectionDomainEventFacet.createMixedIn(objectSpecification, (OneToManyAssociationMixedIn)collection));
+//TODO[CAUSEWAY-3409] even when this lookup returns empty, we still might need an event-type holding facet
+ collection
+ .lookupFacet(CollectionDomainEventFacet.class)
+ .ifPresent(collectionDomainEventFacet->
+ collectionDomainEventFacet.initWithMixee(objectSpecification));
- final CollectionDomainEventDefaultFacetForDomainObjectAnnotation collectionDomainEventDefaultFacet =
- objectSpecification.getFacet(CollectionDomainEventDefaultFacetForDomainObjectAnnotation.class);
- if(collectionDomainEventDefaultFacet != null) {
- final CollectionDomainEventFacet collectionFacet = collection.getFacet(CollectionDomainEventFacet.class);
- if (collectionFacet instanceof CollectionDomainEventFacetAbstract) {
- final CollectionDomainEventFacetAbstract facetAbstract = (CollectionDomainEventFacetAbstract) collectionFacet;
- if (facetAbstract.getEventType() == CollectionDomainEvent.Default.class) {
- final CollectionDomainEventFacetAbstract existing = (CollectionDomainEventFacetAbstract) collectionFacet;
- existing.setEventType(collectionDomainEventDefaultFacet.getEventType());
- }
- }
- }
- }
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/spec/feature/ObjectAction.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/spec/feature/ObjectAction.java
index 29eec9ce699..263d0ca7502 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/spec/feature/ObjectAction.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/spec/feature/ObjectAction.java
@@ -404,7 +404,7 @@ public static String friendlyNameFor(
final @NonNull ObjectAction action,
final @NonNull InteractionHead head) {
- val mixeeAdapter = head.getMixedIn().orElse(null);
+ val mixeeAdapter = head.getMixee().orElse(null);
if(mixeeAdapter != null) {
val mixinSpec = action.getDeclaringType();
diff --git a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/AbstractFacetFactoryJupiterTestCase.java b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/AbstractFacetFactoryJupiterTestCase.java
deleted file mode 100644
index 1b152f3b23c..00000000000
--- a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/AbstractFacetFactoryJupiterTestCase.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets;
-
-import java.lang.reflect.Method;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.mockito.Mockito;
-
-import org.apache.causeway.applib.Identifier;
-import org.apache.causeway.applib.id.LogicalType;
-import org.apache.causeway.commons.collections.ImmutableEnumSet;
-import org.apache.causeway.core.metamodel._testing.MetaModelContext_forTesting;
-import org.apache.causeway.core.metamodel._testing.MethodRemover_forTesting;
-import org.apache.causeway.core.metamodel.context.HasMetaModelContext;
-import org.apache.causeway.core.metamodel.context.MetaModelContext;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facetapi.FeatureType;
-import org.apache.causeway.core.metamodel.facetapi.MethodRemover;
-import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
-import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.causeway.core.metamodel.spec.feature.OneToOneActionParameter;
-import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.causeway.core.metamodel.valuesemantics.IntValueSemantics;
-
-import lombok.Getter;
-import lombok.Setter;
-
-public abstract class AbstractFacetFactoryJupiterTestCase
-implements HasMetaModelContext {
-
- @Getter(onMethod_ = {@Override})
- protected MetaModelContext metaModelContext;
-
- protected MethodRemover mockMethodRemover;
- protected FacetHolder mockFacetHolder;
- protected ObjectSpecification mockOnType;
- protected ObjectSpecification mockObjSpec;
- protected OneToOneAssociation mockOneToOneAssociation;
- protected OneToManyAssociation mockOneToManyAssociation;
- protected OneToOneActionParameter mockOneToOneActionParameter;
-
- protected FacetHolder facetHolder;
- protected FacetedMethod facetedMethod;
- protected FacetedMethodParameter facetedMethodParameter;
-
- public static class Customer {
- @Getter @Setter private String firstName;
- }
-
- protected void setUpMmc() {
- metaModelContext = MetaModelContext_forTesting.builder()
- .valueSemantic(new IntValueSemantics())
- .build();
- }
-
- @BeforeEach
- protected void setUpFacetedMethodAndParameter() throws Exception {
-
- setUpMmc();
-
- mockMethodRemover = Mockito.mock(MethodRemover.class);
- mockFacetHolder = Mockito.mock(FacetHolder.class);
- mockOnType = Mockito.mock(ObjectSpecification.class);
- mockObjSpec = Mockito.mock(ObjectSpecification.class);
- mockOneToOneAssociation = Mockito.mock(OneToOneAssociation.class);
- mockOneToManyAssociation = Mockito.mock(OneToManyAssociation.class);
- mockOneToOneActionParameter = Mockito.mock(OneToOneActionParameter.class);
-
- facetHolder = FacetHolder.simple(
- getMetaModelContext(),
- Identifier.propertyIdentifier(LogicalType.fqcn(Customer.class), "firstName"));
- facetedMethod = facetedSetter(
- AbstractFacetFactoryTest.Customer.class, "firstName");
- facetedMethodParameter = new FacetedMethodParameter(getMetaModelContext(),
- FeatureType.ACTION_PARAMETER_SINGULAR, facetedMethod.getOwningType(),
- facetedMethod.getMethod(), 0);
- }
-
- @AfterEach
- protected void tearDown() throws Exception {
- facetHolder = null;
- facetedMethod = null;
- facetedMethodParameter = null;
- }
-
- protected MethodRemover defaultMethodRemover() {
- return new MethodRemover_forTesting();
- }
-
- protected FacetedMethod facetedSetter(final Class> declaringClass, final String propertyName) {
- return FacetedMethod.createSetterForProperty(getMetaModelContext(),
- declaringClass, propertyName);
- }
-
- protected FacetedMethod facetedAction(final Class> declaringClass, final String methodName) {
- return FacetedMethod.createForAction(getMetaModelContext(),
- declaringClass, methodName);
- }
-
- protected boolean contains(final Class>[] types, final Class> type) {
- return Utils.contains(types, type);
- }
-
- protected static boolean contains(final ImmutableEnumSet featureTypes, final FeatureType featureType) {
- return Utils.contains(featureTypes, featureType);
- }
-
- protected Method findMethod(final Class> type, final String methodName, final Class>[] methodTypes) {
- return Utils.findMethod(type, methodName, methodTypes);
- }
-
- protected Method findMethod(final Class> type, final String methodName) {
- return Utils.findMethod(type, methodName);
- }
-
- protected void expectNoMethodsRemoved() {
- Mockito.verifyNoInteractions(mockMethodRemover);
- }
-
-}
diff --git a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/AbstractFacetFactoryTest.java b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/AbstractFacetFactoryTest.java
deleted file mode 100644
index 5caadfa6314..00000000000
--- a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/AbstractFacetFactoryTest.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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.causeway.core.metamodel.facets;
-
-import java.lang.reflect.Method;
-import java.util.Optional;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.mockito.Mockito;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.apache.causeway.applib.Identifier;
-import org.apache.causeway.applib.annotation.Introspection.IntrospectionPolicy;
-import org.apache.causeway.applib.id.LogicalType;
-import org.apache.causeway.applib.services.i18n.TranslationService;
-import org.apache.causeway.applib.services.iactnlayer.InteractionContext;
-import org.apache.causeway.applib.services.iactnlayer.InteractionService;
-import org.apache.causeway.commons.collections.ImmutableEnumSet;
-import org.apache.causeway.core.metamodel._testing.MetaModelContext_forTesting;
-import org.apache.causeway.core.metamodel._testing.MethodRemover_forTesting;
-import org.apache.causeway.core.metamodel.context.MetaModelContext;
-import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
-import org.apache.causeway.core.metamodel.facetapi.FeatureType;
-import org.apache.causeway.core.metamodel.facets.FacetFactory.ProcessMethodContext;
-import org.apache.causeway.core.metamodel.facets.actions.layout.ActionLayoutFacetFactory;
-import org.apache.causeway.core.metamodel.facets.collections.layout.CollectionLayoutFacetFactory;
-import org.apache.causeway.core.metamodel.facets.properties.propertylayout.PropertyLayoutFacetFactory;
-import org.apache.causeway.core.security.authentication.InteractionContextFactory;
-
-public abstract class AbstractFacetFactoryTest {
-
- public static class Customer {
-
- private String firstName;
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(final String firstName) {
- this.firstName = firstName;
- }
- }
-
- protected TranslationService mockTranslationService;
- protected InteractionService mockInteractionService;
- protected final InteractionContext iaContext = InteractionContextFactory.testing();
- protected MethodRemover_forTesting methodRemover;
-
- protected FacetHolder facetHolder;
- protected FacetedMethod facetedMethod;
- protected FacetedMethodParameter facetedMethodParameter;
- protected MetaModelContext_forTesting metaModelContext;
-
- @BeforeEach
- protected void setUp() throws Exception {
-
- mockTranslationService = Mockito.mock(TranslationService.class);
- mockInteractionService = Mockito.mock(InteractionService.class);
-
- methodRemover = new MethodRemover_forTesting();
-
- metaModelContext = MetaModelContext_forTesting.builder()
- .translationService(mockTranslationService)
- .interactionService(mockInteractionService)
- .build();
-
- Mockito.when(mockInteractionService.currentInteractionContext()).thenReturn(Optional.of(iaContext));
-
- facetHolder = FacetHolder.simple(
- metaModelContext,
- Identifier.propertyIdentifier(LogicalType.fqcn(Customer.class), "firstName"));
-
- facetedMethod = FacetedMethod.createSetterForProperty(metaModelContext, Customer.class, "firstName");
- facetedMethodParameter = new FacetedMethodParameter(
- metaModelContext,
- FeatureType.ACTION_PARAMETER_SINGULAR,
- facetedMethod.getOwningType(),
- facetedMethod.getMethod(), 0);
- }
-
- @AfterEach
- protected void tearDown() throws Exception {
- methodRemover = null;
- facetedMethod = null;
- }
-
- protected static boolean contains(final Class>[] types, final Class> type) {
- return Utils.contains(types, type);
- }
-
- protected static boolean contains(final ImmutableEnumSet featureTypes, final FeatureType featureType) {
- return Utils.contains(featureTypes, featureType);
- }
-
- protected static Method findMethod(final Class> type, final String methodName, final Class>[] signature) {
- return Utils.findMethod(type, methodName, signature);
- }
-
- protected Method findMethod(final Class> type, final String methodName) {
- return Utils.findMethod(type, methodName);
- }
-
- protected void processMethod(
- final FacetFactory facetFactory,
- final Class> type,
- final String methodName,
- final Class>[] signature) {
-
- facetFactory.process(ProcessMethodContext
- .forTesting(type, null,
- findMethod(type, methodName, signature),
- methodRemover, facetedMethod));
- }
-
- protected void processParams(
- final FacetFactory facetFactory,
- final Class> type,
- final String methodName,
- final Class>[] signature) {
-
- facetFactory.processParams(FacetFactory.ProcessParameterContext
- .forTesting(type, IntrospectionPolicy.ANNOTATION_OPTIONAL,
- findMethod(type, methodName, signature),
- null, facetedMethodParameter));
- }
-
- protected void assertNoMethodsRemoved() {
- assertTrue(methodRemover.getRemovedMethodMethodCalls().isEmpty());
- assertTrue(methodRemover.getRemoveMethodArgsCalls().isEmpty());
- }
-
- // -- FACTORIES
-
- protected static PropertyLayoutFacetFactory createPropertyLayoutFacetFactory(final MetaModelContext mmc) {
- return new PropertyLayoutFacetFactory(mmc);
- }
-
- protected static CollectionLayoutFacetFactory createCollectionLayoutFacetFactory(final MetaModelContext mmc) {
- return new CollectionLayoutFacetFactory(mmc);
- }
-
- protected static ActionLayoutFacetFactory createActionLayoutFacetFactory(final MetaModelContext mmc) {
- return new ActionLayoutFacetFactory(mmc);
- }
-
-
-}
diff --git a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/DomainEventHelperTest_newActionInteractionEvent.java b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/DomainEventHelperTest_newActionInteractionEvent.java
index b8e14db1e17..727e10932f0 100644
--- a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/DomainEventHelperTest_newActionInteractionEvent.java
+++ b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/DomainEventHelperTest_newActionInteractionEvent.java
@@ -44,7 +44,7 @@ public void defaultEventType() throws Exception {
final SomeDomainObject sdo = new SomeDomainObject();
final Identifier identifier = Identifier.actionIdentifier(LogicalType.fqcn(SomeDomainObject.class), "foo", new Class[]{int.class, String.class});
- Utils.domainEventHelper();
+ _Utils.domainEventHelper();
final ActionDomainEvent