Developer forum

Currently discussing: Plans to implement a Consent module for GDPR compliance.

Join the discussion!

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
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
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
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

 

You must be logged in to post in the forum