chore: add code split for refactoring inputs (#32928)
This commit is contained in:
parent
9ba7036621
commit
cc306b0c84
|
|
@ -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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Mono<Map<String, String>> prepareAnalyticsProperties(
|
||||||
|
RefactorEntityNameDTO refactorEntityNameDTO,
|
||||||
|
Mono<String> contextIdMono,
|
||||||
|
Map<String, String> analyticsProperties) {
|
||||||
|
return contextIdMono.flatMap(branchedPageId -> {
|
||||||
refactorEntityNameDTO.setPageId(branchedPageId);
|
refactorEntityNameDTO.setPageId(branchedPageId);
|
||||||
return this.isNameAllowed(
|
return newPageService.getById(branchedPageId).map(page -> {
|
||||||
branchedPageId,
|
analyticsProperties.put(FieldName.APPLICATION_ID, page.getApplicationId());
|
||||||
CreatorContextType.PAGE,
|
analyticsProperties.put(FieldName.PAGE_ID, refactorEntityNameDTO.getPageId());
|
||||||
|
return analyticsProperties;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Mono<Void> validateEntityName(RefactorEntityNameDTO refactorEntityNameDTO, String contextId) {
|
||||||
|
return isNameAllowed(
|
||||||
|
contextId,
|
||||||
|
getDefaultContextIfNull(refactorEntityNameDTO.getContextType()),
|
||||||
refactorEntityNameDTO.getLayoutId(),
|
refactorEntityNameDTO.getLayoutId(),
|
||||||
refactorEntityNameDTO.getNewFullyQualifiedName())
|
refactorEntityNameDTO.getNewFullyQualifiedName())
|
||||||
.zipWith(newPageService.getById(branchedPageId));
|
.flatMap(valid -> {
|
||||||
})
|
if (!valid) {
|
||||||
.flatMap(tuple -> {
|
|
||||||
analyticsProperties.put(
|
|
||||||
FieldName.APPLICATION_ID, tuple.getT2().getApplicationId());
|
|
||||||
analyticsProperties.put(FieldName.PAGE_ID, refactorEntityNameDTO.getPageId());
|
|
||||||
if (!tuple.getT1()) {
|
|
||||||
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())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user