Skip to content

Commit

Permalink
#2256 Add new Exception and change message to show Module (#2253)
Browse files Browse the repository at this point in the history
* #1280 Add new Exception and chang message to show Module

* #1280 Add new Exception and chang message to show Module

* #1280 Fix Tabs

* #1280 tabs on select statement

* #1280 Fixes on Code Review

* #1280 Changes on Exception
  • Loading branch information
benjaperez1983 committed Jun 14, 2024
1 parent d689b04 commit 7e8d6df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/OSPSuite.Assets/UIConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,8 @@ public static class Error
public static readonly string FoldValueMustBeGreaterThanOne = "Fold value must be a number greater than one.";
public static readonly string ImporterEmptyFile = "The file you are trying to load is empty.";

public static string CannotFindParentContainerWithPath(string parentPath, string containerName)=> $"Cannot find parent container '{parentPath}' defined as target of container '{containerName}'";
public static string CannotFindParentContainerWithPath(string parentPath, string containerName, string buildingBlockName, string moduleName) =>
$"Cannot find parent container '{parentPath}' defined as target of container '{containerName}' in building block '{buildingBlockName}' in module '{moduleName}'";

public static string NoUnitColumnValues(string mappingName) => $"No values for the unit were found in the excel column mapped for '{mappingName}' \n";

Expand Down
27 changes: 23 additions & 4 deletions src/OSPSuite.Core/Domain/Services/SpatialStructureMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ private void createMergedContainerStructureInRoot(IContainer root, SimulationBui

//Merge all other spatial structures
//make sure we map the container to a model container so that we do not change the original containers

allOtherSpatialStructuresWithMergeBehavior.Select(x => new {x.mergeBehavior, topContainers = x.spatialStructure.TopContainers.Select(mapToModelContainer).ToList()})
.Each(x => x.topContainers.Each(topContainer => mergeTopContainerInStructure(topContainer, root, x.mergeBehavior)));
allOtherSpatialStructuresWithMergeBehavior
.Select(item => new { item.mergeBehavior, topContainers = item.spatialStructure.TopContainers.Select(mapToModelContainer).ToList(), item.spatialStructure })
.Each(x => { x.topContainers.Each(topContainer => { tryMergeTopContainerInStructure(root, topContainer, x.mergeBehavior, x.spatialStructure); }); });

//create the temporary GLOBAL MOLECULE PROPERTIES THAT WILL BE REMOVED AT THE END but used as based for copying
//For molecule properties, we always merged as we used to and never replace
Expand All @@ -89,6 +89,18 @@ private void createMergedContainerStructureInRoot(IContainer root, SimulationBui
}
}

private void tryMergeTopContainerInStructure(IContainer root, IContainer topContainer, MergeBehavior mergeBehavior, SpatialStructure spatialStructure)
{
try
{
mergeTopContainerInStructure(topContainer, root, mergeBehavior);
}
catch (ContainerNotFoundException ex)
{
throw new OSPSuiteException(Error.CannotFindParentContainerWithPath(topContainer.ParentPath.PathAsString, topContainer.Name, spatialStructure.Name, spatialStructure.Module.Name));
}
}

private Func<IContainer, IContainer> mapContainerDef(SimulationBuilder simulationBuilder) => container => _containerMapper.MapFrom(container, simulationBuilder);

private void mergeTopContainerInStructure(IContainer topContainer, IContainer root, MergeBehavior mergeBehavior)
Expand All @@ -108,7 +120,7 @@ private void insertTopContainerIntoStructure(IContainer topContainer, IContainer
{
var parentContainer = topContainer.ParentPath.Resolve<IContainer>(root);
if (parentContainer == null)
throw new OSPSuiteException(Error.CannotFindParentContainerWithPath(topContainer.ParentPath.PathAsString, topContainer.Name));
throw new ContainerNotFoundException();

replaceOrMergeContainerIntoParent(parentContainer, topContainer, mergeBehavior);
}
Expand Down Expand Up @@ -166,4 +178,11 @@ private void addOrReplaceInContainer(IContainer container, IEntity entityToAddOr

public IContainer MergeNeighborhoods(ModelConfiguration modelConfiguration) => _neighborhoodsMapper.MapFrom(modelConfiguration);
}

internal class ContainerNotFoundException : OSPSuiteException
{
public ContainerNotFoundException() : base()
{
}
}
}

0 comments on commit 7e8d6df

Please sign in to comment.