Skip to content

Commit

Permalink
tests: update sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Jan 13, 2024
1 parent 233eb16 commit a7742fa
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +56,7 @@ public PageResult<Assignment> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +55,7 @@ public PageResult<WorkspaceAssignment> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ default Map<String, Set<String>> createMapping(Map<String, DataImportRoleDTOV1>
dtoRoles.forEach((role, item) -> {
Set<String> 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);
});
Expand All @@ -48,11 +45,8 @@ default Map<String, Set<String>> createWorkspaceMapping(Map<String, DataImportRo
dtoRoles.forEach((role, item) -> {
Set<String> 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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,16 @@
@Mapper
public abstract class ExceptionMapper {

public RestResponse<ProblemDetailResponseDTOV1> 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<ProblemDetailParamDTOV1> map(Map<String, Object> 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<ProblemDetailResponseDTOV1> 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<ProblemDetailInvalidParamDTOV1> createErrorValidationResponse(
Expand All @@ -60,4 +46,18 @@ public String mapPath(Path path) {
public enum ErrorKeys {
CONSTRAINT_VIOLATIONS;
}

public List<ProblemDetailParamDTOV1> map(Map<String, Object> 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();
}
}

0 comments on commit a7742fa

Please sign in to comment.