diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java index 1f95d7f46b..ebe45d879b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java @@ -62,6 +62,8 @@ public interface ActionCollectionServiceCE extends CrudService findByPageIds(List pageIds, Optional permission); + Flux findByPageIdsForExport(List pageIds, Optional permission); + Mono findByBranchNameAndDefaultCollectionId( String branchName, String defaultCollectionId, AclPermission permission); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java index 70649c13ad..d6377b65cd 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java @@ -366,7 +366,8 @@ public class ActionCollectionServiceCEImpl extends BaseService { Mono modifiedActionCollectionMono; - if (toDelete.getPublishedCollection() != null) { + if (toDelete.getPublishedCollection() != null + && toDelete.getPublishedCollection().getName() != null) { toDelete.getUnpublishedCollection().setDeletedAt(Instant.now()); modifiedActionCollectionMono = Flux.fromIterable(toDelete.getUnpublishedCollection() .getDefaultToBranchedActionIdsMap() @@ -488,6 +489,11 @@ public class ActionCollectionServiceCEImpl extends BaseService findByPageIdsForExport(List pageIds, Optional permission) { + return repository.findByPageIds(pageIds, permission); + } + @Override public Mono archiveById(String id) { Mono actionCollectionMono = repository diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java index 72465cc358..7163878850 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java @@ -48,8 +48,8 @@ public class ActionCollectionExportableServiceCEImpl implements ExportableServic Optional optionalPermission = Optional.ofNullable(actionPermission.getExportPermission( exportingMetaDTO.getIsGitSync(), exportingMetaDTO.getExportWithConfiguration())); - Flux actionCollectionFlux = - actionCollectionService.findByPageIds(exportingMetaDTO.getUnpublishedPages(), optionalPermission); + Flux actionCollectionFlux = actionCollectionService.findByPageIdsForExport( + exportingMetaDTO.getUnpublishedPages(), optionalPermission); return actionCollectionFlux .collectList() .map(actionCollectionList -> { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java index 291fbdeeb0..0901af500c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java @@ -18,6 +18,7 @@ import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.helpers.DefaultResourcesUtils; import com.appsmith.server.imports.importable.ImportableServiceCE; import com.appsmith.server.repositories.ActionCollectionRepository; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -34,16 +35,11 @@ import java.util.Set; import static com.appsmith.external.helpers.AppsmithBeanUtils.copyNestedNonNullProperties; @Slf4j +@RequiredArgsConstructor public class ActionCollectionImportableServiceCEImpl implements ImportableServiceCE { private final ActionCollectionService actionCollectionService; private final ActionCollectionRepository repository; - public ActionCollectionImportableServiceCEImpl( - ActionCollectionService actionCollectionService, ActionCollectionRepository repository) { - this.actionCollectionService = actionCollectionService; - this.repository = repository; - } - // Requires pageNameMap, pageNameToOldNameMap, pluginMap and actionResultDTO to be present in importable resources. // Updates actionCollectionResultDTO in importable resources. // Also directly updates required information in DB @@ -230,6 +226,10 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic Set existingPolicy = existingActionCollection.getPolicies(); copyNestedNonNullProperties(actionCollection, existingActionCollection); + + populateDomainMappedReferences( + mappedImportableResourcesDTO, existingActionCollection); + // Update branchName existingActionCollection .getDefaultResources() @@ -296,6 +296,8 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic actionCollection.getApplicationId() + "_" + new ObjectId()); } + populateDomainMappedReferences(mappedImportableResourcesDTO, actionCollection); + // it's new actionCollection newActionCollections.add(actionCollection); resultDTO.getSavedActionCollectionIds().add(actionCollection.getId()); @@ -318,6 +320,11 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic }); } + protected void populateDomainMappedReferences( + MappedImportableResourcesDTO mappedImportableResourcesDTO, ActionCollection actionCollection) { + // Nothing needs to be copied into the action collection from mapped resources + } + private NewPage updatePageInActionCollection(ActionCollectionDTO collectionDTO, Map pageNameMap) { NewPage parentPage = pageNameMap.get(collectionDTO.getPageId()); if (parentPage == null) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ImportingMetaDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ImportingMetaDTO.java index 81b2694879..6ea04a37f8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ImportingMetaDTO.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ImportingMetaDTO.java @@ -6,6 +6,8 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.Set; + @Data @AllArgsConstructor @NoArgsConstructor @@ -16,4 +18,5 @@ public class ImportingMetaDTO { String branchName; Boolean appendToApp; ImportApplicationPermissionProvider permissionProvider; + Set currentUserPermissionGroups; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java index badba2e807..b140ef51f6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java @@ -61,7 +61,7 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC private final ExportableService pluginExportableService; private final ExportableService newPageExportableService; protected final ExportableService newActionExportableService; - private final ExportableService actionCollectionExportableService; + protected final ExportableService actionCollectionExportableService; private final ExportableService themeExportableService; private final ExportableService customJSLibExportableService; @@ -193,9 +193,6 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC newPageExportableService.sanitizeEntities(exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor); - newActionExportableService.sanitizeEntities( - exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor); - return Mono.empty().then(); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java index f672f34664..a5f0be931f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java @@ -499,8 +499,7 @@ public class GitFileUtils { private void removeUnwantedFieldFromAction(NewAction action) { // As we are publishing the app and then committing to git we expect the published and unpublished ActionDTO - // will - // be same, so we only commit unpublished ActionDTO. + // will be same, so we only commit unpublished ActionDTO. action.setPublishedAction(null); removeUnwantedFieldsFromBaseDomain(action); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java index 5db393053e..f905cf375c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java @@ -32,6 +32,7 @@ import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.repositories.PermissionGroupRepository; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.ApplicationPageService; +import com.appsmith.server.services.PermissionGroupService; import com.appsmith.server.services.SessionUserService; import com.appsmith.server.services.WorkspaceService; import com.appsmith.server.solutions.ActionPermission; @@ -93,6 +94,7 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC private final ImportableService datasourceImportableService; private final ImportableService newActionImportableService; private final ImportableService actionCollectionImportableService; + private final PermissionGroupService permissionGroupService; @Override public Mono extractFileAndSaveApplication(String workspaceId, Part filePart) { @@ -205,8 +207,13 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC return Mono.error(new AppsmithException( AppsmithError.UNSUPPORTED_IMPORT_OPERATION_FOR_GIT_CONNECTED_APPLICATION)); } else { + Mono> permissionGroupIdsMono = permissionGroupService.getSessionUserPermissionGroupIds(); return getPermissionProviderForUpdateNonGitConnectedAppFromJson() - .flatMap(permissionProvider -> { + .zipWith(permissionGroupIdsMono) + .flatMap(tuple2 -> { + ImportApplicationPermissionProvider permissionProvider = tuple2.getT1(); + Set permissionGroups = tuple2.getT2(); + if (!StringUtils.isEmpty(applicationId) && applicationJson.getExportedApplication() != null) { // Remove the application name from JSON file as updating the application name is not @@ -223,7 +230,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC applicationId, null, false, - permissionProvider) + permissionProvider, + permissionGroups) .onErrorResume(error -> { if (error instanceof AppsmithException) { return Mono.error(error); @@ -268,7 +276,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC .currentUserPermissionGroups(userPermissionGroups) .build(); - return importApplicationInWorkspace(workspaceId, importedDoc, null, null, false, permissionProvider); + return importApplicationInWorkspace( + workspaceId, importedDoc, null, null, false, permissionProvider, userPermissionGroups); }); } @@ -303,7 +312,13 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC .currentUserPermissionGroups(userPermissionGroups) .build(); return importApplicationInWorkspace( - workspaceId, importedDoc, applicationId, branchName, false, permissionProvider); + workspaceId, + importedDoc, + applicationId, + branchName, + false, + permissionProvider, + userPermissionGroups); }); } @@ -326,7 +341,13 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC .currentUserPermissionGroups(userPermissionGroups) .build(); return importApplicationInWorkspace( - workspaceId, importedDoc, applicationId, branchName, false, permissionProvider); + workspaceId, + importedDoc, + applicationId, + branchName, + false, + permissionProvider, + userPermissionGroups); }); } @@ -408,11 +429,11 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC if (importingMetaDTO.getAppendToApp()) { // we don't need to do anything with the imported application importApplicationMono = existingApplicationMono; } else { - importApplicationMono = importApplicationMono - .zipWith(existingApplicationMono) + importApplicationMono = Mono.zip(importApplicationMono, existingApplicationMono) .map(objects -> { Application newApplication = objects.getT1(); Application existingApplication = objects.getT2(); + // This method sets the published mode properties in the imported // application.When a user imports an application from the git repo, // since the git only stores the unpublished version, the current @@ -477,7 +498,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC String applicationId, String branchName, boolean appendToApp, - ImportApplicationPermissionProvider permissionProvider) { + ImportApplicationPermissionProvider permissionProvider, + Set permissionGroups) { /* 1. Migrate resource to latest schema 2. Fetch workspace by id @@ -504,8 +526,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC AppsmithError.VALIDATION_FAILURE, "Field '" + errorField + "' is missing in the JSON.")); } - ImportingMetaDTO importingMetaDTO = - new ImportingMetaDTO(workspaceId, applicationId, branchName, appendToApp, permissionProvider); + ImportingMetaDTO importingMetaDTO = new ImportingMetaDTO( + workspaceId, applicationId, branchName, appendToApp, permissionProvider, permissionGroups); MappedImportableResourcesDTO mappedImportableResourcesDTO = new MappedImportableResourcesDTO(); @@ -886,7 +908,13 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC .currentUserPermissionGroups(userPermissionGroups) .build(); return importApplicationInWorkspace( - workspaceId, applicationJson, applicationId, branchName, true, permissionProvider); + workspaceId, + applicationJson, + applicationId, + branchName, + true, + permissionProvider, + userPermissionGroups); }); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceImpl.java index 1a74c9c47e..fad710977a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceImpl.java @@ -14,6 +14,7 @@ import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.repositories.PermissionGroupRepository; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.ApplicationPageService; +import com.appsmith.server.services.PermissionGroupService; import com.appsmith.server.services.SessionUserService; import com.appsmith.server.services.WorkspaceService; import com.appsmith.server.solutions.ActionPermission; @@ -31,7 +32,6 @@ import org.springframework.transaction.reactive.TransactionalOperator; @Service @Primary public class ImportApplicationServiceImpl extends ImportApplicationServiceCEImpl implements ImportApplicationService { - public ImportApplicationServiceImpl( DatasourceService datasourceService, SessionUserService sessionUserService, @@ -54,7 +54,8 @@ public class ImportApplicationServiceImpl extends ImportApplicationServiceCEImpl ImportableService customJSLibImportableService, ImportableService datasourceImportableService, ImportableService newActionImportableService, - ImportableService actionCollectionImportableService) { + ImportableService actionCollectionImportableService, + PermissionGroupService permissionGroupService) { super( datasourceService, sessionUserService, @@ -77,6 +78,7 @@ public class ImportApplicationServiceImpl extends ImportApplicationServiceCEImpl customJSLibImportableService, datasourceImportableService, newActionImportableService, - actionCollectionImportableService); + actionCollectionImportableService, + permissionGroupService); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java index 025c883685..a5a45caa31 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java @@ -100,8 +100,8 @@ public class PartialImportServiceCEImpl implements PartialImportServiceCE { })) .cache(); - ImportingMetaDTO importingMetaDTO = - new ImportingMetaDTO(workspaceId, applicationId, branchName, false, permissionProvider); + ImportingMetaDTO importingMetaDTO = new ImportingMetaDTO( + workspaceId, applicationId, branchName, false, permissionProvider, null); // Get the Application from DB Mono importedApplicationMono = applicationService diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java index d08ae86b6a..210803b59c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java @@ -117,18 +117,21 @@ public class NewActionExportableServiceCEImpl implements ExportableServiceCE { private final NewActionService newActionService; private final NewActionRepository repository; private final ActionCollectionService actionCollectionService; - public NewActionImportableServiceCEImpl( - NewActionService newActionService, - NewActionRepository repository, - ActionCollectionService actionCollectionService) { - this.newActionService = newActionService; - this.repository = repository; - this.actionCollectionService = actionCollectionService; - } - - // Requires pageNameMap, pageNameToOldNameMap, pluginMap and datasourceNameToIdMap to be present in importable + // Requires pageNameMap, pageNameToOldNameMap, pluginMap and datasourceNameToIdMap, to be present in importable // resources. // Updates actionResultDTO in importable resources. - // Also directly updates required information in DB + // Also, directly updates required information in DB @Override public Mono importEntities( ImportingMetaDTO importingMetaDTO, @@ -102,7 +95,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE invalidActionIds = new HashSet<>(); @@ -163,7 +156,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE invalidCollectionIds = new HashSet<>(); @@ -227,10 +220,8 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE { - Mono> actionsInCurrentAppMono = repository - .findByApplicationId(importedApplication.getId()) - .filter(newAction -> newAction.getGitSyncId() != null) - .collectMap(NewAction::getGitSyncId); + Mono> actionsInCurrentAppMono = + getActionsInCurrentAppMono(importedApplication).collectMap(NewAction::getGitSyncId); // find existing actions in all the branches of this application and put them in a map Mono> actionsInOtherBranchesMono; @@ -341,16 +332,18 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE getActionsInCurrentAppMono(Application importedApplication) { + return repository + .findByApplicationId(importedApplication.getId()) + .filter(newAction -> newAction.getGitSyncId() != null); + } + private NewPage updatePageInAction( ActionDTO action, Map pageNameMap, Map actionIdMap) { NewPage parentPage = pageNameMap.get(action.getPageId()); @@ -449,6 +453,9 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE existingPolicy = existingAction.getPolicies(); + + updateImportableActionFromExistingAction(existingAction, actionToImport); + copyNestedNonNullProperties(actionToImport, existingAction); // Update branchName existingAction.getDefaultResources().setBranchName(branchName); @@ -461,6 +468,10 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE importEntities( ImportingMetaDTO importingMetaDTO, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java index 0c9d2a74f3..1523a69054 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java @@ -1,6 +1,7 @@ package com.appsmith.server.repositories; import com.appsmith.server.acl.AclPermission; +import com.mongodb.client.result.InsertManyResult; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Update; @@ -32,4 +33,19 @@ public interface AppsmithRepository { Mono setUserPermissionsInObject(T obj); Mono updateAndReturn(String id, Update updateObj, Optional permission); + + /** + * This method uses the mongodb bulk operation to save a list of new actions. When calling this method, please note + * the following points: + * 1. All of them will be written to database in a single DB operation. + * 2. The list of domains returned are same as the ones passed in the method. + * 3. If you pass a domain without ID, the ID will be generated by the database but the returned action + * will not have the ID. + * 4. All the auto generated fields e.g. createdAt, updatedAt should be set by the caller. + * They'll not be generated in the bulk write. + * 5. No constraint validation will be performed on the new actions. + * @param domainList List of domains that'll be saved in bulk + * @return List of actions that were passed in the method + */ + Mono> bulkInsert(List domainList); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java index d4e880fdf5..8a5470ee38 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java @@ -11,9 +11,11 @@ import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.repositories.CacheableRepositoryHelper; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; +import com.mongodb.client.result.InsertManyResult; import com.mongodb.client.result.UpdateResult; import com.querydsl.core.types.Path; import jakarta.validation.constraints.NotNull; +import org.bson.Document; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.GenericTypeResolver; import org.springframework.data.domain.Sort; @@ -32,11 +34,13 @@ import reactor.core.publisher.Mono; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.apache.commons.lang3.StringUtils.isBlank; @@ -722,4 +726,24 @@ public abstract class BaseAppsmithRepositoryCEImpl { return mongoOperations.findAndModify(query, updateObj, findAndModifyOptions, this.genericDomain); }); } + + public Mono> bulkInsert(List domainList) { + if (CollectionUtils.isEmpty(domainList)) { + return Mono.just(Collections.emptyList()); + } + + // convert the list of domains to a list of DBObjects + List dbObjects = domainList.stream() + .map(domain -> { + Document document = new Document(); + mongoOperations.getConverter().write(domain, document); + return document; + }) + .collect(Collectors.toList()); + + return mongoOperations + .getCollection(mongoOperations.getCollectionName(genericDomain)) + .flatMapMany(documentMongoCollection -> documentMongoCollection.insertMany(dbObjects)) + .collectList(); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java index 1fadbe80f8..2950953973 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java @@ -5,7 +5,6 @@ import com.appsmith.server.acl.AclPermission; import com.appsmith.server.domains.ActionCollection; import com.appsmith.server.repositories.AppsmithRepository; import com.mongodb.bulk.BulkWriteResult; -import com.mongodb.client.result.InsertManyResult; import org.springframework.data.domain.Sort; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -50,8 +49,6 @@ public interface CustomActionCollectionRepositoryCE extends AppsmithRepository findByPageIds(List pageIds, Optional permission); - Mono> bulkInsert(List newActions); - Mono> bulkUpdate(List actionCollections); Flux findAllByApplicationIds(List applicationIds, List includeFields); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java index 996f4d5d3b..9a781cd003 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java @@ -11,7 +11,6 @@ import com.appsmith.server.repositories.CacheableRepositoryHelper; import com.mongodb.bulk.BulkWriteResult; import com.mongodb.client.model.UpdateOneModel; import com.mongodb.client.model.WriteModel; -import com.mongodb.client.result.InsertManyResult; import org.apache.commons.lang3.StringUtils; import org.bson.Document; import org.bson.types.ObjectId; @@ -237,27 +236,6 @@ public class CustomActionCollectionRepositoryCEImpl extends BaseAppsmithReposito return queryAll(List.of(pageIdCriteria), permission); } - @Override - public Mono> bulkInsert(List actionCollectionList) { - if (CollectionUtils.isEmpty(actionCollectionList)) { - return Mono.just(Collections.emptyList()); - } - - // convert the list of action collections to a list of DBObjects - List dbObjects = actionCollectionList.stream() - .map(actionCollection -> { - Document document = new Document(); - mongoOperations.getConverter().write(actionCollection, document); - return document; - }) - .collect(Collectors.toList()); - - return mongoOperations - .getCollection(mongoOperations.getCollectionName(ActionCollection.class)) - .flatMapMany(documentMongoCollection -> documentMongoCollection.insertMany(dbObjects)) - .collectList(); - } - @Override public Mono> bulkUpdate(List actionCollections) { if (CollectionUtils.isEmpty(actionCollections)) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java index 38a1015ac0..223521d461 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java @@ -6,7 +6,6 @@ import com.appsmith.server.domains.NewAction; import com.appsmith.server.dtos.PluginTypeAndCountDTO; import com.appsmith.server.repositories.AppsmithRepository; import com.mongodb.bulk.BulkWriteResult; -import com.mongodb.client.result.InsertManyResult; import com.mongodb.client.result.UpdateResult; import org.springframework.data.domain.Sort; import reactor.core.publisher.Flux; @@ -74,8 +73,6 @@ public interface CustomNewActionRepositoryCE extends AppsmithRepository findAllNonJsActionsByNameAndPageIdsAndViewMode( String name, List pageIds, Boolean viewMode, AclPermission aclPermission, Sort sort); - Mono> bulkInsert(List newActions); - Mono> bulkUpdate(List newActions); Mono> publishActions(String applicationId, AclPermission permission); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java index f90a30c250..c295376a68 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java @@ -14,7 +14,6 @@ import com.appsmith.server.repositories.CacheableRepositoryHelper; import com.mongodb.bulk.BulkWriteResult; import com.mongodb.client.model.UpdateOneModel; import com.mongodb.client.model.WriteModel; -import com.mongodb.client.result.InsertManyResult; import com.mongodb.client.result.UpdateResult; import lombok.extern.slf4j.Slf4j; import org.bson.Document; @@ -538,39 +537,6 @@ public class CustomNewActionRepositoryCEImpl extends BaseAppsmithRepositoryImpl< return criteriaList; } - /** - * This method uses the mongodb bulk operation to save a list of new actions. When calling this method, please note - * the following points: - * 1. All of them will be written to database in a single DB operation. - * 2. The list of new actions returned are same as the ones passed in the method. - * 3. If you pass an action without ID, the ID will be generated by the database but the returned action - * will not have the ID. - * 4. All the auto generated fields e.g. createdAt, updatedAt should be set by the caller. - * They'll not be generated in the bulk write. - * 5. No constraint validation will be performed on the new actions. - * @param newActions List of actions that'll be saved in bulk - * @return List of actions that were passed in the method - */ - @Override - public Mono> bulkInsert(List newActions) { - if (CollectionUtils.isEmpty(newActions)) { - return Mono.just(Collections.emptyList()); - } - // convert the list of new actions to a list of DBObjects - List dbObjects = newActions.stream() - .map(newAction -> { - Document document = new Document(); - mongoOperations.getConverter().write(newAction, document); - return document; - }) - .collect(Collectors.toList()); - - return mongoOperations - .getCollection(mongoOperations.getCollectionName(NewAction.class)) - .flatMapMany(documentMongoCollection -> documentMongoCollection.insertMany(dbObjects)) - .collectList(); - } - @Override public Mono> bulkUpdate(List newActions) { if (CollectionUtils.isEmpty(newActions)) {