Skip to content

Commit b23ffae

Browse files
committed
Add Support for Dynatypes
Remove caching of typedefs and attribute helpers
1 parent 4269714 commit b23ffae

3 files changed

Lines changed: 41 additions & 77 deletions

File tree

Rally.RestApi/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.12.0")]
35-
[assembly: AssemblyFileVersion("1.0.12.0")]
34+
[assembly: AssemblyVersion("1.0.13.0")]
35+
[assembly: AssemblyFileVersion("1.0.13.0")]
3636

3737
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Rally.RestApi.Test")]

Rally.RestApi/RallyRestApi.cs

Lines changed: 21 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public enum HeaderType
7171

7272
private readonly string wsapiVersion;
7373
internal HttpService Service { get; set; }
74-
private readonly Dictionary<string, DynamicJsonObject> typeDefs = new Dictionary<string, DynamicJsonObject>();
7574

7675
internal string DecodeHeaderName(HeaderType type)
7776
{
@@ -168,15 +167,15 @@ protected Uri GetFullyQualifiedUri(string aRef)
168167
return new Uri(GetFullyQualifiedRef(aRef));
169168
}
170169

171-
internal Uri FormatCreateString(string type)
170+
internal Uri FormatCreateString(string typePath)
172171
{
173-
return new Uri(Service.Server.AbsoluteUri + "slm/webservice/" + wsapiVersion + "/" + type + "/create.js");
172+
return new Uri(Service.Server.AbsoluteUri + "slm/webservice/" + wsapiVersion + "/" + typePath + "/create.js");
174173
}
175174

176-
internal Uri FormatUpdateString(string type, long objectId)
175+
internal Uri FormatUpdateString(string typePath, long objectId)
177176
{
178177
return
179-
new Uri(Service.Server.AbsoluteUri + "slm/webservice/" + wsapiVersion + "/" + type + "/" + objectId +
178+
new Uri(Service.Server.AbsoluteUri + "slm/webservice/" + wsapiVersion + "/" + typePath + "/" + objectId +
180179
".js");
181180
}
182181

@@ -348,13 +347,13 @@ public dynamic GetSubscription(params string[] fetchedFields)
348347
/// <summary>
349348
/// Get the object described by the specified type and object id.
350349
/// </summary>
351-
/// <param name="type">the type</param>
350+
/// <param name="typePath">the type</param>
352351
/// <param name="oid">the object id</param>
353352
/// <param name="fetchedFields">the list of object fields to be fetched</param>
354353
/// <returns>The requested object</returns>
355-
public dynamic GetByReference(string type, long oid, params string[] fetchedFields)
354+
public dynamic GetByReference(string typePath, long oid, params string[] fetchedFields)
356355
{
357-
return GetByReference(string.Format("/{0}/{1}", type, oid), fetchedFields);
356+
return GetByReference(string.Format("/{0}/{1}", typePath, oid), fetchedFields);
358357
}
359358

360359
/// <summary>
@@ -391,12 +390,12 @@ public dynamic GetByReference(string aRef, params string[] fetchedFields)
391390
/// <summary>
392391
/// Delete the object described by the specified type and object id.
393392
/// </summary>
394-
/// <param name="type">the type</param>
393+
/// <param name="typePath">the type</param>
395394
/// <param name="oid">the object id</param>
396395
/// <returns>An OperationResult with information on the status of the request</returns>
397-
public OperationResult Delete(string type, long oid)
396+
public OperationResult Delete(string typePath, long oid)
398397
{
399-
return Delete(string.Format("/{0}/{1}", type, oid));
398+
return Delete(string.Format("/{0}/{1}", typePath, oid));
400399
}
401400

402401
/// <summary>
@@ -420,17 +419,17 @@ public OperationResult Delete(string aRef)
420419
/// <summary>
421420
/// Create an object of the specified type from the specified object
422421
/// </summary>
423-
/// <param name="type">the type to be created</param>
422+
/// <param name="typePath">the type to be created</param>
424423
/// <param name="obj">the object to be created</param>
425424
/// <returns></returns>
426-
public CreateResult Create(string type, DynamicJsonObject obj)
425+
public CreateResult Create(string typePath, DynamicJsonObject obj)
427426
{
428427
var createResponse = new CreateResult();
429428
var data = new DynamicJsonObject();
430-
data[type] = obj;
429+
data[typePath] = obj;
431430
string postData = serializer.Serialize(data);
432431
dynamic response =
433-
serializer.Deserialize(Service.Post(FormatCreateString(type), postData, GetProcessedHeaders()));
432+
serializer.Deserialize(Service.Post(FormatCreateString(typePath), postData, GetProcessedHeaders()));
434433
if(response.CreateResult.HasMember("Object"))
435434
{
436435
createResponse.Reference = response.CreateResult.Object._ref as string;
@@ -456,18 +455,18 @@ public OperationResult Update(string reference, DynamicJsonObject obj)
456455
/// Update the item described by the specified type and object id with
457456
/// the fields of the specified object
458457
/// </summary>
459-
/// <param name="type">the type of the item to be updated</param>
458+
/// <param name="typePath">the type of the item to be updated</param>
460459
/// <param name="oid">the object id of the item to be updated</param>
461460
/// <param name="obj">the object fields to update</param>
462461
/// <returns>An OperationResult describing the status of the request</returns>
463-
public OperationResult Update(string type, long oid, DynamicJsonObject obj)
462+
public OperationResult Update(string typePath, long oid, DynamicJsonObject obj)
464463
{
465464
var result = new OperationResult();
466465
var data = new DynamicJsonObject();
467-
data[type] = obj;
466+
data[typePath] = obj;
468467
string postData = serializer.Serialize(data);
469468
dynamic response =
470-
serializer.Deserialize(Service.Post(FormatUpdateString(type, oid), postData, GetProcessedHeaders()));
469+
serializer.Deserialize(Service.Post(FormatUpdateString(typePath, oid), postData, GetProcessedHeaders()));
471470
result.Errors.AddRange(DecodeArrayList(response.OperationResult.Errors));
472471
result.Warnings.AddRange(DecodeArrayList(response.OperationResult.Warnings));
473472
return result;
@@ -476,63 +475,12 @@ public OperationResult Update(string type, long oid, DynamicJsonObject obj)
476475
/// <summary>
477476
/// Get the allowed values for the specified type and attribute
478477
/// </summary>
479-
/// <param name="type">the type</param>
478+
/// <param name="typePath">the type</param>
480479
/// <param name="attribute">the attribute to retireve allowed values for</param>
481480
/// <returns>The allowed values for the specified attribute</returns>
482-
public DynamicJsonObject GetAllowedAttributeValues(string type, string attribute)
481+
public DynamicJsonObject GetAllowedAttributeValues(string typePath, string attribute)
483482
{
484-
return MakeRequest(GetFullyQualifiedUri(string.Format("/{0}/{1}/allowedValues.js", type, attribute)));
485-
}
486-
487-
public List<DynamicJsonObject> GetTypeAttributes(string typeName, Boolean cache)
488-
{
489-
DynamicJsonObject typeDef = GetTypeDef(typeName, cache);
490-
var attributes = typeDef["Attributes"] as ArrayList;
491-
return attributes.Cast<DynamicJsonObject>().OrderBy(a => a["Name"]).ToList();
492-
}
493-
494-
public DynamicJsonObject GetTypeDef(string typeName, Boolean cache)
495-
{
496-
if (!wsapiVersion.ToLower().Equals(DEFAULT_WSAPI_VERSION.ToLower()))
497-
{
498-
float apiVersion;
499-
500-
if (float.TryParse(wsapiVersion, out apiVersion))
501-
{
502-
if (apiVersion < 1.25)
503-
throw new ArgumentOutOfRangeException(String.Format("webServiveVersion must be '1.25' or greater to use this method. Received '{1}'", wsapiVersion));
504-
}
505-
else
506-
{
507-
throw new ArgumentException(String.Format("webServiveVersion must be '{0}' or a floating point number. Received '{1}'", DEFAULT_WSAPI_VERSION, wsapiVersion));
508-
}
509-
}
510-
511-
DynamicJsonObject typeDef = null;
512-
513-
if (typeDefs.ContainsKey(typeName))
514-
{
515-
typeDef = typeDefs[typeName];
516-
}
517-
else
518-
{
519-
var typeDefRequest = new Request("TypeDefinition");
520-
typeDefRequest.Fetch = new List<string>() { "true" };
521-
typeDefRequest.Query = new Query("Name", RestApi.Query.Operator.Equals, typeName);
522-
QueryResult result = Query(typeDefRequest);
523-
if (!result.Success)
524-
throw new Exception(String.Format("Error fetching TypeDef for '{0}'\n\n{1}", typeName, String.Join("\n",result.Errors)));
525-
else if (result.TotalResultCount == 0)
526-
throw new Exception(String.Format("No TypeDef found for '{0}'",typeName));
527-
else if (result.TotalResultCount > 1)
528-
throw new Exception(String.Format("Too many ({0}) TypeDefs found for '{1}'", result.TotalResultCount, typeName));
529-
typeDef = result.Results.First();
530-
531-
if (cache)
532-
typeDefs[typeName] = typeDef;
533-
}
534-
535-
return typeDef;
483+
return MakeRequest(GetFullyQualifiedUri(string.Format("/{0}/{1}/allowedValues.js", typePath, attribute)));
536484
}
537485

538486
/// <summary>

Rally.RestApi/Ref.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23

34
namespace Rally.RestApi
45
{
@@ -38,8 +39,22 @@ private static string[] TokenizeRef(string reference)
3839
/// <returns>The type of the specified ref</returns>
3940
public static string GetTypeFromRef(string reference)
4041
{
41-
var tokens = TokenizeRef(reference);
42-
return tokens[tokens.Length - 2];
42+
String[] tokens = TokenizeRef(reference);
43+
List<String> typeTokens = new List<string>() { tokens[tokens.Length - 2] };
44+
45+
if (tokens.Length > 2)
46+
{
47+
for (int x = tokens.Length - 3; x >= 0; x--)
48+
{
49+
String token = tokens[x];
50+
double d;
51+
// Stop when we get to the api version
52+
if (token.ToLower() == "x" || Double.TryParse(token, out d))
53+
break;
54+
typeTokens.Insert(0,tokens[x]);
55+
}
56+
}
57+
return String.Join("/",typeTokens);
4358
}
4459

4560
/// <summary>
@@ -50,6 +65,7 @@ public static string GetTypeFromRef(string reference)
5065
public static long GetOidFromRef(string reference)
5166
{
5267
var tokens = TokenizeRef(reference);
68+
// Get the last token
5369
var oidToken = tokens[tokens.Length - 1];
5470
return long.Parse(oidToken.Replace(".js", ""));
5571
}

0 commit comments

Comments
 (0)