Extend event for entity events (#1250)

* Extend event information by it's first interface class and improve constructing the event by providing the directly only.

Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io>

* Check if entity interface is assignable from TenantAwareBaseEntity.

Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io>
This commit is contained in:
Michael Herdt
2022-04-25 15:39:44 +02:00
committed by GitHub
parent 0e6ef2e468
commit 59932b1d6f
38 changed files with 98 additions and 58 deletions

View File

@@ -682,7 +682,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
eventPublisherHolder.getEventPublisher()
.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
JpaTarget.class.getName(), eventPublisherHolder.getApplicationId()));
JpaTarget.class, eventPublisherHolder.getApplicationId()));
}
private void handleErrorOnAction(final JpaAction mergedAction, final JpaTarget mergedTarget) {

View File

@@ -273,7 +273,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
afterCommit.afterCommit(() -> distributionSetIDs.forEach(dsId -> eventPublisherHolder.getEventPublisher()
.publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(), dsId,
JpaDistributionSet.class.getName(), eventPublisherHolder.getApplicationId()))));
JpaDistributionSet.class, eventPublisherHolder.getApplicationId()))));
}
@Override

View File

@@ -354,7 +354,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
afterCommit.afterCommit(() -> groupIds.forEach(rolloutGroupId -> eventPublisherHolder.getEventPublisher()
.publishEvent(new RolloutGroupDeletedEvent(tenantAware.getCurrentTenant(), rolloutGroupId,
JpaRolloutGroup.class.getName(), eventPublisherHolder.getApplicationId()))));
JpaRolloutGroup.class, eventPublisherHolder.getApplicationId()))));
}
private boolean isRolloutComplete(final JpaRollout rollout) {

View File

@@ -352,7 +352,7 @@ public class JpaTargetManagement implements TargetManagement {
.publishEvent(new TargetDeletedEvent(tenantAware.getCurrentTenant(), target.getId(),
target.getControllerId(),
Optional.ofNullable(target.getAddress()).map(URI::toString).orElse(null),
JpaTarget.class.getName(), eventPublisherHolder.getApplicationId()))));
JpaTarget.class, eventPublisherHolder.getApplicationId()))));
}
@Override
@@ -836,7 +836,7 @@ public class JpaTargetManagement implements TargetManagement {
eventPublisherHolder.getEventPublisher()
.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
JpaTarget.class.getName(), eventPublisherHolder.getApplicationId()));
JpaTarget.class, eventPublisherHolder.getApplicationId()));
}
@Override

View File

@@ -341,14 +341,14 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
new DistributionSetUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId(), complete));
if (isSoftDeleted(descriptorEvent)) {
publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), getClass().getName(),
publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), getClass(),
EventPublisherHolder.getInstance().getApplicationId()));
}
}
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), getClass().getName(),
publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), getClass(),
EventPublisherHolder.getInstance().getApplicationId()));
}

View File

@@ -89,7 +89,7 @@ public class JpaDistributionSetTag extends JpaTag implements DistributionSetTag,
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new DistributionSetTagDeletedEvent(
getTenant(), getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -260,6 +260,6 @@ public class JpaDistributionSetType extends AbstractJpaNamedEntity implements Di
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new DistributionSetTypeDeletedEvent(
getTenant(), getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -271,7 +271,7 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
if (isSoftDeleted(descriptorEvent)) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new RolloutDeletedEvent(getTenant(),
getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}
@@ -288,7 +288,7 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new RolloutDeletedEvent(getTenant(),
getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
@Override

View File

@@ -296,6 +296,6 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new RolloutGroupDeletedEvent(getTenant(),
getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -251,7 +251,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
if (isSoftDeleted(descriptorEvent)) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new SoftwareModuleDeletedEvent(
getTenant(), getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}
@@ -268,7 +268,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new SoftwareModuleDeletedEvent(getTenant(),
getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -159,6 +159,6 @@ public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements Sof
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new SoftwareModuleTypeDeletedEvent(
getTenant(), getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -505,6 +505,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher()
.publishEvent(new TargetDeletedEvent(getTenant(), getId(), getControllerId(), address,
getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -175,6 +175,6 @@ public class JpaTargetFilterQuery extends AbstractJpaTenantAwareBaseEntity
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new TargetFilterQueryDeletedEvent(
getTenant(), getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -85,7 +85,7 @@ public class JpaTargetTag extends JpaTag implements TargetTag, EventAwareEntity
@Override
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new TargetTagDeletedEvent(getTenant(),
getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}

View File

@@ -151,6 +151,6 @@ public class JpaTargetType extends AbstractJpaNamedEntity implements TargetType,
@Override
public void fireDeleteEvent(DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new TargetTypeDeletedEvent(
getTenant(), getId(), getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -101,6 +101,6 @@ public class JpaTenantConfiguration extends AbstractJpaTenantAwareBaseEntity
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher()
.publishEvent(new TenantConfigurationDeletedEvent(getTenant(), getId(), getKey(), getValue(),
getClass().getName(), EventPublisherHolder.getInstance().getApplicationId()));
getClass(), EventPublisherHolder.getInstance().getApplicationId()));
}
}

View File

@@ -18,6 +18,8 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -32,7 +34,7 @@ public class RemoteIdEventTest extends AbstractRemoteEventTest {
private static String TENANT = "tenant";
private static String ENTIY_CLASS = "EntityClass";
private static Class<? extends TenantAwareBaseEntity> ENTITY_CLASS = JpaAction.class;
private static String NODE = "Node";
@@ -56,7 +58,7 @@ public class RemoteIdEventTest extends AbstractRemoteEventTest {
@Description("Verifies that the target id is correct reloaded")
public void testTargetDeletedEvent() {
final TargetDeletedEvent deletedEvent = new TargetDeletedEvent(TENANT, ENTITY_ID, CONTROLLER_ID, ADDRESS,
ENTIY_CLASS, NODE);
ENTITY_CLASS, NODE);
assertEntity(deletedEvent);
}
@@ -85,7 +87,7 @@ public class RemoteIdEventTest extends AbstractRemoteEventTest {
.orElseThrow(() -> new IllegalArgumentException("Given event is not RemoteIdEvent compatible"));
try {
final RemoteIdEvent event = (RemoteIdEvent) constructor.newInstance(TENANT, ENTITY_ID, ENTIY_CLASS, NODE);
final RemoteIdEvent event = (RemoteIdEvent) constructor.newInstance(TENANT, ENTITY_ID, ENTITY_CLASS, NODE);
assertEntity(event);
} catch (final ReflectiveOperationException e) {
fail("Exception should not happen " + e.getMessage());