Skip to content

Commit 7cddc91

Browse files
authored
fix(authority-prefix): delete sequence during deletion of authority-source-file (#253)
fix(authority-prefix): delete sequence during deletion of authority-source-file. Previously, during creation of the authority-source-file with the same prefix as previously deleted authority-source-file, program generated an error that states when you try to recreate a sequence with the same name after deleting the associated row, it encounters a conflict because it thinks the sequence already exists. This commit solves this error by deleting sequence linked to authority-source-file during its deletion. - add deleteSequence method - refactor deleteAuthoritySourceFile_positive_deleteExistingEntity test - refactor shouldDeleteAuthoritySourceFileById test Closes MODELINKS-211
1 parent 4b26c76 commit 7cddc91

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* Make system user usage optional ([MODELINKS-150](https://issues.folio.org/browse/MODELINKS-150) and [MODROLESKC-24](https://issues.folio.org/browse/MODROLESKC-24))
2323
* Propagate authority archives deletion to member tenants ([MODELINKS-195](https://issues.folio.org/browse/MODELINKS-195))
2424
* Implement endpoint for bulk authorities upsert from external file ([MODELINKS-173](https://issues.folio.org/browse/MODELINKS-173))
25-
* Create custom Mockito verifies for Hibernate entities ([MODELINKS-209](https://issues.folio.org/browse/MODELINKS-209))
2625
* Add possibility to filter Authority records by (un)defined fields in Cql query ([MODELINKS-214](https://issues.folio.org/browse/MODELINKS-214))
2726

2827
### Bug fixes
@@ -32,9 +31,10 @@
3231
* Remove foreign key for authority_data_stat ([MODELINKS-155](https://issues.folio.org/browse/MODELINKS-155))
3332
* Fix empty links list propagation ([MODELINKS-166](https://issues.folio.org/browse/MODELINKS-166))
3433
* Fix base url of authority file after linking ([MODELINKS-192](https://folio-org.atlassian.net/browse/MODELINKS-192))
34+
* Fix authority source file sequence deletion ([MODELINKS-211](https://issues.folio.org/browse/MODELINKS-211))
3535

3636
### Tech Dept
37-
* Description ([ISSUE_NUMBER](https://issues.folio.org/browse/ISSUE_NUMBER))
37+
* Create custom Mockito verifies for Hibernate entities ([MODELINKS-209](https://issues.folio.org/browse/MODELINKS-209))
3838

3939
### Dependencies
4040
* Bump `folio-spring-support` from `7.2.0` to `7.2.1`

src/main/java/org/folio/entlinks/controller/delegate/AuthoritySourceFileServiceDelegate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public void deleteAuthoritySourceFileById(UUID id) {
8383
var entity = service.getById(id);
8484
validateActionRightsForTenant(DomainEventType.DELETE);
8585

86+
if (entity.getSequenceName() != null) {
87+
service.deleteSequence(entity.getSequenceName());
88+
}
8689
service.deleteById(id);
8790
propagationService.propagate(entity, DELETE, context.getTenantId());
8891
}

src/main/java/org/folio/entlinks/service/authority/AuthoritySourceFileService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ public void createSequence(String sequenceName, int startNumber) {
158158
jdbcTemplate.execute(command);
159159
}
160160

161+
public void deleteSequence(String sequenceName) {
162+
var command = String.format("""
163+
DROP SEQUENCE IF EXISTS %s.%s;
164+
""",
165+
moduleMetadata.getDBSchemaName(folioExecutionContext.getTenantId()), sequenceName);
166+
jdbcTemplate.execute(command);
167+
}
168+
161169
public String nextHrid(UUID id) {
162170
log.debug("nextHrid:: Attempting to get next AuthoritySourceFile HRID [id: {}]", id);
163171
var sourceFile = getById(id);

src/test/java/org/folio/entlinks/controller/AuthoritySourceFilesControllerIT.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,22 @@ void updateWithOldVersion_negative_shouldReturnOptimisticLockingError() throws E
407407
@Test
408408
@DisplayName("DELETE: Should delete existing authority source file")
409409
void deleteAuthoritySourceFile_positive_deleteExistingEntity() {
410-
var sourceFile = prepareAuthoritySourceFile(0);
411-
sourceFile.setSequenceName(String.format("hrid_authority_local_file_%s_seq", SOURCE_FILE_CODE_IDS[0]));
412-
createAuthoritySourceFile(sourceFile);
410+
var id = UUID.randomUUID();
411+
var code = "abc";
412+
var startNumber = 1;
413+
var dto = new AuthoritySourceFilePostDto()
414+
.id(id)
415+
.name("name")
416+
.code(code)
417+
.hridManagement(new AuthoritySourceFilePostDtoHridManagement().startNumber(startNumber));
413418

414-
doDelete(authoritySourceFilesEndpoint(sourceFile.getId()));
419+
doPost(authoritySourceFilesEndpoint(), dto);
420+
doDelete(authoritySourceFilesEndpoint(id));
415421

416422
assertEquals(0, databaseHelper.countRows(DatabaseHelper.AUTHORITY_SOURCE_FILE_TABLE, TENANT_ID));
417423
assertEquals(0, databaseHelper.countRows(DatabaseHelper.AUTHORITY_SOURCE_FILE_CODE_TABLE, TENANT_ID));
418-
assertNull(databaseHelper.queryAuthoritySourceFileSequenceStartNumber(sourceFile.getSequenceName()));
424+
var sequenceName = String.format("hrid_authority_local_file_%s_seq", code);
425+
assertNull(databaseHelper.queryAuthoritySourceFileSequenceStartNumber(sequenceName));
419426
}
420427

421428
@Test

src/test/java/org/folio/entlinks/controller/delegate/AuthoritySourceFileServiceDelegateTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ void shouldDeleteAuthoritySourceFileById() {
246246

247247
delegate.deleteAuthoritySourceFileById(existing.getId());
248248

249+
verify(service).deleteSequence(existing.getSequenceName());
249250
verify(service).deleteById(existing.getId());
250251
verify(propagationService).propagate(existing, DELETE, TENANT_ID);
251252
}

0 commit comments

Comments
 (0)