Skip to content

Commit

Permalink
Merge pull request #74 from europeana/EA-2540_dleteDeprecatedEntity
Browse files Browse the repository at this point in the history
EA-2540: Enable deletion of deprecated entities
  • Loading branch information
ikattey authored May 25, 2021
2 parents 8513464 + 908142d commit d127183
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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<EntityRecord> dbRecordOptional = entityRecordService.retrieveEntityRecordByUri(record.getEntityId());
Assertions.assertTrue(dbRecordOptional.isEmpty());
}

@Test
void migrationExistingEntityShouldBeSuccessful() throws Exception {
String requestBody = "{\"id\" : \"" + BaseMvcTestUtils.VALID_MIGRATION_ID + "\"}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

@RestController
@Validated
Expand Down Expand Up @@ -59,8 +61,14 @@ public ResponseEntity<String> deleteEntity(
if (emConfig.isAuthEnabled()) {
verifyWriteAccess(Operations.DELETE, request);
}
EntityRecord entityRecord = entityRecordService.retrieveEntityRecord(type, identifier.toLowerCase());
LOG.debug("Deleting permanently entity : {}/{}", type, identifier);
String entityUri = EntityRecordUtils.buildEntityIdUri(type, identifier);
Optional<EntityRecord> entityRecordOptional = entityRecordService.retrieveEntityRecordByUri(entityUri);
if (entityRecordOptional.isEmpty()) {
throw new EntityNotFoundException(entityUri);
}
EntityRecord entityRecord = entityRecordOptional.get();

LOG.info("Permanently deleting entityId={}", entityRecord.getEntityId());
entityRecordService.delete(entityRecord.getEntityId());
return ResponseEntity.noContent().build();
}
Expand Down

0 comments on commit d127183

Please sign in to comment.