Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 1.9.2

### Fixed
- Fix `NoSuchElementException` in `revertLinksForComposition` by safely unwrapping `Optional` when looking up draft and active entities in the CDS model
- Skip credential fetch and SDM revert call when no draft links are found, avoiding unnecessary processing

## Version 1.9.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</developers>

<properties>
<revision>1.9.1</revision>
<revision>1.9.2</revision>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,15 @@ private void revertLinksForComposition(

CdsModel model = context.getModel();
String draftEntityName = attachmentCompositionDefinition + "_drafts";
CdsEntity draftEntity = model.findEntity(draftEntityName).get();
CdsEntity activeEntity = model.findEntity(attachmentCompositionDefinition).get();

Optional<CdsEntity> draftEntityOpt = model.findEntity(draftEntityName);
Optional<CdsEntity> activeEntityOpt = model.findEntity(attachmentCompositionDefinition);
if (!draftEntityOpt.isPresent() || !activeEntityOpt.isPresent()) {
logger.debug(
"Entity not found in model, skipping revert for: {}", attachmentCompositionDefinition);
return;
}
CdsEntity draftEntity = draftEntityOpt.get();
CdsEntity activeEntity = activeEntityOpt.get();
final String upIdKey = SDMUtils.getUpIdKey(draftEntity);
if (upIdKey == null || upIdKey.isEmpty()) {
logger.debug("No upIdKey found, skipping revert for: {}", attachmentCompositionDefinition);
Expand All @@ -297,6 +303,9 @@ private void revertLinksForComposition(

Result draftLinks = persistenceService.run(selectDraftLinks);
logger.debug("Found {} draft links to process", draftLinks.rowCount());
if (draftLinks.rowCount() == 0) {
return;
}
SDMCredentials sdmCredentials = tokenHandler.getSDMCredentials();
Boolean isSystemUser = context.getUserInfo().isSystemUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2149,8 +2149,8 @@ void testRevertLinksForComposition() throws Exception {

Result draftLinksResult = mock(Result.class);
Row draftLinkRow = mock(Row.class);
when(draftLinksResult.rowCount()).thenReturn(1L);
when(draftLinksResult.iterator()).thenReturn(Arrays.asList(draftLinkRow).iterator());
when(persistenceService.run(any(CqnSelect.class))).thenReturn(draftLinksResult);

when(draftLinkRow.get("ID")).thenReturn("attachment123");
when(draftLinkRow.get("linkUrl")).thenReturn("http://draft-url.com");
Expand Down Expand Up @@ -2244,8 +2244,8 @@ void testRevertLinksForComposition_NoLinksToRevert() throws Exception {
});

verify(persistenceService, times(1)).run(any(CqnSelect.class));
verify(tokenHandler, times(1)).getSDMCredentials();
verify(context, times(1)).getUserInfo();
verify(tokenHandler, never()).getSDMCredentials();
verify(context, never()).getUserInfo();
}

@Test
Expand All @@ -2266,6 +2266,7 @@ void testRevertLinksForComposition_SameUrls() throws Exception {

Result draftLinksResult = mock(Result.class);
Row draftLinkRow = mock(Row.class);
when(draftLinksResult.rowCount()).thenReturn(1L);
when(draftLinksResult.iterator()).thenReturn(Arrays.asList(draftLinkRow).iterator());

when(draftLinkRow.get("ID")).thenReturn("attachment123");
Expand Down
Loading