public void RecalculateBptModel(ManagingBpt.RootModel root, CalculationTicket ticket) { this.BptManager.RecalculateRootModel( root, this.connectionFactory, this.dataManagerFactory, ticket ); }
public IEnumerable <IValidationIssue> ApplyBroadGlobalActiveModelIfValid(ManagingBpt.RootModel root, String username, CalculationTicket ticket) { string userEmail = ""; using (var connection = this.usersConnectionFactory.CreateConnection()) { var manager = this.dataUsersManagerFactory.CreateDataManager(connection, null); userEmail = manager.GetUserEmail(username); } using (var connection = this.connectionFactory.CreateConnection()) { try { using (var ondemandManager = this.CreateOnDemandDataManager(connection)) { var targetingTypeRepository = this.RepositoryManager.ClaimTargetingTypeRepository(ondemandManager); var securityRepository = this.RepositoryManager.ClaimSecurityRepository(ondemandManager); var basketRepository = this.RepositoryManager.ClaimBasketRepository(ondemandManager); var portfolioRepository = this.RepositoryManager.ClaimPortfolioRepository(ondemandManager); var calculation = new CalculationInfo(); var issues = this.BptManager.ApplyIfValid( root, username, userEmail, connection, targetingTypeRepository, securityRepository, basketRepository, portfolioRepository, ticket, ref calculation ); if (!issues.Any(x => x is ErrorIssue)) { this.Calculate(calculation.Id, true); } return(issues); } } catch (EmailNotificationException e) { throw new ApplicationException("Notification email cannot be sent. Data haven't been saved yet. You can try again. If the problem persist contact IT department.", e); } catch (CalculationException e) { throw new ApplicationException("You change has been saved but portfolio recalculation went wrong. Contact IT department to restart recalculations.", e); } catch (OutputTargetingFileException e) { throw new ApplicationException("You change has been saved but targeting output file cannot be saved. Contact IT department to restart recalculations.", e); } } }
public RootModel DeserializeRoot( JsonReader reader, BasketRepository basketRepository, SecurityRepository securityRepository, PortfolioRepository portfolioRepository, TargetingTypeRepository targetingTypeRepository ) { return(reader.Read(delegate { var residents = new List <IGlobeResident>(); var globe = this.modelBuilder.CreateGlobeModel(residents); var computations = this.modelBuilder.CreateComputations(globe, this.traverser); var targetingTypeId = reader.ReadAsInt32(JsonNames.TargetingTypeId); var portfolioId = reader.ReadAsString(JsonNames.PortfolioId); var benchamrkDate = reader.ReadAsDatetime(JsonNames.BenchmarkDate); var latestChangesets = reader.Read(JsonNames.LatestChangesets, delegate { return new { TargetingTypeBasketBaseValue = reader.Read(JsonNames.TargetingTypeBasketBaseValue, delegate { return this.DeserializeTargetingTypeBasketBaseValueChangeset(reader); }), TargetingTypeBasketPortfolioTarget = reader.Read(JsonNames.TargetingTypeBasketPortfolioTarget, delegate { return this.DeserializeTargetingTypeBasketPortfolioTargetChangeset(reader); }), PortfolioSecurityTargetOverlay = reader.Read(JsonNames.PortfolioSecurityTargetOverlay, delegate { return this.DeserializePortfolioSecurityTargetOverlayChangeset(reader); }), PortfolioSecurityTarget = reader.Read(JsonNames.PortfolioSecurityTarget, delegate { return this.DeserializePortfolioSecurityTargetChangeset(reader); }) }; }); reader.Read(JsonNames.Root, delegate { reader.ReadArray(JsonNames.Residents, delegate { var resident = this.DeserializeBreakdownResidentModelOnceResolver(basketRepository, reader, computations); residents.Add(resident); }); }); var factors = reader.Read(JsonNames.Overlay, delegate { return this.DeserializeOverlay(reader, securityRepository, portfolioRepository); }); var cash = this.modelBuilder.CreateCash(computations); var portfolioScaledTotal = this.modelBuilder.CreateAddExpression(cash.PortfolioScaled, globe.PortfolioScaled); var targetingType = targetingTypeRepository.GetTargetingType(targetingTypeId); var portfolio = portfolioRepository.GetBroadGlobalActivePortfolio(portfolioId); var trueExposureGrandTotal = this.modelBuilder.CreateAddExpression(cash.TrueExposure, globe.TrueExposure); var trueActiveGrandTotal = this.modelBuilder.CreateAddExpression(cash.TrueActive, globe.TrueActive); var result = new RootModel( targetingType, portfolio, latestChangesets.TargetingTypeBasketBaseValue, latestChangesets.TargetingTypeBasketPortfolioTarget, latestChangesets.PortfolioSecurityTargetOverlay, latestChangesets.PortfolioSecurityTarget, globe, cash, factors, portfolioScaledTotal, trueExposureGrandTotal, trueActiveGrandTotal, benchamrkDate, false ); return result; })); }
public ManagingBpt.RootModel GetRootModel( Int32 targetingTypeId, String portfolioId, Boolean shouldBenchmarksBeInitialized, IDataManager manager, String username ) { ManagingBpt.RootModel result; // getting targeting, taxonomy, base values, overlays data from the database var countryRepository = this.repositoryManager.ClaimCountryRepository(manager); var targetingTypeRepository = this.repositoryManager.ClaimTargetingTypeRepository(manager); var targetingType = targetingTypeRepository.GetTargetingType(targetingTypeId); var baseValueResolver = this.CreateBaseValueResolver(manager, targetingType.Id); var securityRepository = this.repositoryManager.ClaimSecurityRepository(manager); var portfolioRepository = this.repositoryManager.ClaimPortfolioRepository(manager); var overlayModel = this.overlayManager.GetOverlayModel( targetingType, portfolioId, portfolioRepository, securityRepository, manager ); var latestTtbbvChangesetInfo = manager.GetLatestTargetingTypeBasketBaseValueChangeset(); var latestTtbptChangesetInfo = manager.GetLatestTargetingTypeBasketPortfolioTargetChangeset(); var latestPstoChangesetInfo = manager.GetLatestBgaPortfolioSecurityFactorChangeset(); var latestPstChangesetInfo = manager.GetLatestPortfolioSecurityTargetChangeSet(); var portfolioSecurityTargetRepository = this.repositoryManager.ClaimPortfolioSecurityTargetRepository(latestPstChangesetInfo, manager); var residents = new List <IGlobeResident>(); var globe = this.modelBuilder.CreateGlobeModel(residents); var computations = this.modelBuilder.CreateComputations(globe, this.Traverser); foreach (var node in targetingType.Taxonomy.GetResidents()) { var resident = this.taxonomyTransformer.CreateModelOnceResolved(computations, node); residents.Add(resident); } var cash = this.modelBuilder.CreateCash(computations); var portfolioScaledGrandTotal = this.modelBuilder.CreateAddExpression(cash.PortfolioScaled, globe.PortfolioScaled); var trueExposureGrandTotal = this.modelBuilder.CreateAddExpression(cash.TrueExposure, globe.TrueExposure); var trueActiveGrandTotal = this.modelBuilder.CreateAddExpression(cash.TrueActive, globe.TrueActive); var portfolio = portfolioRepository.GetBroadGlobalActivePortfolio(portfolioId); var benchmarkDate = manager.GetLastestDateWhichBenchmarkDataIsAvialableOn(); var isUserPermittedToSave = manager.IsSavePermittedForBGAUser(username); result = new RootModel( targetingType, portfolio, latestTtbbvChangesetInfo, latestTtbptChangesetInfo, latestPstoChangesetInfo, latestPstChangesetInfo, globe, cash, overlayModel, portfolioScaledGrandTotal, trueExposureGrandTotal, trueActiveGrandTotal, benchmarkDate, isUserPermittedToSave ); // populating the base and portfolio adjustment columsn first as they don't depend on potentially missing countries this.baseValueInitializer.Initialize(result, baseValueResolver); this.portfolioAdjustmentInitializer.InitializePortfolioAdjustments(result, manager); // in order to proceed we need to make sure all missing countries are there IEnumerable <BenchmarkSumByIsoInfo> benchmarks = new BenchmarkSumByIsoInfo[] { }; // here is the deal with shouldBenchmarksBeInitialized: // when we are editing broad-global-avive composition we need benchmakrs for reference and in order to make sure all countries are considered // but when the hopper process runs we don't need additional counties from bechmakr that can mess around and prevent the hopper from running // so this is why we need this switch if (shouldBenchmarksBeInitialized) { var benchmarkRepository = this.repositoryManager.ClaimBenchmarkRepository(manager, benchmarkDate); benchmarks = benchmarkRepository.GetByBenchmarkId(targetingType.BenchmarkIdOpt); } this.RegisterMissingCountriesIfAny( result, computations, countryRepository, targetingType, securityRepository, portfolioRepository, portfolioSecurityTargetRepository, benchmarks ); // now we can initialize columns that require all missing countries to be in the model this.InitializeOverlay( result, securityRepository, portfolioRepository, portfolioSecurityTargetRepository ); this.benchmarkValueInitializer.Initialize(result, new BenchmarkValueResolver(benchmarks)); var ticket = new CalculationTicket(); this.Validate(result, ticket); return(result); }
public IEnumerable <IValidationIssue> Validate(RootModel root, CalculationTicket ticket) { var issues = this.modelApplier.ValidateModel(root, ticket); return(issues); }
public IEnumerable <IValidationIssue> ValidateModel(RootModel model, CalculationTicket ticket) { var issues = this.modelValidator.ValidateRoot(model, ticket); return(issues); }
public IEnumerable <IValidationIssue> ValidateModelAndPermissions(RootModel model, String username, CalculationTicket ticket) { #warning Make use of the username. return(this.ValidateModel(model, ticket)); }
public Boolean HasChanged(RootModel root) { var expressions = this.expressionTraverser.Traverse(root); return(base.HasChanged(expressions)); }