From 6308d6de85b25abcac1d1b54371f284875da5ebb Mon Sep 17 00:00:00 2001 From: JordenReuter <149687553+JordenReuter@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:11:55 +0100 Subject: [PATCH] fix: removed application deletion (#111) --- .../domain/daos/ApplicationDAO.java | 18 +---------- .../permission/domain/daos/AssignmentDAO.java | 15 +-------- .../permission/domain/daos/PermissionDAO.java | 15 +-------- .../domain/services/ApplicationService.java | 32 ------------------- .../ApplicationRestController.java | 15 --------- .../onecx-permission-internal-openapi.yaml | 23 ------------- .../domain/daos/ApplicationDAOTest.java | 2 -- .../domain/daos/AssignmentDAOTest.java | 2 -- .../domain/daos/PermissionDAOTest.java | 2 -- .../ApplicationRestControllerTest.java | 30 +++-------------- 10 files changed, 7 insertions(+), 147 deletions(-) delete mode 100644 src/main/java/org/tkit/onecx/permission/domain/services/ApplicationService.java diff --git a/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java b/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java index 8b3f5f6..2a8fc23 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java +++ b/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java @@ -44,21 +44,6 @@ public PageResult findByCriteria(ApplicationSearchCriteria criteria } } - public Application loadByName(String appName) { - try { - var cb = this.getEntityManager().getCriteriaBuilder(); - var cq = cb.createQuery(Application.class); - var root = cq.from(Application.class); - cq.where( - cb.equal(root.get(Application_.NAME), appName)); - return this.getEntityManager().createQuery(cq).getSingleResult(); - } catch (NoResultException ne) { - return null; - } catch (Exception ex) { - throw new DAOException(ErrorKeys.ERROR_LOAD_BY_APP_NAME, ex); - } - } - public Application loadByAppId(String productName, String appId) { try { var cb = this.getEntityManager().getCriteriaBuilder(); @@ -93,7 +78,6 @@ public enum ErrorKeys { ERROR_FIND_APPLICATIONS_BY_PRODUCT_NAMES, ERROR_FIND_APPLICATIONS_BY_CRITERIA, - ERROR_LOAD_BY_APP_ID, - ERROR_LOAD_BY_APP_NAME; + ERROR_LOAD_BY_APP_ID; } } diff --git a/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java b/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java index 1c5b255..e44b325 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java +++ b/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java @@ -155,18 +155,6 @@ public void deleteByProducts(String roleId, List productNames) { } } - @Transactional - public void deleteByPermissionIds(List ids) { - try { - var dq = this.deleteQuery(); - var root = dq.from(Assignment.class); - dq.where(root.get(Assignment_.PERMISSION).get(TraceableEntity_.ID).in(ids)); - this.getEntityManager().createQuery(dq).executeUpdate(); - } catch (Exception ex) { - throw new DAOException(ErrorKeys.ERROR_DELETE_BY_PERMISSION_IDS, ex); - } - } - public List findPermissionActionForProducts(Set productNames) { try { var cb = this.getEntityManager().getCriteriaBuilder(); @@ -227,7 +215,6 @@ public enum ErrorKeys { ERROR_LOAD_ASSIGNMENTS, FIND_ENTITY_BY_ID_FAILED, ERROR_FIND_ASSIGNMENT_BY_CRITERIA, - ERROR_SELECT_MANDATORY_BY_ROLE_ID, - ERROR_DELETE_BY_PERMISSION_IDS; + ERROR_SELECT_MANDATORY_BY_ROLE_ID; } } diff --git a/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java b/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java index d77de5e..71d6509 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java +++ b/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java @@ -89,18 +89,6 @@ public List findByProductNames(Collection productNames) { } } - public List findByAppId(String appId) { - try { - var cb = this.getEntityManager().getCriteriaBuilder(); - var cq = cb.createQuery(Permission.class); - var root = cq.from(Permission.class); - cq.where(cb.equal(root.get(Permission_.APP_ID), appId)); - return this.getEntityManager().createQuery(cq).getResultList(); - } catch (Exception ex) { - throw new DAOException(ErrorKeys.ERROR_FIND_BY_APP_ID, ex); - } - } - public List findAllExcludingGivenIds(Collection permissionGuids) { try { var cb = this.getEntityManager().getCriteriaBuilder(); @@ -161,7 +149,6 @@ public enum ErrorKeys { ERROR_FIND_BY_PRODUCT_AND_APP_ID, ERROR_FIND_PERMISSION_BY_CRITERIA, ERROR_FIND_BY_PRODUCT_NAMES, - ERROR_FIND_NOT_BY_IDS, - ERROR_FIND_BY_APP_ID; + ERROR_FIND_NOT_BY_IDS; } } diff --git a/src/main/java/org/tkit/onecx/permission/domain/services/ApplicationService.java b/src/main/java/org/tkit/onecx/permission/domain/services/ApplicationService.java deleted file mode 100644 index 368201c..0000000 --- a/src/main/java/org/tkit/onecx/permission/domain/services/ApplicationService.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.tkit.onecx.permission.domain.services; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import jakarta.transaction.Transactional; - -import org.tkit.onecx.permission.domain.daos.ApplicationDAO; -import org.tkit.onecx.permission.domain.daos.AssignmentDAO; -import org.tkit.onecx.permission.domain.daos.PermissionDAO; -import org.tkit.quarkus.jpa.models.TraceableEntity; - -@ApplicationScoped -public class ApplicationService { - - @Inject - AssignmentDAO assignmentDAO; - - @Inject - PermissionDAO permissionDAO; - - @Inject - ApplicationDAO applicationDAO; - - @Transactional - public void deleteApplicationAndRelatedPermissionsAndAssignmentsById(String id, String applicationId) { - applicationDAO.deleteQueryById(id); - var permissions = permissionDAO.findByAppId(applicationId); - var permissionsIds = permissions.stream().map(TraceableEntity::getId).toList(); - assignmentDAO.deleteByPermissionIds(permissionsIds); - permissionDAO.delete(permissions); - } -} diff --git a/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestController.java b/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestController.java index 4150fae..4f9da73 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestController.java +++ b/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestController.java @@ -8,7 +8,6 @@ import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.server.ServerExceptionMapper; import org.tkit.onecx.permission.domain.daos.ApplicationDAO; -import org.tkit.onecx.permission.domain.services.ApplicationService; import org.tkit.onecx.permission.rs.internal.mappers.ApplicationMapper; import org.tkit.onecx.permission.rs.internal.mappers.ExceptionMapper; import org.tkit.quarkus.log.cdi.LogService; @@ -30,20 +29,6 @@ public class ApplicationRestController implements ApplicationInternalApi { @Inject ApplicationDAO dao; - @Inject - ApplicationService applicationService; - - @Override - public Response deleteByApplicationName(String name) { - var application = dao.loadByName(name); - if (application == null) { - return Response.status(Response.Status.NOT_FOUND).build(); - } - applicationService.deleteApplicationAndRelatedPermissionsAndAssignmentsById(application.getId(), - application.getAppId()); - return Response.status(Response.Status.NO_CONTENT).build(); - } - @Override public Response searchApplications(ApplicationSearchCriteriaDTO applicationSearchCriteriaDTO) { var criteria = mapper.map(applicationSearchCriteriaDTO); diff --git a/src/main/openapi/onecx-permission-internal-openapi.yaml b/src/main/openapi/onecx-permission-internal-openapi.yaml index 6109009..808404d 100644 --- a/src/main/openapi/onecx-permission-internal-openapi.yaml +++ b/src/main/openapi/onecx-permission-internal-openapi.yaml @@ -673,29 +673,6 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetailResponse' - /internal/applications/{name}: - delete: - security: - - oauth2: [ ocx-pm:all, ocx-pm:delete ] - tags: - - applicationInternal - description: delete application by name - operationId: deleteByApplicationName - parameters: - - name: name - in: path - required: true - schema: - type: string - responses: - 204: - description: Application deleted - 400: - description: Bad request - content: - application/json: - schema: - $ref: '#/components/schemas/ProblemDetailResponse' components: securitySchemes: oauth2: diff --git a/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java b/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java index d20a7e7..b22a80b 100644 --- a/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java +++ b/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java @@ -21,8 +21,6 @@ void methodExceptionTests() { ApplicationDAO.ErrorKeys.ERROR_LOAD_BY_APP_ID); methodExceptionTests(() -> dao.findByCriteria(null), ApplicationDAO.ErrorKeys.ERROR_FIND_APPLICATIONS_BY_CRITERIA); - methodExceptionTests(() -> dao.loadByName(null), - ApplicationDAO.ErrorKeys.ERROR_LOAD_BY_APP_NAME); } } diff --git a/src/test/java/org/tkit/onecx/permission/domain/daos/AssignmentDAOTest.java b/src/test/java/org/tkit/onecx/permission/domain/daos/AssignmentDAOTest.java index 17619ec..11fa1e8 100644 --- a/src/test/java/org/tkit/onecx/permission/domain/daos/AssignmentDAOTest.java +++ b/src/test/java/org/tkit/onecx/permission/domain/daos/AssignmentDAOTest.java @@ -37,8 +37,6 @@ void methodExceptionTests() { AssignmentDAO.ErrorKeys.ERROR_FIND_USER_ASSIGNMENTS); methodExceptionTests(() -> dao.loadAssignments(null), AssignmentDAO.ErrorKeys.ERROR_LOAD_ASSIGNMENTS); - methodExceptionTests(() -> dao.deleteByPermissionIds(null), - AssignmentDAO.ErrorKeys.ERROR_DELETE_BY_PERMISSION_IDS); } } diff --git a/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java b/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java index d31e403..8b1bfce 100644 --- a/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java +++ b/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java @@ -29,8 +29,6 @@ void methodExceptionTests() { PermissionDAO.ErrorKeys.ERROR_FIND_NOT_BY_IDS); methodExceptionTests(() -> dao.findUsersPermissions(null, 0, 0), PermissionDAO.ErrorKeys.ERROR_FIND_PERMISSION_FOR_USER); - methodExceptionTests(() -> dao.findByAppId(null), - PermissionDAO.ErrorKeys.ERROR_FIND_BY_APP_ID); } } diff --git a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestControllerTest.java index 9378dde..6645fa7 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/ApplicationRestControllerTest.java @@ -30,7 +30,7 @@ void searchTest() { .auth().oauth2(getKeycloakClientToken("testClient")) .contentType(APPLICATION_JSON) .body(criteria) - .post("/search") + .post() .then() .statusCode(OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -47,7 +47,7 @@ void searchTest() { .auth().oauth2(getKeycloakClientToken("testClient")) .contentType(APPLICATION_JSON) .body(criteria) - .post("/search") + .post() .then() .statusCode(OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -69,7 +69,7 @@ void searchCriteriaTest() { .auth().oauth2(getKeycloakClientToken("testClient")) .contentType(APPLICATION_JSON) .body(criteria) - .post("/search") + .post() .then() .statusCode(OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -87,7 +87,7 @@ void searchNoBodyTest() { var exception = given() .auth().oauth2(getKeycloakClientToken("testClient")) .contentType(APPLICATION_JSON) - .post("/search") + .post() .then() .statusCode(BAD_REQUEST.getStatusCode()) .contentType(APPLICATION_JSON) @@ -98,26 +98,4 @@ void searchNoBodyTest() { assertThat(exception.getErrorCode()).isEqualTo(ExceptionMapper.ErrorKeys.CONSTRAINT_VIOLATIONS.name()); assertThat(exception.getDetail()).isEqualTo("searchApplications.applicationSearchCriteriaDTO: must not be null"); } - - @Test - void deleteApplicationByName() { - given() - .auth().oauth2(getKeycloakClientToken("testClient")) - .contentType(APPLICATION_JSON) - .pathParam("name", "app1") - .delete("/{name}") - .then() - .statusCode(NO_CONTENT.getStatusCode()); - } - - @Test - void deleteApplicationByNotExistingName() { - given() - .auth().oauth2(getKeycloakClientToken("testClient")) - .contentType(APPLICATION_JSON) - .pathParam("name", "notExisting") - .delete("/{name}") - .then() - .statusCode(NOT_FOUND.getStatusCode()); - } }