public void MultiRelation <T>(string name, ICollection <T> values) where T : Entity { if (values.Count > 0) { var def = Resolve(name); FilterTerm valuesTerm = null; FilterTerm notExistsTerm = null; foreach (var t in values) { if (t == null) { if (notExistsTerm == null) { notExistsTerm = new FilterTerm(def); notExistsTerm.NotExists(); } } else { if (valuesTerm == null) { valuesTerm = new FilterTerm(def); } valuesTerm.Equal(GetOid(t.ID)); } } Root.Or(valuesTerm, notExistsTerm); } }
public void QueryTrackedEpicsByProject() { var metaConnector = new V1APIConnector(VersionOneUrl + "meta.v1/", "admin", "admin"); var metaModel = new MetaModel(metaConnector); var epicType = metaModel.GetAssetType("Epic"); var scopeType = metaModel.GetAssetType("Scope"); var query = new Query(epicType); const string scopeId = "Scope:1025"; var notClosedScopeAttribute = scopeType.GetAttributeDefinition("AssetState"); var notClosedEpicAttribute = epicType.GetAttributeDefinition("AssetState"); var notClosedEpicTerm = new FilterTerm(notClosedEpicAttribute); notClosedEpicTerm.NotEqual("Closed"); var notClosedScopeTerm = new FilterTerm(notClosedScopeAttribute); notClosedScopeTerm.NotEqual("Closed"); var scopeAttribute = epicType.GetAttributeDefinition("Scope.ParentMeAndUp"); scopeAttribute = scopeAttribute.Filter(notClosedScopeTerm); var scopeTerm = new FilterTerm(scopeAttribute); scopeTerm.Equal(scopeId); var superAndUpAttribute = epicType.GetAttributeDefinition("SuperAndUp"); superAndUpAttribute = superAndUpAttribute.Filter(scopeTerm); var superAndUpTerm = new FilterTerm(superAndUpAttribute); superAndUpTerm.NotExists(); var filter = new AndFilterTerm(scopeTerm, notClosedEpicTerm, superAndUpTerm); query.Filter = filter; var builder = new QueryURLBuilder(query); var result = builder.ToString(); Assert.AreEqual("Data/Epic?sel=&where=(Epic.Scope.ParentMeAndUp[AssetState!='Closed']='Scope%3a1025';Epic.AssetState!='Closed';-Epic.SuperAndUp[Scope.ParentMeAndUp[AssetState!='Closed']='Scope:1025'])", result); }
public void QueryTrackedEpicsForMultipleProjectsUsingVariables() { var metaConnector = new V1APIConnector(VersionOneUrl + "meta.v1/", "admin", "admin"); var metaModel = new MetaModel(metaConnector); var scopeVariable = new QueryVariable("Scope", "Scope:2176"); var epicType = metaModel.GetAssetType("Epic"); var query = new Query(epicType); var notClosedEpicAttribute = epicType.GetAttributeDefinition("AssetState"); var notClosedEpicTerm = new FilterTerm(notClosedEpicAttribute); notClosedEpicTerm.NotEqual("Closed"); var scopeAttribute = epicType.GetAttributeDefinition("Scope"); var scopeTerm = new FilterTerm(scopeAttribute); scopeTerm.Operate(FilterTerm.Operator.Equal, scopeVariable); var superAndUpAttribute = epicType.GetAttributeDefinition("SuperAndUp").Filter(scopeTerm); var superAndUpTerm = new FilterTerm(superAndUpAttribute); superAndUpTerm.NotExists(); var filter = new AndFilterTerm(notClosedEpicTerm, scopeTerm, superAndUpTerm); query.Filter = filter; query.Variables.Add(scopeVariable); var builder = new QueryURLBuilder(query); var result = builder.ToString(); Assert.AreEqual("Data/Epic?sel=&where=(Epic.AssetState!='Closed';Epic.Scope=$Scope;-Epic.SuperAndUp[Scope=$Scope])&with=$Scope=Scope%3A2176", result); }