Пример #1
0
        public IEnumerable <IValidationIssue> ApplyBpstModelIfValid(
            ManagingBpst.RootModel model,
            String username,
            CalculationTicket ticket)
        {
#warning NEXT: make sure everybody validates before opening a  connection
            var issues = this.BpstManager.Validate(model, ticket);
            if (issues.Any())
            {
                return(issues);
            }
            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
                {
                    CalculationInfo calculationInfo = new CalculationInfo();
                    var             manager         = this.dataManagerFactory.CreateDataManager(connection, null);
                    var             retVal          = this.BpstManager.ApplyIfValid(model, username, userEmail, connection, ticket, this.RepositoryManager.ClaimSecurityRepository(manager), this.RepositoryManager.ClaimBasketRepository(manager), ref calculationInfo);
                    if (!retVal.Any())
                    {
                        this.Calculate(calculationInfo.Id, true);
                    }
                    return(retVal);
                }
                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);
                }
            }
        }
Пример #2
0
        public RootModel SerializeRoot(Core.RootModel model, CalculationTicket ticket)
        {
            var result = new RootModel(
                this.serializer.SerializeChangeset(model.LatestBaseChangeset),
                this.serializer.SerializeChangeset(model.LatestPortfolioTargetChangeset),
                this.serializer.SerializeTargetingTypeGroup(model.Core.TargetingTypeGroup),
                this.serializer.SerializeBasketOnceResolved(model.Core.Basket),
                this.SerializePortfolios(model.Core.Portfolios, ticket),
                this.SerializeSecurities(model.Core.Securities, ticket),
                this.serializer.SerializeNullableExpression(model.Core.BaseTotal, ticket),
                this.serializer.SerializeExpression(model.Core.BenchmarkTotal, ticket),
                this.serializer.SerializeNullableExpression(model.Core.BaseActiveTotal, ticket),
                this.modelChangeDetector.HasChanged(model),
                model.BenchmarkDate
                );

            return(result);
        }
Пример #3
0
        public Core.RootModel DeserializeRoot(RootModel model)
        {
            var targetingTypeGroup  = this.deserializer.DeserializeTargetingTypeGroup(model.TargetingTypeGroup);
            var benchmarkRepository = this.deserializer.ClaimBenchmarkRepository(model.BenchmarkDate);
            var basket     = this.deserializer.DeserializeBasket(model.Basket.Id);
            var securities = this.DeserializeSecurities(model.Securities).ToList();

            if (model.SecurityToBeAddedOpt != null)
            {
                var security = this.DeserializeAdditionalSecurity(
                    basket,
                    model.SecurityToBeAddedOpt,
                    targetingTypeGroup,
                    benchmarkRepository
                    );
                if (!securities.Where(x => x.Security.Id == security.Security.Id).Any())
                {
                    securities.Add(security);
                }
            }
            var baseTotalExpression       = this.modelBuilder.CreateBaseTotalExpression(securities);
            var benchmarkTotalExpression  = this.modelBuilder.CreateBenchmarkTotalExpression(securities);
            var baseActiveTotalExpression = this.modelBuilder.CreateBaseActiveTotalExpression(securities);
            var core = new Core.CoreModel(
                targetingTypeGroup,
                basket,
                this.DeserializePortfolios(model.Portfolios, securities),
                securities,
                baseTotalExpression,
                benchmarkTotalExpression,
                baseActiveTotalExpression
                );

            var result = new Core.RootModel(
                this.DeserializeTargetingTypeGroupBasketSecurityBaseValueChangeset(model.LatestBaseChangeset),
                this.DeserializeBasketPortfolioSecurityTargetChangesetInfo(model.LatestPortfolioTargetChangeset),
                core,
                model.BenchmarkDate
                );

            return(result);
        }
Пример #4
0
        public IEnumerable <IValidationIssue> ValidateRoot(RootModel model, CalculationTicket ticket)
        {
            var issues = this.ValidateCore(model.Core, ticket);

            return(issues);
        }
        public RootModel DeserializeRoot(
            JsonReader reader,
            SecurityRepository securityRepository,
            ManagingTargetingTypes.TargetingTypeGroupRepository targetingTypeGroupRepository,
            ManagingBaskets.BasketRepository basketRepository,
            PortfolioRepository portfolioRepository,
            RepositoryManager repositoryManager,
            IOnDemand <IDataManager> ondemandManager
            )
        {
            var latestBaseChangeset = reader.Read(JsonNames.LatestBaseChangeset, delegate
            {
                return(this.DeserializeLatestBaseChangeset(reader));
            });

            var latestPortfolioTargetChangeset = reader.Read(JsonNames.LatestPortfolioTargetChangeset, delegate
            {
                return(this.DeserializeLatestPortfolioTargetChangeset(reader));
            });

            var targetingTypeGroupId = reader.ReadAsInt32(JsonNames.TargetingTypeGroupId);
            var targetingTypeGroup   = targetingTypeGroupRepository.GetTargetingTypeGroup(targetingTypeGroupId);

            var basketId      = reader.ReadAsInt32(JsonNames.BasketId);
            var basket        = basketRepository.GetBasket(basketId);
            var benchmarkDate = reader.ReadAsDatetime(JsonNames.BenchmarkDate);

            var securityModels = reader.ReadArray("securities", delegate
            {
                var securityModel = this.DeserializeSecurity(
                    reader,
                    securityRepository,
                    portfolioRepository
                    );
                return(securityModel);
            }).ToList();

            // adding a new security if any
            var securityIdTobeAddedOpt = reader.ReadAsNullableString(JsonNames.SecurityIdTobeAdded);

            if (securityIdTobeAddedOpt != null)
            {
                var broadGlobalActivePortfolios = targetingTypeGroup.GetBgaPortfolios();
                var security             = securityRepository.GetSecurity(securityIdTobeAddedOpt);
                var baseExpression       = this.modelBuilder.CreateBaseExpression();
                var benchmarkExpression  = this.modelBuilder.CreateBenchmarkExpression();
                var baseActiveExpression = this.modelBuilder.CreateBaseActiveExpression(baseExpression, benchmarkExpression);
                var securityModel        = new SecurityModel(
                    security,
                    baseExpression,
                    benchmarkExpression,
                    broadGlobalActivePortfolios.Select(bgaPortfolio => new PortfolioTargetModel(
                                                           bgaPortfolio,
                                                           this.modelBuilder.CreatePortfolioTargetExpression(bgaPortfolio.Name)
                                                           )).ToArray(),
                    baseActiveExpression
                    );

                if (!String.IsNullOrWhiteSpace(targetingTypeGroup.BenchmarkIdOpt))
                {
                    var benchmarkRepository = this.repositoryManager.ClaimBenchmarkRepository(ondemandManager, benchmarkDate);
                    this.benchmarkInitializer.InitializeSecurity(basket, targetingTypeGroup.BenchmarkIdOpt, securityModel, benchmarkRepository);
                }
                securityModels.Add(securityModel);
            }


            var portfolios = reader.ReadArray(JsonNames.Portfolios, delegate
            {
                var portfolioId = reader.ReadAsString(JsonNames.Id);
                var portfolio   = portfolioRepository.GetBroadGlobalActivePortfolio(portfolioId);
                var portfolioTargetTotalExpression = this.modelBuilder.CreatePortfolioTargetTotalExpression(
                    portfolio,
                    securityModels
                    );
                return(new PortfolioModel(
                           portfolio,
                           portfolioTargetTotalExpression
                           ));
            });

            var baseTotalExpression       = this.modelBuilder.CreateBaseTotalExpression(securityModels);
            var benchmarkTotalExpression  = this.modelBuilder.CreateBenchmarkTotalExpression(securityModels);
            var baseActiveTotalExpression = this.modelBuilder.CreateBaseActiveTotalExpression(securityModels);

            //var targetingTypeGroup = targetingTypeGroupRepository.Get
            var core = new CoreModel(
                targetingTypeGroup,
                basket,
                portfolios,
                securityModels,
                baseTotalExpression,
                benchmarkTotalExpression,
                baseActiveTotalExpression
                );

            var result = new RootModel(
                latestBaseChangeset,
                latestPortfolioTargetChangeset,
                core,
                benchmarkDate
                );

            return(result);
        }
Пример #6
0
        public RootModel GetRootModel(
            Int32 targetingTypeGroupId,
            Int32 basketId,
            IDataManager manager
            )
        {
            var targetingTypeGroupRepository = this.repositoryManager.ClaimTargetingTypeGroupRepository(manager);
            var targetingTypeGroup           = targetingTypeGroupRepository.GetTargetingTypeGroup(targetingTypeGroupId);

            var basketRepository = this.repositoryManager.ClaimBasketRepository(manager);
            var basket           = basketRepository.GetBasket(basketId);

            var broadGlobalActivePortfolioIds = targetingTypeGroup.GetTargetingTypes()
                                                .SelectMany(x => x.BroadGlobalActivePortfolios)
                                                .Select(x => x.Id).Distinct();

            var ttgbsbvRepository = this.repositoryManager.CreateTargetingTypeGroupBasketSecurityBaseValueRepository(
                targetingTypeGroup,
                basket,
                manager
                );
            var bpstRepository = this.repositoryManager.CreateBasketPortfolioSecurityTargetRepository(
                basket.Id,
                broadGlobalActivePortfolioIds,
                manager
                );
            var securityRepository  = this.repositoryManager.ClaimSecurityRepository(manager);
            var portfolioRepository = this.repositoryManager.ClaimPortfolioRepository(manager);
            var benchmarkDate       = manager.GetLastestDateWhichBenchmarkDataIsAvialableOn();

            var core = this.GetCoreModel(
                targetingTypeGroup,
                basket,
                securityRepository,
                ttgbsbvRepository,
                bpstRepository,
                portfolioRepository
                );

            var latestBaseChangeset            = manager.GetLatestTargetingTypeGroupBasketSecurityBaseValueChangeset();
            var latestPortfolioTargetChangeset = manager.GetLatestBasketPortfolioSecurityTargetChangeset();
            var result = new RootModel(
                latestBaseChangeset,
                latestPortfolioTargetChangeset,
                core,
                benchmarkDate
                );

            if (!String.IsNullOrEmpty(targetingTypeGroup.BenchmarkIdOpt))
            {
                var benchmarkRepository = this.repositoryManager.ClaimBenchmarkRepository(manager, benchmarkDate);
                this.benchmarkInitializer.InitializeCore(
                    basket,
                    targetingTypeGroup.BenchmarkIdOpt,
                    result.Core,
                    benchmarkRepository
                    );
            }

            return(result);
        }
Пример #7
0
        public IEnumerable <IValidationIssue> Validate(RootModel model, CalculationTicket ticket)
        {
            var issues = this.modelValidator.ValidateRoot(model, ticket);

            return(issues);
        }