Developer forum

Forum » Integration » Trouble importing secondary relations

Trouble importing secondary relations

Anders Ebdrup
Anders Ebdrup
Reply

Hi Dynamicweb,

 

We are having some issues with importing secondary user relations as we end up have duplicates entries.

In the method: UpdateUserSecondaryRelationBeforeMoveToMainTable we have this section:

                        if (existingUserId > 0)
                        {
                            string sourceSecondaryUserId = row["AccessUserSecondaryRelationSecondaryUserID"].ToString();
                            List<int> existingSecondaryUserIds = new List<int>();
                            if (!processedSecondaryIdUserIdDictionary.TryGetValue(sourceSecondaryUserId, out existingSecondaryUserIds))
                            {
                                existingSecondaryUserIds = new List<int>();
                                var usersFoundByCustomerNumber = GetExistingUsersBySearchColumn("AccessUserCustomerNumber", sourceSecondaryUserId);
                                if (usersFoundByCustomerNumber != null)
                                {
                                    existingSecondaryUserIds.AddRange(usersFoundByCustomerNumber.Select(u => Converter.ToInt32(u["AccessUserId"])));
                                }
                                int existingSecondaryUserId = GetExistingUserOrGroupID(sourceSecondaryUserId);
                                if (existingSecondaryUserId > 0)
                                {
                                    existingSecondaryUserIds.Add(existingSecondaryUserId);
                                }
                                existingSecondaryUserIds = existingSecondaryUserIds.Distinct().ToList();
                                if (existingSecondaryUserIds.Count == 0)
                                {
                                    _logger.Log(string.Format("Error importing user Secondary Relation: No secondary user or group found with ID or {0} or CustomerNumber equal to: '{1}'", searchColumn, sourceSecondaryUserId));
                                }
                                processedSecondaryIdUserIdDictionary.Add(sourceSecondaryUserId, existingSecondaryUserIds);
                            }

                            if (existingSecondaryUserIds.Count > 0)
                            {
                                row["AccessUserSecondaryRelationUserID"] = existingUserId;
                                row["AccessUserSecondaryRelationSecondaryUserID"] = existingSecondaryUserIds[0];

                                foreach (int existingSecondaryUserId in existingSecondaryUserIds.Skip(1))
                                {
                                    DataRow newRow = dataTable.NewRow();
                                    newRow["AccessUserSecondaryRelationUserID"] = existingUserId;
                                    newRow["AccessUserSecondaryRelationSecondaryUserID"] = existingSecondaryUserId;
                                    rowsToAdd.Add(newRow);
                                }
                            }
                        }                            

Our issue is that: GetExistingUsersBySearchColumn("AccessUserCustomerNumber", sourceSecondaryUserId); is executed no matter what. I think a better approach will be only to search by CustomerNumber if we have no hits. Please see this changed block of code:

                                int existingSecondaryUserId = GetExistingUserOrGroupID(sourceSecondaryUserId);
                                if (existingSecondaryUserId > 0)
                                {
                                    existingSecondaryUserIds.Add(existingSecondaryUserId);
                                }
                                else
                                {
                                    var usersFoundByCustomerNumber = GetExistingUsersBySearchColumn("AccessUserCustomerNumber", sourceSecondaryUserId);
                                    if (usersFoundByCustomerNumber != null)
                                    {
                                        existingSecondaryUserIds.AddRange(usersFoundByCustomerNumber.Select(u => Converter.ToInt32(u["AccessUserId"])));
                                    }
                                    existingSecondaryUserIds = existingSecondaryUserIds.Distinct().ToList();
                                }

I hope you will find it worth changing?

 

Best regards, Anders


Replies

 
Anders Ebdrup
Anders Ebdrup
Reply

Any thoughts on this issue?

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
Bringing that change will bring back a problem when it was needed to associate the users by CustomerNumbers (tfs# 32741).
Regards, Dmitrij

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Dmitrij,

 

I do not think that it will conflict as my suggestion just will try first to find the most specific match of if not it will find by customernumber. So everything should as intended by the change (tfs# 32741)

 

Best regards, Anders

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
tfs# 43629 created.
Regards, Dmitrij

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Dmitrij,

 

That sounds great, but it does not seems to do the job, as the description in the TFS is wrong:

UpdateUserSecondaryRelationBeforeMoveToMainTable :
GetExistingUsersBySearchColumn("AccessUserCustomerNumber", sourceSecondaryUserId); is executed no matter what. I think a better approach will be only to search by CustomerNumber if we have no hits.

Change to search existing users to be associated in the secondary User column(AccessUserSecondaryRelationSecondaryUserID) like that:
1) Find user by AccessUserId
2) if not found in Step1 Finds all users by CustomerNumber
3) If not found in Step2 finds user by AccessUserUserName, Email, AccessUserExternalID, Searching users column(if not Auto searching)

 

You will have to switch 2 and 3 so you will have this work item especially when you have setup a search column:

1) Find user by AccessUserId
3) If not found in Step2 finds user by AccessUserUserName, Email, AccessUserExternalID, Searching users column(if not Auto searching)
2) if not found in Step1 Finds all users by CustomerNumber

Then you will try to find the most specific match before you try the CustomerNumber

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Dmitrij,

 

Can you please give me an update on this one?

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Dw,

 

We are really missing this fix - when will it hit the streets?

 
Anders Ebdrup
Anders Ebdrup
Reply

Hello,

 

Can I please have an update on this one? (and sorry for pushing, but we really need this change).

 

Best regards, Anders

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Anders

It is included in Dynamicweb.DataIntegration.Providers.UserProvider 1.0.21

https://www.myget.org/feed/dynamicweb-packages/package/nuget/Dynamicweb.DataIntegration.Providers.UserProvider

BR Nicolai

Votes for this answer: 1
 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

I can see that the code is not changed yet in order to search for a matching user after this approach:

1) Find user by AccessUserId
3) If not found in Step2 finds user by AccessUserUserName, Email, AccessUserExternalID, Searching users column(if not Auto searching)
2) if not found in Step1 Finds all users by CustomerNumber

 

I really think this logic makes sense, so I hope it can be fixed?

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

After working more with this part and to have a more robust import I will suggest this quite simple order:

 

1) Find user by Searching column (AccessUserUserName, Email, AccessUserExternalID, CustomerNumber)

 

Right now we see that if we import users with number as username it can conflict with the AccessUserId, so if we just would be able to control the logic ourself by the searching column (with fallback to "auto"), then I think that you would satisfy all needs. Right now we struggle a lot with this part!

 

Best regards, Anders

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
TFS# 49254 created. So secondary users will be searched by Search column. If Auto option is selected it will seach by
"AccessUserID", "UserUserName", "CustomerNumber", "Email", "ExternalID"
Regards, Dmitrij

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
It is now included in Dynamicweb.DataIntegration.Providers.UserProvider 1.0.26
Regards, Dmitrij

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Anders

The #49254 has now also been released in build 9.4.10

You are able to find this build in the download section:

http://doc.dynamicweb.com/releases-and-downloads/releases

Please contact Dynamicweb Support if you need any additional help regarding this.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum