chore: Refactored import and export svc methods for modularity (#28330)
This commit is contained in:
parent
1a9de73d3a
commit
1ab5913e61
|
|
@ -36,8 +36,11 @@ public class ActionCollectionExportableServiceCEImpl implements ExportableServic
|
|||
this.actionPermission = actionPermission;
|
||||
}
|
||||
|
||||
// Requires pageIdToNameMap, pluginMap.
|
||||
// Updates collectionId to name map in exportable resources. Also directly updates required collection information
|
||||
// in application json
|
||||
@Override
|
||||
public Mono<List<ActionCollection>> getExportableEntities(
|
||||
public Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
@ -94,7 +97,8 @@ public class ActionCollectionExportableServiceCEImpl implements ExportableServic
|
|||
.put(FieldName.ACTION_COLLECTION_LIST, updatedActionCollectionSet);
|
||||
|
||||
return actionCollections;
|
||||
});
|
||||
})
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -44,8 +44,11 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
|
|||
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
|
||||
@Override
|
||||
public Mono<List<ActionCollection>> importEntities(
|
||||
public Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
@ -61,7 +64,7 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic
|
|||
|
||||
return importActionCollectionMono
|
||||
.doOnNext(mappedImportableResourcesDTO::setActionCollectionResultDTO)
|
||||
.thenReturn(List.of());
|
||||
.then();
|
||||
}
|
||||
|
||||
private Mono<ImportActionCollectionResultDTO> createImportActionCollectionMono(
|
||||
|
|
|
|||
|
|
@ -50,8 +50,10 @@ public class DatasourceExportableServiceCEImpl implements ExportableServiceCE<Da
|
|||
this.datasourceStorageService = datasourceStorageService;
|
||||
}
|
||||
|
||||
// Updates datasourceId to name map in exportable resources. Also directly updates required datasources information
|
||||
// in application json
|
||||
@Override
|
||||
public Mono<List<Datasource>> getExportableEntities(
|
||||
public Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
@ -68,32 +70,36 @@ public class DatasourceExportableServiceCEImpl implements ExportableServiceCE<Da
|
|||
return datasourceService.getAllByWorkspaceIdWithStorages(application.getWorkspaceId(), optionalPermission);
|
||||
});
|
||||
|
||||
return datasourceFlux.collectList().zipWith(defaultEnvironmentIdMono).map(tuple2 -> {
|
||||
List<Datasource> datasourceList = tuple2.getT1();
|
||||
String environmentId = tuple2.getT2();
|
||||
mapNameToIdForExportableEntities(mappedExportableResourcesDTO, datasourceList);
|
||||
return datasourceFlux
|
||||
.collectList()
|
||||
.zipWith(defaultEnvironmentIdMono)
|
||||
.map(tuple2 -> {
|
||||
List<Datasource> datasourceList = tuple2.getT1();
|
||||
String environmentId = tuple2.getT2();
|
||||
mapNameToIdForExportableEntities(mappedExportableResourcesDTO, datasourceList);
|
||||
|
||||
List<DatasourceStorage> storageList = datasourceList.stream()
|
||||
.map(datasource -> {
|
||||
DatasourceStorage storage =
|
||||
datasourceStorageService.getDatasourceStorageFromDatasource(datasource, environmentId);
|
||||
List<DatasourceStorage> storageList = datasourceList.stream()
|
||||
.map(datasource -> {
|
||||
DatasourceStorage storage = datasourceStorageService.getDatasourceStorageFromDatasource(
|
||||
datasource, environmentId);
|
||||
|
||||
if (storage == null) {
|
||||
// This means we were unable to find a storage for default environment
|
||||
// We still need the user to be able to configure this datasource in a
|
||||
// new workspace,
|
||||
// So we will create a fallback storage using transient fields from the
|
||||
// datasource
|
||||
storage = new DatasourceStorage();
|
||||
storage.prepareTransientFields(datasource);
|
||||
}
|
||||
return storage;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
applicationJson.setDatasourceList(storageList);
|
||||
if (storage == null) {
|
||||
// This means we were unable to find a storage for default environment
|
||||
// We still need the user to be able to configure this datasource in a
|
||||
// new workspace,
|
||||
// So we will create a fallback storage using transient fields from the
|
||||
// datasource
|
||||
storage = new DatasourceStorage();
|
||||
storage.prepareTransientFields(datasource);
|
||||
}
|
||||
return storage;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
applicationJson.setDatasourceList(storageList);
|
||||
|
||||
return datasourceList;
|
||||
});
|
||||
return datasourceList;
|
||||
})
|
||||
.then();
|
||||
}
|
||||
|
||||
private void removeSensitiveFields(DatasourceStorage datasourceStorage) {
|
||||
|
|
|
|||
|
|
@ -52,8 +52,11 @@ public class DatasourceImportableServiceCEImpl implements ImportableServiceCE<Da
|
|||
this.sequenceService = sequenceService;
|
||||
}
|
||||
|
||||
// Requires pluginMap to be present in importable resources.
|
||||
// Updates datasourceNameToIdMap in importable resources.
|
||||
// Also directly updates required information in DB
|
||||
@Override
|
||||
public Mono<List<Datasource>> importEntities(
|
||||
public Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
@ -74,10 +77,9 @@ public class DatasourceImportableServiceCEImpl implements ImportableServiceCE<Da
|
|||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO);
|
||||
|
||||
return datasourceMapMono.map(datasourceMap -> {
|
||||
mappedImportableResourcesDTO.setDatasourceNameToIdMap(datasourceMap);
|
||||
return List.of();
|
||||
});
|
||||
return datasourceMapMono
|
||||
.doOnNext(mappedImportableResourcesDTO::setDatasourceNameToIdMap)
|
||||
.then();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import java.util.Set;
|
|||
|
||||
public interface ExportableServiceCE<T extends BaseDomain> {
|
||||
|
||||
Mono<List<T>> getExportableEntities(
|
||||
Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
|
|||
|
|
@ -34,12 +34,14 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.lang.Boolean.TRUE;
|
||||
|
|
@ -136,6 +138,7 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC
|
|||
exportingMetaDTO.setClientSchemaMigrated(isClientSchemaMigrated);
|
||||
exportingMetaDTO.setServerSchemaMigrated(isServerSchemaMigrated);
|
||||
applicationJson.setExportedApplication(application);
|
||||
applicationJson.setUpdatedResources(new ConcurrentHashMap<>());
|
||||
|
||||
List<String> unpublishedPages = application.getPages().stream()
|
||||
.map(ApplicationPage::getId)
|
||||
|
|
@ -143,35 +146,17 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC
|
|||
|
||||
exportingMetaDTO.setUnpublishedPages(unpublishedPages);
|
||||
|
||||
return pluginExportableService
|
||||
.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)
|
||||
.then(themeExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))
|
||||
.then(newPageExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))
|
||||
.then(datasourceExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))
|
||||
.then(actionCollectionExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))
|
||||
.then(newActionExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))
|
||||
.then(customJSLibExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))
|
||||
.map(newActions -> {
|
||||
datasourceExportableService.sanitizeEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor);
|
||||
|
||||
newPageExportableService.sanitizeEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor);
|
||||
|
||||
return getExportableEntities(exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)
|
||||
.then(Mono.defer(() -> sanitizeEntities(
|
||||
serialiseFor, applicationJson, mappedResourcesDTO, exportingMetaDTO)))
|
||||
.then(Mono.fromCallable(() -> {
|
||||
application.makePristine();
|
||||
application.sanitiseToExportDBObject();
|
||||
// Disable exporting the application with datasource config once imported in destination
|
||||
// instance
|
||||
application.setExportWithConfiguration(null);
|
||||
return applicationJson;
|
||||
});
|
||||
}));
|
||||
})
|
||||
.then(sessionUserService.getCurrentUser())
|
||||
.map(user -> {
|
||||
|
|
@ -198,6 +183,92 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC
|
|||
.thenReturn(applicationJson);
|
||||
}
|
||||
|
||||
private Mono<Void> sanitizeEntities(
|
||||
SerialiseApplicationObjective serialiseFor,
|
||||
ApplicationJson applicationJson,
|
||||
MappedExportableResourcesDTO mappedResourcesDTO,
|
||||
ExportingMetaDTO exportingMetaDTO) {
|
||||
datasourceExportableService.sanitizeEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor);
|
||||
|
||||
newPageExportableService.sanitizeEntities(exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor);
|
||||
|
||||
return Mono.empty().then();
|
||||
}
|
||||
|
||||
private Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
ApplicationJson applicationJson) {
|
||||
|
||||
// The idea with both these methods is that any amount of overriding should take care of whether they want to
|
||||
// zip the additional exportables along with these or sequence them, or combine them using any other logic
|
||||
return Flux.merge(getPageIndependentExportables(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))
|
||||
.thenMany(Flux.merge(getPageDependentExportables(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)))
|
||||
.then();
|
||||
}
|
||||
|
||||
protected List<Mono<Void>> getPageIndependentExportables(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
ApplicationJson applicationJson) {
|
||||
// Updates plugin map in exportable resources
|
||||
Mono<Void> pluginExportablesMono = pluginExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson);
|
||||
|
||||
// Directly updates required theme information in application json
|
||||
Mono<Void> themeExportablesMono = themeExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson);
|
||||
|
||||
// Updates pageId to name map in exportable resources.
|
||||
// Also directly updates required pages information in application json
|
||||
Mono<Void> newPageExportablesMono = newPageExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson);
|
||||
|
||||
// Updates datasourceId to name map in exportable resources.
|
||||
// Also directly updates required datasources information in application json
|
||||
Mono<Void> datasourceExportablesMono = datasourceExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson);
|
||||
|
||||
// Directly sets required custom JS lib information in application JSON
|
||||
Mono<Void> customJsLibsExportablesMono = customJSLibExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson);
|
||||
|
||||
return List.of(
|
||||
pluginExportablesMono,
|
||||
datasourceExportablesMono,
|
||||
themeExportablesMono,
|
||||
newPageExportablesMono,
|
||||
customJsLibsExportablesMono);
|
||||
}
|
||||
|
||||
protected List<Mono<Void>> getPageDependentExportables(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
ApplicationJson applicationJson) {
|
||||
|
||||
// Requires pageIdToNameMap, pluginMap.
|
||||
// Updates collectionId to name map in exportable resources.
|
||||
// Also directly updates required collection information in application json
|
||||
Mono<Void> actionCollectionExportablesMono = actionCollectionExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson);
|
||||
|
||||
// Requires datasourceIdToNameMap, pageIdToNameMap, pluginMap, collectionIdToNameMap
|
||||
// Updates actionId to name map in exportable resources.
|
||||
// Also directly updates required collection information in application json
|
||||
Mono<Void> newActionExportablesMono = newActionExportableService.getExportableEntities(
|
||||
exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson);
|
||||
|
||||
Mono<Void> combinedActionExportablesMono = actionCollectionExportablesMono.then(newActionExportablesMono);
|
||||
|
||||
return List.of(combinedActionExportablesMono);
|
||||
}
|
||||
|
||||
public Mono<ApplicationJson> exportApplicationById(String applicationId, String branchName) {
|
||||
return applicationService
|
||||
.findBranchedApplicationId(branchName, applicationId, applicationPermission.getExportPermission())
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@ import com.appsmith.server.dtos.ImportingMetaDTO;
|
|||
import com.appsmith.server.dtos.MappedImportableResourcesDTO;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ImportableServiceCE<T extends BaseDomain> {
|
||||
|
||||
Mono<List<T>> importEntities(
|
||||
Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import org.springframework.dao.DuplicateKeyException;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.transaction.reactive.TransactionalOperator;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
|
@ -516,60 +517,24 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC
|
|||
.cache();
|
||||
|
||||
Mono<User> currUserMono = sessionUserService.getCurrentUser().cache();
|
||||
Mono<List<CustomJSLib>> installedJsLibsMono = customJSLibImportableService.importEntities(
|
||||
importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson);
|
||||
Mono<List<Plugin>> installedPluginsMono = pluginImportableService.importEntities(
|
||||
importingMetaDTO, mappedImportableResourcesDTO, workspaceMono, null, applicationJson);
|
||||
|
||||
Mono<Void> applicationSpecificImportedEntitiesMono =
|
||||
applicationSpecificImportedEntities(applicationJson, importingMetaDTO, mappedImportableResourcesDTO);
|
||||
|
||||
// Start the stopwatch to log the execution time
|
||||
Stopwatch stopwatch = new Stopwatch(AnalyticsEvents.IMPORT.getEventName());
|
||||
final Mono<Application> importedApplicationMono = installedJsLibsMono
|
||||
final Mono<Application> importedApplicationMono = applicationSpecificImportedEntitiesMono
|
||||
.then(getImportApplicationMono(
|
||||
importedApplication, importingMetaDTO, mappedImportableResourcesDTO, currUserMono))
|
||||
.cache();
|
||||
|
||||
Mono<List<Theme>> importedThemesMono = themeImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
Mono<List<NewPage>> importedPagesMono = newPageImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
Mono<List<Datasource>> importedDatasourcesMono = datasourceImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
Mono<List<NewAction>> importedNewActionsMono = newActionImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
Mono<List<ActionCollection>> importedActionCollectionsMono = actionCollectionImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
Mono<Application> importMono = importedApplicationMono
|
||||
.then(installedPluginsMono)
|
||||
.then(importedThemesMono)
|
||||
.then(importedPagesMono)
|
||||
.then(importedDatasourcesMono)
|
||||
.then(importedNewActionsMono)
|
||||
.then(importedActionCollectionsMono)
|
||||
.then(getImportableEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson))
|
||||
.then(importedApplicationMono)
|
||||
.flatMap(application -> {
|
||||
return newActionImportableService
|
||||
|
|
@ -643,6 +608,120 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC
|
|||
return Mono.create(sink -> resultMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
|
||||
}
|
||||
|
||||
private Mono<Void> getImportableEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
Mono<Application> importedApplicationMono,
|
||||
ApplicationJson applicationJson) {
|
||||
|
||||
List<Mono<Void>> pageIndependentImportables = getPageIndependentImportables(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
List<Mono<Void>> pageDependentImportables = getPageDependentImportables(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
return Flux.merge(pageIndependentImportables)
|
||||
.thenMany(Flux.merge(pageDependentImportables))
|
||||
.then();
|
||||
}
|
||||
|
||||
protected List<Mono<Void>> getPageIndependentImportables(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
Mono<Application> importedApplicationMono,
|
||||
ApplicationJson applicationJson) {
|
||||
|
||||
// Updates plugin map in importable resources
|
||||
Mono<Void> installedPluginsMono = pluginImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
// Directly updates required theme information in DB
|
||||
Mono<Void> importedThemesMono = themeImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
// Updates pageNametoIdMap and pageNameMap in importable resources.
|
||||
// Also directly updates required information in DB
|
||||
Mono<Void> importedPagesMono = newPageImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
// Requires pluginMap to be present in importable resources.
|
||||
// Updates datasourceNameToIdMap in importable resources.
|
||||
// Also directly updates required information in DB
|
||||
Mono<Void> importedDatasourcesMono = installedPluginsMono.then(datasourceImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson));
|
||||
|
||||
return List.of(importedDatasourcesMono, importedPagesMono, importedThemesMono);
|
||||
}
|
||||
|
||||
protected List<Mono<Void>> getPageDependentImportables(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
Mono<Application> importedApplicationMono,
|
||||
ApplicationJson applicationJson) {
|
||||
|
||||
// Requires pageNameMap, pageNameToOldNameMap, pluginMap and datasourceNameToIdMap to be present in importable
|
||||
// resources.
|
||||
// Updates actionResultDTO in importable resources.
|
||||
// Also directly updates required information in DB
|
||||
Mono<Void> importedNewActionsMono = newActionImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
// Requires pageNameMap, pageNameToOldNameMap, pluginMap and actionResultDTO to be present in importable
|
||||
// resources.
|
||||
// Updates actionCollectionResultDTO in importable resources.
|
||||
// Also directly updates required information in DB
|
||||
Mono<Void> importedActionCollectionsMono = actionCollectionImportableService.importEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importedApplicationMono,
|
||||
applicationJson);
|
||||
|
||||
Mono<Void> combinedActionExportablesMono = importedNewActionsMono.then(importedActionCollectionsMono);
|
||||
return List.of(combinedActionExportablesMono);
|
||||
}
|
||||
|
||||
private Mono<Void> applicationSpecificImportedEntities(
|
||||
ApplicationJson applicationJson,
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO) {
|
||||
// Persists relevant information and updates mapped resources
|
||||
Mono<Void> installedJsLibsMono = customJSLibImportableService.importEntities(
|
||||
importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson);
|
||||
return installedJsLibsMono;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ApplicationImportDTO> getApplicationImportDTO(
|
||||
String applicationId, String workspaceId, Application application) {
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ public class CustomJSLibExportableServiceCEImpl implements ExportableServiceCE<C
|
|||
this.customJSLibService = customJSLibService;
|
||||
}
|
||||
|
||||
// Directly sets required custom JS lib information in application JSON
|
||||
@Override
|
||||
public Mono<List<CustomJSLib>> getExportableEntities(
|
||||
public Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
@ -62,7 +63,6 @@ public class CustomJSLibExportableServiceCEImpl implements ExportableServiceCE<C
|
|||
.map(lib -> lib.getUidString())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
applicationJson.getUpdatedResources().put(FieldName.CUSTOM_JS_LIB_LIST, updatedCustomJSLibSet);
|
||||
|
||||
/**
|
||||
|
|
@ -73,6 +73,7 @@ public class CustomJSLibExportableServiceCEImpl implements ExportableServiceCE<C
|
|||
Collections.sort(unpublishedCustomJSLibList, Comparator.comparing(CustomJSLib::getUidString));
|
||||
applicationJson.setCustomJSLibList(unpublishedCustomJSLibList);
|
||||
return unpublishedCustomJSLibList;
|
||||
});
|
||||
})
|
||||
.then();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ public class CustomJSLibImportableServiceCEImpl implements ImportableServiceCE<C
|
|||
this.customJSLibService = customJSLibService;
|
||||
}
|
||||
|
||||
// Persists relevant information and updates mapped resources
|
||||
@Override
|
||||
public Mono<List<CustomJSLib>> importEntities(
|
||||
public Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
@ -46,15 +47,10 @@ public class CustomJSLibImportableServiceCEImpl implements ImportableServiceCE<C
|
|||
return customJSLibService.persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO(customJSLib, false);
|
||||
})
|
||||
.collectList()
|
||||
.map(customJSLibApplicationDTOS -> {
|
||||
mappedImportableResourcesDTO.setInstalledJsLibsList(customJSLibApplicationDTOS);
|
||||
return List.<CustomJSLib>of();
|
||||
})
|
||||
.doOnNext(mappedImportableResourcesDTO::setInstalledJsLibsList)
|
||||
.elapsed()
|
||||
.map(objects -> {
|
||||
log.debug("time to import custom jslibs: {}", objects.getT1());
|
||||
return objects.getT2();
|
||||
})
|
||||
.doOnNext(objects -> log.debug("time to import custom jslibs: {}", objects.getT1()))
|
||||
.then()
|
||||
.onErrorResume(e -> {
|
||||
log.error("Error importing custom jslibs", e);
|
||||
return Mono.error(e);
|
||||
|
|
|
|||
|
|
@ -37,8 +37,11 @@ public class NewActionExportableServiceCEImpl implements ExportableServiceCE<New
|
|||
this.actionPermission = actionPermission;
|
||||
}
|
||||
|
||||
// Requires datasourceIdToNameMap, pageIdToNameMap, pluginMap, collectionIdToNameMap
|
||||
// Updates actionId to name map in exportable resources. Also directly updates required collection information in
|
||||
// application json
|
||||
@Override
|
||||
public Mono<List<NewAction>> getExportableEntities(
|
||||
public Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
@ -101,7 +104,8 @@ public class NewActionExportableServiceCEImpl implements ExportableServiceCE<New
|
|||
.removeIf(datasource -> !dbNamesUsedInActions.contains(datasource.getName()));
|
||||
|
||||
return actionList;
|
||||
});
|
||||
})
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -56,8 +56,12 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
|
|||
this.actionCollectionService = actionCollectionService;
|
||||
}
|
||||
|
||||
// Requires pageNameMap, pageNameToOldNameMap, pluginMap and datasourceNameToIdMap to be present in importable
|
||||
// resources.
|
||||
// Updates actionResultDTO in importable resources.
|
||||
// Also directly updates required information in DB
|
||||
@Override
|
||||
public Mono<List<NewAction>> importEntities(
|
||||
public Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
@ -124,7 +128,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE<New
|
|||
log.error("Error while importing actions and deleting unused ones", throwable);
|
||||
return Mono.error(throwable);
|
||||
})
|
||||
.thenReturn(List.of());
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -37,8 +36,10 @@ public class NewPageExportableServiceCEImpl implements ExportableServiceCE<NewPa
|
|||
this.pagePermission = pagePermission;
|
||||
}
|
||||
|
||||
// Updates pageId to name map in exportable resources. Also directly updates required pages information in
|
||||
// application json
|
||||
@Override
|
||||
public Mono<List<NewPage>> getExportableEntities(
|
||||
public Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
@ -109,13 +110,11 @@ public class NewPageExportableServiceCEImpl implements ExportableServiceCE<NewPa
|
|||
newPage.sanitiseToExportDBObject();
|
||||
});
|
||||
applicationJson.setPageList(newPageList);
|
||||
applicationJson.setUpdatedResources(new HashMap<>() {
|
||||
{
|
||||
put(FieldName.PAGE_LIST, updatedPageSet);
|
||||
}
|
||||
});
|
||||
applicationJson.getUpdatedResources().put(FieldName.PAGE_LIST, updatedPageSet);
|
||||
|
||||
return newPageList;
|
||||
});
|
||||
})
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -60,8 +60,10 @@ public class NewPageImportableServiceCEImpl implements ImportableServiceCE<NewPa
|
|||
this.newActionService = newActionService;
|
||||
}
|
||||
|
||||
// Updates pageNametoIdMap and pageNameMap in importable resources.
|
||||
// Also directly updates required information in DB
|
||||
@Override
|
||||
public Mono<List<NewPage>> importEntities(
|
||||
public Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
@ -104,7 +106,7 @@ public class NewPageImportableServiceCEImpl implements ImportableServiceCE<NewPa
|
|||
mappedImportableResourcesDTO)
|
||||
.cache();
|
||||
|
||||
return updatedApplicationMono.then(importedNewPagesMono).map(Tuple2::getT1);
|
||||
return updatedApplicationMono.then(importedNewPagesMono).then();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ public class PluginExportableServiceCEImpl implements ExportableServiceCE<Plugin
|
|||
this.workspaceService = workspaceService;
|
||||
}
|
||||
|
||||
// Updates plugin map in exportable resources
|
||||
@Override
|
||||
public Mono<List<Plugin>> getExportableEntities(
|
||||
public Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
@ -49,6 +50,7 @@ public class PluginExportableServiceCEImpl implements ExportableServiceCE<Plugin
|
|||
plugin.getPluginName() == null ? plugin.getPackageName() : plugin.getPluginName());
|
||||
return plugin;
|
||||
})
|
||||
.collectList();
|
||||
.collectList()
|
||||
.then();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ public class PluginImportableServiceCEImpl implements ImportableServiceCE<Plugin
|
|||
this.pluginService = pluginService;
|
||||
}
|
||||
|
||||
// Updates plugin map in importable resources
|
||||
@Override
|
||||
public Mono<List<Plugin>> importEntities(
|
||||
public Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
@ -50,9 +51,7 @@ public class PluginImportableServiceCEImpl implements ImportableServiceCE<Plugin
|
|||
})
|
||||
.collectList()
|
||||
.elapsed()
|
||||
.map(tuples -> {
|
||||
log.debug("time to get plugin map: {}", tuples.getT1());
|
||||
return tuples.getT2();
|
||||
});
|
||||
.doOnNext(tuples -> log.debug("time to get plugin map: {}", tuples.getT1()))
|
||||
.then();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ public class ThemeExportableServiceCEImpl implements ExportableServiceCE<Theme>
|
|||
this.themeService = themeService;
|
||||
}
|
||||
|
||||
// Directly sets required theme information in application json
|
||||
@Override
|
||||
public Mono<List<Theme>> getExportableEntities(
|
||||
public Mono<Void> getExportableEntities(
|
||||
ExportingMetaDTO exportingMetaDTO,
|
||||
MappedExportableResourcesDTO mappedExportableResourcesDTO,
|
||||
Mono<Application> applicationMono,
|
||||
|
|
@ -38,23 +39,25 @@ public class ThemeExportableServiceCEImpl implements ExportableServiceCE<Theme>
|
|||
})
|
||||
.cache();
|
||||
|
||||
return applicationMono.flatMap(application -> themeService
|
||||
.getThemeById(application.getEditModeThemeId(), READ_THEMES)
|
||||
.switchIfEmpty(Mono.defer(() -> defaultThemeMono)) // setting default theme if theme is missing
|
||||
.zipWith(
|
||||
themeService
|
||||
.getThemeById(application.getPublishedModeThemeId(), READ_THEMES)
|
||||
.switchIfEmpty(
|
||||
Mono.defer(() -> defaultThemeMono)) // setting default theme if theme is missing
|
||||
)
|
||||
.map(themesTuple -> {
|
||||
Theme editModeTheme = themesTuple.getT1();
|
||||
Theme publishedModeTheme = themesTuple.getT2();
|
||||
editModeTheme.sanitiseToExportDBObject();
|
||||
publishedModeTheme.sanitiseToExportDBObject();
|
||||
applicationJson.setEditModeTheme(editModeTheme);
|
||||
applicationJson.setPublishedTheme(publishedModeTheme);
|
||||
return List.of(themesTuple.getT1(), themesTuple.getT2());
|
||||
}));
|
||||
return applicationMono
|
||||
.flatMap(application -> themeService
|
||||
.getThemeById(application.getEditModeThemeId(), READ_THEMES)
|
||||
.switchIfEmpty(Mono.defer(() -> defaultThemeMono)) // setting default theme if theme is missing
|
||||
.zipWith(
|
||||
themeService
|
||||
.getThemeById(application.getPublishedModeThemeId(), READ_THEMES)
|
||||
.switchIfEmpty(Mono.defer(
|
||||
() -> defaultThemeMono)) // setting default theme if theme is missing
|
||||
)
|
||||
.map(themesTuple -> {
|
||||
Theme editModeTheme = themesTuple.getT1();
|
||||
Theme publishedModeTheme = themesTuple.getT2();
|
||||
editModeTheme.sanitiseToExportDBObject();
|
||||
publishedModeTheme.sanitiseToExportDBObject();
|
||||
applicationJson.setEditModeTheme(editModeTheme);
|
||||
applicationJson.setPublishedTheme(publishedModeTheme);
|
||||
return List.of(themesTuple.getT1(), themesTuple.getT2());
|
||||
}))
|
||||
.then();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ import com.appsmith.server.domains.Workspace;
|
|||
import com.appsmith.server.dtos.ApplicationJson;
|
||||
import com.appsmith.server.dtos.ImportingMetaDTO;
|
||||
import com.appsmith.server.dtos.MappedImportableResourcesDTO;
|
||||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.imports.importable.ImportableServiceCE;
|
||||
import com.appsmith.server.repositories.ThemeRepository;
|
||||
import com.appsmith.server.services.ApplicationService;
|
||||
|
|
@ -16,8 +14,6 @@ import com.appsmith.server.themes.base.ThemeService;
|
|||
import org.springframework.util.StringUtils;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.appsmith.server.acl.AclPermission.MANAGE_THEMES;
|
||||
|
||||
public class ThemeImportableServiceCEImpl implements ImportableServiceCE<Theme> {
|
||||
|
|
@ -48,11 +44,11 @@ public class ThemeImportableServiceCEImpl implements ImportableServiceCE<Theme>
|
|||
* - If current theme is a customized one and source theme is system theme, set the current theme to system and delete the old one
|
||||
* - If current theme is system theme, update the current theme as per source theme
|
||||
*
|
||||
* @param applicationJson ApplicationJSON from file or Git
|
||||
* @param applicationJson ApplicationJSON from file or Git
|
||||
* @return Updated application that has editModeThemeId and publishedModeThemeId set
|
||||
*/
|
||||
@Override
|
||||
public Mono<List<Theme>> importEntities(
|
||||
public Mono<Void> importEntities(
|
||||
ImportingMetaDTO importingMetaDTO,
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO,
|
||||
Mono<Workspace> workspaceMono,
|
||||
|
|
@ -60,7 +56,7 @@ public class ThemeImportableServiceCEImpl implements ImportableServiceCE<Theme>
|
|||
ApplicationJson applicationJson) {
|
||||
if (Boolean.TRUE.equals(importingMetaDTO.getAppendToApp())) {
|
||||
// appending to existing app, theme should not change
|
||||
return Mono.just(List.of());
|
||||
return Mono.empty().then();
|
||||
}
|
||||
return applicationMono.flatMap(destinationApp -> {
|
||||
Mono<Theme> editModeTheme = updateExistingAppThemeFromJSON(
|
||||
|
|
@ -78,18 +74,13 @@ public class ThemeImportableServiceCEImpl implements ImportableServiceCE<Theme>
|
|||
destinationApp.setEditModeThemeId(editModeThemeId);
|
||||
destinationApp.setPublishedModeThemeId(publishedModeThemeId);
|
||||
// this will update the theme id in DB
|
||||
// also returning the updated application object so that theme id are available to the next
|
||||
// pipeline
|
||||
return applicationService
|
||||
.setAppTheme(
|
||||
destinationApp.getId(),
|
||||
editModeThemeId,
|
||||
publishedModeThemeId,
|
||||
applicationPermission.getEditPermission())
|
||||
.thenReturn(List.<Theme>of());
|
||||
return applicationService.setAppTheme(
|
||||
destinationApp.getId(),
|
||||
editModeThemeId,
|
||||
publishedModeThemeId,
|
||||
applicationPermission.getEditPermission());
|
||||
})
|
||||
.switchIfEmpty(Mono.error(
|
||||
new AppsmithException(AppsmithError.GENERIC_BAD_REQUEST, "Failed to import theme")));
|
||||
.then();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user