private ConstraintViewModel BuildConstraint(DB.IObjectRepository tdb, string baseLink, IGSettingsManager igSettings, DB.TemplateConstraint dbConstraint, int constraintCount, int?aParentConstraintId = null) { IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, dbConstraint); WIKIParser wikiParser = new WIKIParser(tdb); ConstraintViewModel lGreenViewModel = new ConstraintViewModel() { constraintLabel = dbConstraint.Label, headingDescription = dbConstraint.HeadingDescription, id = dbConstraint.Id, order = dbConstraint.Order, isHeading = dbConstraint.IsHeading, isPrimitive = dbConstraint.IsPrimitive, primitiveText = dbConstraint.PrimitiveText, templateId = dbConstraint.TemplateId, number = dbConstraint.Number, text = fc.GetPlainText(false, false, false), conformance = dbConstraint.Conformance, value = dbConstraint.Value }; lGreenViewModel.constraintDescription = GetConstraintDescription(dbConstraint); DB.GreenConstraint lGreenConstraint = dbConstraint.GreenConstraints.DefaultIfEmpty(null).FirstOrDefault(); if (lGreenConstraint != null) { lGreenViewModel.Use(c => { c.businessName = lGreenConstraint.Description; c.elementName = lGreenConstraint.Name; c.xPath = lGreenConstraint.RootXpath; c.greenConstraintId = lGreenConstraint.Id; c.hasGreenConstraint = true; if (lGreenConstraint.ImplementationGuideTypeDataTypeId.HasValue) { c.datatype = lGreenConstraint.ImplementationGuideTypeDataType.DataTypeName; c.datatypeId = lGreenConstraint.ImplementationGuideTypeDataType.Id; } }); } if (aParentConstraintId.HasValue) { lGreenViewModel.parentConstraintId = aParentConstraintId.Value; } int nextConstraintCount = 0; foreach (DB.TemplateConstraint cDbConstraint in dbConstraint.ChildConstraints.Where(cc => cc.IsPrimitive == false).OrderBy(y => y.Order)) { ConstraintViewModel nextNewConstraint = BuildConstraint(tdb, baseLink, igSettings, cDbConstraint, ++nextConstraintCount, dbConstraint.Id); lGreenViewModel.children.Add(nextNewConstraint); } return(lGreenViewModel); }
private void CreateIfRequiredGreenTemplateTree(ConstraintViewModel aStartConstraint) { if (aStartConstraint.hasGreenConstraint) { return; } if (aStartConstraint.conformance != "SHALL" && aStartConstraint.conformance != "SHOULD") { return; } if (!string.IsNullOrEmpty(aStartConstraint.value)) { return; } var lChildren = aStartConstraint.children .Where(c => c.conformance == "SHALL" || c.conformance == "SHOULD") .Where(c => string.IsNullOrEmpty(c.value)); foreach (ConstraintViewModel lChild in lChildren) { CreateIfRequiredGreenTemplateTree(lChild); } if (aStartConstraint.children.Count > 0) { return; //Leaf-level only } DB.TemplateConstraint lRootConstraint = _tdb.TemplateConstraints.Single(c => c.Id == aStartConstraint.id); aStartConstraint.Use(c => { c.businessName = c.elementName = lRootConstraint.Context; c.hasGreenConstraint = true; string lDataTypeToUse = null; // --- Identify data type to use, which will come from data types contained in the IG if (!string.IsNullOrEmpty(lRootConstraint.DataType) && lRootConstraint.DataType != "ANY") { lDataTypeToUse = lRootConstraint.DataType; } else { ConstraintXpathBuilder lBuilder = new ConstraintXpathBuilder(_tdb); string lXpath = lBuilder.GenerateXpath(lRootConstraint); ConstraintDataTypeResolver lResolver = new ConstraintDataTypeResolver(); string lDataType = lResolver.GetConstraintDataType(lRootConstraint, lXpath); lDataTypeToUse = lDataType; } // --- Load data type, only use if constraint is leaf-level DB.ImplementationGuideTypeDataType lUnderlyingType = _tdb.ImplementationGuideTypeDataTypes.SingleOrDefault(d => d.DataTypeName == lDataTypeToUse); if (lUnderlyingType != null && lRootConstraint.ChildConstraints.Count(y => !y.IsPrimitive) == 0) { c.datatypeId = lUnderlyingType.Id; c.datatype = lUnderlyingType.DataTypeName; } }); }