From d96b681e1fb36679636c02bae462163b6b58b1f1 Mon Sep 17 00:00:00 2001 From: srishtisingh-eu Date: Fri, 21 May 2021 17:46:08 +0200 Subject: [PATCH 1/3] EA-2560 delete deprected Entity --- .../web/EntityAdminControllerIT.java | 21 +++++++++++++++++++ .../web/EntityAdminController.java | 10 ++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/entity-management-web/src/integration-test/java/eu/europeana/entitymanagement/web/EntityAdminControllerIT.java b/entity-management-web/src/integration-test/java/eu/europeana/entitymanagement/web/EntityAdminControllerIT.java index 4778e2d0..dd8da0b1 100644 --- a/entity-management-web/src/integration-test/java/eu/europeana/entitymanagement/web/EntityAdminControllerIT.java +++ b/entity-management-web/src/integration-test/java/eu/europeana/entitymanagement/web/EntityAdminControllerIT.java @@ -94,6 +94,27 @@ void permanentDeletionShouldBeSuccessful() throws Exception { Assertions.assertTrue(dbRecordOptional.isEmpty()); } + @Test + void permanentDeletionForDeprecatedEntityShouldBeSuccessful() throws Exception { + // create disabled entity in DB + Concept concept = objectMapper.readValue(loadFile(CONCEPT_JSON), Concept.class); + EntityRecord entityRecord = new EntityRecord(); + entityRecord.setEntity(concept); + entityRecord.setEntityId(concept.getEntityId()); + entityRecord.setDisabled(true); + EntityRecord record = entityRecordService.saveEntityRecord(entityRecord); + + String requestPath = getEntityRequestPath(record.getEntityId()); + + mockMvc.perform(delete(BASE_SERVICE_URL + "/" + requestPath + BASE_ADMIN_URL) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isNoContent()); + + // check that record is deleted + Optional dbRecordOptional = entityRecordService.retrieveEntityRecordByUri(record.getEntityId()); + Assertions.assertTrue(dbRecordOptional.isEmpty()); + } + @Test void migrationExistingEntityShouldBeSuccessful() throws Exception { String requestBody = "{\"id\" : \"" + BaseMvcTestUtils.VALID_MIGRATION_ID + "\"}"; diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java index 6d3fd007..b759a758 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java @@ -8,6 +8,7 @@ import eu.europeana.api.commons.web.model.vocabulary.Operations; import eu.europeana.entitymanagement.common.config.EntityManagementConfiguration; import eu.europeana.entitymanagement.definitions.model.EntityRecord; +import eu.europeana.entitymanagement.exception.EntityNotFoundException; import eu.europeana.entitymanagement.vocabulary.EntityProfile; import eu.europeana.entitymanagement.vocabulary.FormatTypes; import eu.europeana.entitymanagement.vocabulary.WebEntityConstants; @@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; +import java.util.Optional; @RestController @Validated @@ -59,7 +61,13 @@ public ResponseEntity deleteEntity( if (emConfig.isAuthEnabled()) { verifyWriteAccess(Operations.DELETE, request); } - EntityRecord entityRecord = entityRecordService.retrieveEntityRecord(type, identifier.toLowerCase()); + String entityUri = EntityRecordUtils.buildEntityIdUri(type, identifier); + Optional entityRecordOptional = entityRecordService.retrieveEntityRecordByUri(entityUri); + if (entityRecordOptional.isEmpty()) { + throw new EntityNotFoundException(entityUri); + } + EntityRecord entityRecord = entityRecordOptional.get(); + LOG.debug("Deleting permanently entity : {}/{}", type, identifier); entityRecordService.delete(entityRecord.getEntityId()); return ResponseEntity.noContent().build(); From b9e49d05809df3c0f7df7683d940a3b14497a03d Mon Sep 17 00:00:00 2001 From: srishtisingh-eu Date: Fri, 21 May 2021 17:53:31 +0200 Subject: [PATCH 2/3] EA-2560 improved log --- .../europeana/entitymanagement/web/EntityAdminController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java index b759a758..7bb55098 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java @@ -68,7 +68,7 @@ public ResponseEntity deleteEntity( } EntityRecord entityRecord = entityRecordOptional.get(); - LOG.debug("Deleting permanently entity : {}/{}", type, identifier); + LOG.debug("Deleting permanently{}entity : {}/{}", (entityRecord.isDisabled() ? " deprecated " : " "), type, identifier); entityRecordService.delete(entityRecord.getEntityId()); return ResponseEntity.noContent().build(); } From 908142db49567beb9b537fa54e3a807fa71cccb4 Mon Sep 17 00:00:00 2001 From: Immanuel Kattey Date: Tue, 25 May 2021 17:23:02 +0100 Subject: [PATCH 3/3] EA-2540: Small logging improvement --- .../europeana/entitymanagement/web/EntityAdminController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java index 7bb55098..747335dc 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EntityAdminController.java @@ -68,7 +68,7 @@ public ResponseEntity deleteEntity( } EntityRecord entityRecord = entityRecordOptional.get(); - LOG.debug("Deleting permanently{}entity : {}/{}", (entityRecord.isDisabled() ? " deprecated " : " "), type, identifier); + LOG.info("Permanently deleting entityId={}", entityRecord.getEntityId()); entityRecordService.delete(entityRecord.getEntityId()); return ResponseEntity.noContent().build(); }