PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Atlassian.Jira/JiraNamedEntity.cs

https://bitbucket.org/yyo/atlassian.net-sdk-v2.0
C# | 92 lines | 71 code | 11 blank | 10 comment | 4 complexity | 441588c2069d055f9f37be4a477251a5 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Atlassian.Jira.Remote;
  6. namespace Atlassian.Jira
  7. {
  8. /// <summary>
  9. /// Represents a named entity within JIRA. Abstracts the Version and Component used on issues
  10. /// </summary>
  11. /// <remarks>http://docs.atlassian.com/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/beans/AbstractNamedRemoteEntity.html</remarks>
  12. public class JiraNamedEntity
  13. {
  14. private Jira _jira;
  15. private string _id;
  16. protected string _name;
  17. internal JiraNamedEntity(AbstractNamedRemoteEntity remoteEntity)
  18. {
  19. _id = remoteEntity.id;
  20. _name = remoteEntity.name;
  21. }
  22. internal JiraNamedEntity(Jira jira, string id)
  23. {
  24. _jira = jira;
  25. _id = id;
  26. }
  27. internal JiraNamedEntity(string name)
  28. {
  29. _name = name;
  30. }
  31. /// <summary>
  32. /// Id of the entity
  33. /// </summary>
  34. public string Id
  35. {
  36. get
  37. {
  38. return _id;
  39. }
  40. }
  41. /// <summary>
  42. /// Name of the entity
  43. /// </summary>
  44. public string Name
  45. {
  46. get
  47. {
  48. if (String.IsNullOrEmpty(_name))
  49. {
  50. _name = GetEntities(_jira).First(e => e.Id.Equals(_id, StringComparison.OrdinalIgnoreCase)).Name;
  51. }
  52. return _name;
  53. }
  54. }
  55. internal JiraNamedEntity Load(Jira jira, string projectKey)
  56. {
  57. var entity = GetEntities(jira, projectKey).FirstOrDefault(e => e.Name.Equals(_name, StringComparison.OrdinalIgnoreCase));
  58. if (entity != null)
  59. {
  60. _id = entity._id;
  61. _name = entity._name;
  62. }
  63. return this;
  64. }
  65. protected virtual IEnumerable<JiraNamedEntity> GetEntities(Jira jira, string projectKey = null)
  66. {
  67. throw new NotImplementedException();
  68. }
  69. public override string ToString()
  70. {
  71. if (!String.IsNullOrEmpty(_name))
  72. {
  73. return _name;
  74. }
  75. else
  76. {
  77. return _id;
  78. }
  79. }
  80. }
  81. }