You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/07/31 13:58:52 UTC
[isis] branch master updated: ISIS-2794: fixes creation events
triggered twice
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 24c0ecb ISIS-2794: fixes creation events triggered twice
24c0ecb is described below
commit 24c0ecbf553147678ea9bbbe2f8ee1a899a4f4b4
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Jul 31 15:58:44 2021 +0200
ISIS-2794: fixes creation events triggered twice
---
.../create/ObjectCreator_builtinHandlers.java | 7 ++++---
.../factory/FactoryServiceDefault.java | 9 ++++-----
.../LifecycleEventPublishingTestAbstract.java | 5 ++++-
.../apache/isis/testdomain/jpa/entities/JpaBook.java | 2 +-
.../publishing/PublishingTestFactoryAbstract.java | 19 +------------------
.../publishing/PublishingTestFactoryJdo.java | 1 +
.../publishing/PublishingTestFactoryJpa.java | 3 ++-
7 files changed, 17 insertions(+), 29 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/create/ObjectCreator_builtinHandlers.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/create/ObjectCreator_builtinHandlers.java
index f1fd59f..2d0aa78 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/create/ObjectCreator_builtinHandlers.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/create/ObjectCreator_builtinHandlers.java
@@ -22,7 +22,9 @@ import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
+import org.apache.isis.commons.internal._Constants;
import org.apache.isis.commons.internal.exceptions._Exceptions;
+import org.apache.isis.commons.internal.factory._InstanceUtil;
import org.apache.isis.core.metamodel.context.MetaModelContext;
import org.apache.isis.core.metamodel.services.objectlifecycle.ObjectLifecyclePublisher;
import org.apache.isis.core.metamodel.spec.ManagedObject;
@@ -97,11 +99,10 @@ final class ObjectCreator_builtinHandlers {
try {
- val newInstance = type.getDeclaredConstructor().newInstance();
+ val newInstance = _InstanceUtil.createInstance(type, _Constants.emptyObjects);
return newInstance;
- } catch (IllegalAccessException | InstantiationException | IllegalArgumentException
- | InvocationTargetException | NoSuchMethodException | SecurityException e) {
+ } catch (Exception e) {
throw _Exceptions.unrecoverable(
"Failed to create instance of type " + spec.getFullIdentifier(), e);
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/factory/FactoryServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/factory/FactoryServiceDefault.java
index 9257e9a..9c6460b 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/factory/FactoryServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/factory/FactoryServiceDefault.java
@@ -60,7 +60,7 @@ public class FactoryServiceDefault implements FactoryService {
@Inject private SpecificationLoader specificationLoader;
@Inject private ServiceInjector serviceInjector;
@Inject private IsisSystemEnvironment isisSystemEnvironment;
- @Inject private ObjectLifecyclePublisher persistenceLifecyclePublisher;
+ @Inject private ObjectLifecyclePublisher objectLifecyclePublisher;
@Override
public <T> T getOrCreate(final @NonNull Class<T> requiredType) {
@@ -96,7 +96,7 @@ public class FactoryServiceDefault implements FactoryService {
entityClass);
}
serviceInjector.injectServicesInto(entityPojo);
- persistenceLifecyclePublisher.onPostCreate(ManagedObject.of(spec, entityPojo));
+ objectLifecyclePublisher.onPostCreate(ManagedObject.of(spec, entityPojo));
return entityPojo;
}
@@ -141,7 +141,7 @@ public class FactoryServiceDefault implements FactoryService {
viewModelClass);
}
serviceInjector.injectServicesInto(viewModelPojo);
- persistenceLifecyclePublisher.onPostCreate(ManagedObject.of(spec, viewModelPojo));
+ objectLifecyclePublisher.onPostCreate(ManagedObject.of(spec, viewModelPojo));
return viewModelPojo;
}
@@ -182,10 +182,9 @@ public class FactoryServiceDefault implements FactoryService {
}
private Object createObject(final ObjectSpecification spec) {
+ // already handles injection and publishing
val domainObject = spec.createObject();
- persistenceLifecyclePublisher.onPostCreate(domainObject);
return domainObject.getPojo();
}
-
}
diff --git a/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java
index e567076..38d9667 100644
--- a/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java
+++ b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java
@@ -59,6 +59,9 @@ extends PublishingTestAbstract {
final ChangeScenario changeScenario,
final VerificationStage verificationStage) {
+ val bookSamplesForCreate = Can.of(
+ BookDto.sample(),
+ BookDto.builder().build()); // empty-defaults
val bookSample1 = Can.of( // initial
BookDto
.sample());
@@ -129,7 +132,7 @@ extends PublishingTestAbstract {
switch(changeScenario) {
case ENTITY_CREATION:
- assertHasCreatedLifecycleEvents(bookSample1);
+ assertHasCreatedLifecycleEvents(bookSamplesForCreate);
assertHasLoadedLifecycleEvents(Can.empty());
assertHasPersistingLifecycleEvents(Can.empty());
assertHasPersistedLifecycleEvents(Can.empty());
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/jpa/entities/JpaBook.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/jpa/entities/JpaBook.java
index 2ee6426..2ecd833 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/jpa/entities/JpaBook.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/jpa/entities/JpaBook.java
@@ -66,7 +66,7 @@ import lombok.extern.log4j.Log4j2;
, updatingLifecycleEvent = JpaBook.UpdatingLifecycleEvent.class
, updatedLifecycleEvent = JpaBook.UpdatedLifecycleEvent.class
, removingLifecycleEvent = JpaBook.RemovingLifecycleEvent.class)
-@NoArgsConstructor(access = AccessLevel.PROTECTED)
+@NoArgsConstructor(access = AccessLevel.PUBLIC)
@ToString(callSuper = true)
@Log4j2
public class JpaBook extends JpaProduct {
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryAbstract.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryAbstract.java
index a72a428..6c85e90 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryAbstract.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryAbstract.java
@@ -40,7 +40,6 @@ import org.apache.isis.applib.services.wrapper.DisabledException;
import org.apache.isis.applib.services.xactn.TransactionService;
import org.apache.isis.applib.services.xactn.TransactionState;
import org.apache.isis.commons.collections.Can;
-import org.apache.isis.commons.functional.Result;
import org.apache.isis.commons.internal.assertions._Assert;
import org.apache.isis.commons.internal.collections._Lists;
import org.apache.isis.commons.internal.debug._Probe;
@@ -342,22 +341,6 @@ public abstract class PublishingTestFactoryAbstract {
assertFalse(getInteractionService().isInInteraction());
assert_no_initial_tx_context();
-// val result = getInteractionService().callAnonymous(()->{
-// val currentInteraction = getInteractionService().currentInteraction();
-// xrayEnterInteraction(currentInteraction);
-//
-// Result<Boolean> result;
-// try {
-// testRunner.run(testContext);
-// result = Result.success(true);
-// } catch (Exception e) {
-// result = Result.failure(e);
-// }
-//
-// xrayExitInteraction();
-// return result;
-// });
-
val result = getInteractionService().runAnonymousAndCatch(()->{
val currentInteraction = getInteractionService().currentInteraction();
xrayEnterInteraction(currentInteraction);
@@ -386,7 +369,7 @@ public abstract class PublishingTestFactoryAbstract {
if(result.isFailure()) {
// unexpected failure
- fail("unexpeted exception during test: " + result.getFailure().get());
+ fail("unexpeted exception during test: ", result.getFailure().get());
}
failWhenContextHasErrors(testContext);
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java
index a042cb6..2d4e4e1 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java
@@ -134,6 +134,7 @@ extends PublishingTestFactoryAbstract {
context.runGiven();
//when
factoryService.detachedEntity(BookDto.sample().toJdoBook()); // should trigger an ObjectCreatedEvent
+ factoryService.detachedEntity(JdoBook.class); // should trigger a second ObjectCreatedEvent
break;
case ENTITY_PERSISTING:
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java
index 421a3f3..1ee6620 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java
@@ -130,7 +130,8 @@ extends PublishingTestFactoryAbstract {
context.runGiven();
//when
- factoryService.detachedEntity(BookDto.sample().toJdoBook()); // should trigger an ObjectCreatedEvent
+ factoryService.detachedEntity(BookDto.sample().toJpaBook()); // should trigger an ObjectCreatedEvent
+ factoryService.detachedEntity(JpaBook.class); // should trigger a second ObjectCreatedEvent
break;
case ENTITY_PERSISTING: