/// <summary> /// Insert a new database record from the supplied data transfer object. /// </summary> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="siteReferenceDataLibrary"> /// The siteReferenceDataLibrary DTO that is to be persisted. /// </param> /// <param name="container"> /// The container of the DTO to be persisted. /// </param> /// <returns> /// True if the concept was successfully persisted. /// </returns> public virtual bool Write(NpgsqlTransaction transaction, string partition, CDP4Common.DTO.SiteReferenceDataLibrary siteReferenceDataLibrary, CDP4Common.DTO.Thing container = null) { bool isHandled; var valueTypeDictionaryAdditions = new Dictionary <string, string>(); var beforeWrite = this.BeforeWrite(transaction, partition, siteReferenceDataLibrary, container, out isHandled, valueTypeDictionaryAdditions); if (!isHandled) { beforeWrite = beforeWrite && base.Write(transaction, partition, siteReferenceDataLibrary, container); var valueTypeDictionaryContents = new Dictionary <string, string> { { "IsDeprecated", !this.IsDerived(siteReferenceDataLibrary, "IsDeprecated") ? siteReferenceDataLibrary.IsDeprecated.ToString() : string.Empty }, }.Concat(valueTypeDictionaryAdditions).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); using (var command = new NpgsqlCommand()) { var sqlBuilder = new System.Text.StringBuilder(); sqlBuilder.AppendFormat("INSERT INTO \"{0}\".\"SiteReferenceDataLibrary\"", partition); sqlBuilder.AppendFormat(" (\"Iid\", \"ValueTypeDictionary\", \"Container\")"); sqlBuilder.AppendFormat(" VALUES (:iid, :valueTypeDictionary, :container);"); command.Parameters.Add("iid", NpgsqlDbType.Uuid).Value = siteReferenceDataLibrary.Iid; command.Parameters.Add("valueTypeDictionary", NpgsqlDbType.Hstore).Value = valueTypeDictionaryContents; command.Parameters.Add("container", NpgsqlDbType.Uuid).Value = container.Iid; command.CommandText = sqlBuilder.ToString(); command.Connection = transaction.Connection; command.Transaction = transaction; this.ExecuteAndLogCommand(command); } } return(this.AfterWrite(beforeWrite, transaction, partition, siteReferenceDataLibrary, container)); }
/// <summary> /// The mapping from a database record to data transfer object. /// </summary> /// <param name="reader"> /// An instance of the SQL reader. /// </param> /// <returns> /// A deserialized instance of <see cref="CDP4Common.DTO.SiteReferenceDataLibrary"/>. /// </returns> public virtual CDP4Common.DTO.SiteReferenceDataLibrary MapToDto(NpgsqlDataReader reader) { string tempIsDeprecated; string tempModifiedOn; string tempName; string tempShortName; string tempThingPreference; var valueDict = (Dictionary <string, string>)reader["ValueTypeSet"]; var iid = Guid.Parse(reader["Iid"].ToString()); var revisionNumber = int.Parse(valueDict["RevisionNumber"]); var dto = new CDP4Common.DTO.SiteReferenceDataLibrary(iid, revisionNumber); dto.Alias.AddRange(Array.ConvertAll((string[])reader["Alias"], Guid.Parse)); dto.BaseQuantityKind.AddRange(Utils.ParseOrderedList <Guid>(reader["BaseQuantityKind"] as string[, ])); dto.BaseUnit.AddRange(Array.ConvertAll((string[])reader["BaseUnit"], Guid.Parse)); dto.Constant.AddRange(Array.ConvertAll((string[])reader["Constant"], Guid.Parse)); dto.DefinedCategory.AddRange(Array.ConvertAll((string[])reader["DefinedCategory"], Guid.Parse)); dto.Definition.AddRange(Array.ConvertAll((string[])reader["Definition"], Guid.Parse)); dto.ExcludedDomain.AddRange(Array.ConvertAll((string[])reader["ExcludedDomain"], Guid.Parse)); dto.ExcludedPerson.AddRange(Array.ConvertAll((string[])reader["ExcludedPerson"], Guid.Parse)); dto.FileType.AddRange(Array.ConvertAll((string[])reader["FileType"], Guid.Parse)); dto.Glossary.AddRange(Array.ConvertAll((string[])reader["Glossary"], Guid.Parse)); dto.HyperLink.AddRange(Array.ConvertAll((string[])reader["HyperLink"], Guid.Parse)); dto.ParameterType.AddRange(Array.ConvertAll((string[])reader["ParameterType"], Guid.Parse)); dto.ReferenceSource.AddRange(Array.ConvertAll((string[])reader["ReferenceSource"], Guid.Parse)); dto.RequiredRdl = reader["RequiredRdl"] is DBNull ? (Guid?)null : Guid.Parse(reader["RequiredRdl"].ToString()); dto.Rule.AddRange(Array.ConvertAll((string[])reader["Rule"], Guid.Parse)); dto.Scale.AddRange(Array.ConvertAll((string[])reader["Scale"], Guid.Parse)); dto.Unit.AddRange(Array.ConvertAll((string[])reader["Unit"], Guid.Parse)); dto.UnitPrefix.AddRange(Array.ConvertAll((string[])reader["UnitPrefix"], Guid.Parse)); if (valueDict.TryGetValue("IsDeprecated", out tempIsDeprecated)) { dto.IsDeprecated = bool.Parse(tempIsDeprecated); } if (valueDict.TryGetValue("ModifiedOn", out tempModifiedOn)) { dto.ModifiedOn = Utils.ParseUtcDate(tempModifiedOn); } if (valueDict.TryGetValue("Name", out tempName)) { dto.Name = tempName.UnEscape(); } if (valueDict.TryGetValue("ShortName", out tempShortName)) { dto.ShortName = tempShortName.UnEscape(); } if (valueDict.TryGetValue("ThingPreference", out tempThingPreference) && tempThingPreference != null) { dto.ThingPreference = tempThingPreference.UnEscape(); } return(dto); }
public void SetUp() { this.uri = new Uri("http://www.rheagroup.com"); this.testInput = new List <Dto.Thing>(); //Top container this.siteDir = new Dto.SiteDirectory(Guid.NewGuid(), 1); this.siteRdl = new Dto.SiteReferenceDataLibrary(Guid.NewGuid(), 1); this.siteDir.SiteReferenceDataLibrary.Add(this.siteRdl.Iid); var category1 = new Dto.Category(Guid.NewGuid(), 1); category1.PermissibleClass.Add(ClassKind.ParameterType); category1.PermissibleClass.Add(ClassKind.Person); var category2 = new Dto.Category(Guid.NewGuid(), 1); category2.PermissibleClass.Add(ClassKind.TelephoneNumber); category2.PermissibleClass.Add(ClassKind.EmailAddress); this.siteRdl.DefinedCategory.Add(category1.Iid); this.siteRdl.DefinedCategory.Add(category2.Iid); //topContainer var siteRDL2 = new Dto.SiteReferenceDataLibrary(Guid.NewGuid(), 1); this.siteDir.SiteReferenceDataLibrary.Add(siteRDL2.Iid); var booleanParameterType = new Dto.BooleanParameterType(Guid.NewGuid(), 1); booleanParameterType.Category = new List <Guid> { category1.Iid, category2.Iid }; var definition = new Dto.Definition(Guid.NewGuid(), 1); booleanParameterType.Definition.Add(definition.Iid); siteRDL2.ParameterType.Add(booleanParameterType.Iid); this.testInput.Add(this.siteDir); this.testInput.Add(this.siteRdl); this.testInput.Add(category1); this.testInput.Add(category2); this.testInput.Add(definition); this.testInput.Add(siteRDL2); this.testInput.Add(booleanParameterType); }
public async Task VerifyThatCitationIsResolvedWhenRdlIsLoaded() { var sitedir = new Dto.SiteDirectory(Guid.NewGuid(), 1); var domain = new Dto.DomainOfExpertise(Guid.NewGuid(), 1); var definition = new Dto.Definition(Guid.NewGuid(), 1); var citation = new Dto.Citation(Guid.NewGuid(), 1); var referenceSource = new Dto.ReferenceSource(Guid.NewGuid(), 1); var srdl = new Dto.SiteReferenceDataLibrary(Guid.NewGuid(), 1); srdl.ReferenceSource.Add(referenceSource.Iid); citation.Source = referenceSource.Iid; sitedir.Domain.Add(domain.Iid); domain.Definition.Add(definition.Iid); definition.Citation.Add(citation.Iid); var assembler = new Assembler(this.uri); var input = new List <Dto.Thing>(); input.Add(sitedir); input.Add(domain); input.Add(definition); input.Add(citation); await assembler.Synchronize(input); var citationPoco = (Citation) assembler.Cache.Select(x => x.Value).Select(x => x.Value).Single(x => x.Iid == citation.Iid); Assert.AreEqual(citationPoco.Source.Iid, Guid.Empty); Assert.IsNotEmpty(citationPoco.ValidationErrors); sitedir.SiteReferenceDataLibrary.Add(srdl.Iid); input.Clear(); input.Add(sitedir); input.Add(srdl); input.Add(referenceSource); await assembler.Synchronize(input); Assert.IsNotNull(citationPoco.Source); }
public async Task VerifyThatAssemblerCanMoveThings() { var sitedir = new Dto.SiteDirectory(Guid.NewGuid(), 0); var srdl1 = new Dto.SiteReferenceDataLibrary(Guid.NewGuid(), 0); var srdl2 = new Dto.SiteReferenceDataLibrary(Guid.NewGuid(), 0); var category = new Dto.Category(Guid.NewGuid(), 0); sitedir.SiteReferenceDataLibrary.Add(srdl1.Iid); sitedir.SiteReferenceDataLibrary.Add(srdl2.Iid); srdl1.DefinedCategory.Add(category.Iid); var dtos = new List <Dto.Thing> { sitedir, srdl1, srdl2, category }; var assembler = new Assembler(this.uri); await assembler.Synchronize(dtos); Assert.AreEqual(4, assembler.Cache.Count); srdl1.DefinedCategory.Clear(); srdl2.DefinedCategory.Add(category.Iid); // move category var movedDtos = new List <Dto.Thing> { sitedir, srdl1, srdl2 }; await assembler.Synchronize(movedDtos); var srdl1poco = (SiteReferenceDataLibrary)assembler.Cache[new CacheKey(srdl1.Iid, null)].Value; var srdl2poco = (SiteReferenceDataLibrary)assembler.Cache[new CacheKey(srdl2.Iid, null)].Value; var catpoco = assembler.Cache[new CacheKey(category.Iid, null)].Value; Assert.AreEqual(4, assembler.Cache.Count); Assert.IsEmpty(srdl1poco.DefinedCategory); Assert.IsTrue(srdl2poco.DefinedCategory.Contains(catpoco)); }
public void VerifyThatMultipleIterationCanBeSynchronized() { var sitedir = new Dto.SiteDirectory(Guid.NewGuid(), 0); var srdl1 = new Dto.SiteReferenceDataLibrary(Guid.NewGuid(), 0); var srdl2 = new Dto.SiteReferenceDataLibrary(Guid.NewGuid(), 0); var category = new Dto.Category(Guid.NewGuid(), 0); var modeldto = new Dto.EngineeringModel(Guid.NewGuid(), 1); var iteration1dto = new Dto.Iteration(Guid.NewGuid(), 1); var iteration2dto = new Dto.Iteration(Guid.NewGuid(), 1); var element1dto = new Dto.ElementDefinition(Guid.NewGuid(), 1); element1dto.IterationContainerId = iteration1dto.Iid; element1dto.Category.Add(category.Iid); var element2dto = new Dto.ElementDefinition(element1dto.Iid, 1); element2dto.IterationContainerId = iteration2dto.Iid; element2dto.Category.Add(category.Iid); var usage1dto = new Dto.ElementUsage(Guid.NewGuid(), 1); usage1dto.IterationContainerId = iteration1dto.Iid; usage1dto.Category.Add(category.Iid); var usage2dto = new Dto.ElementUsage(usage1dto.Iid, 1); usage2dto.IterationContainerId = iteration2dto.Iid; usage2dto.Category.Add(category.Iid); sitedir.SiteReferenceDataLibrary.Add(srdl1.Iid); sitedir.SiteReferenceDataLibrary.Add(srdl2.Iid); srdl1.DefinedCategory.Add(category.Iid); modeldto.Iteration.Add(iteration1dto.Iid); modeldto.Iteration.Add(iteration2dto.Iid); iteration1dto.Element.Add(element1dto.Iid); iteration2dto.Element.Add(element2dto.Iid); element1dto.ContainedElement.Add(usage1dto.Iid); element2dto.ContainedElement.Add(usage2dto.Iid); var dtos = new List <Dto.Thing> { sitedir, srdl1, srdl2, category }; var assembler = new Assembler(this.uri); assembler.Synchronize(dtos); dtos = new List <Dto.Thing> { modeldto, iteration1dto, iteration2dto, element1dto, element2dto, usage1dto, usage2dto }; assembler.Synchronize(dtos); Assert.AreEqual(11, assembler.Cache.Count); }