protected void FillConnectorObjectTypeImportAttributeFlowsDataSet()

in src/MIMConfigDocumenter/ConnectorDocumenter.cs [1822:1953]


        protected void FillConnectorObjectTypeImportAttributeFlowsDataSet(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 table = dataSet.Tables[0];

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

                if (connector != null)
                {
                    var connectorId = ((string)connector.Element("id") ?? string.Empty).ToUpperInvariant();
                    var connectorIdXPath = "translate(@src-ma, '" + Documenter.LowercaseLetters + "', '" + Documenter.UppercaseLetters + "') = '" + connectorId + "'";
                    var importFlowsXPath = Documenter.GetMetaverseXmlRootXPath(pilotConfig) + "/mv-data/import-attribute-flow/import-flow-set" + "[@mv-object-type = '" + this.currentMetaverseObjectType + "']/import-flows/import-flow[@cd-object-type = '" + this.currentDataSourceObjectType + "' and " + connectorIdXPath + "]";
                    var metaverseAttributes = from importFlow in connector.XPathSelectElements(importFlowsXPath)
                                              let metaverseAttribute = (string)importFlow.Parent.Attribute("mv-attribute")
                                              orderby metaverseAttribute
                                              select metaverseAttribute;

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

                    var importFlowRuleIndex = 0; // This will be the relative rule number if there are more than one inbound sync rule import flows for the same metaverse attribute.
                    var previousMetaverseAttribute = string.Empty;
                    foreach (var metaverseAttribute in metaverseAttributes.Distinct())
                    {
                        var allImportFlowsXPath = Documenter.GetMetaverseXmlRootXPath(pilotConfig) + "/mv-data/import-attribute-flow/import-flow-set[@mv-object-type = '" + this.currentMetaverseObjectType + "']/import-flows[@mv-attribute = '" + metaverseAttribute + "']";
                        var precedenceType = config.XPathSelectElement(allImportFlowsXPath) != null ? (string)config.XPathSelectElement(allImportFlowsXPath).Attribute("type") : string.Empty;
                        var allImportFlows = config.XPathSelectElements(allImportFlowsXPath + "/import-flow");

                        var importFlowRank = 0;
                        var importFlowIndex = 0;
                        foreach (var importFlow in allImportFlows)
                        {
                            ++importFlowIndex;

                            var importFlowConnectorId = ((string)importFlow.Attribute("src-ma") ?? string.Empty).ToUpperInvariant();

                            importFlowRank = precedenceType.Equals("ranked", StringComparison.OrdinalIgnoreCase) ? importFlowRank + 1 : 0;

                            if (importFlowConnectorId != connectorId)
                            {
                                continue;
                            }

                            importFlowRuleIndex = metaverseAttribute == previousMetaverseAttribute ? importFlowRuleIndex + 1 : 0;
                            previousMetaverseAttribute = metaverseAttribute;

                            var dataSourceAttribute = string.Empty;
                            var mappingType = string.Empty;
                            var scopeExpression = string.Empty;

                            if (importFlow.XPathSelectElement("direct-mapping/src-attribute") != null)
                            {
                                dataSourceAttribute = importFlow.XPathSelectElement("direct-mapping/src-attribute").Value;
                                mappingType = "Direct";
                            }
                            else if (importFlow.XPathSelectElement("scripted-mapping/src-attribute") != null)
                            {
                                foreach (var sourceAttribute in importFlow.XPathSelectElements("scripted-mapping/src-attribute"))
                                {
                                    dataSourceAttribute += (string)sourceAttribute + "<br/>";
                                }

                                dataSourceAttribute = !string.IsNullOrEmpty(dataSourceAttribute) ? dataSourceAttribute.Substring(0, dataSourceAttribute.Length - "<br/>".Length) : dataSourceAttribute;
                                mappingType = "Rules Extension - " + importFlow.XPathSelectElement("scripted-mapping/script-context").Value;
                            }
                            else if (importFlow.XPathSelectElement("constant-mapping/constant-value") != null)
                            {
                                dataSourceAttribute = string.Empty;
                                mappingType = "Constant - " + importFlow.XPathSelectElement("constant-mapping/constant-value").Value;
                            }
                            else if (importFlow.XPathSelectElement("dn-part-mapping/dn-part") != null)
                            {
                                dataSourceAttribute = string.Empty;
                                mappingType = "DN Component - ( " + importFlow.XPathSelectElement("dn-part-mapping/dn-part").Value + " )";
                            }
                            else if (importFlow.XPathSelectElement("sync-rule-mapping") != null)
                            {
                                mappingType = (string)importFlow.XPathSelectElement("sync-rule-mapping").Attribute("mapping-type") ?? string.Empty;
                                if (mappingType.Equals("direct", StringComparison.OrdinalIgnoreCase))
                                {
                                    dataSourceAttribute = importFlow.XPathSelectElement("sync-rule-mapping/src-attribute").Value;
                                    mappingType = "Sync Rule - Direct";
                                }
                                else if (mappingType.Equals("constant", StringComparison.OrdinalIgnoreCase))
                                {
                                    dataSourceAttribute = importFlow.XPathSelectElement("sync-rule-mapping/sync-rule-value").Value;
                                    mappingType = "Sync Rule - Constant";
                                }
                                else
                                {
                                    foreach (var sourceAttribute in importFlow.XPathSelectElements("sync-rule-mapping/src-attribute"))
                                    {
                                        dataSourceAttribute += (string)sourceAttribute + "<br/>";
                                    }

                                    dataSourceAttribute = !string.IsNullOrEmpty(dataSourceAttribute) ? dataSourceAttribute.Substring(0, dataSourceAttribute.Length - "<br/>".Length) : dataSourceAttribute;
                                    mappingType = "Sync Rule - Expression";  // TODO: Print the Sync Rule Expression
                                }

                                var syncRuleId = (string)importFlow.XPathSelectElement("sync-rule-mapping").Attribute("sync-rule-id") ?? string.Empty;

                                foreach (var scope in connector.XPathSelectElements("join/join-profile/join-criterion[@sync-rule-id='" + syncRuleId + "']/scoping/scope"))
                                {
                                    scopeExpression += string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} AND ", (string)scope.Element("csAttribute"), (string)scope.Element("csOperator"), (string)scope.Element("csValue"));
                                }

                                if (scopeExpression.Length > 5)
                                {
                                    scopeExpression = scopeExpression.Substring(0, scopeExpression.Length - " AND ".Length);
                                }
                            }

                            Documenter.AddRow(table, new object[] { metaverseAttribute + importFlowRuleIndex, dataSourceAttribute, "&#8594;", metaverseAttribute, mappingType, scopeExpression, precedenceType.Equals("ranked", StringComparison.OrdinalIgnoreCase) ? importFlowRank.ToString(CultureInfo.InvariantCulture) : precedenceType });
                        }
                    }

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