Small refactoring (#2115)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -198,8 +198,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
|
||||
}
|
||||
|
||||
private List<Action> giveConfirmationForActiveActions(final AutoConfirmationStatus autoConfirmationStatus) {
|
||||
final Target target = autoConfirmationStatus.getTarget();
|
||||
return findActiveActionsHavingStatus(target.getControllerId(), Status.WAIT_FOR_CONFIRMATION).stream()
|
||||
return findActiveActionsHavingStatus(autoConfirmationStatus.getTarget().getControllerId(), Status.WAIT_FOR_CONFIRMATION).stream()
|
||||
.map(action -> autoConfirmAction(action, autoConfirmationStatus))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -298,10 +298,11 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet jpaDistributionSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
final Long distSetTypeId = jpaDistributionSet.getType().getId();
|
||||
|
||||
return targetRepository.count(AccessController.Operation.UPDATE,
|
||||
return targetRepository.count(
|
||||
AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RSQLUtility.buildRsqlSpecification(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer, database),
|
||||
RSQLUtility.buildRsqlSpecification(
|
||||
targetFilterQuery, TargetFields.class, virtualPropertyReplacer, database),
|
||||
TargetSpecifications.hasNotDistributionSetInActions(distributionSetId),
|
||||
TargetSpecifications.isCompatibleWithDistributionSetType(distSetTypeId))));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.jpa.model;
|
||||
import java.io.Serial;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -148,7 +147,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@OneToOne(fetch = FetchType.LAZY, mappedBy = "target", orphanRemoval = true)
|
||||
@OneToOne(fetch = FetchType.LAZY, mappedBy = "target", cascade = { CascadeType.ALL }, orphanRemoval = true)
|
||||
@PrimaryKeyJoinColumn
|
||||
private JpaAutoConfirmationStatus autoConfirmationStatus;
|
||||
|
||||
|
||||
@@ -294,8 +294,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
|
||||
final R repository, @NonNull final AccessController<T> accessController) {
|
||||
Objects.requireNonNull(repository);
|
||||
Objects.requireNonNull(accessController);
|
||||
final BaseEntityRepositoryACM<T> repositoryACM =
|
||||
new BaseEntityRepositoryACM<>(repository, accessController);
|
||||
final BaseEntityRepositoryACM<T> repositoryACM = new BaseEntityRepositoryACM<>(repository, accessController);
|
||||
final R acmProxy = (R) Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
repository.getClass().getInterfaces(),
|
||||
@@ -312,6 +311,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
|
||||
}
|
||||
if (method.getName().startsWith("find") || method.getName().startsWith("get")) {
|
||||
final Object result = method.invoke(repository, args);
|
||||
// Iterable, List, Page, Slice
|
||||
if (Iterable.class.isAssignableFrom(method.getReturnType())) {
|
||||
for (final Object e : (Iterable<?>) result) {
|
||||
if (repository.getDomainClass().isAssignableFrom(e.getClass())) {
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* Spring data repositories for {@link TargetFilterQuery}s.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public interface TargetFilterQueryRepository
|
||||
extends BaseEntityRepository<JpaTargetFilterQuery> {
|
||||
public interface TargetFilterQueryRepository extends BaseEntityRepository<JpaTargetFilterQuery> {
|
||||
|
||||
/**
|
||||
* Find customer target filter by name
|
||||
@@ -37,8 +36,7 @@ public interface TargetFilterQueryRepository
|
||||
Optional<TargetFilterQuery> findByName(String name);
|
||||
|
||||
/**
|
||||
* Sets the auto assign distribution sets and action types to null which
|
||||
* match the ds ids.
|
||||
* Sets the auto assign distribution sets and action types to null which match the ds ids.
|
||||
* <p/>
|
||||
* No access control applied
|
||||
*
|
||||
@@ -46,12 +44,11 @@ public interface TargetFilterQueryRepository
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("update JpaTargetFilterQuery d set d.autoAssignDistributionSet = NULL, d.autoAssignActionType = NULL, d.accessControlContext = NULL where d.autoAssignDistributionSet in :ids")
|
||||
@Query("UPDATE JpaTargetFilterQuery d SET d.autoAssignDistributionSet = NULL, d.autoAssignActionType = NULL, d.accessControlContext = NULL WHERE d.autoAssignDistributionSet.id IN :ids")
|
||||
void unsetAutoAssignDistributionSetAndActionTypeAndAccessContext(@Param("ids") Long... dsIds);
|
||||
|
||||
/**
|
||||
* Counts all target filters that have a given auto assign distribution set
|
||||
* assigned.
|
||||
* Counts all target filters that have a given auto assign distribution set assigned.
|
||||
* <p/>
|
||||
* No access control applied
|
||||
*
|
||||
@@ -61,10 +58,8 @@ public interface TargetFilterQueryRepository
|
||||
long countByAutoAssignDistributionSetId(long autoAssignDistributionSetId);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant
|
||||
* manually to query even if this will by done by {@link EntityManager}
|
||||
* anyhow. The DB should take care of optimizing this away.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety reasons (this is a "delete everything" query after all) we add
|
||||
* the tenant manually to query even if this will by done by {@link EntityManager} anyhow. The DB should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant to delete data from
|
||||
*/
|
||||
@@ -72,4 +67,4 @@ public interface TargetFilterQueryRepository
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaTargetFilterQuery t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user