diff --git a/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs b/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs index b901f034b..b205f07b6 100644 --- a/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs +++ b/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs @@ -255,8 +255,14 @@ public async Task VerifyWriteEnumerableOperationContainer() var operationContainers = new[] { new OperationContainer("/SiteDirectory/00000000-0000-0000-0000-000000000000", 0) }; Assert.Throws(() => this.dal.Write(operationContainers, files)); - var domain = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "SYS" }; - this.siteDirectoryData.Domain.Add(domain); + var domainSys = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "SYS" }; + this.siteDirectoryData.Domain.Add(domainSys); + + var domainAer = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "AER" }; + this.siteDirectoryData.Domain.Add(domainAer); + + var domainProp = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "PROP" }; + this.siteDirectoryData.Domain.Add(domainProp); // PersonRole var role = new PersonRole(Guid.NewGuid(), null, null); @@ -269,8 +275,10 @@ public async Task VerifyWriteEnumerableOperationContainer() this.siteDirectoryData.DefaultParticipantRole = participantRole; // Organization - var organization = new Organization(Guid.NewGuid(), null, null); - organization.Container = this.siteDirectoryData; + var organization = new Organization(Guid.NewGuid(), null, null) + { + Container = this.siteDirectoryData + }; var sitedirectoryDto = (CDP4Common.DTO.SiteDirectory)this.siteDirectoryData.ToDto(); var clone = sitedirectoryDto.DeepClone(); @@ -289,16 +297,34 @@ public async Task VerifyWriteEnumerableOperationContainer() var iterationSetupPoco = new CDP4Common.SiteDirectoryData.IterationSetup(iterationSetup.Iid, cache, this.credentials.Uri); var model = new EngineeringModel(Guid.NewGuid(), cache, this.credentials.Uri); var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(); - modelSetup.ActiveDomain.Add(domain); + modelSetup.ActiveDomain.Add(domainSys); + + var source = new ReferenceSource(Guid.NewGuid(), cache, this.credentials.Uri) + { + Publisher = new Organization(Guid.NewGuid(), cache, this.credentials.Uri) + { + Container = this.siteDirectoryData + } + }; + + var requiredRdl = new ModelReferenceDataLibrary + { + RequiredRdl = new SiteReferenceDataLibrary(), + ReferenceSource = { source } + }; - var requiredRdl = new CDP4Common.SiteDirectoryData.ModelReferenceDataLibrary(); + var person = new Person + { + ShortName = "admin", + Organization = organization, + DefaultDomain = domainAer + }; - var person = new Person { ShortName = "admin" }; - person.Organization = organization; - var participant = new Participant(Guid.NewGuid(), cache, this.credentials.Uri) {Person = person}; + var participant = new Participant(Guid.NewGuid(), cache, this.credentials.Uri) { Person = person }; participant.Person.Role = role; participant.Role = participantRole; - participant.Domain.Add(domain); + participant.Domain.Add(domainSys); + participant.Domain.Add(domainProp); modelSetup.Participant.Add(participant); var lazyPerson = new Lazy(() => person); @@ -308,14 +334,17 @@ public async Task VerifyWriteEnumerableOperationContainer() model.EngineeringModelSetup = modelSetup; this.siteDirectoryData.Model.Add(modelSetup); modelSetup.RequiredRdl.Add(requiredRdl); + modelSetup.IterationSetup.Add(iterationSetupPoco); cache.TryAdd(new CacheKey(person.Iid, this.siteDirectoryData.Iid), lazyPerson); this.siteDirectoryData.Cache = cache; iteration.IterationSetup = iterationSetup.Iid; + var clone1 = iteration.DeepClone(); operation = new Operation(iteration, clone1, OperationKind.Update); - operationContainers = new[] { new OperationContainer("/EngineeringModel/" + model.Iid + "/iteration/" + iteration.Iid, 0) }; - operationContainers.Single().AddOperation(operation); + var operationContainer = new OperationContainer("/EngineeringModel/" + model.Iid + "/iteration/" + iteration.Iid, 0); + operationContainer.AddOperation(operation); + operationContainers = new[] { operationContainer, operationContainer }; Assert.IsEmpty(await this.dal.Write(operationContainers, files)); } diff --git a/CDP4JsonFileDal/JsonFileDal.cs b/CDP4JsonFileDal/JsonFileDal.cs index b20a82037..23162de35 100644 --- a/CDP4JsonFileDal/JsonFileDal.cs +++ b/CDP4JsonFileDal/JsonFileDal.cs @@ -176,7 +176,7 @@ public override Task> Write(IEnumerable o var iterations = new HashSet(); var siteReferenceDataLibraries = new HashSet(); var modelReferenceDataLibraries = new HashSet(); - var domainsOfExpertises = new HashSet(); + var domainOfExpertises = new HashSet(); var persons = new HashSet(); var personRoles = new HashSet(); var participantRoles = new HashSet(); @@ -207,7 +207,7 @@ public override Task> Write(IEnumerable o } // add the domains-of-expertise that are to be included in the File - JsonFileDalUtils.AddDomainsOfExpertise(engineeringModelSetup, ref domainsOfExpertises); + JsonFileDalUtils.AddDomainsOfExpertise(engineeringModelSetup, ref domainOfExpertises); // add the Persons that are to be included in the File JsonFileDalUtils.AddPersons(engineeringModelSetup, ref persons, ref personRoles, ref participantRoles, ref organizations); @@ -221,7 +221,7 @@ public override Task> Write(IEnumerable o var prunedSiteDirectoryDtos = JsonFileDalUtils.CreateSiteDirectoryAndPrunedContainedThingDtos( siteDirectory, siteReferenceDataLibraries, - domainsOfExpertises, + domainOfExpertises, persons, personRoles, participantRoles, diff --git a/CDP4JsonFileDal/JsonFileDalUtils.cs b/CDP4JsonFileDal/JsonFileDalUtils.cs index 1f9a3c4ad..29fa303d0 100644 --- a/CDP4JsonFileDal/JsonFileDalUtils.cs +++ b/CDP4JsonFileDal/JsonFileDalUtils.cs @@ -152,6 +152,23 @@ internal static void AddDomainsOfExpertise(EngineeringModelSetup engineeringMode domainOfExpertises.Add(domainOfExpertise); } } + + foreach (var participant in engineeringModelSetup.Participant) + { + foreach (var domainOfExpertise in participant.Domain) + { + if (!domainOfExpertises.Contains(domainOfExpertise)) + { + domainOfExpertises.Add(domainOfExpertise); + } + } + + if (participant.Person.DefaultDomain != null && + !domainOfExpertises.Contains(participant.Person.DefaultDomain)) + { + domainOfExpertises.Add(participant.Person.DefaultDomain); + } + } } ///