diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java index 4ced8f9749..a99be5b959 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationServiceCEImpl.java @@ -515,8 +515,7 @@ public class ApplicationServiceCEImpl extends BaseService updatedDatasourcesMono1 = policySolution .updateWithNewPoliciesToDatasourcesByDatasourceIdsWithoutPermission( datasourceIds, datasourcePolicyMap, addViewAccess) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceStorageServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceStorageServiceCEImpl.java index 6e929811d3..b94103d8d9 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceStorageServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceStorageServiceCEImpl.java @@ -310,6 +310,12 @@ public class DatasourceStorageServiceCEImpl implements DatasourceStorageServiceC } DatasourceStorageDTO datasourceStorageDTO = this.getDatasourceStorageDTOFromDatasource(datasource, environmentId); + + if (datasourceStorageDTO == null) { + // If this environment does not have a storage configured, return null + return null; + } + DatasourceStorage datasourceStorage = new DatasourceStorage(datasourceStorageDTO); datasourceStorage.prepareTransientFields(datasource); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java index 962c4a10c0..c82de2ce9d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java @@ -396,8 +396,22 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica datasourceList.forEach(datasource -> datasourceIdToNameMap.put(datasource.getId(), datasource.getName())); List storageList = datasourceList.stream() - .map(datasource -> datasourceStorageService.getDatasourceStorageFromDatasource( - datasource, environmentId)) + .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); @@ -2073,6 +2087,11 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica Boolean isUnConfiguredDatasource = datasources.stream().anyMatch(datasource -> { DatasourceStorageDTO datasourceStorageDTO = datasource.getDatasourceStorages().get(environmentId); + if (datasourceStorageDTO == null) { + // If this environment has not been configured, + // We do not expect to find a storage, user will have to reconfigure + return Boolean.FALSE; + } return Boolean.FALSE.equals(datasourceStorageDTO.getIsConfigured()); }); if (Boolean.TRUE.equals(isUnConfiguredDatasource)) { diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java index 8b6b6526f7..124145cf1f 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java @@ -120,6 +120,7 @@ import static com.appsmith.server.constants.FieldName.DEFAULT_PAGE_LAYOUT; import static com.appsmith.server.dtos.CustomJSLibApplicationDTO.getDTOFromCustomJSLib; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; @Slf4j @ExtendWith(SpringExtension.class) @@ -2559,6 +2560,7 @@ public class ImportExportApplicationServiceTests { DEFAULT_PAGE_LAYOUT, new TypeReference>() {})); } catch (JsonProcessingException e) { e.printStackTrace(); + fail(); } ArrayList children = (ArrayList) dsl.get("children");