Skip to content

Commit

Permalink
#203 Using SAT to migrate models(Take into account the DefaultDomain …
Browse files Browse the repository at this point in the history
…of the included Person objects) (#188)

* Take into account the DefaultDomain of the included Person objects.

* Remove wrong null asignment.

* Whitespace

* A more correct conjugation.

* Move/Add Person DefaultDomain and Participant Domain logic inside AddDomainOfExpertise method.

* Code review changes.

* Increase code coverage.

* Fix spelling issue.

* Increase code coverage

Co-authored-by: Cozmin Velciu <[email protected]>
Co-authored-by: Adrian Chivu <[email protected]>
  • Loading branch information
3 people authored May 18, 2021
1 parent 14f813c commit c3b67e5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
53 changes: 41 additions & 12 deletions CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,14 @@ public async Task VerifyWriteEnumerableOperationContainer()
var operationContainers = new[] { new OperationContainer("/SiteDirectory/00000000-0000-0000-0000-000000000000", 0) };
Assert.Throws<ArgumentException>(() => 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);
Expand All @@ -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<CDP4Common.DTO.SiteDirectory>();
Expand All @@ -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<Thing>(() => person);
Expand All @@ -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<Iteration>();
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));
}
Expand Down
6 changes: 3 additions & 3 deletions CDP4JsonFileDal/JsonFileDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public override Task<IEnumerable<Thing>> Write(IEnumerable<OperationContainer> o
var iterations = new HashSet<CDP4Common.EngineeringModelData.Iteration>();
var siteReferenceDataLibraries = new HashSet<CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary>();
var modelReferenceDataLibraries = new HashSet<CDP4Common.SiteDirectoryData.ModelReferenceDataLibrary>();
var domainsOfExpertises = new HashSet<CDP4Common.SiteDirectoryData.DomainOfExpertise>();
var domainOfExpertises = new HashSet<CDP4Common.SiteDirectoryData.DomainOfExpertise>();
var persons = new HashSet<CDP4Common.SiteDirectoryData.Person>();
var personRoles = new HashSet<CDP4Common.SiteDirectoryData.PersonRole>();
var participantRoles = new HashSet<CDP4Common.SiteDirectoryData.ParticipantRole>();
Expand Down Expand Up @@ -207,7 +207,7 @@ public override Task<IEnumerable<Thing>> Write(IEnumerable<OperationContainer> 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);
Expand All @@ -221,7 +221,7 @@ public override Task<IEnumerable<Thing>> Write(IEnumerable<OperationContainer> o
var prunedSiteDirectoryDtos = JsonFileDalUtils.CreateSiteDirectoryAndPrunedContainedThingDtos(
siteDirectory,
siteReferenceDataLibraries,
domainsOfExpertises,
domainOfExpertises,
persons,
personRoles,
participantRoles,
Expand Down
17 changes: 17 additions & 0 deletions CDP4JsonFileDal/JsonFileDalUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

/// <summary>
Expand Down

0 comments on commit c3b67e5

Please sign in to comment.