public void Complex1() { var termA = new FilterTerm(WorkitemParent); termA.Equal(Oid.FromToken("Theme:5", Meta)); termA.Equal(Oid.FromToken("Theme:6", Meta)); var termB = new FilterTerm(WorkitemScope); termB.Equal(Oid.FromToken("Scope:0", Meta)); var termC = new FilterTerm(WorkitemParent); termC.NotEqual(Oid.FromToken("Theme:7", Meta)); termC.NotEqual(Oid.FromToken("Theme:8", Meta)); var termD = new FilterTerm(WorkitemScope); termD.NotEqual(Oid.FromToken("Scope:1", Meta)); var and1 = new AndFilterTerm(termA, termB); var and2 = new AndFilterTerm(termC, termD); var o = new OrFilterTerm(and1, and2); Assert.AreEqual( "((Workitem.Parent='Theme%3a5','Theme%3a6';Workitem.Scope='Scope%3a0')|(Workitem.Parent!='Theme%3a7','Theme%3a8';Workitem.Scope!='Scope%3a1'))", o.Token); }
public ICollection <Scope> LookupProjects(string term) { var projectType = services.Meta.GetAssetType(ScopeType); var parentDef = projectType.GetAttributeDefinition("Parent"); var nameDef = projectType.GetAttributeDefinition(Entity.NameProperty); var stateDef = projectType.GetAttributeDefinition(AssetStateAttribute); var filter = new FilterTerm(stateDef); filter.NotEqual(AssetState.Closed); var query = new Query(projectType, parentDef) { Filter = filter }; query.Selection.Add(nameDef); query.OrderBy.MajorSort(projectType.DefaultOrderBy, OrderBy.Order.Ascending); var assets = services.Retrieve(query).Assets.Flatten(); var selectAll = string.IsNullOrEmpty(term.Trim()); return(assets .Where(x => selectAll || x.GetAttribute(nameDef).Value.ToString().ToLowerInvariant().Contains(term.ToLowerInvariant())) .Select(asset => new Scope(asset)) .ToList()); }
public GroupFilterTerm GetFilter(IAssetType type) { var terms = new List <IFilterTerm>(); foreach (var value in values) { var term = new FilterTerm(type.GetAttributeDefinition(Name)); switch (value.Action) { case FilterValuesActions.Equal: term.Equal(value.Value); break; case FilterValuesActions.NotEqual: term.NotEqual(value.Value); break; case FilterValuesActions.Greater: term.Greater(value.Value); break; default: throw new NotSupportedException(); } terms.Add(term); } return(Operation == FilterActions.And ? (GroupFilterTerm) new AndFilterTerm(terms.ToArray()) : new OrFilterTerm(terms.ToArray())); }
/// <summary> /// Gets the active values of a standard list type. /// </summary> /// <typeparam name="T">The type of Entity that represents the V1 List Type.</typeparam> /// <returns>A list of active values for this list type.</returns> public IEnumerable <T> ListTypeValues <T>() where T : ListValue { var typeToGet = instance.MetaModel.GetAssetType(GetAssetTypeToken(typeof(T))); var query = new Query(typeToGet); var assetStateTerm = new FilterTerm(typeToGet.GetAttributeDefinition("AssetState")); assetStateTerm.NotEqual(AssetState.Closed); query.Filter = new AndFilterTerm(assetStateTerm); return(instance.QueryToEntityEnum <T>(query)); }
internal IEnumerable <CustomListValue> GetCustomListTypeValues(Entity entity, string attributeName) { var typeToGet = GetRelatedType(entity, attributeName); var query = new Query(typeToGet); var assetStateTerm = new FilterTerm(typeToGet.GetAttributeDefinition("AssetState")); assetStateTerm.NotEqual(AssetState.Closed); query.Filter = new AndFilterTerm(assetStateTerm); return(Services.Retrieve(query).Assets.Select(asset => CreateWrapper <CustomListValue>(new AssetID(asset.Oid.Token), false)).ToList()); }
// TODO use filters private Asset GetProjectById(string projectId) { var scopeType = services.Meta.GetAssetType(Workitem.ScopeProperty); var scopeState = scopeType.GetAttributeDefinition(AssetStateAttribute); var scopeStateTerm = new FilterTerm(scopeState); scopeStateTerm.NotEqual(AssetState.Closed); var query = new Query(services.GetOid(projectId)) { Filter = scopeStateTerm }; var result = services.Retrieve(query); return result.Assets.FirstOrDefault(); }
//TODO refactor private Asset GetRootProject() { var scopeType = services.Meta.GetAssetType(Workitem.ScopeProperty); var scopeName = scopeType.GetAttributeDefinition(Entity.NameProperty); var scopeState = scopeType.GetAttributeDefinition(AssetStateAttribute); var scopeStateTerm = new FilterTerm(scopeState); scopeStateTerm.NotEqual(AssetState.Closed); var scopeQuery = new Query(scopeType, scopeType.GetAttributeDefinition(Entity.ParentProperty)) { Filter = scopeStateTerm }; scopeQuery.Selection.Add(scopeName); var nameQueryResult = services.Retrieve(scopeQuery); return nameQueryResult.Assets.FirstOrDefault(); }
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 IList <Project> GetProjectTree() { try { var scopeQuery = new Query(ProjectType, ProjectType.GetAttributeDefinition("Parent")); var stateTerm = new FilterTerm(ProjectType.GetAttributeDefinition("AssetState")); stateTerm.NotEqual(AssetState.Closed); scopeQuery.Filter = stateTerm; AddSelection(scopeQuery, Entity.ProjectType); var result = connector.Services.Retrieve(scopeQuery); var roots = result.Assets.Select(asset => WorkitemFactory.CreateProject(asset, null)).ToList(); return(roots); } catch (WebException ex) { connector.IsConnected = false; Logger.Error("Can't get projects list.", ex); return(null); } catch (Exception ex) { Logger.Error("Can't get projects list.", ex); return(null); } }
static void Main(string[] args) { var dataConnector = new VersionOneAPIConnector(BASE_URL + "/rest-1.v1/").WithOAuth2(SecretsFile, CredsFile); var metaConnector = new VersionOneAPIConnector(BASE_URL + "/meta.v1/"); var metaModel = new MetaModel(metaConnector); var services = new Services(metaModel, dataConnector); var scopeType = metaModel.GetAssetType("Member"); var nameAttr = scopeType.GetAttributeDefinition("Name"); var descAttr = scopeType.GetAttributeDefinition("Nickname"); var worksItemsNameAttr = scopeType.GetAttributeDefinition("OwnedWorkitems.Name"); var query = new Query(scopeType); var whereAdmin = new FilterTerm(descAttr); whereAdmin.Equal("admin"); var whereNotTheAdmin = new FilterTerm(nameAttr); whereNotTheAdmin.NotEqual("theAdmin"); var andFilter = new AndFilterTerm(whereAdmin, whereNotTheAdmin); query.Filter = andFilter; query.Selection.AddRange(new[] { nameAttr, descAttr, worksItemsNameAttr }); var result = services.Retrieve(query); foreach (var asset in result.Assets) { Console.WriteLine("Name: " + asset.GetAttribute(nameAttr).Value); Console.WriteLine("Description: " + asset.GetAttribute(descAttr).Value); var workItems = asset.GetAttribute(worksItemsNameAttr).ValuesList; Console.WriteLine("Workitems count: " + workItems.Count); foreach (var workitem in workItems) { Console.WriteLine("Workitem: " + workitem); } } Console.ReadLine(); }
private IFilterTerm GetScopeFilter(IAssetType assetType) { var terms = new List <FilterTerm>(4); var term = new FilterTerm(assetType.GetAttributeDefinition("Scope.AssetState")); term.NotEqual(AssetState.Closed); terms.Add(term); term = new FilterTerm(assetType.GetAttributeDefinition("Scope.ParentMeAndUp")); term.Equal(CurrentProjectId); terms.Add(term); term = new FilterTerm(assetType.GetAttributeDefinition("Timebox.State.Code")); term.Equal("ACTV"); terms.Add(term); term = new FilterTerm(assetType.GetAttributeDefinition("AssetState")); term.NotEqual(AssetState.Closed); terms.Add(term); return(new AndFilterTerm(terms.Cast <IFilterTerm>().ToArray())); }
private void CreateSingleScopeFilter(FilterBuilder builder) { var project = projects.First(); var metaModel = builder.Instance.ApiClient.MetaModel; var epicType = metaModel.GetAssetType("Epic"); var scopeType = metaModel.GetAssetType("Scope"); var notClosedScopeAttribute = scopeType.GetAttributeDefinition("AssetState"); var notClosedScopeTerm = new FilterTerm(notClosedScopeAttribute); notClosedScopeTerm.NotEqual("Closed"); var scopeAttribute = epicType.GetAttributeDefinition("Scope.ParentMeAndUp").Filter(notClosedScopeTerm); var scopeTerm = builder.Root.Term(scopeAttribute); scopeTerm.Equal(project.ToString()); var superAndUpAttribute = epicType.GetAttributeDefinition("SuperAndUp"); superAndUpAttribute = superAndUpAttribute.Filter(scopeTerm); var superAndUpTerm = builder.Root.Term(superAndUpAttribute); superAndUpTerm.NotExists(); }
public List <ProjectWrapper> GetProjectList() { var projectType = services.Meta.GetAssetType(ProjectTypeToken); var scopeQuery = new Query(projectType, projectType.GetAttributeDefinition("Parent")); var stateTerm = new FilterTerm(projectType.GetAttributeDefinition("AssetState")); stateTerm.NotEqual(AssetState.Closed); scopeQuery.Filter = stateTerm; var nameDef = projectType.GetAttributeDefinition("Name"); scopeQuery.Selection.Add(nameDef); scopeQuery.OrderBy.MajorSort(projectType.DefaultOrderBy, OrderBy.Order.Ascending); var result = services.Retrieve(scopeQuery); var roots = new List <ProjectWrapper>(result.Assets.Count); foreach (Asset asset in result.Assets) { roots.AddRange(GetProjectWrapperList(asset, nameDef, 0)); } return(roots); }
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); }
private int GetCustomFields(string attributeName, string attributeType) { IAssetType assetType = _metaAPI.GetAssetType(_InternalAssetType); Query query = new Query(assetType); int assetCount = 0; IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition(attributeName); query.Selection.Add(nameAttribute); //Test for LongText Fields because they will not pull from the API with an Empty String Filter switch (attributeType) { case "LongText": break; default: //Filter to ensure that we have a value. FilterTerm filter = new FilterTerm(nameAttribute); filter.NotEqual(String.Empty); query.Filter = filter; break; } QueryResult result = _dataAPI.Retrieve(query); string SQL = BuildCustomFieldInsertStatement(); foreach (Asset asset in result.Assets) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = _sqlConn; cmd.CommandText = SQL; cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@AssetOID", asset.Oid.ToString()); cmd.Parameters.AddWithValue("@FieldName", attributeName); cmd.Parameters.AddWithValue("@FieldType", attributeType); if (attributeType == "Relation") { cmd.Parameters.AddWithValue("@FieldValue", GetSingleListValue(asset.GetAttribute(nameAttribute))); } else { //Remove NULL Records from LongText Fields Object fieldValue = GetScalerValue(asset.GetAttribute(nameAttribute)); if (fieldValue.Equals(DBNull.Value)) { continue; } else { cmd.Parameters.AddWithValue("@FieldValue", fieldValue); } } cmd.ExecuteNonQuery(); assetCount++; } } return(assetCount); }