protected void FillConnectorJoinRulesDataSet()

in src/MIMConfigDocumenter/ConnectorDocumenter.cs [1402:1489]


        protected void FillConnectorJoinRulesDataSet(bool pilotConfig)
        {
            Logger.Instance.WriteMethodEntry("Pilot Config: '{0}'.", pilotConfig);

            try
            {
                var config = pilotConfig ? this.PilotXml : this.ProductionXml;
                var dataSet = pilotConfig ? this.PilotDataSet : this.ProductionDataSet;

                var connector = config.XPathSelectElement(Documenter.GetConnectorXmlRootXPath(pilotConfig) + "/ma-data[name ='" + this.ConnectorName + "']");

                if (connector != null)
                {
                    var table = dataSet.Tables[0];
                    var table2 = dataSet.Tables[1];

                    var joinProfiles = from joinProfile in connector.XPathSelectElements("join/join-profile")
                                       let sourceObjectType = (string)joinProfile.Attribute("cd-object-type")
                                       orderby sourceObjectType
                                       select joinProfile;

                    if (joinProfiles.Count() == 0)
                    {
                        return;
                    }

                    var sourceObjectTypePrevious = "!Uninitialised!";
                    var mappingGroupIndex = 0;
                    var joinProfileIndex = 0;
                    foreach (var joinProfile in joinProfiles)
                    {
                        ++joinProfileIndex;

                        var sourceObjectType = (string)joinProfile.Attribute("cd-object-type");

                        var joinCriteria = joinProfile.Elements("join-criterion");

                        foreach (var joinCriterion in joinCriteria)
                        {
                            mappingGroupIndex = sourceObjectTypePrevious != sourceObjectType ? 1 : mappingGroupIndex + 1;
                            sourceObjectTypePrevious = sourceObjectType;
                            var metaverseObjectType = (string)joinCriterion.Element("search").Attribute("mv-object-type") ?? "Any";
                            var joinResoution = (string)joinCriterion.XPathSelectElement("resolution/script-context");

                            Documenter.AddRow(table, new object[] { sourceObjectType, mappingGroupIndex, metaverseObjectType, joinResoution });

                            var joinRuleType = (string)joinCriterion.Attribute("join-cri-type") ?? string.Empty;
                            foreach (var attributeMapping in joinCriterion.XPathSelectElements("search/attribute-mapping"))
                            {
                                var metaverseAttribute = (string)attributeMapping.Attribute("mv-attribute");
                                var sourceAttribute = (string)attributeMapping.XPathSelectElement("direct-mapping/src-attribute");

                                var mappingType = "Direct";
                                if (string.IsNullOrEmpty(sourceAttribute))
                                {
                                    foreach (var srcAttribute in attributeMapping.XPathSelectElements("scripted-mapping/src-attribute"))
                                    {
                                        sourceAttribute += (string)srcAttribute + ",";
                                    }

                                    sourceAttribute = sourceAttribute.TrimEnd(',');
                                    mappingType = "Rules Extension - " + (string)attributeMapping.XPathSelectElement("scripted-mapping/script-context");
                                }
                                else if (joinRuleType.Equals("sync-rule", StringComparison.OrdinalIgnoreCase))
                                {
                                    var scopeExpression = string.Empty;
                                    foreach (var scope in joinCriterion.XPathSelectElements("scoping/scope"))
                                    {
                                        scopeExpression += string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} AND ", (string)scope.Element("csAttribute"), (string)scope.Element("csOperator"), (string)scope.Element("csValue"));
                                    }

                                    mappingType = string.IsNullOrEmpty(scopeExpression) ? "Sync Rule - Direct" : "Sync Rule - Scoped - " + scopeExpression.Substring(0, scopeExpression.Length - " AND ".Length);
                                }

                                Documenter.AddRow(table2, new object[] { sourceObjectType, mappingGroupIndex, metaverseObjectType, sourceAttribute, mappingType, metaverseAttribute });
                            }
                        }
                    }

                    table.AcceptChanges();
                    table2.AcceptChanges();
                }
            }
            finally
            {
                Logger.Instance.WriteMethodExit("Pilot Config: '{0}'", pilotConfig);
            }
        }