PageRenderTime 81ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/net/suddenelfilio/ws/tag/Category.java

https://bitbucket.org/suddenelfilio/mstagjavalib
Java | 96 lines | 76 code | 20 blank | 0 comment | 17 complexity | 601754b1a0419cbdaf2b273b0f81260c MD5 | raw file
  1. package net.suddenelfilio.ws.tag;
  2. import java.net.URL;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. public final class Category extends TagItemAPIBase
  6. {
  7. public String Name;
  8. public String CurrentName;
  9. public Status CategoryStatus;
  10. public String UTCEndDate;
  11. public String UTCStartDate;
  12. @Override
  13. public URL ToURL(URLType type) throws Exception
  14. {
  15. if (MSTagService.SVCAPITOKEN == null || MSTagService.SVCAPITOKEN.equals(""))
  16. throw new Exception("Did you forget to set the MSTagService.SVCAPITOKEN with your token?");
  17. Map<String, String> mp = new HashMap<String, String>();
  18. mp.put("at", MSTagService.SVCAPITOKEN);
  19. switch (type)
  20. {
  21. case CREATE :
  22. if (IsNullOrEmpty(Name))
  23. throw new Exception("The Name cannot be null or empty when creating a Tag.");
  24. else
  25. mp.put("cn", Name);
  26. if (CategoryStatus == null)
  27. mp.put("s", "");
  28. else
  29. mp.put("s", CategoryStatus.toString());
  30. if (IsNullOrEmpty(UTCEndDate))
  31. mp.put("ued", "");
  32. else
  33. mp.put("ued", UTCEndDate);
  34. if (IsNullOrEmpty(UTCStartDate))
  35. mp.put("usd", "");
  36. else
  37. mp.put("usd", UTCStartDate);
  38. return new URL(GenerateURL(mp, "CreateCategory"));
  39. case EDIT :
  40. if (IsNullOrEmpty(Name))
  41. throw new Exception("The Name cannot be null or empty when editing a Category.");
  42. else
  43. mp.put("ncn", Name);
  44. if (IsNullOrEmpty(CurrentName))
  45. throw new Exception("The CurrentName cannot be null or empty when editing a Category.");
  46. else
  47. mp.put("ocn", CurrentName);
  48. if (CategoryStatus == null)
  49. mp.put("s", "");
  50. else
  51. mp.put("s", CategoryStatus.toString());
  52. if (IsNullOrEmpty(UTCEndDate))
  53. mp.put("ued", "");
  54. else
  55. mp.put("ued", UTCEndDate);
  56. if (IsNullOrEmpty(UTCStartDate))
  57. mp.put("usd", "");
  58. else
  59. mp.put("usd", UTCStartDate);
  60. return new URL(GenerateURL(mp, "EditCategory"));
  61. case ACTIVE :
  62. if (IsNullOrEmpty(Name))
  63. throw new Exception("The Name cannot be null or empty when activating a Category.");
  64. else
  65. mp.put("cn", Name);
  66. return new URL(GenerateURL(mp, "ActivateCategory"));
  67. case PAUSE :
  68. if (IsNullOrEmpty(Name))
  69. throw new Exception("The Name cannot be null or empty when pausing a Category.");
  70. else
  71. mp.put("cn", Name);
  72. return new URL(GenerateURL(mp, "PauseCategory"));
  73. }
  74. return null;
  75. }
  76. }