UploadResult.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author masensio
  5. * Copyright (C) 2015 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.db;
  21. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  22. public enum UploadResult {
  23. UPLOADED(0),
  24. NETWORK_CONNECTION(1),
  25. CREDENTIAL_ERROR(2),
  26. FOLDER_ERROR(3),
  27. CONFLICT_ERROR(4),
  28. FILE_ERROR(5),
  29. PRIVILEDGES_ERROR(6),
  30. CANCELLED(7),
  31. UNKNOWN(8);
  32. private final int value;
  33. UploadResult(int value) {
  34. this.value = value;
  35. }
  36. public int getValue() {
  37. return value;
  38. }
  39. public static UploadResult fromValue(int value) {
  40. switch (value) {
  41. case 0:
  42. return UPLOADED;
  43. case 1:
  44. return NETWORK_CONNECTION;
  45. case 2:
  46. return CREDENTIAL_ERROR;
  47. case 3:
  48. return FOLDER_ERROR;
  49. case 4:
  50. return CONFLICT_ERROR;
  51. case 5:
  52. return FILE_ERROR;
  53. case 6:
  54. return PRIVILEDGES_ERROR;
  55. case 7:
  56. return CANCELLED;
  57. case 8:
  58. return UNKNOWN;
  59. }
  60. return null;
  61. }
  62. public static UploadResult fromOperationResult(RemoteOperationResult result){
  63. switch (result.getCode()){
  64. case UNKNOWN_ERROR:
  65. return UNKNOWN;
  66. case OK:
  67. return UPLOADED;
  68. case NO_NETWORK_CONNECTION:
  69. case HOST_NOT_AVAILABLE:
  70. case TIMEOUT:
  71. case WRONG_CONNECTION:
  72. return NETWORK_CONNECTION;
  73. case ACCOUNT_EXCEPTION:
  74. return CREDENTIAL_ERROR;
  75. // case
  76. // return FOLDER_ERROR;
  77. case CONFLICT:
  78. return CONFLICT_ERROR;
  79. case FILE_NOT_FOUND:
  80. return FILE_ERROR;
  81. case UNAUTHORIZED:
  82. return PRIVILEDGES_ERROR;
  83. case CANCELLED:
  84. return CANCELLED;
  85. }
  86. return null;
  87. }
  88. }