Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0853b38
refactor datasource import flow to add support for dryOps queries
AnaghHegde Jun 26, 2024
c41ef62
add dryOps repository class to execute the queries
AnaghHegde Jun 27, 2024
1f13f37
fix null check
AnaghHegde Jun 27, 2024
4ab0ed3
fix map issue
AnaghHegde Jun 27, 2024
a61b08c
fix issue with map and partial import query execution
AnaghHegde Jun 30, 2024
4304142
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
AnaghHegde Jun 30, 2024
d3f21eb
fix spotless failures
AnaghHegde Jun 30, 2024
51dd46d
Merge branch 'release' into pg-transaction-datsoure-import-flow
AnaghHegde Jul 1, 2024
d7092d2
refactor import custom js lib to collect dry ops
AnaghHegde Jul 1, 2024
c5daa09
review comments
AnaghHegde Jul 1, 2024
3a0653f
refactor dryOps repo class to execute all the entities in one go
AnaghHegde Jul 1, 2024
239a42f
update add to map logic
AnaghHegde Jul 1, 2024
bf4278a
null check for datasource id
AnaghHegde Jul 1, 2024
36fe881
Merge branch 'pg-transaction-datsoure-import-flow' into pg-transactio…
AnaghHegde Jul 2, 2024
50a335f
use dry ops for custom js lib
AnaghHegde Jul 2, 2024
d1def50
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
AnaghHegde Jul 3, 2024
5f96873
fix sptless checks
AnaghHegde Jul 3, 2024
f5899f9
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
AnaghHegde Jul 8, 2024
7cb411e
review comments
AnaghHegde Jul 9, 2024
b9dfe1d
review comment
AnaghHegde Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.appsmith.external.models.Datasource;
import com.appsmith.external.models.DatasourceStorage;
import com.appsmith.server.domains.Context;
import com.appsmith.server.domains.CustomJSLib;
import com.appsmith.server.dtos.CustomJSLibContextDTO;
import com.appsmith.server.dtos.ImportActionCollectionResultDTO;
import com.appsmith.server.dtos.ImportActionResultDTO;
Expand Down Expand Up @@ -50,4 +51,6 @@ public class MappedImportableResourcesCE_DTO {
Map<String, List<Datasource>> datasourceDryRunQueries = new HashMap<>();

Map<String, List<DatasourceStorage>> datasourceStorageDryRunQueries = new HashMap<>();

Map<String, List<CustomJSLib>> customJSLibsDryOps = new HashMap<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface CustomJSLibServiceCE extends CrudService<CustomJSLib, String> {
Expand All @@ -32,6 +33,12 @@ Mono<List<CustomJSLib>> getAllJSLibsInContext(
Mono<CustomJSLibContextDTO> persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO(
CustomJSLib jsLib, Boolean isForceInstall);

Mono<CustomJSLibContextDTO> persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO(
CustomJSLib jsLib,
Boolean isForceInstall,
Map<String, List<CustomJSLib>> customJSLibsDryOps,
boolean isDryOps);

Flux<CustomJSLib> getAllVisibleJSLibsInContext(
@NotNull String contextId, CreatorContextType contextType, String branchName, Boolean isViewMode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.CustomJSLib;
import com.appsmith.server.dtos.CustomJSLibContextDTO;
import com.appsmith.server.dtos.DBOpsType;
import com.appsmith.server.jslibs.context.ContextBasedJsLibService;
import com.appsmith.server.repositories.CustomJSLibRepository;
import com.appsmith.server.services.AnalyticsService;
Expand All @@ -14,8 +15,10 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -73,11 +76,27 @@ public Mono<Boolean> addJSLibsToContext(
@Override
public Mono<CustomJSLibContextDTO> persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO(
CustomJSLib jsLib, Boolean isForceInstall) {
return persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO(jsLib, isForceInstall, null, false);
}

@Override
public Mono<CustomJSLibContextDTO> persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO(
CustomJSLib jsLib,
Boolean isForceInstall,
Map<String, List<CustomJSLib>> customJSLibsDryOps,
boolean isDryOps) {
return repository
.findUniqueCustomJsLib(jsLib)
// Read more why Mono.defer is used here.
// https://stackoverflow.com/questions/54373920/mono-switchifempty-is-always-called
.switchIfEmpty(Mono.defer(() -> repository.save(jsLib)))
.switchIfEmpty(Mono.defer(() -> {
if (isDryOps) {
jsLib.updateForBulkWriteOperation();
addDryOpsForEntity(DBOpsType.SAVE.name(), customJSLibsDryOps, jsLib);
return Mono.just(jsLib);
}
return repository.save(jsLib);
}))
.flatMap(foundJSLib -> {
/*
The first check is to make sure that we are able to detect any previously truncated data and overwrite it the next time we receive valid data.
Expand All @@ -86,6 +105,10 @@ public Mono<CustomJSLibContextDTO> persistCustomJSLibMetaDataIfDoesNotExistAndGe
*/
if ((jsLib.getDefs().length() > foundJSLib.getDefs().length()) || isForceInstall) {
jsLib.setId(foundJSLib.getId());
if (isDryOps) {
addDryOpsForEntity(DBOpsType.SAVE.name(), customJSLibsDryOps, jsLib);
return Mono.just(jsLib);
}
return repository.save(jsLib);
}

Expand Down Expand Up @@ -141,4 +164,15 @@ public Flux<CustomJSLib> getAllVisibleJSLibsInContext(
.getAllVisibleJSLibContextDTOFromContext(contextId, branchName, isViewMode)
.flatMapMany(repository::findCustomJsLibsInContext);
}

private void addDryOpsForEntity(
String queryType, Map<String, List<CustomJSLib>> dryRunOpsMap, CustomJSLib createdCustomJsLib) {
if (dryRunOpsMap.containsKey(queryType)) {
dryRunOpsMap.get(queryType).add(createdCustomJsLib);
} else {
List<CustomJSLib> customJsLibList = new ArrayList<>();
customJsLibList.add(createdCustomJsLib);
dryRunOpsMap.put(queryType, customJsLibList);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.appsmith.external.models.Datasource;
import com.appsmith.external.models.DatasourceStorage;
import com.appsmith.server.domains.CustomJSLib;
import com.appsmith.server.dtos.MappedImportableResourcesDTO;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,13 +23,16 @@ public class DryOperationRepository {

private final DatasourceStorageRepository datasourceStorageRepository;

private final CustomJSLibRepository customJSLibRepository;

private Map<Class<?>, AppsmithRepository<?>> repoByEntityClass;

@PostConstruct
public void init() {
final Map<Class<?>, AppsmithRepository<?>> map = new HashMap<>();
map.put(Datasource.class, datasourceRepository);
map.put(DatasourceStorage.class, datasourceStorageRepository);
map.put(CustomJSLib.class, customJSLibRepository);
repoByEntityClass = Collections.unmodifiableMap(map);
}

Expand All @@ -44,6 +48,10 @@ public Flux<DatasourceStorage> saveDatasourceStorageToDb(List<DatasourceStorage>
return datasourceStorageRepository.saveAll(datasourceStorage);
}

private Flux<CustomJSLib> saveCustomJSLibToDb(List<CustomJSLib> customJSLibs) {
return customJSLibRepository.saveAll(customJSLibs);
}

public Mono<Void> executeAllDbOps(MappedImportableResourcesDTO mappedImportableResourcesDTO) {

Flux<List<Datasource>> datasourceFLux = Flux.fromIterable(mappedImportableResourcesDTO
Expand All @@ -65,6 +73,16 @@ public Mono<Void> executeAllDbOps(MappedImportableResourcesDTO mappedImportableR
.get(key);
return saveDatasourceStorageToDb(datasourceStorageList).collectList();
});
return Flux.merge(datasourceFLux, datasourceStorageFLux).then();

Flux<List<CustomJSLib>> customJSLibFLux = Flux.fromIterable(
mappedImportableResourcesDTO.getCustomJSLibsDryOps().keySet())
.flatMap(key -> {
List<CustomJSLib> customJSLibList =
mappedImportableResourcesDTO.getCustomJSLibsDryOps().get(key);
return saveCustomJSLibToDb(customJSLibList).collectList();
});

return Flux.merge(datasourceFLux, datasourceStorageFLux, customJSLibFLux)
.then();
}
}