//{sampleeventid:<id>, datatype:<det type>} //returns map of [{type:<det type>, id:<detfileid>}, ...] // note datatype is optional - if omitted, get list of all dets for that sample event internal static void Get(UserSecurityContext user, JToken dat, HttpContext context, CancellationToken cancel) { if (dat != null) { JObject payload = dat as JObject; if (payload != null) { CompoundIdentity seId = JsonUtils.ToId(dat[JsonUtils.Id]); if (seId != null) { GeneralDetProcessor prov = DetProcessorManager.Instance.GetProvider(user); if (prov != null) { SampleEventMap map = prov.GetMap(seId); if (map != null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, ToJson(map).ToString())); return; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); //no dets in sample event return; } } } } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }
internal string EncodeBundleIds(SampleEventMap map) { if (map != null) { StringBuilder sb = new StringBuilder(); foreach (SampleEventMapItem cur in map) { sb.Append((int)(cur.DetType)); sb.Append(':'); foreach (Guid cc in cur.BundleIds) { sb.Append(cc.ToString()); sb.Append(','); } sb.Length = sb.Length - 1; sb.Append('|'); } if (sb.Length > 0) { sb.Length = sb.Length - 1; //trailing | } return(sb.ToString()); } return(null); }
internal SampleEventMap Create(CompoundIdentity sampleEventId) { if (this.connString != null && sampleEventId != null && !sampleEventId.IsEmpty && this.Get(sampleEventId) == null) { try { SampleEventMap map = SampleEventMap.Create(sampleEventId); NpgsqlCommand cmd = GetCmd(this.connString); cmd.CommandText = Insert; cmd.Parameters.AddWithValue("sid", map.SampleEventId.DataStoreIdentity); cmd.Parameters.AddWithValue("id", map.SampleEventId.Identity); List <Guid> fileIds = new List <Guid>(); List <int> fileTypes = new List <int>(); List <bool> privacies = new List <bool>(); cmd.Parameters.AddWithValue("fts", fileTypes.ToArray()); cmd.Parameters.AddWithValue("fis", fileIds.ToArray()); cmd.Parameters.AddWithValue("bis", EncodeBundleIds(map)); cmd.Parameters.AddWithValue("pri", privacies.ToArray()); ExecuteNonQuery(cmd); return(map); } catch { } } return(null); }
internal bool Update(SampleEventMap item) { if (this.connString != null && item != null && item.Count > 0 && this.Get(item.SampleEventId) != null) //can't push an empty item { try { NpgsqlCommand cmd = GetCmd(this.connString); cmd.CommandText = UpdateSql; cmd.Parameters.AddWithValue("sid", item.SampleEventId.DataStoreIdentity); cmd.Parameters.AddWithValue("id", item.SampleEventId.Identity); List <Guid> fileIds = new List <Guid>(); List <int> fileTypes = new List <int>(); List <bool> privacies = new List <bool>(); foreach (SampleEventMapItem cur in item) { fileIds.Add(cur.DetId); fileTypes.Add((int)cur.DetType); privacies.Add(cur.IsPrivate); } cmd.Parameters.AddWithValue("fts", fileTypes.ToArray()); cmd.Parameters.AddWithValue("fis", fileIds.ToArray()); cmd.Parameters.AddWithValue("bis", EncodeBundleIds(item)); cmd.Parameters.AddWithValue("pri", privacies.ToArray()); ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public override bool Delete(SampleEventMap map, bool fileOnly) { if (map != null) { SampleEventMapItem id = map.Get(KnownDetType.Veg); if (id != null) { IFileStoreProvider p = FileStore; if (p != null) { IVegSurveyProvider srvProv = VegetationManager.Instance.GetSurveyProvider(this.Context); if (srvProv != null && srvProv.CanDelete()) { if (p.Delete(id.DetId)) { if (fileOnly) { return(true); } return(DeleteData(map)); } } } } } return(false); }
public override bool Delete(SampleEventMap map, bool fileOnly) { if (map != null) { SampleEventMapItem id = map.Get(KnownDetType.Fish); if (id != null) { IFileStoreProvider p = FileStore; if (p != null) { ICatchEffortProvider wqProv = FishManager.Instance.GetCatchEffortProvider(this.Context); if (wqProv != null && wqProv.CanDelete()) { if (p.Delete(id.DetId)) { if (fileOnly) { return(true); } return(DeleteData(map)); } } } } } return(false); }
public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle instruments) { if (this.CanModify(map)) { Guid id = Guid.NewGuid(); WaterQualityDET det = new WaterQualityDET(); det.Id = id; det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + instruments.PrincipalOrgId.Identity.ToString(); int ct = 0; foreach (BundleElement cur in sites.Elements) { SiteDTO tmp = new SiteDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Sites.Add(tmp); ct++; } if (ct > 0) //has to be elements in the collection { ct = 0; foreach (BundleElement cur in instruments.Elements) { InstrumentDTO tmp = new InstrumentDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Instruments.Add(tmp); ct++; } if (ct > 0) { det.Validate(); if (det.ValidationIssues.Count == 0) { IFileStoreProvider prov = this.FileStore; if (prov != null) { FilestoreFile fil = prov.Make(id); if (fil != null) { ExcelWaterQualityDET excel = new ExcelWaterQualityDET(det); excel.Save(fil); fil.Flush(); fil.Seek(0, System.IO.SeekOrigin.Begin); return(fil); } } } } } } return(null); }
private static JToken ToJson(SampleEventMap map) { JObject o = new JObject(); foreach (SampleEventMapItem s in map) { o.Add(s.DetType.ToString(), new JValue(s.DetId.ToString())); } return(o); }
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); }
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); }
public FilestoreFile Get(CompoundIdentity sampleEventId, KnownDetType type) { SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map != null) { SampleEventMapItem it = map.Get(type); if (it != null) { return(Get(it.DetId)); } } return(null); }
private bool DeleteData(SampleEventMap map) { IWQDeploymentProvider wqProv = WaterQualityManager.Instance.GetDeploymentProvider(this.Context); if (wqProv != null && wqProv.CanDelete()) { IEnumerable <WaterQualityDeployment> deploys = wqProv.GetForSampleEvent(map.SampleEventId); foreach (WaterQualityDeployment cur in deploys) { wqProv.Delete(cur); } return(true); } return(false); }
private bool DeleteData(SampleEventMap map) { IVegSurveyProvider srvProv = VegetationManager.Instance.GetSurveyProvider(this.Context); if (srvProv != null && srvProv.CanDelete()) { IEnumerable <VegSurvey> deploys = srvProv.GetForSampleEvent(map.SampleEventId); foreach (VegSurvey cur in deploys) { srvProv.Delete(cur); } return(true); } return(false); }
private bool DeleteData(SampleEventMap map) { ICatchEffortProvider wqProv = FishManager.Instance.GetCatchEffortProvider(this.Context); if (wqProv != null && wqProv.CanDelete()) { IEnumerable <CatchEffort> deploys = wqProv.GetForSampleEvent(map.SampleEventId); foreach (CatchEffort cur in deploys) { wqProv.Delete(cur); } return(true); } return(false); }
public override FilestoreFile Get(SampleEventMap map) { if (map != null) { SampleEventMapItem id = map.Get(KnownDetType.Fish); if (id != null) { IFileStoreProvider p = FileStore; if (p != null) { return(p.Get(id.DetId)); //TODO add validation checking if we want } } } return(null); }
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); }
//format: int:guid,guid,...|int:guid,guid,... internal void DecodeBundleIds(string item, SampleEventMap map) { if (!string.IsNullOrEmpty(item)) { try { string[] blocks = item.Split('|'); foreach (string cur in blocks) { int idx = cur.IndexOf(':'); KnownDetType tp = (KnownDetType)int.Parse(cur.Substring(0, idx)); string[] ids = cur.Substring(idx + 1).Split(','); List <Guid> parts = map.GetBundles(tp); foreach (string id in ids) { parts.Add(Guid.Parse(id)); } } } catch { } } }
internal SampleEventMap Get(CompoundIdentity sampleEventId) { if (this.connString != null && sampleEventId != null && !sampleEventId.IsEmpty) { NpgsqlCommand cmd = GetCmd(connString); cmd.CommandText = Select + " WHERE \"SampleEventSystemId\"=:sid AND \"SampleEventId\"=:id"; cmd.Parameters.AddWithValue("sid", sampleEventId.DataStoreIdentity); cmd.Parameters.AddWithValue("id", sampleEventId.Identity); NpgsqlDataReader rdr = ExecuteReader(cmd); try { if (rdr.Read()) { int[] fileTypes = (int[])rdr[2]; Guid[] fileIds = (Guid[])rdr[3]; bool[] privacies = (bool[])rdr[5]; SampleEventMap tmp = SampleEventMap.Create(sampleEventId); for (int i = 0; i < fileTypes.Length; i++) { tmp.Add(fileIds[i], (KnownDetType)fileTypes[i], privacies[i]); } if (!DBNull.Value.Equals(rdr[4])) { DecodeBundleIds((string)rdr[4], tmp); } return(tmp); } } catch { } finally { cmd.Dispose(); } } return(null); }
public FilestoreFile CreateWQ(CompoundIdentity sampleEventId, EntityBundle sites, EntityBundle instruments, bool isPrivate) { if (!sampleEventId.IsNullOrEmpty() && sites != null && instruments != null && sites.DataType == BundleDataType.Site && instruments.DataType == BundleDataType.Instrument) { SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map == null) { map = DetRegistry.Instance.Create(sampleEventId); } else if (map.Contains(KnownDetType.WaterQuality)) { return(null); //can't have more than 1 } WqDetProcessor wq = new WqDetProcessor(this.ctx); FilestoreFile fil = wq.Create(map, sites, instruments); //note the permission is checked in there if (fil != null) { map.Add(fil.FileId, KnownDetType.WaterQuality, isPrivate); List <Guid> bundles = map.Get(KnownDetType.WaterQuality).BundleIds; bundles.Add(sites.Id); bundles.Add(instruments.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 + "_WQ.xlsx"; FileStoreManager.Instance.GetProvider().Update(fil); } } return(fil); } return(null); }
internal SampleEventMap Get(Guid fileId) { if (this.connString != null && !Guid.Empty.Equals(fileId)) { NpgsqlCommand cmd = GetCmd(connString); cmd.CommandText = Select + " WHERE :id = ANY(\"FileIds\")"; cmd.Parameters.AddWithValue("id", fileId); NpgsqlDataReader rdr = ExecuteReader(cmd); try { if (rdr.Read()) { CompoundIdentity id = new CompoundIdentity((Guid)rdr[0], (Guid)rdr[1]); int[] fileTypes = (int[])rdr[2]; Guid[] fileIds = (Guid[])rdr[3]; bool[] privacies = (bool[])rdr[5]; SampleEventMap tmp = SampleEventMap.Create(id); for (int i = 0; i < fileTypes.Length; i++) { tmp.Add(fileIds[i], (KnownDetType)fileTypes[i], privacies[i]); } if (!DBNull.Value.Equals(rdr[4])) { DecodeBundleIds((string)rdr[4], tmp); } return(tmp); } } catch { } finally { cmd.Dispose(); } } return(null); }
private UpdateStatus DeltaLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle nets, EntityBundle fishSpecies, EntityBundle macroSpecies, FishDET curdet, FishDET olddet, ICatchEffortProvider depl, ICatchHaulProvider haul, IFishProvider fish, SampleEventMap map) { UpdateStatus stat = null; if (curdet.CatchEfforts.Count < 1) //ok, old file had data, this file has none { //what do we want to do? -- could just do a delete all stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Fish); //fetch it back if (this.Delete(map, false)) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } else { //data in both files, this is a change/append situation stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Fish); //fetch it back if (this.DeleteData(map)) { if (this.InitialLoad(seId, sites, nets, fishSpecies, macroSpecies, curdet, depl, haul, fish, tmp.IsPrivate) != null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Create", UpdateIssue.Security, stat); } } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } return(stat); }
public override UpdateStatus Update(FilestoreFile tempFileUpload, SampleEventMap map) { if (tempFileUpload != null) { FilestoreFile oldFile = this.Get(map); if (oldFile != null) { if (this.CanModify(map)) { FishDET curdet = new FishDET(); ExcelFishDET curexcel = new ExcelFishDET(curdet); curexcel.Load(tempFileUpload); ValidationIssues curIssues = curdet.ValidationIssues; if (curIssues.Count < 1) { FishDET olddet = new FishDET(); ExcelFishDET excel = new ExcelFishDET(olddet); excel.Load(oldFile); ValidationIssues issues = olddet.ValidationIssues; if (issues.Count < 1) //should be this is the old file { UpdateStatus status = null; if (olddet.CatchEfforts.Count < 1) //old file has no data - bare det { if (curdet.CatchEfforts.Count < 1) //nothing to do really, new file has no data either { olddet = null; excel = null; oldFile.Dispose(); curdet = null; curexcel = null; FileStoreManager.Instance.GetProvider().Delete(tempFileUpload); status = new UpdateStatus(UpdateIssue.AllOk); status.Add(new IssueNotice("NoDataInEither", "nothing to do")); return(status); } SampleEventMapItem item = map.Get(KnownDetType.Fish); if (item != null) { olddet = null; //release old reference excel = null; //release old reference //ok, no data in old file, but data in new file -- we have work to do -- handle first-time data insertion ICatchEffortProvider depl = FishManager.Instance.GetCatchEffortProvider(this.Context); ICatchHaulProvider meas = FishManager.Instance.GetCatchHaulProvider(this.Context); IFishProvider fi = FishManager.Instance.GetFishProvider(this.Context); if (depl != null && meas != null && fi != null) { if (depl.CanCreate()) { List <EntityBundle> bundles = this.GetBundles(map, KnownDetType.Fish); if (bundles != null && bundles.Count >= 3) { EntityBundle mac = null; if (bundles.Count > 3) { mac = bundles[3]; } status = this.InitialLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], mac, curdet, depl, meas, fi, item.IsPrivate); if (status != null && status.Issue == UpdateIssue.AllOk) //success, so we overwrite the file { curdet = null; curexcel = null; olddet = null; excel = null; IFileStoreProvider ip = FileStoreManager.Instance.GetProvider(); if (ip.Replace(tempFileUpload, oldFile)) //overwrite the existing file with the new one { tempFileUpload.Dispose(); oldFile.Dispose(); //ip.Delete(tempFileUpload); //may still be references so delete can fail return(status); //we're done here } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("File", "Failed to replace file")); } } } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("Bundles", "Failed to get bundles")); } } else { status = new UpdateStatus(UpdateIssue.Security); status.Add(new IssueNotice("Permissions", "create denied")); } } else { status = new UpdateStatus(UpdateIssue.SystemIssue); status.Add(new IssueNotice("Failure", "Failed to get provider")); } } else { status = new UpdateStatus(UpdateIssue.NoExistingFile); status.Add(new IssueNotice("NoMapEntry", "Failed to find map reference")); } return(status); } else //crap -- this is an update where existing file already had data { ICatchEffortProvider depl = FishManager.Instance.GetCatchEffortProvider(this.Context); ICatchHaulProvider meas = FishManager.Instance.GetCatchHaulProvider(this.Context); IFishProvider fi = FishManager.Instance.GetFishProvider(this.Context); if (depl != null && meas != null && fi != null) { if (depl.CanCreate()) { SampleEventMapItem item = map.Get(KnownDetType.Fish); List <EntityBundle> bundles = this.GetBundles(map, KnownDetType.Fish); if (item != null && bundles != null && bundles.Count >= 3) { EntityBundle mac = null; if (bundles.Count > 3) { mac = bundles[3]; } status = this.DeltaLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], mac, curdet, olddet, depl, meas, fi, map); if (status != null && status.Issue == UpdateIssue.AllOk) //success, so we overwrite the file { curdet = null; curexcel = null; olddet = null; excel = null; //NOTE -- making new file the permanent file and removing old file, then updating map for new file IFileStoreProvider ip = FileStoreManager.Instance.GetProvider(); if (ip.Replace(tempFileUpload, oldFile)) //overwrite the existing file with the new one { tempFileUpload.Dispose(); oldFile.Dispose(); //ip.Delete(tempFileUpload); //may still be references so delete can fail return(status); //we're done here } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("File", "Failed to replace file")); } } } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("Bundles", "Failed to get bundles")); } } else { status = new UpdateStatus(UpdateIssue.Security); status.Add(new IssueNotice("Permissions", "create denied")); } } else { status = new UpdateStatus(UpdateIssue.SystemIssue); status.Add(new IssueNotice("Failure", "Failed to get provider")); } return(status); } } else { UpdateStatus stat = new UpdateStatus(UpdateIssue.NoExistingFile); foreach (ValidationIssue cur in issues) { stat.Add(new IssueNotice(cur.IssueCode.ToString(), cur.IssueMessage)); } return(stat); } } else { UpdateStatus stat = new UpdateStatus(UpdateIssue.FileValidationIssues); foreach (ValidationIssue cur in curIssues) { stat.Add(new IssueNotice(cur.IssueCode.ToString(), cur.IssueMessage)); } return(stat); } } else { UpdateStatus status = new UpdateStatus(UpdateIssue.Security); status.Add(new IssueNotice("Permissions", "create denied")); return(status); } } return(new UpdateStatus(UpdateIssue.NoExistingFile)); } return(new UpdateStatus(UpdateIssue.NoFilePosted)); }
private UpdateStatus DeltaLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, VegDET curdet, VegDET olddet, IVegSurveyProvider depl, IVegSampleProvider meas, SampleEventMap map) { UpdateStatus stat = null; if (curdet.Surveys.Count < 1) //ok, old file had data, this file has none { //what do we want to do? -- could just do a delete all stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Veg); //fetch it back if (this.Delete(map, false)) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } else { //data in both files, this is a change/append situation stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Veg); //fetch it back if (this.DeleteData(map)) { if (this.InitialLoad(seId, sites, plotTypes, shrubSpecies, treeSpecies, herbSpecies, nonLiving, curdet, depl, meas, tmp.IsPrivate) != null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Create", UpdateIssue.Security, stat); } } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } return(stat); }
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); }
private UpdateStatus DeltaLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle instruments, WaterQualityDET curdet, WaterQualityDET olddet, IWQDeploymentProvider depl, IWQMeasurementProvider meas, SampleEventMap map) { UpdateStatus stat = new UpdateStatus(UpdateIssue.SystemIssue); //Not implemented if (curdet.Deployments.Count < 1) //ok, old file had data, this file has none { //what do we want to do? -- could just do a delete all stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.WaterQuality); //fetch it back if (this.Delete(map, false)) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } else { //data in both files, this is a change/append situation stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.WaterQuality); //fetch it back if (this.DeleteData(map)) { if (this.InitialLoad(seId, sites, instruments, curdet, depl, meas, tmp.IsPrivate) != null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Create", UpdateIssue.Security, stat); } } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } return(stat); }
public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, bool isPrivate) { if (this.CanModify(map)) { Guid id = Guid.NewGuid(); VegDET det = new VegDET(); det.Id = id; det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + plotTypes.PrincipalOrgId.Identity.ToString(); int ct = 0; foreach (BundleElement cur in sites.Elements) { SiteDTO tmp = new SiteDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Sites.Add(tmp); ct++; } if (ct > 0) //has to be elements in the collection { ct = 0; foreach (BundleElement cur in plotTypes.Elements) { PlotTypeDTO tmp = new PlotTypeDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.PlotTypes.Add(tmp); ct++; } if (ct > 0) { ct = 0; foreach (BundleElement cur in shrubSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.ShrubSpecies.Add(tmp); ct++; } if (treeSpecies != null) { foreach (BundleElement cur in treeSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.TreeSpecies.Add(tmp); ct++; } } if (herbSpecies != null) { foreach (BundleElement cur in herbSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.HerbSpecies.Add(tmp); ct++; } } if (nonLiving != null) { foreach (BundleElement cur in nonLiving.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.NonLiving.Add(tmp); } } if (ct > 0) //have to have at least one of herb, tree, shrub to POSSIBLY be valid { det.Validate(); if (det.ValidationIssues.Count == 0) { IFileStoreProvider prov = this.FileStore; if (prov != null) { FilestoreFile fil = prov.Make(id); if (fil != null) { ExcelVegDET excel = new ExcelVegDET(det); excel.Save(fil); fil.Flush(); fil.Seek(0, System.IO.SeekOrigin.Begin); return(fil); } } } } } } } return(null); }