public void GetEntitySearchFromDosesCheckCircleId()
        {
            // assign

            var agroSearchOperation = new AgroSearch <GeoPointTs>(MockHelper.BaseSearch(), new SearchQueries(), new ImplementMock(), new HashEntityAgroSearch());


            var prd = AgroInputData.Product1;

            prd.Doses[0].Id = ConstantGuids.Value[0];

            var doseInput = prd.Doses[0];
            var doseModel = new Dose
            {
                Active = doseInput.Active,
                ApplicationDaysInterval = doseInput.ApplicationDaysInterval,
                Default          = doseInput.Default,
                DosesQuantityMax = doseInput.DosesQuantityMax,
                IdSpecies        = doseInput.IdSpecies,
                DosesQuantityMin = doseInput.DosesQuantityMin,
                IdProduct        = doseInput.IdProduct,
                NumberOfSequentialApplication = doseInput.NumberOfSequentialApplication,
                HoursToReEntryToBarrack       = doseInput.HoursToReEntryToBarrack,
                IdVarieties          = doseInput.IdVarieties,
                IdsApplicationTarget = doseInput.IdsApplicationTarget,
                WaitingDaysLabel     = doseInput.WaitingDaysLabel,
                WaitingToHarvest     = doseInput.WaitingToHarvest.Select(s => new WaitingHarvest {
                    IdCertifiedEntity = s.IdCertifiedEntity, Ppm = s.Ppm, WaitingDays = s.WaitingDays
                }).ToList(),
                Id = doseInput.Id,
                WettingRecommendedByHectares = doseInput.WettingRecommendedByHectares
            };

            // action
            var result = agroSearchOperation.GetEntitySearch(doseModel);

            var waitingHarvesRelated = result.First(s => s.index == (int)EntityRelated.DOSES).rel.Where(s => s.index == (int)EntityRelated.WAITINGHARVEST).ToList();

            var waitingHarvestEntitySearchs = result.Where(q => q.index == (int)EntityRelated.WAITINGHARVEST).Select(s => s.id).ToList();

            // assert
            Assert.True(waitingHarvesRelated.All(a => waitingHarvestEntitySearchs.Any(o => o.Equals(a.id))));
        }
        public void GetEntitySearchFromProduct()
        {
            // assign

            var agroSearchOperation = new AgroSearch <GeoPointTs>(MockHelper.BaseSearch(), new SearchQueries(), new ImplementMock(), new HashEntityAgroSearch());


            var prd = AgroInputData.Product1;


            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ProductInput, Product>());

            var mapperLocal = mapper.CreateMapper();
            var prdModel    = mapperLocal.Map <Product>(prd);

            // action
            var result = agroSearchOperation.GetEntitySearch(prdModel);

            // assert
            Assert.True(result.First().index == 12);
        }
Beispiel #3
0
        public static async Task UpdateSearch()
        {
            var dbArguments = new AgroDbArguments
            {
                EndPointUrl = "https://agricola-jhm.documents.azure.com:443/",
                NameDb      = "agrodb",
                PrimaryKey  = "yG6EIAT1dKSBaS7oSZizTrWQGGfwSb2ot2prYJwQOLHYk3cGmzvvhGohSzFZYHueSFDiptUAqCQYYSeSetTiKw=="
            };

            var searchServiceInstance = new AgroSearch("agrosearch", "016DAA5EF1158FEEEE58DA60996D5981");



            var agroManager = new AgroManager(dbArguments, null, null, null, searchServiceInstance, "ba7e86c8-6c2d-491d-bb2e-0dd39fdf5dc1", false);


            var rootStocks = await agroManager.Rootstock.GetElements();

            var roles = await agroManager.Role.GetElements();

            var seasons = await agroManager.Season.GetElements();

            var costCenter = await agroManager.CostCenter.GetElements();



            var species = await agroManager.Specie.GetElements();             // search

            var varieties = await agroManager.Variety.GetElements();          // search

            var barracks = await agroManager.Barrack.GetElements();           // search

            var businessNames = await agroManager.BusinessName.GetElements(); // search


            var sectors = await agroManager.Sector.GetElements();

            var certifiedEntity = await agroManager.CertifiedEntity.GetElements(); // seach

            var plotlands = await agroManager.PlotLand.GetElements();

            //var users = await agroManager.UserApplicator.GetElements(); // search
            var jobs = await agroManager.Job.GetElements(); // search

            var ingredients = await agroManager.Ingredient.GetElements();

            var targets = await agroManager.ApplicationTarget.GetElements();

            var products = await agroManager.Product.GetElements();

            var doses = await agroManager.Dose.GetElements();



            if (products.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in products.Result)
                {
                    var dosesProductId   = doses.Result.Where(s => s.IdProduct.Equals(item.Id) && s.Active).ToList();
                    var listEntitySearch = new List <EntitySearch>();

                    if (dosesProductId.Any())
                    {
                        var dosesEntities = dosesProductId.SelectMany(searchServiceInstance.GetEntitySearch).ToList();
                        listEntitySearch.AddRange(dosesEntities);
                    }


                    var relatedIdsDoseByProduct = listEntitySearch.Where(s => s.EntityIndex.Contains((int)EntityRelated.DOSES)).Select(s =>
                                                                                                                                       new RelatedId
                    {
                        EntityId    = s.Id,
                        EntityIndex = (int)EntityRelated.DOSES
                    }
                                                                                                                                       );

                    var entityProducts = searchServiceInstance.GetEntitySearch(item);

                    var product = entityProducts.FirstOrDefault(s => s.EntityIndex.Contains((int)EntityRelated.PRODUCT));
                    var related = product.RelatedIds.ToList();
                    related.AddRange(relatedIdsDoseByProduct);
                    product.RelatedIds = related.ToArray();
                    listEntitySearch.AddRange(entityProducts);

                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(listEntitySearch.ToList());
                }
            }


            if (targets.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in targets.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }



            if (ingredients.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in ingredients.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }


            if (jobs.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in jobs.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }

            if (costCenter.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in costCenter.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }

            //if (users.StatusResult == ExtGetDataResult.Success)
            //{
            //    foreach (var item in users.Result)
            //    {
            //        await agroManager.UserApplicator.Save(new UserApplicatorInput
            //        {
            //            Id = item.Id,
            //            Name = item.Name,
            //            Email = item.Email,
            //            IdJob = item.IdJob,
            //            IdNebulizer = item.IdNebulizer,
            //            IdsRoles = item.IdsRoles,
            //            IdTractor = item.IdTractor,
            //            Rut = item.Rut
            //        });
            //    }
            //}


            if (roles.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in roles.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }


            if (plotlands.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in plotlands.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }



            if (certifiedEntity.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in certifiedEntity.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }

            if (rootStocks.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in rootStocks.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }

            if (sectors.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in sectors.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }


            if (seasons.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in seasons.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }


            if (businessNames.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in businessNames.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }

            if (species.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in species.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }

            if (varieties.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in varieties.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }

            if (barracks.StatusResult == ExtGetDataResult.Success)
            {
                foreach (var item in barracks.Result)
                {
                    var searchs = searchServiceInstance.GetEntitySearch(item);
                    searchServiceInstance.AddElements(searchs.ToList());
                }
            }
        }