Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -16,6 +16,7 @@
import com.appsmith.external.models.MustacheBindingToken;
import com.appsmith.external.models.PaginationField;
import com.appsmith.external.models.Param;
import com.appsmith.external.models.Property;
import com.appsmith.external.models.RequestParamDTO;
import com.appsmith.external.plugins.BasePlugin;
import com.appsmith.external.plugins.PluginExecutor;
Expand Down Expand Up @@ -909,6 +910,8 @@ public Mono<Firestore> datasourceCreate(DatasourceConfiguration datasourceConfig
final String projectId = authentication.getUsername();
final String clientJson = authentication.getPassword();

final String databaseId = getDatabaseId(datasourceConfiguration);

InputStream serviceAccount = new ByteArrayInputStream(clientJson.getBytes());

return Mono.fromSupplier(() -> {
Expand Down Expand Up @@ -938,10 +941,24 @@ public Mono<Firestore> datasourceCreate(DatasourceConfiguration datasourceConfig
return FirebaseApp.initializeApp(options, projectId);
}
})
.map(FirestoreClient::getFirestore)
.map(app -> FirestoreClient.getFirestore(app, databaseId))
.subscribeOn(scheduler);
}

String getDatabaseId(DatasourceConfiguration datasourceConfiguration) {
if (!CollectionUtils.isEmpty(datasourceConfiguration.getProperties())) {
for (Property property : datasourceConfiguration.getProperties()) {
if (property != null
&& "databaseId".equals(property.getKey())
&& property.getValue() instanceof String
&& !StringUtils.isEmpty((String) property.getValue())) {
return (String) property.getValue();
}
}
}
return "(default)";
}

@Override
public Mono<DatasourceTestResult> testDatasource(DatasourceConfiguration datasourceConfiguration) {
log.debug(Thread.currentThread().getName() + ": testDatasource() called for Firestore plugin.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
"dataType": "PASSWORD",
"isRequired": true,
"initialValue": ""
},
{
"label": "Database ID",
"configProperty": "datasourceConfiguration.properties[0].value",
"controlType": "INPUT_TEXT",
"isRequired": false,
"initialValue": "(default)",
"placeholderText": "(default)"
},
{
"label": "Database ID key",
"configProperty": "datasourceConfiguration.properties[0].key",
"controlType": "INPUT_TEXT",
"initialValue": "databaseId",
"hidden": true
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,58 @@ public void testJsonSmartSubstitution() {
.verifyComplete();
}

@Test
public void testGetDatabaseId_withNoProperties_returnsDefault() {
DatasourceConfiguration config = new DatasourceConfiguration();
assertEquals("(default)", pluginExecutor.getDatabaseId(config));
}

@Test
public void testGetDatabaseId_withNullProperties_returnsDefault() {
DatasourceConfiguration config = new DatasourceConfiguration();
config.setProperties(null);
assertEquals("(default)", pluginExecutor.getDatabaseId(config));
}

@Test
public void testGetDatabaseId_withCustomDatabaseId_returnsCustomValue() {
DatasourceConfiguration config = new DatasourceConfiguration();
List<Property> properties = new ArrayList<>();
Property databaseIdProperty = new Property();
databaseIdProperty.setKey("databaseId");
databaseIdProperty.setValue("my-custom-database");
properties.add(databaseIdProperty);
config.setProperties(properties);

assertEquals("my-custom-database", pluginExecutor.getDatabaseId(config));
}

@Test
public void testGetDatabaseId_withEmptyValue_returnsDefault() {
DatasourceConfiguration config = new DatasourceConfiguration();
List<Property> properties = new ArrayList<>();
Property databaseIdProperty = new Property();
databaseIdProperty.setKey("databaseId");
databaseIdProperty.setValue("");
properties.add(databaseIdProperty);
config.setProperties(properties);

assertEquals("(default)", pluginExecutor.getDatabaseId(config));
}

@Test
public void testGetDatabaseId_withNonStringValue_returnsDefault() {
DatasourceConfiguration config = new DatasourceConfiguration();
List<Property> properties = new ArrayList<>();
Property databaseIdProperty = new Property();
databaseIdProperty.setKey("databaseId");
databaseIdProperty.setValue(12345);
properties.add(databaseIdProperty);
config.setProperties(properties);

assertEquals("(default)", pluginExecutor.getDatabaseId(config));
}
Comment thread
RaikaSurendra marked this conversation as resolved.

@Test
public void verifyUniquenessOfFirestorePluginErrorCode() {
assert (Arrays.stream(FirestorePluginError.values())
Expand Down