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

@@ -20,6 +20,11 @@ public interface EntityIdEvent extends TenantAwareEvent {
*/
String getEntityClass();
/**
* @return the class of entities interface
*/
String getInterfaceClass();
/**
* @return the ID of the entity of this event.
*/

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
* Defines the remote event for deletion of {@link DistributionSet}.
@@ -35,8 +36,8 @@ public class DistributionSetDeletedEvent extends RemoteIdEvent implements Entity
* @param applicationId
* the origin application id
*/
public DistributionSetDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public DistributionSetDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
* Defines the the remote event of delete a {@link DistributionSetTag}.
@@ -38,8 +39,8 @@ public class DistributionSetTagDeletedEvent extends RemoteIdEvent implements Ent
* the origin application id
*/
public DistributionSetTagDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public DistributionSetTagDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -38,8 +39,8 @@ public class DistributionSetTypeDeletedEvent extends RemoteIdEvent implements En
* @param applicationId
* the origin application id
*/
public DistributionSetTypeDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public DistributionSetTypeDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}

View File

@@ -8,6 +8,10 @@
*/
package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import java.util.Arrays;
/**
* An base definition class for an event which contains an id.
*
@@ -20,6 +24,8 @@ public class RemoteIdEvent extends RemoteTenantAwareEvent {
private String entityClass;
private String interfaceClass;
/**
* Default constructor.
*/
@@ -39,13 +45,21 @@ public class RemoteIdEvent extends RemoteTenantAwareEvent {
* @param applicationId
* the origin application id
*/
protected RemoteIdEvent(final Long entityId, final String tenant, final String entityClass,
final String applicationId) {
protected RemoteIdEvent(final Long entityId, final String tenant,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, applicationId);
this.entityClass = entityClass;
this.entityClass = entityClass.getName();
this.interfaceClass = entityClass.isInterface() ? entityClass.getName()
: getInterfaceEntity(entityClass).getName();
this.entityId = entityId;
}
private static Class<?> getInterfaceEntity(final Class<? extends TenantAwareBaseEntity> baseEntity) {
final Class<?>[] interfaces = baseEntity.getInterfaces();
return Arrays.stream(interfaces).filter(TenantAwareBaseEntity.class::isAssignableFrom).findFirst()
.orElse(baseEntity);
}
/**
* @return the entityClass
*/
@@ -57,4 +71,7 @@ public class RemoteIdEvent extends RemoteTenantAwareEvent {
return entityId;
}
public String getInterfaceClass() {
return interfaceClass;
}
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -38,8 +39,8 @@ public class RolloutDeletedEvent extends RemoteIdEvent implements EntityDeletedE
* @param applicationId
* the origin application id
*/
public RolloutDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public RolloutDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -38,8 +39,8 @@ public class RolloutGroupDeletedEvent extends RemoteIdEvent implements EntityDel
* @param applicationId
* the origin application id
*/
public RolloutGroupDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public RolloutGroupDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -38,8 +39,8 @@ public class SoftwareModuleDeletedEvent extends RemoteIdEvent implements EntityD
* @param applicationId
* the origin application id
*/
public SoftwareModuleDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public SoftwareModuleDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -38,8 +39,8 @@ public class SoftwareModuleTypeDeletedEvent extends RemoteIdEvent implements Ent
* @param applicationId
* the origin application id
*/
public SoftwareModuleTypeDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public SoftwareModuleTypeDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
* Defines the remote event of triggering attribute updates of a {@link Target}.
@@ -42,7 +43,8 @@ public class TargetAttributesRequestedEvent extends RemoteIdEvent {
* the origin application id
*/
public TargetAttributesRequestedEvent(final String tenant, final Long entityId, final String controllerId,
final String targetAddress, final String entityClass, final String applicationId) {
final String targetAddress, final Class<? extends TenantAwareBaseEntity> entityClass,
final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
this.controllerId = controllerId;
this.targetAddress = targetAddress;

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -44,7 +45,8 @@ public class TargetDeletedEvent extends RemoteIdEvent implements EntityDeletedEv
* the origin application id
*/
public TargetDeletedEvent(final String tenant, final Long entityId, final String controllerId,
final String targetAddress, final String entityClass, final String applicationId) {
final String targetAddress, final Class<? extends TenantAwareBaseEntity> entityClass,
final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
this.controllerId = controllerId;
this.targetAddress = targetAddress;

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -37,8 +38,8 @@ public class TargetFilterQueryDeletedEvent extends RemoteIdEvent implements Enti
* @param applicationId
* the origin application id
*/
public TargetFilterQueryDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public TargetFilterQueryDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
* Defines the remote event of delete a {@link TargetTag}.
@@ -38,8 +39,8 @@ public class TargetTagDeletedEvent extends RemoteIdEvent implements EntityDelete
* @param applicationId
* the origin application id
*/
public TargetTagDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public TargetTagDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -38,8 +39,8 @@ public class TargetTypeDeletedEvent extends RemoteIdEvent implements EntityDelet
* @param applicationId
* the origin application id
*/
public TargetTypeDeletedEvent(final String tenant, final Long entityId, final String entityClass,
final String applicationId) {
public TargetTypeDeletedEvent(final String tenant, final Long entityId,
final Class<? extends TenantAwareBaseEntity> entityClass, final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
}

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.event.entity.EntityDeletedEvent;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
/**
*
@@ -43,7 +44,8 @@ public class TenantConfigurationDeletedEvent extends RemoteIdEvent implements En
* the origin application id
*/
public TenantConfigurationDeletedEvent(final String tenant, final Long entityId, final String configKey,
final String configValue, final String entityClass, final String applicationId) {
final String configValue, final Class<? extends TenantAwareBaseEntity> entityClass,
final String applicationId) {
super(entityId, tenant, entityClass, applicationId);
this.configKey = configKey;
this.configValue = configValue;

View File

@@ -49,7 +49,7 @@ public class RemoteEntityEvent<E extends TenantAwareBaseEntity> extends RemoteId
* the origin application id
*/
protected RemoteEntityEvent(final E baseEntity, final String applicationId) {
super(baseEntity.getId(), baseEntity.getTenant(), baseEntity.getClass().getName(), applicationId);
super(baseEntity.getId(), baseEntity.getTenant(), baseEntity.getClass(), applicationId);
this.entity = baseEntity;
}

View File

@@ -76,7 +76,7 @@ public class RepositoryManagementMethodPreAuthorizeAnnotatedTest {
}
final PreAuthorize annotation = method.getAnnotation(PreAuthorize.class);
assertThat(annotation).as("The public method " + method.getName() + " in class " + clazz.getName()
+ " is not annoated with @PreAuthorize, security leak?").isNotNull();
+ " is not annotated with @PreAuthorize, security leak?").isNotNull();
}
}