Example #1
0
        public FilestoreFile CreateFish(CompoundIdentity sampleEventId, EntityBundle sites, EntityBundle nets, EntityBundle fishSpecies, EntityBundle macroSpecies, bool isPrivate)
        {
            if (!sampleEventId.IsNullOrEmpty() && sites != null && nets != null && fishSpecies != null &&
                sites.DataType == BundleDataType.Site && nets.DataType == BundleDataType.Instrument && fishSpecies.DataType == BundleDataType.TaxaUnit)
            {
                if (macroSpecies != null)
                {
                    if (macroSpecies.DataType != BundleDataType.TaxaUnit)
                    {
                        return(null); //if we have macroSpecies, they better be taxaunits
                    }
                }

                SampleEventMap map = DetRegistry.Instance.Get(sampleEventId);
                if (map == null)
                {
                    map = DetRegistry.Instance.Create(sampleEventId);
                }
                else if (map.Contains(KnownDetType.Fish))
                {
                    return(null); //can't have more than 1
                }
                FishDetProcessor wq  = new FishDetProcessor(this.ctx);
                FilestoreFile    fil = wq.Create(map, sites, nets, fishSpecies, macroSpecies, isPrivate); //note the permission is checked in there
                if (fil != null)
                {
                    map.Add(fil.FileId, KnownDetType.Fish, isPrivate);
                    List <Guid> bundles = map.Get(KnownDetType.Fish).BundleIds;
                    bundles.Add(sites.Id);
                    bundles.Add(nets.Id);
                    bundles.Add(fishSpecies.Id);
                    if (macroSpecies != null)
                    {
                        bundles.Add(macroSpecies.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 + "_Fish.xlsx";
                        FileStoreManager.Instance.GetProvider().Update(fil);
                    }
                }
                return(fil);
            }
            return(null);
        }
Example #2
0
 public UpdateStatus Update(FilestoreFile tempFileUpload)
 {
     if (tempFileUpload != null)
     {
         Guid fileId = DetProcessorBase.GetFileId(tempFileUpload);
         if (!Guid.Empty.Equals(fileId))
         {
             SampleEventMap map = DetRegistry.Instance.Get(fileId);
             if (map != null)
             {
                 SampleEventMapItem typ = map.Get(fileId); //this is to lookup the DET type this file was for
                 if (typ != null && typ.DetType == KnownDetType.WaterQuality)
                 {
                     WqDetProcessor wq   = new WqDetProcessor(this.ctx);
                     UpdateStatus   stat = wq.Update(tempFileUpload, map);
                     if (stat != null && stat.Issue == UpdateIssue.AllOk)
                     {
                         DetRegistry.Instance.Update(map);
                     }
                     return(stat);
                 }
                 else if (typ != null && typ.DetType == KnownDetType.Fish)
                 {
                     FishDetProcessor f    = new FishDetProcessor(this.ctx);
                     UpdateStatus     stat = f.Update(tempFileUpload, map);
                     if (stat != null && stat.Issue == UpdateIssue.AllOk)
                     {
                         DetRegistry.Instance.Update(map);
                     }
                     return(stat);
                 }
                 else if (typ != null && typ.DetType == KnownDetType.Veg)
                 {
                     VegDetProcessor v    = new VegDetProcessor(this.ctx);
                     UpdateStatus    stat = v.Update(tempFileUpload, map);
                     if (stat != null && stat.Issue == UpdateIssue.AllOk)
                     {
                         DetRegistry.Instance.Update(map);
                     }
                     return(stat);
                 }
             }
         }
     }
     return(null);
 }
Example #3
0
        public bool Delete(CompoundIdentity sampleEventId, bool fileOnly, KnownDetType type)
        {
            if (type == KnownDetType.WaterQuality)  //For each known type, we need to add a block here
            {
                WqDetProcessor p = new WqDetProcessor(this.ctx);

                SampleEventMap map = DetRegistry.Instance.Get(sampleEventId);
                if (map.Contains(type))
                {
                    SampleEventMapItem it = map.Get(type);
                    if (it != null)
                    {
                        if (p.Delete(map, fileOnly)) //note the permission is checked in there
                        {
                            map.Remove(it.DetId);
                            if (!map.IsEmpty)
                            {
                                return(DetRegistry.Instance.Update(map));
                            }
                            else
                            {
                                return(DetRegistry.Instance.Delete(map.SampleEventId));
                            }
                        }
                    }
                }
            }
            else if (type == KnownDetType.Fish)
            {
                FishDetProcessor f = new FishDetProcessor(this.ctx);

                SampleEventMap map = DetRegistry.Instance.Get(sampleEventId);
                if (map.Contains(type))
                {
                    SampleEventMapItem it = map.Get(type);
                    if (it != null)
                    {
                        if (f.Delete(map, fileOnly)) //note the permission is checked in there
                        {
                            map.Remove(it.DetId);
                            if (!map.IsEmpty)
                            {
                                return(DetRegistry.Instance.Update(map));
                            }
                            else
                            {
                                return(DetRegistry.Instance.Delete(map.SampleEventId));
                            }
                        }
                    }
                }
            }
            else if (type == KnownDetType.Veg)
            {
                VegDetProcessor v   = new VegDetProcessor(this.ctx);
                SampleEventMap  map = DetRegistry.Instance.Get(sampleEventId);
                if (map.Contains(type))
                {
                    SampleEventMapItem it = map.Get(type);
                    if (it != null)
                    {
                        if (v.Delete(map, fileOnly)) //note the permission is checked in there
                        {
                            map.Remove(it.DetId);
                            if (!map.IsEmpty)
                            {
                                return(DetRegistry.Instance.Update(map));
                            }
                            else
                            {
                                return(DetRegistry.Instance.Delete(map.SampleEventId));
                            }
                        }
                    }
                }
            }

            return(false);
        }