Skip to content

Commit

Permalink
Add missing Salesforce types. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbranco80 authored Oct 22, 2024
1 parent cbda77d commit 0d7e238
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package com.rawlabs.das.salesforce
import com.rawlabs.das.sdk.{DASExecuteResult, DASTable}
import com.rawlabs.protocol.das.{ColumnDefinition, Qual, Row, SortKey, TableDefinition}
import com.rawlabs.protocol.raw.{
AttrType,
BinaryType,
BoolType,
DateType,
Expand Down Expand Up @@ -108,6 +109,8 @@ abstract class DASSalesforceTable(
Type.newBuilder().setTimestamp(TimestampType.newBuilder().setTriable(false).setNullable(true)).build()
case "picklist" =>
Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
case "multipicklist" =>
Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
case "boolean" => Type.newBuilder().setBool(BoolType.newBuilder().setTriable(false).setNullable(true)).build()
case "textarea" =>
Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
Expand All @@ -129,7 +132,32 @@ abstract class DASSalesforceTable(
case "phone" => Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
case "url" => Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
case "email" => Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
case _ => throw new IllegalArgumentException(s"Unsupported type: ${f.getType}")
case "encryptedstring" =>
Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
case "location" => Type
.newBuilder()
.setRecord(
RecordType
.newBuilder()
.addAtts(
AttrType
.newBuilder()
.setIdn("latitude")
.setTipe(Type.newBuilder().setDouble(DoubleType.newBuilder().setTriable(false).setNullable(true)))
)
.addAtts(
AttrType
.newBuilder()
.setIdn("longitude")
.setTipe(Type.newBuilder().setDouble(DoubleType.newBuilder().setTriable(false).setNullable(true)))
)
)
.build()
case "anyType" =>
Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
case _ =>
logger.warn(s"Unhandled Salesforce field type: ${f.getType}, defaulting to StringType.")
Type.newBuilder().setString(StringType.newBuilder().setTriable(false).setNullable(true)).build()
}
ColumnDefinition
.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ object DASSalesforceUtils {
// Convert e.g. account_number to AccountNumber
// This only works because Salesforce native fields never have underscores
def renameToSalesforce(name: String): String = {
if (name.endsWith("__c")) name // Custom objects must be left as is
if (name.endsWith("__c") || name.endsWith("__s")) name // Custom objects must be left as is
else name.split("_").map(_.capitalize).mkString
}

// Convert e.g. Price2Book to price_2_book
// This only works because Salesforce native fields never have underscores
def renameFromSalesforce(name: String): String = {
if (name.endsWith("__c")) name // Custom objects must be left as is
if (name.endsWith("__c") || name.endsWith("__s")) name // Custom objects must be left as is
else {
val parts = name.split("(?=[A-Z0-9])")
parts.mkString("_").toLowerCase
Expand Down

0 comments on commit 0d7e238

Please sign in to comment.