Beispiel #1
0
        public FilestoreFile CreateVeg(CompoundIdentity sampleEventId, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, bool isPrivate)
        {
            if (!sampleEventId.IsNullOrEmpty() && sites != null && plotTypes != null && shrubSpecies != null && treeSpecies != null && herbSpecies != null &&
                sites.DataType == BundleDataType.Site && plotTypes.DataType == BundleDataType.PlotType &&
                shrubSpecies.DataType == BundleDataType.TaxaUnit && treeSpecies.DataType == BundleDataType.TaxaUnit && herbSpecies.DataType == BundleDataType.TaxaUnit)
            {
                if (nonLiving != null)
                {
                    if (nonLiving.DataType != BundleDataType.TaxaUnit)
                    {
                        return(null); //if we have nonLiving, they better be taxaunits
                    }
                }

                SampleEventMap map = DetRegistry.Instance.Get(sampleEventId);
                if (map == null)
                {
                    map = DetRegistry.Instance.Create(sampleEventId);
                }
                else if (map.Contains(KnownDetType.Veg))
                {
                    return(null); //can't have more than 1
                }
                VegDetProcessor wq  = new VegDetProcessor(this.ctx);
                FilestoreFile   fil = wq.Create(map, sites, plotTypes, shrubSpecies, treeSpecies, herbSpecies, nonLiving, isPrivate); //note the permission is checked in there
                if (fil != null)
                {
                    map.Add(fil.FileId, KnownDetType.Veg, isPrivate);
                    List <Guid> bundles = map.Get(KnownDetType.Veg).BundleIds;
                    bundles.Add(sites.Id);
                    bundles.Add(plotTypes.Id);
                    bundles.Add(shrubSpecies.Id);
                    bundles.Add(treeSpecies.Id);
                    bundles.Add(herbSpecies.Id);
                    if (nonLiving != null)
                    {
                        bundles.Add(nonLiving.Id);
                    }
                    DetRegistry.Instance.Update(map);
                    SamplingEvent e = this.GetSampleEvent(map.SampleEventId);
                    if (e != null)
                    {
                        string tmp = e.Name.Trim().Replace(' ', '_');
                        if (tmp.Length > 25)
                        {
                            tmp = tmp.Substring(0, 24);
                        }
                        fil.FileName = tmp + "_Veg.xlsx";
                        FileStoreManager.Instance.GetProvider().Update(fil);
                    }
                }
                return(fil);
            }
            return(null);
        }