chore: Split update layout (#29149)

This commit is contained in:
subratadeypappu 2023-11-28 11:14:27 +06:00 committed by GitHub
parent 2b7c4178f8
commit da2e1c2822
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 48 deletions

View File

@ -16,4 +16,6 @@ public interface UpdateLayoutServiceCE {
String defaultApplicationId, String branchName, UpdateMultiplePageLayoutDTO updateMultiplePageLayoutDTO);
JSONObject unescapeMongoSpecialCharacters(Layout layout);
Mono<String> updatePageLayoutsByPageId(String pageId);
}

View File

@ -285,6 +285,24 @@ public class UpdateLayoutServiceCEImpl implements UpdateLayoutServiceCE {
return dsl;
}
@Override
public Mono<String> updatePageLayoutsByPageId(String pageId) {
return Mono.justOrEmpty(pageId)
// fetch the unpublished page
.flatMap(id -> newPageService.findPageById(id, pagePermission.getEditPermission(), false))
.flatMapMany(page -> {
if (page.getLayouts() == null) {
return Mono.empty();
}
return Flux.fromIterable(page.getLayouts()).flatMap(layout -> {
layout.setDsl(this.unescapeMongoSpecialCharacters(layout));
return this.updateLayout(page.getId(), page.getApplicationId(), layout.getId(), layout);
});
})
.collectList()
.then(Mono.just(pageId));
}
private JSONObject unEscapeDslKeys(JSONObject dsl, Set<String> escapedWidgetNames) {
String widgetName = (String) dsl.get(FieldName.WIDGET_NAME);

View File

@ -15,8 +15,6 @@ public interface LayoutActionServiceCE {
Mono<ActionDTO> updateSingleAction(String id, ActionDTO action);
Mono<String> updatePageLayoutsByPageId(String pageId);
Mono<ActionDTO> updateSingleActionWithBranchName(String id, ActionDTO action, String branchName);
Mono<ActionDTO> setExecuteOnLoad(String id, Boolean isExecuteOnLoad);

View File

@ -74,9 +74,9 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
// The change was not in CollectionId, just go ahead and update normally
if (action.getCollectionId() == null) {
return this.updateSingleAction(id, action)
.flatMap(updatedAction -> this.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
return this.updateSingleAction(id, action).flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
} else if (action.getCollectionId().length() == 0) {
// The Action has been removed from existing collection.
return newActionService
@ -86,9 +86,9 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
.flatMap(action1 -> {
log.debug("Action {} has been removed from its collection.", action1.getId());
action.setCollectionId(null);
return this.updateSingleAction(id, action)
.flatMap(updatedAction -> this.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
return this.updateSingleAction(id, action).flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
});
} else {
// If the code flow has reached this point, that means that the collectionId has been changed to another
@ -114,9 +114,9 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
log.debug(
"Action {} removed from its previous collection and added to the new collection",
action1.getId());
return this.updateSingleAction(id, action)
.flatMap(updatedAction -> this.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
return this.updateSingleAction(id, action).flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
});
}
}
@ -260,7 +260,8 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
return newActionService
.findByBranchNameAndDefaultActionId(branchName, defaultActionId, actionPermission.getEditPermission())
.flatMap(newAction -> updateSingleAction(newAction.getId(), action))
.flatMap(updatedAction -> this.updatePageLayoutsByPageId(pageId).thenReturn(updatedAction))
.flatMap(updatedAction ->
updateLayoutService.updatePageLayoutsByPageId(pageId).thenReturn(updatedAction))
.map(responseUtils::updateActionDTOWithDefaultResources)
.zipWith(
newPageService.findPageById(pageId, pagePermission.getEditPermission(), false),
@ -287,7 +288,8 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
newAction.setUnpublishedAction(action);
return newActionService.save(newAction).flatMap(savedAction -> updatePageLayoutsByPageId(
return newActionService.save(newAction).flatMap(savedAction -> updateLayoutService
.updatePageLayoutsByPageId(
savedAction.getUnpublishedAction().getPageId())
.then(newActionService.generateActionByViewMode(savedAction, false)));
});
@ -308,7 +310,8 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
public Mono<ActionDTO> deleteUnpublishedAction(String id) {
return newActionService
.deleteUnpublishedAction(id)
.flatMap(actionDTO -> Mono.zip(Mono.just(actionDTO), updatePageLayoutsByPageId(actionDTO.getPageId())))
.flatMap(actionDTO -> Mono.zip(
Mono.just(actionDTO), updateLayoutService.updatePageLayoutsByPageId(actionDTO.getPageId())))
.flatMap(tuple -> {
ActionDTO actionDTO = tuple.getT1();
return Mono.just(actionDTO);
@ -322,25 +325,6 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
.map(responseUtils::updateActionDTOWithDefaultResources);
}
@Override
public Mono<String> updatePageLayoutsByPageId(String pageId) {
return Mono.justOrEmpty(pageId)
// fetch the unpublished page
.flatMap(id -> newPageService.findPageById(id, pagePermission.getEditPermission(), false))
.flatMapMany(page -> {
if (page.getLayouts() == null) {
return Mono.empty();
}
return Flux.fromIterable(page.getLayouts()).flatMap(layout -> {
layout.setDsl(updateLayoutService.unescapeMongoSpecialCharacters(layout));
return updateLayoutService.updateLayout(
page.getId(), page.getApplicationId(), layout.getId(), layout);
});
})
.collectList()
.then(Mono.just(pageId));
}
@Override
public Mono<ActionDTO> createSingleActionWithBranch(ActionDTO action, String branchName) {

View File

@ -231,7 +231,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE
actionDTOList,
false));
})
.flatMap(updatedCollection -> layoutActionService
.flatMap(updatedCollection -> updateLayoutService
.updatePageLayoutsByPageId(updatedCollection.getPageId())
.thenReturn(updatedCollection));
});
@ -578,7 +578,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE
})
.flatMap(actionCollection -> actionCollectionService.update(actionCollection.getId(), actionCollection))
.flatMap(actionCollectionRepository::setUserPermissionsInObject)
.flatMap(savedActionCollection -> layoutActionService
.flatMap(savedActionCollection -> updateLayoutService
.updatePageLayoutsByPageId(
savedActionCollection.getUnpublishedCollection().getPageId())
.thenReturn(savedActionCollection))

View File

@ -289,7 +289,7 @@ public class ActionCollectionServiceImplTest {
Mockito.when(layoutActionService.createAction(Mockito.any())).thenReturn(Mono.just(new ActionDTO()));
Mockito.when(layoutActionService.updatePageLayoutsByPageId(Mockito.anyString()))
Mockito.when(updateLayoutService.updatePageLayoutsByPageId(Mockito.anyString()))
.thenAnswer(invocationOnMock -> {
return Mono.just(actionCollectionDTO.getPageId());
});
@ -359,7 +359,7 @@ public class ActionCollectionServiceImplTest {
return Mono.just(argument);
});
Mockito.when(layoutActionService.updatePageLayoutsByPageId(Mockito.anyString()))
Mockito.when(updateLayoutService.updatePageLayoutsByPageId(Mockito.anyString()))
.thenAnswer(invocationOnMock -> {
return Mono.just(actionCollectionDTO.getPageId());
});
@ -530,7 +530,7 @@ public class ActionCollectionServiceImplTest {
Mockito.when(actionCollectionRepository.setUserPermissionsInObject(Mockito.any()))
.thenReturn(Mono.just(modifiedActionCollection));
Mockito.when(layoutActionService.updatePageLayoutsByPageId(Mockito.anyString()))
Mockito.when(updateLayoutService.updatePageLayoutsByPageId(Mockito.anyString()))
.thenAnswer(invocationOnMock -> {
return Mono.just(actionCollection.getUnpublishedCollection().getPageId());
});

View File

@ -293,7 +293,7 @@ public class LayoutActionServiceTest {
// Save updated configuration and re-compute on page load actions.
return layoutActionService
.updateSingleAction(savedAction.getId(), updates)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
})
@ -362,7 +362,7 @@ public class LayoutActionServiceTest {
updates.setDatasource(datasource);
return layoutActionService
.updateSingleAction(savedAction.getId(), updates)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
})
@ -375,7 +375,7 @@ public class LayoutActionServiceTest {
updates.setDatasource(datasource);
return layoutActionService
.updateSingleAction(savedAction.getId(), updates)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
})
@ -390,7 +390,7 @@ public class LayoutActionServiceTest {
updates.setDatasource(d2);
return layoutActionService
.updateSingleAction(savedAction.getId(), updates)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
})
@ -564,7 +564,7 @@ public class LayoutActionServiceTest {
updates.setDatasource(ds);
return layoutActionService
.updateSingleAction(savedAction.getId(), updates)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
});
@ -836,7 +836,7 @@ public class LayoutActionServiceTest {
// Save updated configuration and re-compute on page load actions.
return layoutActionService
.updateSingleAction(savedAction.getId(), updates)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
})
@ -852,7 +852,7 @@ public class LayoutActionServiceTest {
// Save updated configuration and re-compute on page load actions.
return layoutActionService
.updateSingleAction(savedAction.getId(), updates)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
})

View File

@ -848,7 +848,7 @@ public class ActionServiceCE_Test {
actionUpdate.getActionConfiguration().setBody("New Body");
return layoutActionService
.updateSingleAction(preUpdateAction.getId(), actionUpdate)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
});
@ -1069,7 +1069,7 @@ public class ActionServiceCE_Test {
actionUpdate.getActionConfiguration().setBody("New Body");
return layoutActionService
.updateSingleAction(preUpdateAction.getId(), actionUpdate)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
});
@ -1105,7 +1105,7 @@ public class ActionServiceCE_Test {
action.getActionConfiguration().setBody("New Body");
return layoutActionService
.updateSingleAction(preUpdateAction.getId(), action)
.flatMap(updatedAction -> layoutActionService
.flatMap(updatedAction -> updateLayoutService
.updatePageLayoutsByPageId(updatedAction.getPageId())
.thenReturn(updatedAction));
});