-
Notifications
You must be signed in to change notification settings - Fork 3
Add salesforce connector #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeppe742
wants to merge
11
commits into
main
Choose a base branch
from
jjol_salesforce_connector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d03e662
Move CsvOperations to common extensions
jeppe742 0e77bee
Initial working version
jeppe742 6e7caed
Clean up
jeppe742 6f566fa
Remove address type since it's not supported
jeppe742 e497a46
clean up comment
jeppe742 dda3893
clean up
jeppe742 1f9feba
Add location tag
jeppe742 b2df90d
more descriptive error codes
jeppe742 77967e7
more cleanup
jeppe742 8e408dd
Fix locator logic
jeppe742 641e994
Merge remote-tracking branch 'origin/main' into jjol_salesforce_conne…
jeppe742 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Sources/SalesForce/Exceptions/SalesForceJobAbortedException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System; | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace Arcane.Framework.Sources.SalesForce.Exceptions; | ||
|
|
||
| /// <summary> | ||
| /// Thrown if the Salesforce job was aborted. | ||
| /// </summary> | ||
| [ExcludeFromCodeCoverage(Justification = "Trivial")] | ||
| public class SalesForceJobAbortedException : SalesForceJobException | ||
| { | ||
| public SalesForceJobAbortedException(string message) : base(message) | ||
| { | ||
| } | ||
|
|
||
| public SalesForceJobAbortedException(string message, Exception inner) : base(message, inner) | ||
| { | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
src/Sources/SalesForce/Exceptions/SalesForceJobException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using System; | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace Arcane.Framework.Sources.SalesForce.Exceptions; | ||
|
|
||
| /// <summary> | ||
| /// Base class for all Salesforce-related exceptions | ||
| /// </summary> | ||
| [ExcludeFromCodeCoverage(Justification = "Trivial")] | ||
| public class SalesForceJobException : Exception | ||
| { | ||
| public SalesForceJobException(string message) | ||
| : base(message) | ||
| { | ||
| } | ||
|
|
||
| public SalesForceJobException(string message, Exception inner) | ||
| : base(message, inner) | ||
| { | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/Sources/SalesForce/Exceptions/SalesForceJobFailedException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System; | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace Arcane.Framework.Sources.SalesForce.Exceptions; | ||
|
|
||
| /// <summary> | ||
| /// Thrown if the Salesforce job return with failed status. | ||
| /// </summary> | ||
| [ExcludeFromCodeCoverage(Justification = "Trivial")] | ||
| public class SalesForceJobFailedException : SalesForceJobException | ||
| { | ||
| public SalesForceJobFailedException(string message) : base(message) | ||
| { | ||
| } | ||
|
|
||
| public SalesForceJobFailedException(string message, Exception inner) : base(message, inner) | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Arcane.Framework.Sources.SalesForce.Models; | ||
|
|
||
| /// <summary> | ||
| /// Represents Salesforce attribute | ||
| /// </summary> | ||
| public class SalesForceAttribute | ||
| { | ||
| private static readonly Dictionary<string, Type> salesforceTypeMap = new() | ||
| { | ||
| { "string", typeof(string) }, | ||
| { "id", typeof(string) }, | ||
| { "datetime", typeof(DateTime) }, | ||
| { "date", typeof(DateTime) }, | ||
| { "decimal", typeof(decimal) }, | ||
| { "integer", typeof(int) }, | ||
| { "long", typeof(long) }, | ||
| { "double", typeof(double) }, | ||
| { "boolean", typeof(bool) }, | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Attribute name | ||
| /// </summary> | ||
| [JsonPropertyName("Name")] | ||
| public string Name { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Attribute data type | ||
| /// </summary> | ||
| [JsonPropertyName("ValueTypeId")] | ||
| public string DataType { get; set; } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Attribute comparer | ||
| /// </summary> | ||
| public static IEqualityComparer<SalesForceAttribute> SalesForceAttributeComparer { get; } = | ||
| new SalesForceAttributeEqualityComparer(); | ||
|
|
||
| /// <summary> | ||
| /// Maps Salesforce type to .NET type | ||
| /// </summary> | ||
| /// <param name="salesforceTypeName">Salesforce type name</param> | ||
| /// <returns>.NET type instance</returns> | ||
| /// <exception cref="InvalidOperationException">Thrown if type is not supported</exception> | ||
| public static Type MapSalesforceType(string salesforceTypeName) | ||
| { | ||
| if (salesforceTypeMap.ContainsKey(salesforceTypeName.ToLower())) | ||
| { | ||
| return salesforceTypeMap[salesforceTypeName.ToLower()]; | ||
| } | ||
|
|
||
| throw new InvalidOperationException($"Unsupported type: {salesforceTypeName}"); | ||
| } | ||
|
|
||
| private sealed class SalesForceAttributeEqualityComparer : IEqualityComparer<SalesForceAttribute> | ||
| { | ||
| public bool Equals(SalesForceAttribute x, SalesForceAttribute y) | ||
| { | ||
| if (ReferenceEquals(x, y)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (ReferenceEquals(x, null)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (ReferenceEquals(y, null)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (x.GetType() != y.GetType()) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return x.Name == y.Name && | ||
| x.DataType == y.DataType; | ||
| } | ||
|
|
||
| public int GetHashCode(SalesForceAttribute obj) | ||
| { | ||
| return HashCode.Combine(obj.Name, obj.DataType); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Data; | ||
| using System.Linq; | ||
| using System.Text.Json; | ||
|
|
||
| namespace Arcane.Framework.Sources.SalesForce.Models; | ||
|
|
||
| /// <summary> | ||
| /// Represents Salesforce entity | ||
| /// </summary> | ||
| public class SalesForceEntity | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The classes that are not intended for use by plugins should always be |
||
| { | ||
| /// <summary> | ||
| /// Entity name | ||
| /// </summary> | ||
| public string EntityName { get; set; } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Attributes collection | ||
| /// </summary> | ||
| public SalesForceAttribute[] Attributes { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Comparer class | ||
| /// </summary> | ||
| public static IEqualityComparer<SalesForceEntity> SalesForceEntityComparer { get; } = | ||
| new SalesForceEntityEqualityComparer(); | ||
|
|
||
| /// <summary> | ||
| /// Parse Salesforce entity from a JSON document | ||
| /// </summary> | ||
| /// <param name="entityName">Name of the Salesforce entity </param> | ||
| /// <param name="document">Json document to parse</param> | ||
| /// <returns>Parsed SalesForceEntity object</returns> | ||
| public static SalesForceEntity FromJson(string entityName, JsonDocument document) | ||
| { | ||
| var entity = new SalesForceEntity | ||
| { | ||
| EntityName = entityName, | ||
| Attributes = document.RootElement.GetProperty("records").Deserialize<SalesForceAttribute[]>() | ||
| }; | ||
|
|
||
|
|
||
| return entity; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Create DataReader for the entity | ||
| /// </summary> | ||
| /// <returns>DataReader instance</returns> | ||
| public IDataReader GetReader() | ||
| { | ||
| var dt = new DataTable(); | ||
|
|
||
| foreach (var attr in this.Attributes) | ||
| { | ||
| dt.Columns.Add(new DataColumn(attr.Name, SalesForceAttribute.MapSalesforceType(attr.DataType))); | ||
| } | ||
|
|
||
| return dt.CreateDataReader(); | ||
| } | ||
|
|
||
| private sealed class SalesForceEntityEqualityComparer : IEqualityComparer<SalesForceEntity> | ||
| { | ||
| public bool Equals(SalesForceEntity x, SalesForceEntity y) | ||
| { | ||
| if (ReferenceEquals(x, y)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (ReferenceEquals(x, null)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (ReferenceEquals(y, null)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (x.GetType() != y.GetType()) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return x.EntityName == y.EntityName | ||
| && x.Attributes.SequenceEqual(y.Attributes, SalesForceAttribute.SalesForceAttributeComparer); | ||
| } | ||
|
|
||
| public int GetHashCode(SalesForceEntity obj) | ||
| { | ||
| return HashCode.Combine(obj.EntityName, obj.Attributes); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Arcane.Framework.Sources.SalesForce.Models; | ||
|
|
||
| /// <summary> | ||
| /// Job status types | ||
| /// </summary> | ||
| [JsonConverter(typeof(JsonStringEnumConverter))] | ||
| public enum SalesforceJobStatus | ||
| { | ||
| UploadComplete, | ||
| InProgress, | ||
| Aborted, | ||
| JobComplete, | ||
| Failed, | ||
| None | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents Salesforce job | ||
| /// </summary> | ||
| public class SalesForceJob | ||
| { | ||
| /// <summary> | ||
| /// Id | ||
| /// </summary> | ||
| [JsonPropertyName("id")] | ||
| public string Id { get; set; } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Job status | ||
| /// </summary> | ||
| [JsonPropertyName("state")] | ||
| public SalesforceJobStatus Status { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// object | ||
| /// </summary> | ||
| [JsonPropertyName("object")] | ||
| public string Object { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Total processing time of the job | ||
| /// </summary> | ||
| [JsonPropertyName("totalProcessingTime")] | ||
| public long? TotalProcessingTime { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Numbers of records processed by the job | ||
| /// </summary> | ||
| [JsonPropertyName("numberRecordsProcessed")] | ||
| public long? NumberRecordsProcessed { get; set; } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warnings about comment should be fixed, here and below.