fix: appsmith ai app git import issue fixed (#37921)

## Description
This PR fixes the issue when trying to import git connected app which
has Appsmith AI plugin and query added.

Steps to test the fixes:
1. Create an app and connect it to git
2. Create appsmith ai plugin and add a query
3. Commit all the changes
4. In a new workspace, import this app from git, import should go
through successfully


Fixes #37833 
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.Datasource"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12142783624>
> Commit: f4c90b129022c328b667bf2e34fe9e635d6d0ce7
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12142783624&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource`
> Spec:
> <hr>Tue, 03 Dec 2024 17:11:00 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Enhanced null safety checks in the `getFileIds` method to prevent
potential `NullPointerExceptions`.

- **Tests**
- Introduced unit tests for the `FileUtils` class to validate the
behavior of the `getFileIds` method under various conditions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: “sneha122” <“sneha@appsmith.com”>
This commit is contained in:
sneha122 2024-12-04 15:40:32 +05:30 committed by GitHub
parent 1078a03b23
commit 1f07be34fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 1 deletions

View File

@ -19,7 +19,8 @@ public class FileUtils {
}
public static List<String> getFileIds(DatasourceConfiguration datasourceConfiguration) {
if (datasourceConfiguration.getProperties() != null
if (datasourceConfiguration != null
&& datasourceConfiguration.getProperties() != null
&& datasourceConfiguration.getProperties().size() > 0) {
for (Property property : datasourceConfiguration.getProperties()) {
if (property.getKey().equalsIgnoreCase(FILES)

View File

@ -0,0 +1,44 @@
package com.external.plugins.services;
import com.appsmith.external.models.DatasourceConfiguration;
import com.appsmith.external.models.Property;
import com.external.plugins.utils.FileUtils;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
@Testcontainers
public class FileUtilTest {
@Test
public void getFileIds_withNullDatasourceConfig_returnsEmptyList() {
DatasourceConfiguration datasourceConfiguration = null;
List<String> actualFileIds = FileUtils.getFileIds(datasourceConfiguration);
assertThat(actualFileIds).isEmpty();
}
@Test
public void getFileIds_withValidDatasourceConfig_returnsFileIdList() {
DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
datasourceConfiguration.setUrl("https://example.com");
// create file object
Map<String, Object> fileMap = new HashMap<String, Object>();
fileMap.put("id", "fileId");
fileMap.put("name", "fileName");
fileMap.put("size", 10);
fileMap.put("mimetype", "fileMimetype");
Property property = new Property();
property.setKey("Files");
property.setValue(List.of(fileMap));
datasourceConfiguration.setProperties(List.of(property));
List<String> actualFileIds = FileUtils.getFileIds(datasourceConfiguration);
assertThat(actualFileIds).contains("fileId");
}
}