public override TaxaDomain Get(CompoundIdentity id) { if (!id.IsNullOrEmpty() && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectDomain + Db.SelectDomainById; cmd.Parameters.AddWithValue("id", id.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); TaxaDomain t = null; if (rdr != null) { try { rdr.Read(); t = TaxaDomainBuilder.Instance.Build(rdr); if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(t); } return(null); }
public override bool Update(TaxaDomain domain) { if (domain != null && this.CanUpdate(domain)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.UpdateDomain + Db.SelectById; cmd.Parameters.AddWithValue("name", domain.Name); if (string.IsNullOrEmpty(domain.Description)) { cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("desc", NpgsqlTypes.NpgsqlDbType.Varchar)); } else { cmd.Parameters.AddWithValue("desc", domain.Description); } cmd.Parameters.AddWithValue("tid", domain.TaxonomyId); cmd.Parameters.AddWithValue("id", domain.Identity.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public override TaxaUnitType GetParent(TaxaDomain domain, TaxaUnitType child) { if (domain != null && child != null && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectTaxaUnitType + " WHERE \"Id\"=(SELECT \"ParentUnitTypeId\" FROM oncor.\"TaxaDomainUnitTypes\" WHERE \"TaxonDomainId\"=:tdid AND \"TaxonUnitTypeId\"=:tutid)"; cmd.Parameters.AddWithValue("tdid", domain.Identity.Identity); cmd.Parameters.AddWithValue("tutid", child.Identity.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); TaxaUnitType t = null; if (rdr != null) { try { rdr.Read(); t = TaxaUnitTypeBuilder.Instance.Build(rdr); if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(t); } return(null); }
public override bool IsParentOf(TaxaDomain domain, TaxaUnitType parent, TaxaUnitType child) { if (domain != null && parent != null && child != null && this.CanGet() && parent.TaxonomyId.Identity == child.TaxonomyId.Identity) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.CountDomainUnitType + Db.SelectDomainUnitTypeByDomain + " AND" + Db.SelectDomainUnitTypeByTaxaUnitType + " AND" + Db.SelectDomainUnitTypeByParent; cmd.Parameters.AddWithValue("tdid", domain.Identity.Identity); cmd.Parameters.AddWithValue("tutid", child.Identity.Identity); cmd.Parameters.AddWithValue("putid", parent.Identity.Identity); return(Db.Exists(cmd)); } return(false); }
public override bool IsDescendantOf(TaxaDomain domain, TaxaUnitType parent, TaxaUnitType child) { if (domain != null && parent != null && child != null) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = "SELECT oncor\"taxadomainunittypeisdescendant\"(:tdid, :cutid, :putid)"; cmd.Parameters.AddWithValue("tdid", domain.Identity.Identity); cmd.Parameters.AddWithValue("tutid", child.Identity.Identity); cmd.Parameters.AddWithValue("putid", parent.Identity.Identity); return(Db.Exists(cmd)); } return(false); }
public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel) { if (context.Request.Method == "POST") { if (method.Equals("all", StringComparison.OrdinalIgnoreCase)) { Get(user, context, cancel); return; } else if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { TaxaDomainUnitTypeProviderBase dutprovider = TaxonomyManager.Instance.GetTaxaDomainUnitTypeProvider(user); TaxaDomainProviderBase domprovider = TaxonomyManager.Instance.GetTaxaDomainProvider(user); JToken token = JsonUtils.GetDataPayload(context.Request); JArray junittypes = null; if (dutprovider != null && domprovider != null && token != null) { CompoundIdentity domainId = JsonUtils.ToId(token["domainid"]); TaxaDomain domain = domprovider.Get(domainId); if (domain != null) { IEnumerable <TaxaUnitType> units = dutprovider.GetTaxaUnitTypeByDomain(domain); junittypes = Jsonifier.ToJson(units); } if (junittypes != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, junittypes.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); return; } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }
public static JObject ToJson(TaxaDomain domain) { if (domain != null) { JObject o = new JObject(); o.Add(JsonUtils.Id, JsonUtils.ToJson(domain.Identity)); o.Add(JsonUtils.Name, domain.Name); o.Add(JsonUtils.Description, domain.Description); if (domain.TaxonomyId != null) { o.Add("taxonomyid", JsonUtils.ToJson(domain.TaxonomyId)); } return(o); } return(null); }
public override IEnumerable <TaxaUnitType> GetDescendants(TaxaDomain domain, TaxaUnitType taxaUnitType) { if (domain != null && taxaUnitType != null && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = "SELECT oncor.\"taxadomainunittypegetdescendants(:did, :tutid)"; cmd.Parameters.AddWithValue("did", domain.Identity.Identity); cmd.Parameters.AddWithValue("tutid", taxaUnitType.Identity.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); List <TaxaUnitType> unitTypes = new List <TaxaUnitType>(); TaxaUnitType t = null; if (rdr != null) { try { while (rdr.Read()) { t = TaxaUnitTypeBuilder.Instance.Build(rdr); if (t != null) { unitTypes.Add(t); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(unitTypes); } return(null); }
public override IEnumerable <TaxaUnitType> GetChildren(TaxaDomain domain, TaxaUnitType parent) { if (domain != null && parent != null && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectTaxaUnitType + " WHERE \"Id\"=(SELECT \"TaxonUnitTypeId\" FROM oncor.\"TaxaDomainUnitTypes\" WHERE \"TaxonDomainId\"=:tdid AND \"ParentUnitTypeId\"=:putid)"; cmd.Parameters.AddWithValue("tdid", domain.Identity.Identity); cmd.Parameters.AddWithValue("putid", parent.Identity.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); List <TaxaUnitType> unitTypes = new List <TaxaUnitType>(); TaxaUnitType t = null; if (rdr != null) { try { while (rdr.Read()) { t = TaxaUnitTypeBuilder.Instance.Build(rdr); if (t != null) { unitTypes.Add(t); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(unitTypes); } return(null); }
public override bool CanUpdate(TaxaDomain domain) { return(this.CanUpdate()); //TODO -- add fine grained security }