chore: add code split for refactoring inputs (#32928)

This commit is contained in:
subratadeypappu 2024-04-29 11:26:04 +06:00 committed by GitHub
parent 9ba7036621
commit cc306b0c84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,6 +39,7 @@ import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.appsmith.server.helpers.ContextTypeUtils.getDefaultContextIfNull;
import static com.appsmith.server.services.ce.ApplicationPageServiceCEImpl.EVALUATION_VERSION; import static com.appsmith.server.services.ce.ApplicationPageServiceCEImpl.EVALUATION_VERSION;
@Slf4j @Slf4j
@ -193,27 +194,38 @@ public class RefactoringServiceCEImpl implements RefactoringServiceCE {
RefactorEntityNameDTO refactorEntityNameDTO, RefactorEntityNameDTO refactorEntityNameDTO,
Mono<String> contextIdMono, Mono<String> contextIdMono,
Map<String, String> analyticsProperties) { Map<String, String> analyticsProperties) {
return contextIdMono return contextIdMono.flatMap(branchedContextId -> validateEntityName(refactorEntityNameDTO, branchedContextId)
.flatMap(branchedPageId -> { .then(prepareAnalyticsProperties(refactorEntityNameDTO, contextIdMono, analyticsProperties)));
refactorEntityNameDTO.setPageId(branchedPageId); }
return this.isNameAllowed(
branchedPageId, protected Mono<Map<String, String>> prepareAnalyticsProperties(
CreatorContextType.PAGE, RefactorEntityNameDTO refactorEntityNameDTO,
refactorEntityNameDTO.getLayoutId(), Mono<String> contextIdMono,
refactorEntityNameDTO.getNewFullyQualifiedName()) Map<String, String> analyticsProperties) {
.zipWith(newPageService.getById(branchedPageId)); return contextIdMono.flatMap(branchedPageId -> {
}) refactorEntityNameDTO.setPageId(branchedPageId);
.flatMap(tuple -> { return newPageService.getById(branchedPageId).map(page -> {
analyticsProperties.put( analyticsProperties.put(FieldName.APPLICATION_ID, page.getApplicationId());
FieldName.APPLICATION_ID, tuple.getT2().getApplicationId()); analyticsProperties.put(FieldName.PAGE_ID, refactorEntityNameDTO.getPageId());
analyticsProperties.put(FieldName.PAGE_ID, refactorEntityNameDTO.getPageId()); return analyticsProperties;
if (!tuple.getT1()) { });
});
}
protected Mono<Void> validateEntityName(RefactorEntityNameDTO refactorEntityNameDTO, String contextId) {
return isNameAllowed(
contextId,
getDefaultContextIfNull(refactorEntityNameDTO.getContextType()),
refactorEntityNameDTO.getLayoutId(),
refactorEntityNameDTO.getNewFullyQualifiedName())
.flatMap(valid -> {
if (!valid) {
return Mono.error(new AppsmithException( return Mono.error(new AppsmithException(
AppsmithError.NAME_CLASH_NOT_ALLOWED_IN_REFACTOR, AppsmithError.NAME_CLASH_NOT_ALLOWED_IN_REFACTOR,
refactorEntityNameDTO.getOldFullyQualifiedName(), refactorEntityNameDTO.getOldFullyQualifiedName(),
refactorEntityNameDTO.getNewFullyQualifiedName())); refactorEntityNameDTO.getNewFullyQualifiedName()));
} }
return Mono.just(analyticsProperties); return Mono.empty();
}); });
} }
@ -223,7 +235,7 @@ public class RefactoringServiceCEImpl implements RefactoringServiceCE {
EntityRefactoringService<?> service, EntityRefactoringService<?> service,
Map<String, String> analyticsProperties) { Map<String, String> analyticsProperties) {
return service.updateRefactoredEntity(refactorEntityNameDTO, branchName) return service.updateRefactoredEntity(refactorEntityNameDTO, branchName)
.then(this.refactorName(refactorEntityNameDTO)) .then(Mono.defer(() -> this.refactorName(refactorEntityNameDTO)))
.flatMap(tuple2 -> { .flatMap(tuple2 -> {
AnalyticsEvents event = service.getRefactorAnalyticsEvent(refactorEntityNameDTO.getEntityType()); AnalyticsEvents event = service.getRefactorAnalyticsEvent(refactorEntityNameDTO.getEntityType());
return this.sendRefactorAnalytics(event, analyticsProperties, tuple2.getT2()) return this.sendRefactorAnalytics(event, analyticsProperties, tuple2.getT2())