Skip to content

Commit

Permalink
feat: add log params (#31)
Browse files Browse the repository at this point in the history
* feat: add log params

* feat: update log params
  • Loading branch information
andrejpetras authored Feb 29, 2024
1 parent 0e96173 commit e2bb75c
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public Image findByRefIdAndRefType(String refId, String refType) {

@Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = DAOException.class)
public void deleteQueryByRefId(String refId) throws DAOException {
if (refId == null) {
return;
}
try {
var cq = deleteQuery();
var root = cq.from(Image.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;

import org.tkit.onecx.workspace.domain.daos.ImageDAO;
import org.tkit.onecx.workspace.domain.daos.WorkspaceDAO;
import org.tkit.onecx.workspace.domain.models.Workspace;

@ApplicationScoped
public class WorkspaceService {
Expand All @@ -16,8 +16,16 @@ public class WorkspaceService {
@Inject
MenuService menuService;

@Inject
ImageDAO imageDAO;

@Transactional
public void deleteWorkspace(Workspace workspace) {
public void deleteWorkspace(String id) {
var workspace = workspaceDAO.findById(id);
if (workspace == null) {
return;
}
imageDAO.deleteQueryByRefId(workspace.getId());
menuService.deleteAllMenuItemsForWorkspace(workspace.getId());
workspaceDAO.delete(workspace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@ public Response createWorkspace(CreateWorkspaceRequestDTO createWorkspaceRequest
}

@Override
@Transactional
public Response deleteWorkspace(String id) {
var workspace = dao.findById(id);
if (workspace == null) {
return Response.noContent().build();
}
service.deleteWorkspace(workspace);
service.deleteWorkspace(id);
return Response.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.tkit.onecx.workspace.rs.internal.log;

import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;

import org.tkit.quarkus.log.cdi.LogParam;

import gen.org.tkit.onecx.workspace.rs.internal.model.*;

@ApplicationScoped
public class AssignmentLogParam implements LogParam {

@Override
public List<Item> getClasses() {
return List.of(
item(10, CreateAssignmentRequestDTO.class,
x -> CreateAssignmentRequestDTO.class.getSimpleName() + "["
+ ((CreateAssignmentRequestDTO) x).getRoleId() + ","
+ ((CreateAssignmentRequestDTO) x).getMenuItemId() + "]"),
item(10, AssignmentSearchCriteriaDTO.class, x -> {
AssignmentSearchCriteriaDTO d = (AssignmentSearchCriteriaDTO) x;
return AssignmentSearchCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + d.getPageSize()
+ "]";
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ public List<Item> getClasses() {
x -> UpdateMenuItemRequestDTO.class.getSimpleName() + "[" + ((UpdateMenuItemRequestDTO) x).getKey()
+ "]"),
this.item(10, CreateMenuItemDTO.class,
x -> CreateMenuItemDTO.class.getSimpleName() + "[" + ((CreateMenuItemDTO) x).getKey()
+ "," + ((CreateMenuItemDTO) x).getUrl() + "]")
x -> CreateMenuItemDTO.class.getSimpleName() + "[" + ((CreateMenuItemDTO) x).getKey() + "]"),

);
item(10, MenuStructureSearchCriteriaDTO.class,
x -> MenuStructureSearchCriteriaDTO.class.getSimpleName() + "["
+ ((MenuStructureSearchCriteriaDTO) x).getWorkspaceId() + "]"),

item(10, MenuItemSearchCriteriaDTO.class, x -> {
MenuItemSearchCriteriaDTO d = (MenuItemSearchCriteriaDTO) x;
return MenuItemSearchCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + d.getPageSize()
+ "]";
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.tkit.quarkus.log.cdi.LogParam;

import gen.org.tkit.onecx.workspace.rs.internal.model.CreateProductRequestDTO;
import gen.org.tkit.onecx.workspace.rs.internal.model.ProductSearchCriteriaDTO;
import gen.org.tkit.onecx.workspace.rs.internal.model.UpdateProductRequestDTO;

@ApplicationScoped
Expand All @@ -17,18 +18,14 @@ public List<Item> getClasses() {
return List.of(
this.item(10, CreateProductRequestDTO.class,
x -> CreateProductRequestDTO.class.getSimpleName() + "["
+ ((CreateProductRequestDTO) x).getProductName()
+ "," + ((CreateProductRequestDTO) x).getBaseUrl() + ","
+ (((CreateProductRequestDTO) x).getMicrofrontends() != null
? ((CreateProductRequestDTO) x).getMicrofrontends().size()
: "null")
+ "]"),
+ ((CreateProductRequestDTO) x).getWorkspaceId() + "]"),
this.item(10, UpdateProductRequestDTO.class,
x -> UpdateProductRequestDTO.class.getSimpleName() + "[" + ((UpdateProductRequestDTO) x).getBaseUrl()
+ ","
+ (((UpdateProductRequestDTO) x).getMicrofrontends() != null
? ((UpdateProductRequestDTO) x).getMicrofrontends().size()
: "null")
+ "]"));
+ "]"),
item(10, ProductSearchCriteriaDTO.class, x -> {
ProductSearchCriteriaDTO d = (ProductSearchCriteriaDTO) x;
return ProductSearchCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + d.getPageSize()
+ "]";
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.tkit.onecx.workspace.rs.internal.log;

import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;

import org.tkit.quarkus.log.cdi.LogParam;

import gen.org.tkit.onecx.workspace.rs.internal.model.*;

@ApplicationScoped
public class RoleLogParam implements LogParam {

@Override
public List<Item> getClasses() {
return List.of(
item(10, CreateRoleRequestDTO.class,
x -> CreateRoleRequestDTO.class.getSimpleName() + "["
+ ((CreateRoleRequestDTO) x).getName() + ","
+ ((CreateRoleRequestDTO) x).getWorkspaceId() + "]"),
item(10, UpdateRoleRequestDTO.class,
x -> UpdateRoleRequestDTO.class.getSimpleName() + "[" + ((UpdateRoleRequestDTO) x).getName()
+ "]"),
item(10, RoleSearchCriteriaDTO.class, x -> {
RoleSearchCriteriaDTO d = (RoleSearchCriteriaDTO) x;
return RoleSearchCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + d.getPageSize()
+ "]";
}));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.tkit.onecx.workspace.domain.daos;

import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.mockito.Mockito;
import org.tkit.quarkus.jpa.exceptions.DAOException;

import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class ImageDAOTest {

@Inject
ImageDAO dao;

@InjectMock
EntityManager em;

@BeforeEach
void beforeAll() {
Mockito.when(em.getCriteriaBuilder()).thenThrow(new RuntimeException("Test technical error exception"));
}

@Test
void methodExceptionTests() {
methodExceptionTests(() -> dao.deleteQueryByRefId(null),
ImageDAO.ErrorKeys.FAILED_TO_DELETE_BY_REF_ID_QUERY);
methodExceptionTests(() -> dao.findByRefIdAndRefType(null, null),
ImageDAO.ErrorKeys.FIND_ENTITY_BY_REF_ID_REF_TYPE_FAILED);
}

void methodExceptionTests(Executable fn, Enum<?> key) {
var exc = Assertions.assertThrows(DAOException.class, fn);
Assertions.assertEquals(key, exc.key);
}
}

0 comments on commit e2bb75c

Please sign in to comment.