I need to write a query to extract from Rally the user stories (HierarchicalRequirement) with a given value for a custom field and release name, ordering them by their iteration end-date first and user story rank as second parameter, in a Java application.
I can write the working query itself, but the order condition on the iteration end date doesnt work *the condition on the rank is straightforward: "Rank desc")
To order by iteration end date I passed to the "order" parameter of the SOAP API the string "Iteration.EndDate desc" but it doesnt work.
What's wrong with this?
I'm not sure how to do this with SOAP but with the REST api it is straightforward:
http://developer.rallydev.com/help/java-toolkit-rally-rest-api
RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"),
"user#company.com", "password");
QueryRequest stories = new QueryRequest("hierarchicalrequirement");
stories.setFetch(new Fetch("FormattedID", "Name", "ScheduleState"));
stories.setOrder("Iteration.EndDate DESC,Rank DESC");
QueryResponse queryResponse = restApi.query(stories);
if (queryResponse.wasSuccessful()) {
for (JsonElement result : queryResponse.getResults()) {
JsonObject story = result.getAsJsonObject();
System.out.println(String.format("\t%s - %s: ScheduleState=%s",
story.get("FormattedID").getAsString(),
story.get("Name").getAsString(),
story.get("ScheduleState").getAsString()));
}
}
Related
I want to get with a wiql query all workitem that have an empty HTML field.
Is there a way to do so?
To query out those work items who have empty HTML field like Description, using the query from TFS web page couldn't do that. There's no operator like "isEmpty or isNotEmpty" to use. Here is a uservoice about your request, and according to it, this feature is under review now.
As a workaround, you could use Excel to filter those work items. Write a simple query and export those work items to Excel. Then use the filter In Excel.
You could also use TFS object model api to get those empty field workitems, here is an example:
WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();
string queryString = "Select [State], [Title],[Description] From WorkItems Where [Work Item Type] = 'User Story' and [System.TeamProject] = 'TeamProjectName'";
// Create and run the query.
Query query = new Query(workItemStore, queryString);
WorkItemCollection witCollection = query.RunQuery();
foreach (WorkItem workItem in witCollection)
{
//check if the field is empty
if(workItem.Fields["Description"].Value.ToString() == string.Empty || workItem.Fields["Description"].Value.ToString() == "")
{
Console.WriteLine(workItem.Title);
}
}
I want to detect when a collection or index was last modified or written to.
Note: This works on document level, but i need on collection/index level. How to get last write date of a RavenDB document via C#
RavenQueryStatistics stats;
using(var session = _documentStore.OpenSession()) {
session.Query<MyDocument>()
.Statistics(out stats)
.Take(0) // don't load any documents as we need only the stats
.ToArray(); // this is needed to trigger server side query execution
}
DateTime indexTimestamp = stats.IndexTimestamp;
string indexEtag = stats.IndexEtag;;
getting meta data only via RavenDB Http Api:
GET http://localhost:8080/indexes/dynamic/MyDocuments/?metadata-only=true
would return:
{ "Results":[],
"Includes":[],
"IsStale":false,
"IndexTimestamp":"2013-09-16T15:54:58.2465733Z",
"TotalResults":0,
"SkippedResults":0,
"IndexName":"Raven/DocumentsByEntityName",
"IndexEtag":"01000000-0000-0008-0000-000000000006",
"ResultEtag":"3B5CA9C6-8934-1999-45C2-66A9769444F0",
"Highlightings":{},
"NonAuthoritativeInformation":false,
"LastQueryTime":"2013-09-16T15:55:00.8397216Z",
"DurationMilliseconds":102 }
ResultEtag and IndexTimestamp change on every write
In RavenDB (build 2330) I'm trying to order my results by the string length of one of the indexed terms.
var result = session.Query<Entity, IndexDefinition>()
.Where(condition)
.OrderBy(x => x.Token.Length);
However the results look to be un-sorted. Is this possible in RavenDB (or via a Lucene query) and if so what is the syntax?
You need to add a field to IndexDefinition to order by, and define the SortOption to Int or something more appropriate (however you don't want to use String which is default).
If you want to use the Linq API like in your example you need to add a field named Token_Length to the index' Map function (see Matt's comment):
from doc in docs
select new
{
...
Token_Length = doc.TokenLength
}
And then you can query using the Linq API:
var result = session.Query<Entity, IndexDefinition>()
.Where(condition)
.OrderBy(x => x.Token.Length);
Or if you really want the field to be called TokenLength (or something other than Token_Length) you can use a LuceneQuery:
from doc in docs
select new
{
...
TokenLength = doc.Token.Length
}
And you'd query like this:
var result = session.Advanced.LuceneQuery<Entity, IndexDefinition>()
.Where(condition)
.OrderBy("TokenLength");
I have a webservice I call from a WP7 app. I get a list of high scores in a table (name/score).. What is the simpliest way to add a 3rd column on the far left which is simply the row?
Do I need to add a property to the entity? Is there someway to get the row #?
I tried these things below with no success..
[OperationContract]
public List<DMHighScore> GetScores()
{
using (var db = new DMModelContainer())
{
// return db.DMHighScores.ToList();
var collOrderedHighScoreItem = (from o in db.DMHighScores
orderby o.UserScore ascending
select new
{
o.UserName,
o.UserScore
}).Take(20);
var collOrderedHighScoreItem2 = collOrderedHighScoreItem.AsEnumerable().Select((x, i) => new DMHighScoreDTO
{
UserName = x.UserName,
UserScore = x.UserScore
}).ToList();
}
}
[DataContract]
public class DMHighScoreDTO
{
int Rank;
string UserName;
string UserScore;
}
So lets assume you want to load top 100 users in leaderboard and you want to have their rank included:
[OperationContract]
public List<ScoreDto> GetTop100()
{
// Linq to entities query
var query = (from u from context.Users
order by u.Score
select new
{
u.Name,
u.Score
}).Take(100);
// Linq to objects query from working on 100 records loaded from DB
// Select with index doesn't work in linq to entities
var data = query.AsEnumerable().Select((x, i) => new ScoreDto
{
Rank = i + 1,
Name = x.Name,
Score = x.Score
}).ToList();
return data;
}
what will the row number be used for? if this is for ordering might I suggest adding a column named Order, then map the column to your entity.
if you require a row index, you could also call the .ToList() on the query and fetch the index locations for each entity.
Edit:
you could add the Rank property and set it to Ignore. This will enable you to go through the collection set the rank with a simple for loop. This will also not be persisted in the database. It will also not have any required columns in the database.
It does add an extra iteration.
the other way to go about it. This would be to add the rank number in the generated UI and not in the data collection being used to bind.
I am using the Facebook C# SDK in a canvas app.
When running this code...
public IEnumerable<string> GetFansIds(string pageId, IEnumerable<string> userIds)
{
if (userIds.Count() == 0)
return new List<string>();
var fb = new FacebookApp();
string query = String.Format("select uid from page_fan where uid IN ( {0} ) and page_id = {1}",
String.Join(",", userIds),
pageId
);
dynamic result = fb.Fql(query);
return result.Select((Func<dynamic, string>)(x => x.uid)).ToList();
}
I get the following Exception:
RuntimeBinderException: Cannot perform runtime binding on a null reference
The code does the following:
It performs a FQL query to get an JsonArray contaning JsonObject each with a uid Property (containing the uids of the users that are not fan of some fanpage.
The Select just converts all the dynamic objects into a List<string>
The FQL part just works correctly as i can see the results in the debugger.
The problem is with the Select that I can't make it work.
How can I fix the dynamic lambda ??? (Please don't just tell me to use a foreach, which is what I am currently doing right now)
The problem is that extension methods cannot be used on dynamic objects. Cast the result of the query to a JsonArray and then you can use linq expressions on the JsonArray.
var result = (JsonArray)fb.Fql(query);
return result.Select((Func<dynamic, string>)(x => x.uid)).ToList();