public string GenerateXpath(DB.TemplateConstraint aStartConstraint) { if (!aStartConstraint.ParentConstraintId.HasValue) { return(aStartConstraint.Context); } StringBuilder lXpathBuilder = new StringBuilder(); lXpathBuilder.Append(aStartConstraint.Context); DB.TemplateConstraint lParentConstraint = aStartConstraint.ParentConstraint; do { string addition = lParentConstraint.Context; if (!string.IsNullOrEmpty(lParentConstraint.DataType)) { addition += string.Format("[{0}]", lParentConstraint.DataType); } addition += "/"; lXpathBuilder.Insert(0, addition); lParentConstraint = _tdb.TemplateConstraints.DefaultIfEmpty(null) .SingleOrDefault(tc => tc.Id == (lParentConstraint.ParentConstraintId ?? -1)); } while (lParentConstraint != null); return(lXpathBuilder.ToString()); }
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 string GetConstraintDescription(DB.TemplateConstraint constraint) { StringBuilder description = new StringBuilder(); if (constraint.IsHeading) { description.Append(string.Format("<p><b>{0}</b></p>\r\n", constraint.Context)); if (!string.IsNullOrEmpty(constraint.HeadingDescription)) { description.Append(string.Format("<p>{0}</p>\r\n", constraint.HeadingDescription)); } } if (!string.IsNullOrEmpty(constraint.Description)) { description.Append(string.Format("<p>{0}</p>\r\n", constraint.Description)); } if (!string.IsNullOrEmpty(constraint.Label)) { description.Append(string.Format("<p>Label: {0}</p>\r\n", constraint.Label)); } return(description.ToString()); }
private void UpdateTemplateConstraints(PublishModel aModel, DB.Template aTemplate) { foreach (PublishConstraint lConstraintView in aModel.Constraints) { DB.TemplateConstraint lConstraint = _tdb.TemplateConstraints.Single(tc => tc.Id == lConstraintView.Id && tc.TemplateId == aTemplate.Id); this.UpdateConstraint(lConstraint, lConstraintView); } }
private void UpdateConstraint(DB.TemplateConstraint aConstraint, PublishConstraint aConstraintView) { aConstraint.IsHeading = aConstraintView.IsHeading; aConstraint.HeadingDescription = aConstraintView.HeadingDescription; aConstraint.Description = aConstraintView.ConstraintDescription; aConstraint.Label = aConstraintView.ConstraintLabel; aConstraint.PrimitiveText = aConstraintView.PrimitiveText; // Remove all samples and the heading description if the constraint is no longer a heading if (!aConstraint.IsHeading) { aConstraintView.HeadingDescription = null; foreach (var sampleView in aConstraintView.Samples) { sampleView.IsDeleted = true; } } foreach (ConstraintSample lSample in aConstraintView.Samples.Where(s => s.Id.HasValue && s.IsDeleted)) { DB.TemplateConstraintSample lDeletedSample = _tdb.TemplateConstraintSamples.Single(tcs => tcs.Id == lSample.Id); _tdb.TemplateConstraintSamples.Remove(lDeletedSample); } foreach (ConstraintSample lSample in aConstraintView.Samples.Where(s => s.Id.HasValue && s.IsDeleted == false)) { DB.TemplateConstraintSample lUpdatedSample = _tdb.TemplateConstraintSamples.Single(tcs => tcs.Id == lSample.Id); if (!string.Equals(lUpdatedSample.Name, lSample.Name)) { lUpdatedSample.Name = lSample.Name; } if (!string.Equals(lUpdatedSample.SampleText, lSample.SampleText)) { lUpdatedSample.SampleText = lSample.SampleText; } } foreach (ConstraintSample lSample in aConstraintView.Samples.Where(s => s.Id.HasValue == false && s.IsDeleted == false)) { DB.TemplateConstraintSample lNewSample = new DB.TemplateConstraintSample(); lNewSample.Name = lSample.Name; lNewSample.SampleText = lSample.SampleText; aConstraint.Samples.Add(lNewSample); } foreach (PublishConstraint lChildConstraint in aConstraintView.ChildConstraints) { DB.TemplateConstraint lConstraint = _tdb.TemplateConstraints.Single(tc => tc.Id == lChildConstraint.Id); this.UpdateConstraint(lConstraint, lChildConstraint); } }
public string GetConstraintDataType(DB.TemplateConstraint aConstraint, string aConstraintXpath) { var templateType = aConstraint.Template.TemplateType; string context = !string.IsNullOrEmpty(aConstraint.Template.PrimaryContextType) ? aConstraint.Template.PrimaryContextType : templateType.RootContextType; var schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current.Application, templateType.ImplementationGuideType); schema = schema.GetSchemaFromContext(context); SimpleSchema.SchemaObject lSchemaObject = schema.FindFromPath(aConstraintXpath); return(lSchemaObject.DataType); }
private bool AssertRequiredShallConstraints(DB.TemplateConstraint aRootConstraint, GreenTemplateViewModel aModel) { foreach (DB.TemplateConstraint lChildConstraint in aRootConstraint.ChildConstraints.Where(tc => tc.Conformance == "SHALL")) { if (!AssertRequiredShallConstraints(lChildConstraint, aModel)) { return(false); } } if (aRootConstraint.IsPrimitive) { return(true); } if (!string.IsNullOrEmpty(aRootConstraint.Value)) { return(true); } if (aRootConstraint.ChildConstraints.Count > 0) { return(true); } ConstraintViewModel lFoundModel = null; foreach (ConstraintViewModel lViewConstraint in aModel.childConstraints) { lFoundModel = this.FindConstraint(lViewConstraint, c => c.id == aRootConstraint.Id); if (lFoundModel != null) { break; } } if (lFoundModel == null) { return(false); } if (lFoundModel.isDeleted) { return(false); } return(lFoundModel.hasGreenConstraint); }
private PublishConstraint BuildConstraint( DB.IObjectRepository tdb, string baseLink, IGSettingsManager igSettings, IIGTypePlugin igTypePlugin, DB.TemplateConstraint dbConstraint, int constraintCount, int?aParentConstraintId = null) { IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, igTypePlugin, dbConstraint); PublishConstraint newConstraint = new PublishConstraint(dbConstraint, fc); foreach (DB.TemplateConstraintSample lSample in dbConstraint.Samples) { ConstraintSample lSampleView = new ConstraintSample() { Id = lSample.Id, Name = lSample.Name, SampleText = lSample.SampleText, ConstraintId = dbConstraint.Id }; newConstraint.Samples.Add(lSampleView); } if (aParentConstraintId.HasValue) { newConstraint.ParentConstraintId = aParentConstraintId.Value; } int nextConstraintCount = 0; foreach (DB.TemplateConstraint cDbConstraint in dbConstraint.ChildConstraints.OrderBy(y => y.Order)) { PublishConstraint nextNewConstraint = BuildConstraint(tdb, baseLink, igSettings, igTypePlugin, cDbConstraint, ++nextConstraintCount, dbConstraint.Id); newConstraint.ChildConstraints.Add(nextNewConstraint); } return(newConstraint); }
private DB.GreenConstraint AddNewConstraint(ConstraintViewModel aNewConstraint) { DB.TemplateConstraint lUnderlyingConstraint = _tdb.TemplateConstraints.Single(tc => tc.Id == aNewConstraint.id); ConstraintXpathBuilder lXpathBuilder = new ConstraintXpathBuilder(_tdb); string lXpath = lXpathBuilder.GenerateXpath(lUnderlyingConstraint); DB.GreenConstraint lNewModel = new DB.GreenConstraint() { Description = aNewConstraint.businessName, Name = aNewConstraint.elementName, TemplateConstraintId = aNewConstraint.id, RootXpath = lXpath }; if (aNewConstraint.datatypeId.HasValue) { DB.ImplementationGuideTypeDataType lDataType = _tdb.ImplementationGuideTypeDataTypes.Single(dt => dt.Id == aNewConstraint.datatypeId.Value); lNewModel.ImplementationGuideTypeDataType = lDataType; } return(lNewModel); }
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; } }); }