Exemple #1
0
        internal T GetListValueByName <T>(string value) where T : ListValue
        {
            var typeToken = GetAssetTypeToken(typeof(T));
            var listType  = MetaModel.GetAssetType(typeToken);

            return(GetListValueByName <T>(listType, value));
        }
Exemple #2
0
        private IAssetType GetRelatedType(Entity entity, string name)
        {
            var owningType  = MetaModel.GetAssetType(GetAssetTypeToken(entity.GetType()));
            var listTypeDef = owningType.GetAttributeDefinition(name);

            return(listTypeDef.RelatedAsset);
        }
Exemple #3
0
        public void ReOpenAnAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            // create a new story
            var projectId     = Oid.FromToken("Scope:0", metaModel);
            var assetType     = metaModel.GetAssetType("Story");
            var story         = services.New(assetType, projectId);
            var nameAttribute = assetType.GetAttributeDefinition("Name");

            story.SetAttributeValue(nameAttribute, "My New Story");
            services.Save(story);

            // closes the story
            var closeOperation = metaModel.GetOperation("Story.Inactivate");
            var closeId        = services.ExecuteOperation(closeOperation, story.Oid);

            //reopens the story
            var activateOperation = metaModel.GetOperation("Story.Reactivate");
            var activeId          = services.ExecuteOperation(activateOperation, story.Oid);

            var query      = new Query(activeId.Momentless);
            var assetState = metaModel.GetAttributeDefinition("Story.AssetState");

            query.Selection.Add(assetState);
            var   result      = services.Retrieve(query);
            Asset activeStory = result.Assets[0];

            Assert.AreEqual("Active", activeStory.GetAttribute(assetState).Value.ToString());
        }
Exemple #4
0
        public void HistorySingleAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var memberType          = metaModel.GetAssetType("Member");
            var idAttribute         = memberType.GetAttributeDefinition("ID");
            var changeDateAttribute = memberType.GetAttributeDefinition("ChangeDate");
            var emailAttribute      = memberType.GetAttributeDefinition("Email");

            // the boolean parameter specifies we want the historical data
            var query = new Query(memberType, true);

            query.Selection.Add(changeDateAttribute);
            query.Selection.Add(emailAttribute);

            var idTerm = new FilterTerm(idAttribute);

            idTerm.Equal("Member:20");
            query.Filter = idTerm;

            var result = services.Retrieve(query);

            Assert.AreNotEqual(0, result.Assets.Count);
        }
Exemple #5
0
        public void UpdateMultiValueRelationTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyId         = Oid.FromToken("Story:1124", metaModel);
            var query           = new Query(storyId);
            var storyType       = metaModel.GetAssetType("Story");
            var ownersAttribute = storyType.GetAttributeDefinition("Owners");

            query.Selection.Add(ownersAttribute);

            var result = services.Retrieve(query);
            var story  = result.Assets[0];
            var values = story.GetAttribute(ownersAttribute).Values;
            var owners = values.Cast <object>().ToList();

            if (owners.Count >= 1)
            {
                story.RemoveAttributeValue(ownersAttribute, owners[0]);
            }

            services.Save(story);
        }
        protected Object GetSingleListValue(VersionOne.SDK.APIClient.Attribute attribute)
        {
            if (attribute.Value != null && attribute.Value.ToString() != "NULL")
            {
                IAssetType assetType = _metaAPI.GetAssetType("List");
                Query      query     = new Query(assetType);

                IAttributeDefinition assetIDAttribute = assetType.GetAttributeDefinition("ID");
                query.Selection.Add(assetIDAttribute);

                IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
                query.Selection.Add(nameAttribute);

                FilterTerm assetName = new FilterTerm(assetIDAttribute);
                assetName.Equal(attribute.Value.ToString());
                query.Filter = assetName;

                QueryResult result = _dataAPI.Retrieve(query);
                return(result.Assets[0].GetAttribute(nameAttribute).Value.ToString());
            }
            else
            {
                return(DBNull.Value);
            }
        }
Exemple #7
0
        public void FindListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType         = metaModel.GetAssetType("Story");
            var query             = new Query(assetType);
            var nameAttribute     = assetType.GetAttributeDefinition("Name");
            var priorityAttribute = assetType.GetAttributeDefinition("Priority");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(priorityAttribute);
            query.Find = new QueryFind("High");
            var result = services.Retrieve(query);

            result.Assets.ForEach(
                asset => Assert.IsTrue(asset.GetAttribute(nameAttribute)
                                       .Value
                                       .ToString()
                                       .IndexOf("High", StringComparison.OrdinalIgnoreCase)
                                       >= 0));

            Assert.IsTrue(result.Assets.Count > 1);
        }
Exemple #8
0
        public void DeleteAnAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            // create a new story so we can delete it
            var projectId     = Oid.FromToken("Scope:0", metaModel);
            var assetType     = metaModel.GetAssetType("Story");
            var newStory      = services.New(assetType, projectId);
            var nameAttribute = assetType.GetAttributeDefinition("Name");

            newStory.SetAttributeValue(nameAttribute, "My New Story");
            services.Save(newStory);
            // delete the story
            var         deleteOperation = metaModel.GetOperation("Story.Delete");
            var         deletedId       = services.ExecuteOperation(deleteOperation, newStory.Oid);
            var         query           = new Query(deletedId.Momentless);
            QueryResult result          = services.Retrieve(query);

            Assert.AreEqual(0, result.TotalAvaliable);

            // The delete operation returns the Oid with the new Moment of the deleted asset.
            // Future queries will automatically exclude deleted assets from results.
            // Currently there is no support for undeleting a deleted asset.
        }
        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);
        }
        protected string CheckForDuplicateInV1(string AssetType, string AttributeName, string AttributeValue)
        {
            //if (AssetType.StartsWith("Custom_"))
            //{
            //    return null;
            //}

            IAssetType assetType = _metaAPI.GetAssetType(AssetType);
            //_logger.Info("CheckForDuplicateInV1: assetType is {0} amd value is {1} ", AssetType, AttributeValue);

            Query query = new Query(assetType);

            IAttributeDefinition valueAttribute = assetType.GetAttributeDefinition(AttributeName);

            query.Selection.Add(valueAttribute);
            FilterTerm idFilter = new FilterTerm(valueAttribute);

            idFilter.Equal(AttributeValue);
            query.Filter = idFilter;
            QueryResult result = _dataAPI.Retrieve(query);

            if (result.TotalAvaliable > 0)
            {
                return(result.Assets[0].Oid.Token.ToString());
            }
            else
            {
                return(null);
            }
        }
Exemple #11
0
        /// <summary>
        /// Find an asset in the asset cache or create one for this id
        /// </summary>
        /// <param name="id"></param>
        /// <param name="assetTypeToken">The Asset Type Token of the asset to create if one does not already exist</param>
        /// <returns>An Asset that will exist in the asset cache</returns>
        private Asset GetAsset(object id, string assetTypeToken)
        {
            Asset result;

            if (!assetCache.TryGetValue(id, out result))
            {
                var assetType = MetaModel.GetAssetType(assetTypeToken);
                var assetId   = id as AssetID;
                result = assetId != null ? new Asset(Oid.FromToken(assetId, MetaModel)) : new Asset(assetType);
                SetAsset(id, result);
            }

            return(result);
        }
		public void TestFixtureSetUp()
		{
			V1APIConnector dataConnector = new V1APIConnector(v1Url + dataPath, username, password);
			V1APIConnector metaConnector = new V1APIConnector(v1Url + metaPath);
			V1APIConnector localConnector = new V1APIConnector(v1Url + localizationPath);
			
			localizer = new Localizer(localConnector);
			metaModel = new MetaModel(metaConnector);
			services = new Services(metaModel, dataConnector);

			timeboxType = metaModel.GetAssetType("Timebox");
			timeboxName = timeboxType.GetAttributeDefinition("Name");
			timeboxID = timeboxType.GetAttributeDefinition("ID");
		}
        public void TestFixtureSetUp()
        {
            V1APIConnector dataConnector  = new V1APIConnector(v1Url + dataPath, username, password);
            V1APIConnector metaConnector  = new V1APIConnector(v1Url + metaPath);
            V1APIConnector localConnector = new V1APIConnector(v1Url + localizationPath);

            localizer = new Localizer(localConnector);
            metaModel = new MetaModel(metaConnector);
            services  = new Services(metaModel, dataConnector);

            timeboxType = metaModel.GetAssetType("Timebox");
            timeboxName = timeboxType.GetAttributeDefinition("Name");
            timeboxID   = timeboxType.GetAttributeDefinition("ID");
        }
		public void QueryProjects() {
			var proxyProvider = new ProxyProvider(new Uri(ProxyPath), ProxyUsername, ProxyPassword);
			IAPIConnector metaConnector = new V1APIConnector(V1Path + "meta.v1/", V1Username, V1Password, false, proxyProvider);
			IMetaModel metaModel = new MetaModel(metaConnector);

			IAPIConnector dataConnector = new V1APIConnector(V1Path + "rest-1.v1/", V1Username, V1Password, false, proxyProvider);
			IServices services = new Services(metaModel, dataConnector);

			var projectType = metaModel.GetAssetType("Scope");
			var scopeQuery = new Query(projectType);
			var result = services.Retrieve(scopeQuery);

			Assert.IsTrue(result.Assets.Count > 0);
		}
Exemple #15
0
        internal T New <T>(Entity inTheContextOf) where T : Entity
        {
            var contextOid = GetOid(inTheContextOf);

            var assetTypeToken = GetAssetTypeToken(typeof(T));
            var typeToCreate   = MetaModel.GetAssetType(assetTypeToken);

            var shell = Services.New(typeToCreate, contextOid);

            var result = CreateWrapper <T>();

            SetAsset(result.InstanceKey, shell);

            return(result);
        }
Exemple #16
0
        public void QueryProjects()
        {
            var           proxyProvider = new ProxyProvider(new Uri(ProxyPath), ProxyUsername, ProxyPassword);
            IAPIConnector metaConnector = new V1APIConnector(V1Path + "meta.v1/", V1Username, V1Password, false, proxyProvider);
            IMetaModel    metaModel     = new MetaModel(metaConnector);

            IAPIConnector dataConnector = new V1APIConnector(V1Path + "rest-1.v1/", V1Username, V1Password, false, proxyProvider);
            IServices     services      = new Services(metaModel, dataConnector);

            var projectType = metaModel.GetAssetType("Scope");
            var scopeQuery  = new Query(projectType);
            var result      = services.Retrieve(scopeQuery);

            Assert.IsTrue(result.Assets.Count > 0);
        }
Exemple #17
0
        public void AddNewAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var projectId     = Oid.FromToken("Scope:0", metaModel);
            var assetType     = metaModel.GetAssetType("Story");
            var newStory      = services.New(assetType, projectId);
            var nameAttribute = assetType.GetAttributeDefinition("Name");

            newStory.SetAttributeValue(nameAttribute, "My New Story");
            services.Save(newStory);

            Assert.IsFalse(newStory.Oid.IsNull);
        }
Exemple #18
0
        public void GetMultipleAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType         = metaModel.GetAssetType("Story");
            var query             = new Query(assetType);
            var nameAttribute     = assetType.GetAttributeDefinition("Name");
            var estimateAttribute = assetType.GetAttributeDefinition("Estimate");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(estimateAttribute);
            var result = services.Retrieve(query);

            Assert.IsTrue(result.Assets.Count > 1);
        }
Exemple #19
0
        public void PageListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyType = metaModel.GetAssetType("Story");
            var query     = new Query(storyType)
            {
                Paging = { PageSize = 3, Start = 0 }
            };
            var result = services.Retrieve(query);

            Assert.AreEqual(3, result.Assets.Count);
            // The PageSize property shown asks for 3 items, and the Start property indicates to start at 0.
            // The next 3 items can be retrieved with PageSize=3, Start=3.
        }
Exemple #20
0
        public void HistoryListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var memberType          = metaModel.GetAssetType("Member");
            var query               = new Query(memberType, true);
            var changeDateAttribute = memberType.GetAttributeDefinition("ChangeDate");
            var emailAttribute      = memberType.GetAttributeDefinition("Email");

            query.Selection.Add(changeDateAttribute);
            query.Selection.Add(emailAttribute);
            var result = services.Retrieve(query);

            Assert.AreNotEqual(0, result.TotalAvaliable);
        }
        public void GetMultipleAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType = metaModel.GetAssetType("Story");
            var query = new Query(assetType);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            var estimateAttribute = assetType.GetAttributeDefinition("Estimate");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(estimateAttribute);
            var result = services.Retrieve(query);

            Assert.Greater(result.Assets.Count, 1);
        }
Exemple #22
0
        public void SortListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType         = metaModel.GetAssetType("Story");
            var query             = new Query(assetType);
            var nameAttribute     = assetType.GetAttributeDefinition("Name");
            var estimateAttribute = assetType.GetAttributeDefinition("Estimate");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(estimateAttribute);
            query.OrderBy.MinorSort(estimateAttribute, OrderBy.Order.Ascending);

            var result = services.Retrieve(query);
        }
Exemple #23
0
        public void UpdateSingleValueRelationTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyId         = Oid.FromToken("Story:1094", metaModel);
            var query           = new Query(storyId);
            var storyType       = metaModel.GetAssetType("Story");
            var sourceAttribute = storyType.GetAttributeDefinition("Source");

            query.Selection.Add(sourceAttribute);
            var result    = services.Retrieve(query);
            var story     = result.Assets[0];
            var oldSource = story.GetAttribute(sourceAttribute).Value.ToString();

            story.SetAttributeValue(sourceAttribute, GetNextSourceId(oldSource));
            services.Save(story);
        }
Exemple #24
0
        public void HistoryAsOfTimeTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyType         = metaModel.GetAssetType("Story");
            var query             = new Query(storyType, true);
            var nameAttribute     = storyType.GetAttributeDefinition("Name");
            var estimateAttribute = storyType.GetAttributeDefinition("Estimate");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(estimateAttribute);

            query.AsOf = DateTime.Now.AddDays(-7);
            QueryResult result = services.Retrieve(query);

            Assert.AreNotEqual(0, result.TotalAvaliable);
        }
        /**************************************************************************************
        * Protected methods used by derived classes.
        **************************************************************************************/
        protected Asset GetAssetFromV1(string AssetID)
        {
            Oid   assetId = Oid.FromToken(AssetID, _metaAPI);
            Query query   = new Query(assetId);

            IAssetType           assetType           = _metaAPI.GetAssetType("Epic");
            IAttributeDefinition assetStateAttribute = assetType.GetAttributeDefinition("AssetState");

            query.Selection.Add(assetStateAttribute);

            QueryResult result = _dataAPI.Retrieve(query);

            if (result.Assets.Count > 0)
            {
                return(result.Assets[0]);
            }
            else
            {
                return(null);
            }
        }
Exemple #26
0
        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();
        }
Exemple #27
0
        public void UpdateScalarAttributeTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyId       = Oid.FromToken("Story:1094", metaModel);
            var query         = new Query(storyId);
            var storyType     = metaModel.GetAssetType("Story");
            var nameAttribute = storyType.GetAttributeDefinition("Name");

            query.Selection.Add(nameAttribute);
            var result  = services.Retrieve(query);
            var story   = result.Assets[0];
            var oldName = story.GetAttribute(nameAttribute).Value.ToString();

            story.SetAttributeValue(nameAttribute, Guid.NewGuid().ToString());
            services.Save(story);

            Assert.AreNotEqual(oldName, story.GetAttribute(nameAttribute).Value.ToString());
        }
Exemple #28
0
        /// <summary>
        /// Use the Filter property of the Query object to filter the results that are returned.
        /// This query will retrieve only Story assets with a "ToDo" of zero.
        /// </summary>
        public void FilterListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices  services  = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType     = metaModel.GetAssetType("Task");
            var query         = new Query(assetType);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            var todoAttribute = assetType.GetAttributeDefinition("ToDo");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(todoAttribute);

            var toDoTerm = new FilterTerm(todoAttribute);

            toDoTerm.Equal(0);
            query.Filter = toDoTerm;
            var result = services.Retrieve(query);

            result.Assets.ForEach(asset =>
                                  Assert.AreEqual(0, asset.GetAttribute(todoAttribute).Value));
        }
        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);
        }
Exemple #30
0
 internal bool MultiRelationIsReadOnly(Entity entity, string attributeName)
 {
     return
         (MetaModel.GetAssetType(GetAssetTypeToken(entity.GetType())).GetAttributeDefinition(attributeName).
          IsReadOnly);
 }
        public void DeleteAnAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            // create a new story so we can delete it
            var projectId = Oid.FromToken("Scope:0", metaModel);
            var assetType = metaModel.GetAssetType("Story");
            var newStory = services.New(assetType, projectId);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            newStory.SetAttributeValue(nameAttribute, "My New Story");
            services.Save(newStory);
            // delete the story
            var deleteOperation = metaModel.GetOperation("Story.Delete");
            var deletedId = services.ExecuteOperation(deleteOperation, newStory.Oid);
            var query = new Query(deletedId.Momentless);
            QueryResult result = services.Retrieve(query);

            Assert.AreEqual(0, result.TotalAvaliable);

            // The delete operation returns the Oid with the new Moment of the deleted asset. 
            // Future queries will automatically exclude deleted assets from results.
            // Currently there is no support for undeleting a deleted asset.
        }
        public void ReOpenAnAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            // create a new story
            var projectId = Oid.FromToken("Scope:0", metaModel);
            var assetType = metaModel.GetAssetType("Story");
            var story = services.New(assetType, projectId);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            story.SetAttributeValue(nameAttribute, "My New Story");
            services.Save(story);

            // closes the story
            var closeOperation = metaModel.GetOperation("Story.Inactivate");
            var closeId = services.ExecuteOperation(closeOperation, story.Oid);

            //reopens the story
            var activateOperation = metaModel.GetOperation("Story.Reactivate");
            var activeId = services.ExecuteOperation(activateOperation, story.Oid);

            var query = new Query(activeId.Momentless);
            var assetState = metaModel.GetAttributeDefinition("Story.AssetState");
            query.Selection.Add(assetState);
            var result = services.Retrieve(query);
            Asset activeStory = result.Assets[0];

            Assert.AreEqual("Active", activeStory.GetAttribute(assetState).Value.ToString());
        }
        public void UpdateMultiValueRelationTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyId = Oid.FromToken("Story:1124", metaModel);
            var query = new Query(storyId);
            var storyType = metaModel.GetAssetType("Story");
            var ownersAttribute = storyType.GetAttributeDefinition("Owners");

            query.Selection.Add(ownersAttribute);

            var result = services.Retrieve(query);
            var story = result.Assets[0];
            var values = story.GetAttribute(ownersAttribute).Values;
            var owners = values.Cast<object>().ToList();

            if (owners.Count >= 1) story.RemoveAttributeValue(ownersAttribute, owners[0]);

            services.Save(story);
        }
        public void AddNewAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var projectId = Oid.FromToken("Scope:0", metaModel);
            var assetType = metaModel.GetAssetType("Story");
            var newStory = services.New(assetType, projectId);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            newStory.SetAttributeValue(nameAttribute, "My New Story");
            services.Save(newStory);

            Assert.False(newStory.Oid.IsNull);
        }
Exemple #35
0
        public static QueryBuilder For(string assetTypeToken, MetaModel metaModel)
        {
            var assetType = metaModel.GetAssetType(assetTypeToken);

            return(new QueryBuilder(assetType, metaModel));
        }
        public void UpdateSingleValueRelationTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyId = Oid.FromToken("Story:1094", metaModel);
            var query = new Query(storyId);
            var storyType = metaModel.GetAssetType("Story");
            var sourceAttribute = storyType.GetAttributeDefinition("Source");
            query.Selection.Add(sourceAttribute);
            var result = services.Retrieve(query);
            var story = result.Assets[0];
            var oldSource = story.GetAttribute(sourceAttribute).Value.ToString();
            story.SetAttributeValue(sourceAttribute, GetNextSourceId(oldSource));
            services.Save(story);
        }
        public void HistoryListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var memberType = metaModel.GetAssetType("Member");
            var query = new Query(memberType, true);
            var changeDateAttribute = memberType.GetAttributeDefinition("ChangeDate");
            var emailAttribute = memberType.GetAttributeDefinition("Email");
            query.Selection.Add(changeDateAttribute);
            query.Selection.Add(emailAttribute);
            var result = services.Retrieve(query);

            Assert.AreNotEqual(0, result.TotalAvaliable);
        }
        public void HistoryAsOfTimeTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyType = metaModel.GetAssetType("Story");
            var query = new Query(storyType, true);
            var nameAttribute = storyType.GetAttributeDefinition("Name");
            var estimateAttribute = storyType.GetAttributeDefinition("Estimate");
            query.Selection.Add(nameAttribute);
            query.Selection.Add(estimateAttribute);

            query.AsOf = DateTime.Now.AddDays(-7);
            QueryResult result = services.Retrieve(query);

            Assert.AreNotEqual(0, result.TotalAvaliable);
        }
        public void PageListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyType = metaModel.GetAssetType("Story");
            var query = new Query(storyType) { Paging = { PageSize = 3, Start = 0 } };
            var result = services.Retrieve(query);

            Assert.AreEqual(3, result.Assets.Count);
            // The PageSize property shown asks for 3 items, and the Start property indicates to start at 0. 
            // The next 3 items can be retrieved with PageSize=3, Start=3.
        }
        public void HistorySingleAssetTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var memberType = metaModel.GetAssetType("Member");
            var idAttribute = memberType.GetAttributeDefinition("ID");
            var changeDateAttribute = memberType.GetAttributeDefinition("ChangeDate");
            var emailAttribute = memberType.GetAttributeDefinition("Email");

            // the boolean parameter specifies we want the historical data
            var query = new Query(memberType, true);
            query.Selection.Add(changeDateAttribute);
            query.Selection.Add(emailAttribute);

            var idTerm = new FilterTerm(idAttribute);
            idTerm.Equal("Member:20");
            query.Filter = idTerm;

            var result = services.Retrieve(query);

            Assert.AreNotEqual(0, result.Assets.Count);
        }
        public void SortListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType = metaModel.GetAssetType("Story");
            var query = new Query(assetType);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            var estimateAttribute = assetType.GetAttributeDefinition("Estimate");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(estimateAttribute);
            query.OrderBy.MinorSort(estimateAttribute, OrderBy.Order.Ascending);

            var result = services.Retrieve(query);
        }
        public void FindListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType = metaModel.GetAssetType("Story");
            var query = new Query(assetType);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            var priorityAttribute = assetType.GetAttributeDefinition("Priority");
            query.Selection.Add(nameAttribute);
            query.Selection.Add(priorityAttribute);
            query.Find = new QueryFind("High");
            var result = services.Retrieve(query);

            result.Assets.ForEach(
                asset => Assert.GreaterOrEqual(asset.GetAttribute(nameAttribute)
                    .Value
                    .ToString()
                    .IndexOf("High", StringComparison.OrdinalIgnoreCase)
                    , 0));

            Assert.Greater(result.Assets.Count, 1);
        }
		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);
		}
        /// <summary>
        /// Use the Filter property of the Query object to filter the results that are returned. 
        /// This query will retrieve only Story assets with a "ToDo" of zero.
        /// </summary>
        public void FilterListOfAssetsTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var assetType = metaModel.GetAssetType("Task");
            var query = new Query(assetType);
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            var todoAttribute = assetType.GetAttributeDefinition("ToDo");

            query.Selection.Add(nameAttribute);
            query.Selection.Add(todoAttribute);

            var toDoTerm = new FilterTerm(todoAttribute);
            toDoTerm.Equal(0);
            query.Filter = toDoTerm;
            var result = services.Retrieve(query);

            result.Assets.ForEach(asset =>
                    Assert.AreEqual(0, asset.GetAttribute(todoAttribute).Value));
        }
        public void UpdateScalarAttributeTest()
        {
            IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl));
            IServices services = new Services(
                metaModel,
                new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password));

            var storyId = Oid.FromToken("Story:1094", metaModel);
            var query = new Query(storyId);
            var storyType = metaModel.GetAssetType("Story");
            var nameAttribute = storyType.GetAttributeDefinition("Name");

            query.Selection.Add(nameAttribute);
            var result = services.Retrieve(query);
            var story = result.Assets[0];
            var oldName = story.GetAttribute(nameAttribute).Value.ToString();
            story.SetAttributeValue(nameAttribute, Guid.NewGuid().ToString());
            services.Save(story);

            Assert.AreNotEqual(oldName, story.GetAttribute(nameAttribute).Value.ToString());
        }
		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);
		}
Exemple #47
0
        static void Main(string[] args)
        {
            //string file = args[0];
            string file = @"C:\Users\MIRVIN\Desktop\Training Wheels\SampleAttachment\bin\Debug\testfile.rtf";

            if (File.Exists(file))
            {
                Console.WriteLine("Uploading {0}", file);
                string mimeType = MimeType.Resolve(file);

                IMetaModel   metaModel   = new MetaModel(new V1APIConnector(ApplicationURL + "meta.v1/"));
                IServices    services    = new Services(metaModel, new V1APIConnector(ApplicationURL + "rest-1.v1/", _username, _password, _integrated));
                IAttachments attachments = new Attachments(new V1APIConnector(ApplicationURL + "attachment.img/", _username, _password, _integrated));


                //cleanjeans scope
                Oid attachmentContext = Oid.FromToken("Scope:5067", metaModel);



                IAssetType attachmentType = metaModel.GetAssetType("Attachment");

                IAttributeDefinition attachmentNameDef = attachmentType.GetAttributeDefinition("Name");

                IAttributeDefinition attachmentContentDef = attachmentType.GetAttributeDefinition("Content");

                IAttributeDefinition attachmentContentTypeDef = attachmentType.GetAttributeDefinition("ContentType");

                IAttributeDefinition attachmentFileNameDef = attachmentType.GetAttributeDefinition("Filename");



                Asset newAttachment = services.New(attachmentType, attachmentContext);

                newAttachment.SetAttributeValue(attachmentNameDef, "New Attachment");

                newAttachment.SetAttributeValue(attachmentContentDef, string.Empty);

                newAttachment.SetAttributeValue(attachmentContentTypeDef, mimeType);

                newAttachment.SetAttributeValue(attachmentFileNameDef, file);

                services.Save(newAttachment);

                //Setup and attach the payload

                string attachmentKey = newAttachment.Oid.Key.ToString();
                int    buffersize    = 4096;

                using (FileStream input = new FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    using (Stream output = attachments.GetWriteStream(attachmentKey))
                    {
                        byte[] buffer = new byte[buffersize];

                        for (; ;)
                        {
                            int read = input.Read(buffer, 0, buffersize);

                            if (read == 0)
                            {
                                break;
                            }

                            output.Write(buffer, 0, read);
                        }
                    }
                }

                attachments.SetWriteStream(attachmentKey, mimeType);



                Console.WriteLine("{0} uploaded", file);
            }

            else
            {
                Console.WriteLine("{0} does not exist", file);
            }
        }