Optimize get targets via REST API (#2757)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-10-15 14:08:58 +03:00
committed by GitHub
parent 6ad20252ba
commit 811b163d22
2 changed files with 6 additions and 15 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -55,15 +56,14 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
public ResponseEntity<PagedList<MgmtTargetType>> getTargetTypes(
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTargetTypeSortParam(sortParam));
final Page<? extends TargetType> findTargetTypesAll;
final Page<? extends TargetType> findTargetTypes;
if (rsqlParam != null) {
findTargetTypesAll = targetTypeManagement.findByRsql(rsqlParam, pageable);
findTargetTypes = targetTypeManagement.findByRsql(rsqlParam, pageable);
} else {
findTargetTypesAll = targetTypeManagement.findAll(pageable);
findTargetTypes = targetTypeManagement.findAll(pageable);
}
final List<MgmtTargetType> rest = MgmtTargetTypeMapper.toListResponse(findTargetTypesAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, targetTypeManagement.count()));
return ResponseEntity.ok(
new PagedList<>(MgmtTargetTypeMapper.toListResponse(findTargetTypes.getContent()), findTargetTypes.getTotalElements()));
}
@Override

View File

@@ -18,12 +18,10 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.ContextAware;
import org.eclipse.hawkbit.repository.QueryField;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.jpa.ql.QLSupport;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
@@ -35,8 +33,6 @@ public class DefaultAccessController<A extends Enum<A> & QueryField, T> implemen
private final Class<A> queryFieldType;
private final Map<Operation, List<String>> permissions = new EnumMap<>(Operation.class);
private ContextAware contextAware;
public DefaultAccessController(final Class<A> queryFieldType, final String... permissionTypes) {
if (ObjectUtils.isEmpty(permissionTypes)) {
throw new IllegalArgumentException("Permission types must not be empty");
@@ -50,11 +46,6 @@ public class DefaultAccessController<A extends Enum<A> & QueryField, T> implemen
}
}
@Autowired
void setContextAware(final ContextAware contextAware) {
this.contextAware = contextAware;
}
@Override
public Optional<Specification<T>> getAccessRules(final Operation operation) {
if (SystemSecurityContext.isCurrentThreadSystemCode()) {