Skip to content

Commit

Permalink
fix: removed application deletion (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter authored Nov 22, 2024
1 parent ebc91e9 commit 6308d6d
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ public PageResult<Application> 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();
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,6 @@ public void deleteByProducts(String roleId, List<String> productNames) {
}
}

@Transactional
public void deleteByPermissionIds(List<String> 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<PermissionAction> findPermissionActionForProducts(Set<String> productNames) {
try {
var cb = this.getEntityManager().getCriteriaBuilder();
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ public List<Permission> findByProductNames(Collection<String> productNames) {
}
}

public List<Permission> 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<Permission> findAllExcludingGivenIds(Collection<String> permissionGuids) {
try {
var cb = this.getEntityManager().getCriteriaBuilder();
Expand Down Expand Up @@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
23 changes: 0 additions & 23 deletions src/main/openapi/onecx-permission-internal-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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());
}
}

0 comments on commit 6308d6d

Please sign in to comment.