From a7742fa0ea9ae8c16e0fdab79b6f8c30fc8efe93 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Sat, 13 Jan 2024 14:12:46 +0100 Subject: [PATCH] tests: update sonar issues --- .../permission/domain/daos/AssignmentDAO.java | 3 +- .../domain/daos/WorkspaceAssignmentDAO.java | 3 +- .../domain/di/mappers/DataImportV1Mapper.java | 14 +++----- .../domain/models/WorkspaceAssignment.java | 12 +++---- .../external/v1/mappers/ExceptionMapper.java | 36 +++++++++---------- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/main/java/io/github/onecx/permission/domain/daos/AssignmentDAO.java b/src/main/java/io/github/onecx/permission/domain/daos/AssignmentDAO.java index de854ff..7df5327 100644 --- a/src/main/java/io/github/onecx/permission/domain/daos/AssignmentDAO.java +++ b/src/main/java/io/github/onecx/permission/domain/daos/AssignmentDAO.java @@ -12,6 +12,7 @@ import org.tkit.quarkus.jpa.daos.Page; import org.tkit.quarkus.jpa.daos.PageResult; import org.tkit.quarkus.jpa.exceptions.DAOException; +import org.tkit.quarkus.jpa.models.AbstractTraceableEntity_; import org.tkit.quarkus.jpa.models.TraceableEntity_; import io.github.onecx.permission.domain.criteria.AssignmentSearchCriteria; @@ -55,7 +56,7 @@ public PageResult findByCriteria(AssignmentSearchCriteria criteria) cq.where(predicates.toArray(new Predicate[] {})); } - cq.orderBy(cb.asc(root.get(TraceableEntity_.creationDate))); + cq.orderBy(cb.asc(root.get(AbstractTraceableEntity_.creationDate))); return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult(); } catch (Exception ex) { diff --git a/src/main/java/io/github/onecx/permission/domain/daos/WorkspaceAssignmentDAO.java b/src/main/java/io/github/onecx/permission/domain/daos/WorkspaceAssignmentDAO.java index eac3503..1e3631f 100644 --- a/src/main/java/io/github/onecx/permission/domain/daos/WorkspaceAssignmentDAO.java +++ b/src/main/java/io/github/onecx/permission/domain/daos/WorkspaceAssignmentDAO.java @@ -12,6 +12,7 @@ import org.tkit.quarkus.jpa.daos.Page; import org.tkit.quarkus.jpa.daos.PageResult; import org.tkit.quarkus.jpa.exceptions.DAOException; +import org.tkit.quarkus.jpa.models.AbstractTraceableEntity_; import org.tkit.quarkus.jpa.models.TraceableEntity_; import io.github.onecx.permission.domain.criteria.WorkspaceAssignmentSearchCriteria; @@ -54,7 +55,7 @@ public PageResult findByCriteria(WorkspaceAssignmentSearchC cq.where(predicates.toArray(new Predicate[] {})); } - cq.orderBy(cb.asc(root.get(TraceableEntity_.creationDate))); + cq.orderBy(cb.asc(root.get(AbstractTraceableEntity_.creationDate))); return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult(); } catch (Exception ex) { diff --git a/src/main/java/io/github/onecx/permission/domain/di/mappers/DataImportV1Mapper.java b/src/main/java/io/github/onecx/permission/domain/di/mappers/DataImportV1Mapper.java index 45f8305..ece39a7 100644 --- a/src/main/java/io/github/onecx/permission/domain/di/mappers/DataImportV1Mapper.java +++ b/src/main/java/io/github/onecx/permission/domain/di/mappers/DataImportV1Mapper.java @@ -29,11 +29,8 @@ default Map> createMapping(Map dtoRoles.forEach((role, item) -> { Set perms = new HashSet<>(); - item.getAssignments().forEach((appId, an) -> { - an.forEach((resource, actions) -> { - actions.forEach(action -> perms.add(appId + resource + action)); - }); - }); + item.getAssignments().forEach((appId, an) -> an + .forEach((resource, actions) -> actions.forEach(action -> perms.add(appId + resource + action)))); mapping.put(role, perms); }); @@ -48,11 +45,8 @@ default Map> createWorkspaceMapping(Map { Set perms = new HashSet<>(); - item.getWorkspacesAssignments().forEach((workspaceId, an) -> { - an.forEach((resource, actions) -> { - actions.forEach(action -> perms.add(workspaceId + resource + action)); - }); - }); + item.getWorkspacesAssignments().forEach((workspaceId, an) -> an + .forEach((resource, actions) -> actions.forEach(action -> perms.add(workspaceId + resource + action)))); mapping.put(role, perms); }); diff --git a/src/main/java/io/github/onecx/permission/domain/models/WorkspaceAssignment.java b/src/main/java/io/github/onecx/permission/domain/models/WorkspaceAssignment.java index 29fb5f4..0a9cd2c 100644 --- a/src/main/java/io/github/onecx/permission/domain/models/WorkspaceAssignment.java +++ b/src/main/java/io/github/onecx/permission/domain/models/WorkspaceAssignment.java @@ -21,12 +21,6 @@ public class WorkspaceAssignment extends TraceableEntity { @Column(name = "TENANT_ID") private String tenantId; - @Column(name = "ROLE_ID", insertable = false, updatable = false) - private String roleId; - - @Column(name = "PERMISSION_ID", insertable = false, updatable = false) - private String permissionId; - @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "ROLE_ID") private Role role; @@ -35,6 +29,12 @@ public class WorkspaceAssignment extends TraceableEntity { @JoinColumn(name = "PERMISSION_ID") private WorkspacePermission permission; + @Column(name = "ROLE_ID", insertable = false, updatable = false) + private String roleId; + + @Column(name = "PERMISSION_ID", insertable = false, updatable = false) + private String permissionId; + @PostPersist void postPersist() { roleId = role.getId(); diff --git a/src/main/java/io/github/onecx/permission/rs/external/v1/mappers/ExceptionMapper.java b/src/main/java/io/github/onecx/permission/rs/external/v1/mappers/ExceptionMapper.java index 2eb84cc..2615233 100644 --- a/src/main/java/io/github/onecx/permission/rs/external/v1/mappers/ExceptionMapper.java +++ b/src/main/java/io/github/onecx/permission/rs/external/v1/mappers/ExceptionMapper.java @@ -20,30 +20,16 @@ @Mapper public abstract class ExceptionMapper { - public RestResponse constraint(ConstraintViolationException ex) { - var dto = exception(ErrorKeys.CONSTRAINT_VIOLATIONS.name(), ex.getMessage()); - dto.setInvalidParams(createErrorValidationResponse(ex.getConstraintViolations())); - return RestResponse.status(Response.Status.BAD_REQUEST, dto); - } - @Mapping(target = "removeParamsItem", ignore = true) @Mapping(target = "params", ignore = true) @Mapping(target = "invalidParams", ignore = true) @Mapping(target = "removeInvalidParamsItem", ignore = true) public abstract ProblemDetailResponseDTOV1 exception(String errorCode, String detail); - public List map(Map params) { - if (params == null) { - return List.of(); - } - return params.entrySet().stream().map(e -> { - var item = new ProblemDetailParamDTOV1(); - item.setKey(e.getKey()); - if (e.getValue() != null) { - item.setValue(e.getValue().toString()); - } - return item; - }).toList(); + public RestResponse constraint(ConstraintViolationException ex) { + var dto = exception(ErrorKeys.CONSTRAINT_VIOLATIONS.name(), ex.getMessage()); + dto.setInvalidParams(createErrorValidationResponse(ex.getConstraintViolations())); + return RestResponse.status(Response.Status.BAD_REQUEST, dto); } public abstract List createErrorValidationResponse( @@ -60,4 +46,18 @@ public String mapPath(Path path) { public enum ErrorKeys { CONSTRAINT_VIOLATIONS; } + + public List map(Map params) { + if (params == null) { + return List.of(); + } + return params.entrySet().stream().map(e -> { + var item = new ProblemDetailParamDTOV1(); + item.setKey(e.getKey()); + if (e.getValue() != null) { + item.setValue(e.getValue().toString()); + } + return item; + }).toList(); + } }