Sonar Fixes (8) (#2220)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -78,7 +78,7 @@ public class JpaActionManagement {
|
||||
}
|
||||
|
||||
log.debug(
|
||||
"Update of actionStatus {} for action {} not possible since action not active anymore.",
|
||||
"Update of actionStatus {} for action {} not possible since action not active anymore and not allowed as an action terminating.",
|
||||
actionStatus.getStatus(), action.getId());
|
||||
return action;
|
||||
}
|
||||
@@ -133,16 +133,17 @@ public class JpaActionManagement {
|
||||
* status updates only once.
|
||||
*/
|
||||
private boolean isUpdatingActionStatusAllowed(final JpaAction action, final JpaActionStatus actionStatus) {
|
||||
if (action.isActive()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final boolean intermediateStatus = isIntermediateStatus(actionStatus);
|
||||
|
||||
final boolean isAllowedByRepositoryConfiguration = intermediateStatus && !repositoryProperties.isRejectActionStatusForClosedAction();
|
||||
|
||||
//in case of download_only action Status#DOWNLOADED is treated as 'final' already, so we accept one final status from device in case it sends
|
||||
final boolean isAllowedForDownloadOnlyActions = isDownloadOnly(
|
||||
action) && action.getStatus() == Action.Status.DOWNLOADED && !intermediateStatus;
|
||||
|
||||
return action.isActive() || isAllowedByRepositoryConfiguration || isAllowedForDownloadOnlyActions;
|
||||
if (isIntermediateStatus(actionStatus)) {
|
||||
return !repositoryProperties.isRejectActionStatusForClosedAction();
|
||||
} else {
|
||||
// in case of download_only action Status#DOWNLOADED is treated as 'final' already,
|
||||
// so we accept one final status from device in case it sends
|
||||
return isDownloadOnly(action) && action.getStatus() == Action.Status.DOWNLOADED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,7 +58,7 @@ public interface ACMRepository<T> {
|
||||
* @return matching entity
|
||||
*/
|
||||
@NonNull
|
||||
Optional<T> findOne(@Nullable AccessController.Operation operation, @Nullable Specification<T> spec);
|
||||
Optional<T> findOne(@Nullable AccessController.Operation operation, @NonNull Specification<T> spec);
|
||||
|
||||
/**
|
||||
* Returns all entries that match specification and the operation is allowed for.
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -39,6 +38,10 @@ import org.springframework.lang.Nullable;
|
||||
@Slf4j
|
||||
public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity> 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;
|
||||
|
||||
@@ -147,7 +150,12 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
|
||||
@Override
|
||||
@NonNull
|
||||
public Optional<T> findOne(final Specification<T> spec) {
|
||||
return repository.findOne(accessController.appendAccessRules(AccessController.Operation.READ, 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(AccessController.Operation.READ, spec),
|
||||
APPENDED_ACCESS_RULES_SPEC_OF_NON_NULL_SPEC_MUST_NOT_BE_NULL));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,7 +194,13 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
|
||||
|
||||
@Override
|
||||
public <S extends T, R> R findBy(final Specification<T> spec, final Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction) {
|
||||
return repository.findBy(accessController.appendAccessRules(AccessController.Operation.READ, spec), 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(AccessController.Operation.READ, spec),
|
||||
APPENDED_ACCESS_RULES_SPEC_OF_NON_NULL_SPEC_MUST_NOT_BE_NULL),
|
||||
queryFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,11 +246,16 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<T> findOne(@Nullable AccessController.Operation operation, @Nullable Specification<T> spec) {
|
||||
public Optional<T> findOne(@Nullable AccessController.Operation operation, @NonNull Specification<T> spec) {
|
||||
Objects.requireNonNull(spec, SPEC_MUST_NOT_BE_NULL);
|
||||
if (operation == null) {
|
||||
return repository.findOne(spec);
|
||||
} else {
|
||||
return repository.findOne(accessController.appendAccessRules(operation, spec));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class HawkbitBaseRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<T> findOne(@Nullable AccessController.Operation operation, @Nullable Specification<T> spec) {
|
||||
public Optional<T> findOne(@Nullable AccessController.Operation operation, @NonNull Specification<T> spec) {
|
||||
return findOne(spec);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user