Fix sonar findings (#3015)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -36,6 +36,7 @@ import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
/**
|
||||
@@ -159,13 +160,13 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
|
||||
return false;
|
||||
}
|
||||
final BaseEntity other = (BaseEntity) obj;
|
||||
final Long id = getId();
|
||||
final Long thisId = getId();
|
||||
final Long otherId = other.getId();
|
||||
if (id == null) {
|
||||
if (thisId == null) {
|
||||
if (otherId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!id.equals(otherId)) {
|
||||
} else if (!thisId.equals(otherId)) {
|
||||
return false;
|
||||
}
|
||||
return getOptLockRevision() == other.getOptLockRevision();
|
||||
@@ -203,9 +204,9 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
|
||||
}
|
||||
|
||||
protected boolean isController() {
|
||||
return SecurityContextHolder.getContext().getAuthentication() != null
|
||||
&& SecurityContextHolder.getContext().getAuthentication()
|
||||
.getDetails() instanceof TenantAwareAuthenticationDetails tenantAwareDetails
|
||||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
return authentication != null
|
||||
&& authentication.getDetails() instanceof TenantAwareAuthenticationDetails tenantAwareDetails
|
||||
&& tenantAwareDetails.controller();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -35,9 +37,9 @@ public class DefaultRolloutApprovalStrategy implements RolloutApprovalStrategy {
|
||||
*/
|
||||
@Override
|
||||
public boolean isApprovalNeeded(final Rollout rollout) {
|
||||
return TenantConfigHelper.getAsSystem(TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED, Boolean.class) &&
|
||||
hasNoApproveRolloutPermission(
|
||||
getCurrentAuthentication().getAuthorities().stream().map(GrantedAuthority::getAuthority).toList());
|
||||
return TenantConfigHelper.getAsSystem(TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED, Boolean.class)
|
||||
&& hasNoApproveRolloutPermission(getCurrentAuthentication().map(Authentication::getAuthorities).orElseGet(List::of).stream()
|
||||
.map(GrantedAuthority::getAuthority).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,11 +49,11 @@ public class DefaultRolloutApprovalStrategy implements RolloutApprovalStrategy {
|
||||
|
||||
@Override
|
||||
public String getApprovalUser(final Rollout rollout) {
|
||||
return getCurrentAuthentication().getName();
|
||||
return getCurrentAuthentication().map(Authentication::getName).orElse(null);
|
||||
}
|
||||
|
||||
private static Authentication getCurrentAuthentication() {
|
||||
return SecurityContextHolder.getContext().getAuthentication();
|
||||
private static Optional<Authentication> getCurrentAuthentication() {
|
||||
return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
private static boolean hasNoApproveRolloutPermission(final Collection<String> authorities) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import jakarta.persistence.PersistenceContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.HawkbitBaseRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.ExceptionMapper;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -103,7 +104,7 @@ public class HawkbitBaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID
|
||||
private @Nullable BeanFactory beanFactory;
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(final BeanFactory beanFactory) {
|
||||
public void setBeanFactory(@NonNull final BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
super.setBeanFactory(beanFactory);
|
||||
}
|
||||
@@ -132,7 +133,7 @@ public class HawkbitBaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID
|
||||
}
|
||||
|
||||
@PersistenceContext
|
||||
public void setEntityManager(final EntityManager entityManager) {
|
||||
public void setEntityManager(@NonNull final EntityManager entityManager) {
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
@@ -144,18 +145,19 @@ public class HawkbitBaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMappingContext(final MappingContext<?, ?> mappingContext) {
|
||||
public void setMappingContext(@NonNull final MappingContext<?, ?> mappingContext) {
|
||||
super.setMappingContext(mappingContext);
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S3776") // this way is more readable
|
||||
@Override
|
||||
protected RepositoryFactorySupport doCreateRepositoryFactory() {
|
||||
protected @NonNull RepositoryFactorySupport doCreateRepositoryFactory() {
|
||||
Objects.requireNonNull(entityManager, "EntityManager must not be null");
|
||||
final JpaRepositoryFactory jpaRepositoryFactory = new JpaRepositoryFactory(entityManager) {
|
||||
|
||||
@Override
|
||||
protected JpaRepositoryImplementation<?, ?> getTargetRepository(
|
||||
final RepositoryInformation information, final EntityManager entityManager) {
|
||||
protected @NonNull JpaRepositoryImplementation<?, ?> getTargetRepository(
|
||||
@NonNull final RepositoryInformation information, @NonNull final EntityManager entityManager) {
|
||||
final JpaRepositoryImplementation<?, ?> jpaRepositoryImplementation = super.getTargetRepository(information, entityManager);
|
||||
return (JpaRepositoryImplementation<?, ?>) Proxy.newProxyInstance(
|
||||
jpaRepositoryImplementation.getClass().getClassLoader(),
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@@ -87,6 +88,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -111,7 +113,6 @@ import org.springframework.integration.jdbc.lock.JdbcLockRegistry;
|
||||
import org.springframework.integration.jdbc.lock.LockRepository;
|
||||
import org.springframework.integration.support.locks.DefaultLockRegistry;
|
||||
import org.springframework.integration.support.locks.LockRegistry;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.resilience.annotation.EnableResilientMethods;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.security.authorization.AuthorizationDeniedException;
|
||||
@@ -209,8 +210,9 @@ public class JpaRepositoryConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public LockRegistry lockRegistry(final Optional<LockRepository> lockRepository) {
|
||||
return lockRepository.<LockRegistry> map(JdbcLockRegistry::new).orElseGet(DefaultLockRegistry::new);
|
||||
@SuppressWarnings("java:S1452") // it could be any LockRegistry<? extends Lock>
|
||||
public LockRegistry<? extends Lock> lockRegistry(final Optional<LockRepository> lockRepository) {
|
||||
return lockRepository.<LockRegistry<? extends Lock>> map(JdbcLockRegistry::new).orElseGet(DefaultLockRegistry::new);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -302,7 +304,7 @@ public class JpaRepositoryConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
RolloutHandler rolloutHandler(final RolloutManagement rolloutManagement,
|
||||
final RolloutExecutor rolloutExecutor, final LockRegistry lockRegistry,
|
||||
final RolloutExecutor rolloutExecutor, final LockRegistry<? extends Lock> lockRegistry,
|
||||
final PlatformTransactionManager txManager, final Optional<MeterRegistry> meterRegistry) {
|
||||
return new JpaRolloutHandler(rolloutManagement, rolloutExecutor, lockRegistry, txManager, meterRegistry);
|
||||
}
|
||||
@@ -354,7 +356,7 @@ public class JpaRepositoryConfiguration {
|
||||
AutoAssignScheduler autoAssignScheduler(
|
||||
final SystemManagement systemManagement, final AutoAssignHandler autoAssignHandler,
|
||||
@Value("${hawkbit.autoassign.executor.thread-pool.size:1}") final int threadPoolSize,
|
||||
final LockRegistry lockRegistry, final Optional<MeterRegistry> meterRegistry) {
|
||||
final Optional<MeterRegistry> meterRegistry) {
|
||||
return new AutoAssignScheduler(systemManagement, autoAssignHandler, threadPoolSize, meterRegistry);
|
||||
}
|
||||
|
||||
@@ -377,7 +379,7 @@ public class JpaRepositoryConfiguration {
|
||||
@ConditionalOnProperty(prefix = "hawkbit.autocleanup.scheduler", name = "enabled", matchIfMissing = true)
|
||||
AutoCleanupScheduler autoCleanupScheduler(
|
||||
final List<AutoCleanupScheduler.CleanupTask> cleanupTasks,
|
||||
final SystemManagement systemManagement, final LockRegistry lockRegistry) {
|
||||
final SystemManagement systemManagement, final LockRegistry<? extends Lock> lockRegistry) {
|
||||
return new AutoCleanupScheduler(cleanupTasks, systemManagement, lockRegistry);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,12 @@ import java.util.Optional;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.springframework.data.jpa.domain.DeleteSpecification;
|
||||
import org.springframework.data.jpa.domain.PredicateSpecification;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.domain.UpdateSpecification;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Interface of an extended access control by providing means or fine-grained access control.
|
||||
@@ -47,25 +48,24 @@ public interface AccessController<T> {
|
||||
* @param specification is the root specification which needs to be appended by the resource limitation
|
||||
* @return a new appended specification
|
||||
*/
|
||||
@Nullable
|
||||
default Specification<T> appendAccessRules(final Operation operation, @Nullable final Specification<T> specification) {
|
||||
default @NonNull Specification<T> appendAccessRules(final Operation operation, @Nullable final Specification<T> specification) {
|
||||
return getAccessRules(operation)
|
||||
.map(accessRules -> specification == null ? accessRules : specification.and(accessRules))
|
||||
.orElse(specification);
|
||||
.orElseGet(() -> specification == null ? Specification.unrestricted() : specification);
|
||||
}
|
||||
|
||||
default UpdateSpecification<T> appendAccessRules(final Operation operation, @Nullable final UpdateSpecification<T> specification) {
|
||||
default @NonNull UpdateSpecification<T> appendAccessRules(final Operation operation, @Nullable final UpdateSpecification<T> specification) {
|
||||
return getAccessRules(operation)
|
||||
.map(this::predicateSpec)
|
||||
.map(accessRules -> specification == null ? UpdateSpecification.where(accessRules) : specification.and(accessRules))
|
||||
.orElse(specification);
|
||||
.orElseGet(() -> specification == null ? UpdateSpecification.unrestricted() : specification);
|
||||
}
|
||||
|
||||
default DeleteSpecification<T> appendAccessRules(final Operation operation, @Nullable final DeleteSpecification<T> specification) {
|
||||
default @NonNull DeleteSpecification<T> appendAccessRules(final Operation operation, @Nullable final DeleteSpecification<T> specification) {
|
||||
return getAccessRules(operation)
|
||||
.map(this::predicateSpec)
|
||||
.map(accessRules -> specification == null ? DeleteSpecification.where(accessRules) : specification.and(accessRules))
|
||||
.orElse(specification);
|
||||
.orElseGet(() -> specification == null ? DeleteSpecification.unrestricted() : specification);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +87,8 @@ public interface AccessController<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
// TODO - since Spring 4.x migration, reconsider if it is the best way
|
||||
// shall not be used externally
|
||||
default PredicateSpecification<T> predicateSpec(final Specification<T> spec) {
|
||||
return (from, cb) -> spec.toPredicate((Root<T>) from, cb.createQuery(), cb);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class AutoCleanupScheduler {
|
||||
private static final String PROP_AUTO_CLEANUP_INTERVAL = "${hawkbit.autocleanup.scheduler.fixedDelay:86400000}";
|
||||
|
||||
private final SystemManagement systemManagement;
|
||||
private final LockRegistry lockRegistry;
|
||||
private final LockRegistry<? extends Lock> lockRegistry;
|
||||
private final List<CleanupTask> cleanupTasks;
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class AutoCleanupScheduler {
|
||||
*/
|
||||
public AutoCleanupScheduler(
|
||||
final List<CleanupTask> cleanupTasks,
|
||||
final SystemManagement systemManagement, final LockRegistry lockRegistry) {
|
||||
final SystemManagement systemManagement, final LockRegistry<? extends Lock> lockRegistry) {
|
||||
this.systemManagement = systemManagement;
|
||||
this.lockRegistry = lockRegistry;
|
||||
this.cleanupTasks = cleanupTasks;
|
||||
|
||||
@@ -394,8 +394,8 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
log.info("Deleting actions matching rsql {}", rsql);
|
||||
actionRepository.delete(DeleteSpecification.where(predicateSpec(QLSupport.getInstance().buildSpec(rsql, ActionFields.class))));
|
||||
}
|
||||
@Deprecated
|
||||
static <T> PredicateSpecification<T> predicateSpec(final Specification<T> spec) {
|
||||
// TODO - since Spring 4.x migration, reconsider if it is the best way
|
||||
private static <T> PredicateSpecification<T> predicateSpec(final Specification<T> spec) {
|
||||
return (from, cb) -> spec.toPredicate((Root<T>) from, cb.createQuery(), cb);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JpaDistributionSetInvalidationManagement implements DistributionSet
|
||||
private final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement;
|
||||
private final PlatformTransactionManager txManager;
|
||||
private final RepositoryProperties repositoryProperties;
|
||||
private final LockRegistry lockRegistry;
|
||||
private final LockRegistry<? extends Lock> lockRegistry;
|
||||
|
||||
@SuppressWarnings("java:S107")
|
||||
protected JpaDistributionSetInvalidationManagement(
|
||||
@@ -56,7 +56,7 @@ public class JpaDistributionSetInvalidationManagement implements DistributionSet
|
||||
final RolloutManagement rolloutManagement, final DeploymentManagement deploymentManagement,
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final PlatformTransactionManager txManager, final RepositoryProperties repositoryProperties,
|
||||
final LockRegistry lockRegistry) {
|
||||
final LockRegistry<? extends Lock> lockRegistry) {
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.rolloutManagement = rolloutManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
|
||||
@@ -41,8 +41,6 @@ import org.jspecify.annotations.Nullable;
|
||||
public class BaseEntityRepositoryACM<T extends AbstractJpaBaseEntity> implements BaseEntityRepository<T> {
|
||||
|
||||
private static final String SPEC_MUST_NOT_BE_NULL = "Specification must not be null";
|
||||
private static final String APPENDED_ACCESS_RULES_SPEC_OF_NON_NULL_SPEC_MUST_NOT_BE_NULL =
|
||||
"Appended access rules specification of non-null specification must not be null";
|
||||
|
||||
private final BaseEntityRepository<T> repository;
|
||||
private final AccessController<T> accessController;
|
||||
@@ -160,11 +158,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaBaseEntity> implements
|
||||
@NonNull
|
||||
public Optional<T> findOne(final Specification<T> spec) {
|
||||
Objects.requireNonNull(spec, SPEC_MUST_NOT_BE_NULL);
|
||||
return repository.findOne(
|
||||
// spec shall be non-null and the result of appending rules shall be non-null
|
||||
Objects.requireNonNull(
|
||||
accessController.appendAccessRules(Operation.READ, spec),
|
||||
APPENDED_ACCESS_RULES_SPEC_OF_NON_NULL_SPEC_MUST_NOT_BE_NULL));
|
||||
return repository.findOne(accessController.appendAccessRules(Operation.READ, spec));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,51 +169,45 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaBaseEntity> implements
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Page<T> findAll(final Specification<T> spec, @NonNull final Pageable pageable) {
|
||||
public Page<T> findAll(@Nullable final Specification<T> spec, @NonNull final Pageable pageable) {
|
||||
return repository.findAll(accessController.appendAccessRules(Operation.READ, spec), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<T> findAll(final Specification<T> spec, final Specification<T> countSpec, final Pageable pageable) {
|
||||
public Page<T> findAll(@Nullable final Specification<T> spec, @NonNull final Specification<T> countSpec, @NonNull final Pageable pageable) {
|
||||
return repository.findAll(accessController.appendAccessRules(Operation.READ, spec), countSpec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<T> findAll(final Specification<T> spec, @NonNull final Sort sort) {
|
||||
public List<T> findAll(@Nullable final Specification<T> spec, @NonNull final Sort sort) {
|
||||
return repository.findAll(accessController.appendAccessRules(Operation.READ, spec), sort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count(final Specification<T> spec) {
|
||||
public long count(@Nullable final Specification<T> spec) {
|
||||
return repository.count(accessController.appendAccessRules(Operation.READ, spec));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(@NonNull final Specification<T> spec) {
|
||||
return repository.exists(
|
||||
Objects.requireNonNull(accessController.appendAccessRules(Operation.READ, spec)));
|
||||
return repository.exists(accessController.appendAccessRules(Operation.READ, Objects.requireNonNull(spec, SPEC_MUST_NOT_BE_NULL)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long update(final UpdateSpecification<T> spec) {
|
||||
public long update(@Nullable final UpdateSpecification<T> spec) {
|
||||
return repository.update(accessController.appendAccessRules(Operation.UPDATE, spec));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long delete(final DeleteSpecification<T> spec) {
|
||||
public long delete(@Nullable final DeleteSpecification<T> spec) {
|
||||
return repository.delete(accessController.appendAccessRules(Operation.DELETE, spec));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends T, R> R findBy(final Specification<T> spec, final Function<? super SpecificationFluentQuery<S>, R> queryFunction) {
|
||||
public <S extends T, R> R findBy(@NonNull final Specification<T> spec, final Function<? super SpecificationFluentQuery<S>, R> queryFunction) {
|
||||
Objects.requireNonNull(spec, SPEC_MUST_NOT_BE_NULL);
|
||||
return repository.findBy(
|
||||
// spec shall be non-null and the result of appending rules shall be non-null
|
||||
Objects.requireNonNull(
|
||||
accessController.appendAccessRules(Operation.READ, spec),
|
||||
APPENDED_ACCESS_RULES_SPEC_OF_NON_NULL_SPEC_MUST_NOT_BE_NULL),
|
||||
queryFunction);
|
||||
return repository.findBy(accessController.appendAccessRules(Operation.READ, spec), queryFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,11 +258,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaBaseEntity> implements
|
||||
if (operation == null) {
|
||||
return repository.findOne(spec);
|
||||
} else {
|
||||
return repository.findOne(
|
||||
// spec shall be non-null and the result of appending rules shall be non-null
|
||||
Objects.requireNonNull(
|
||||
accessController.appendAccessRules(operation, spec),
|
||||
APPENDED_ACCESS_RULES_SPEC_OF_NON_NULL_SPEC_MUST_NOT_BE_NULL));
|
||||
return repository.findOne(accessController.appendAccessRules(operation, spec));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,20 +273,19 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaBaseEntity> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public boolean exists(final Operation operation, Specification<T> spec) {
|
||||
Objects.requireNonNull(spec, SPEC_MUST_NOT_BE_NULL);
|
||||
if (operation == null) {
|
||||
return repository.exists(spec);
|
||||
} else {
|
||||
return repository.exists(
|
||||
Objects.requireNonNull(accessController.appendAccessRules(operation, spec)));
|
||||
return repository.exists(accessController.appendAccessRules(operation, spec));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count(final Operation operation, @Nullable final Specification<T> spec) {
|
||||
if (operation == null) {
|
||||
return repository.count(spec);
|
||||
return spec == null ? repository.count() : repository.count(spec);
|
||||
} else {
|
||||
return repository.count(accessController.appendAccessRules(operation, spec));
|
||||
}
|
||||
@@ -326,29 +309,25 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaBaseEntity> implements
|
||||
|
||||
@Override
|
||||
public Optional<T> findOne(final Specification<T> spec, final String entityGraph) {
|
||||
return repository.findOne(
|
||||
accessController.appendAccessRules(Operation.READ, spec), entityGraph);
|
||||
return repository.findOne(accessController.appendAccessRules(Operation.READ, spec), entityGraph);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAll(final Specification<T> spec, final String entityGraph) {
|
||||
return repository.findAll(
|
||||
accessController.appendAccessRules(Operation.READ, spec), entityGraph);
|
||||
return repository.findAll(accessController.appendAccessRules(Operation.READ, spec), entityGraph);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<T> findAll(final Specification<T> spec, final String entityGraph, final Pageable pageable) {
|
||||
return repository.findAll(
|
||||
accessController.appendAccessRules(Operation.READ, spec), entityGraph, pageable);
|
||||
return repository.findAll(accessController.appendAccessRules(Operation.READ, spec), entityGraph, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAll(final Specification<T> spec, final String entityGraph, final Sort sort) {
|
||||
return repository.findAll(
|
||||
accessController.appendAccessRules(Operation.READ, spec), entityGraph, sort);
|
||||
return repository.findAll(accessController.appendAccessRules(Operation.READ, spec), entityGraph, sort);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "java:S3776"}) // java:S3776 - better readable in one places
|
||||
static <T extends AbstractJpaBaseEntity, R extends BaseEntityRepository<T>> R of(
|
||||
final R repository, @NonNull final AccessController<T> accessController) {
|
||||
Objects.requireNonNull(repository);
|
||||
|
||||
@@ -76,13 +76,14 @@ public class JpaAutoAssignHandler implements AutoAssignHandler {
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
private final LockRegistry lockRegistry;
|
||||
private final LockRegistry<? extends Lock> lockRegistry;
|
||||
private final Optional<MeterRegistry> meterRegistry;
|
||||
|
||||
public JpaAutoAssignHandler(
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final TargetManagement<? extends Target> targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final PlatformTransactionManager transactionManager, final LockRegistry lockRegistry, final Optional<MeterRegistry> meterRegistry) {
|
||||
final PlatformTransactionManager transactionManager, final LockRegistry<? extends Lock> lockRegistry,
|
||||
final Optional<MeterRegistry> meterRegistry) {
|
||||
this.targetFilterQueryManagement = targetFilterQueryManagement;
|
||||
this.targetManagement = targetManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class JpaRolloutHandler implements RolloutHandler {
|
||||
|
||||
private final RolloutManagement rolloutManagement;
|
||||
private final RolloutExecutor rolloutExecutor;
|
||||
private final LockRegistry lockRegistry;
|
||||
private final LockRegistry<? extends Lock> lockRegistry;
|
||||
private final PlatformTransactionManager txManager;
|
||||
private final Optional<MeterRegistry> meterRegistry;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JpaRolloutHandler implements RolloutHandler {
|
||||
* @param txManager transaction manager interface
|
||||
*/
|
||||
public JpaRolloutHandler(final RolloutManagement rolloutManagement,
|
||||
final RolloutExecutor rolloutExecutor, final LockRegistry lockRegistry,
|
||||
final RolloutExecutor rolloutExecutor, final LockRegistry<? extends Lock> lockRegistry,
|
||||
final PlatformTransactionManager txManager, final Optional<MeterRegistry> meterRegistry) {
|
||||
this.rolloutManagement = rolloutManagement;
|
||||
this.rolloutExecutor = rolloutExecutor;
|
||||
|
||||
@@ -13,6 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoCleanupScheduler.CleanupTask;
|
||||
@@ -33,7 +34,7 @@ class AutoCleanupSchedulerTest extends AbstractJpaIntegrationTest {
|
||||
private final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
@Autowired
|
||||
private LockRegistry lockRegistry;
|
||||
private LockRegistry<Lock> lockRegistry;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
@@ -58,7 +58,7 @@ class AutoAssignHandlerTest {
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Mock
|
||||
LockRegistry lockRegistry;
|
||||
LockRegistry<Lock> lockRegistry;
|
||||
|
||||
private JpaAutoAssignHandler autoAssignHandler;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.ArtifactStorage;
|
||||
import org.eclipse.hawkbit.artifact.fs.FileArtifactProperties;
|
||||
@@ -96,7 +97,7 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
LockRegistry lockRegistry() {
|
||||
LockRegistry<Lock> lockRegistry() {
|
||||
return new DefaultLockRegistry();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user