/// <summary> /// Makes the other <see cref="CohortAggregateContainer"/> into a subcontainer of this container /// </summary> /// <param name="child"></param> public void AddChild(CohortAggregateContainer child) { if (child.IsRootContainer()) { throw new InvalidOperationException("Root containers cannot be added as subcontainers"); } CreateInsertionPointAtOrder(child, child.Order, true); _manager.Add(this, child); }
/// <summary> /// Splits the root container of a <see cref="CohortIdentificationConfiguration"/> into multiple new cic. /// </summary> /// <param name="rootContainer"></param> /// <returns>All new configurations unmerged out of the <paramref name="rootContainer"/></returns> public CohortIdentificationConfiguration[] UnMerge(CohortAggregateContainer rootContainer) { if (!rootContainer.IsRootContainer()) { throw new ArgumentException("Container must be a root container to be unmerged", nameof(rootContainer)); } if (rootContainer.GetAggregateConfigurations().Any()) { throw new ArgumentException("Container must contain only sub-containers (i.e. no aggregates)", nameof(rootContainer)); } if (rootContainer.GetSubContainers().Length <= 1) { throw new ArgumentException("Container must contain 2+ sub-containers to be unmerged", nameof(rootContainer)); } var cic = rootContainer.GetCohortIdentificationConfiguration(); var toReturn = new List <CohortIdentificationConfiguration>(); try { // clone the input cic cic = cic.CreateClone(new ThrowImmediatelyCheckNotifier()); // grab the new clone root container rootContainer = cic.RootCohortAggregateContainer; } catch (Exception ex) { throw new Exception("Error during pre merge cloning stage, no UnMerge will be attempted", ex); } using (_repository.BeginNewTransactedConnection()) { // For each of these foreach (var subContainer in rootContainer.GetSubContainers().OrderBy(c => c.Order)) { // create a new config var newCic = new CohortIdentificationConfiguration(_repository, $"Un Merged { subContainer.Name } ({subContainer.ID }) "); //take the container we are splitting out subContainer.MakeIntoAnOrphan(); //make it the root container of the new cic newCic.RootCohortAggregateContainer_ID = subContainer.ID; newCic.SaveToDatabase(); // Make the new name of all the AggregateConfigurations match the new cic foreach (var child in subContainer.GetAllAggregateConfigurationsRecursively()) { EnsureNamingConvention(newCic, child); } toReturn.Add(newCic); } //Now delete the original clone that we unmerged the containers out of cic.DeleteInDatabase(); //finish transaction _repository.EndTransactedConnection(true); } return(toReturn.ToArray()); }