fork download
  1. import com.google.gson.Gson;
  2. import com.google.gson.JsonArray;
  3. import com.google.gson.JsonObject;
  4. import com.google.gson.JsonParser;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.Arrays;
  8. import java.util.List;
  9.  
  10. public class Folder extends IMContainer{
  11.  
  12. ArrayList<Folder> subFolders = new ArrayList<>();
  13. Gson gson = new Gson();
  14. JsonParser parser = new JsonParser();
  15. JsonArray foldersJsonArray;
  16.  
  17. //<editor-fold desc="Class Vars"
  18.  
  19. // main vars
  20. private String database;
  21. private String defaultSecurity;
  22. private String editDate;
  23. private String effectiveSecurity;
  24. private String folderType;
  25. private String id;
  26. private String inheritedDefaultSecurity;
  27. private String name;
  28. private String owner;
  29. private String parentID;
  30. private String viewType;
  31. private String workspaceID;
  32. private String workspaceName;
  33. private String wsType;
  34.  
  35.  
  36. //profile vars
  37. private String author;
  38. private String authorDescription;
  39. private String iMClass;
  40. private String iMSubclass;
  41. private String[] customField = new String[30];
  42.  
  43.  
  44. //bools
  45. private boolean hasDocuments;
  46. private boolean hasSubfolders;
  47. private boolean containerSavedSearch;
  48. private boolean contentSavedSearch;
  49. private boolean externalAsNormal;
  50. private boolean hidden;
  51.  
  52. //</editor-fold>
  53.  
  54. //main constructor, parses response string to JSON and pulls all data to fill class variables.
  55. public Folder(JsonObject folderProfile) {
  56.  
  57. if (folderProfile.has("database")) {
  58. this.database = folderProfile.get("database").getAsString();
  59. }
  60.  
  61. if (folderProfile.has("default_security")) {
  62. this.defaultSecurity = folderProfile.get("default_security").getAsString();
  63. }
  64.  
  65. if (folderProfile.has("edit_date")) {
  66. this.editDate = folderProfile.get("edit_date").getAsString();
  67. }
  68.  
  69. if (folderProfile.has("effective_security")) {
  70. this.effectiveSecurity = folderProfile.get("effective_security").getAsString();
  71. }
  72.  
  73. if (folderProfile.has("folder_type")) {
  74. this.folderType = folderProfile.get("folder_type").getAsString();
  75. }
  76.  
  77. if (folderProfile.has("has_documents")) {
  78. this.hasDocuments = folderProfile.get("has_documents").getAsBoolean();
  79. }
  80.  
  81. if (folderProfile.has("has_subfolders")) {
  82. this.hasSubfolders = folderProfile.get("has_subfolders").getAsBoolean();
  83. }
  84.  
  85. if (folderProfile.has("id")) {
  86. this.id = folderProfile.get("id").getAsString();
  87. }
  88.  
  89. if (folderProfile.has("inherited_default_security")) {
  90. this.inheritedDefaultSecurity = folderProfile.get("inherited_default_security").getAsString();
  91. }
  92.  
  93. if (folderProfile.has("is_container_saved_search")) {
  94. this.containerSavedSearch = folderProfile.get("is_container_saved_search").getAsBoolean();
  95. }
  96.  
  97. if (folderProfile.has("is_content_saved_search")) {
  98. this.contentSavedSearch = folderProfile.get("is_content_saved_search").getAsBoolean();
  99. }
  100.  
  101. if (folderProfile.has("is_external_as_normal")) {
  102. this.externalAsNormal = folderProfile.get("is_external_as_normal").getAsBoolean();
  103. }
  104.  
  105. if (folderProfile.has("is_hidden")) {
  106. this.hidden = folderProfile.get("is_hidden").getAsBoolean();
  107. }
  108.  
  109. if (folderProfile.has("name")) {
  110. this.name = folderProfile.get("name").getAsString();
  111. }
  112.  
  113. if (folderProfile.has("owner")) {
  114. this.owner = folderProfile.get("owner").getAsString();
  115. }
  116.  
  117. if (folderProfile.has("parent_id")) {
  118. this.parentID = folderProfile.get("parent_id").getAsString();
  119. }
  120.  
  121. if (folderProfile.has("profile")) {
  122.  
  123. JsonObject imProfile = folderProfile.get("profile").getAsJsonObject();
  124.  
  125. if (imProfile.has("author")) {
  126. this.author = imProfile.get("author").getAsString();
  127. }
  128.  
  129. if (imProfile.has("author_description")) {
  130. this.authorDescription = imProfile.get("author_description").getAsString();
  131. }
  132.  
  133. if (imProfile.has("class")) {
  134. this.iMClass = imProfile.get("class").getAsString();
  135. }
  136.  
  137. if (imProfile.has("subclass")) {
  138. this.iMSubclass = imProfile.get("subclass").getAsString();
  139. }
  140.  
  141. for (int x = 0; x <= 30; x++) {
  142.  
  143. if (imProfile.has("custom" + (x + 1))) { // add one to x var at member name to account for array starting at 0
  144. this.customField[x] = imProfile.get("custom" + (x + 1)).getAsString();
  145. }
  146. }
  147. }
  148.  
  149. if (folderProfile.has("view_type")) {
  150. this.viewType = folderProfile.get("view_type").getAsString();
  151. }
  152.  
  153. if (folderProfile.has("workspace_id")) {
  154. this.workspaceID = folderProfile.get("workspace_id").getAsString();
  155. }
  156.  
  157. if (folderProfile.has("workspace_name")) {
  158. this.workspaceName = folderProfile.get("workspace_name").getAsString();
  159. }
  160.  
  161. if (folderProfile.has("wstype")) {
  162. this.wsType = folderProfile.get("wstype").getAsString();
  163. }
  164. }
  165.  
  166. public Folder addSubfolder(JsonObject folderProfile){
  167. System.out.println("Adding " + folderProfile.get("id") + " to subfolders of " + this.getId());
  168. Folder subfolder = new Folder(folderProfile);
  169. this.subFolders.add(subfolder);
  170. System.out.println("subfolder added at index " + this.subFolders.indexOf(subfolder));
  171. return subfolder;
  172. }
  173.  
  174. public void saveFolders() {
  175.  
  176. for (int x = 0; x < this.foldersJsonArray.size(); x++) {
  177. this.subFolders.add(new Folder(this.foldersJsonArray.get(x).getAsJsonObject()));
  178. }
  179.  
  180. for(int x = 0; x < subFolders.size(); x++){
  181. if(subFolders.get(x).hasSubfolders()){
  182. subFolders.get(x).saveFolders();
  183. }
  184. }
  185. }
  186.  
  187. @Override
  188. public String toString() {
  189. return "Folder{" +
  190. "database='" + database + '\'' + "\n" +
  191. ", defaultSecurity='" + defaultSecurity + '\'' + "\n" +
  192. ", editDate='" + editDate + '\'' + "\n" +
  193. ", effectiveSecurity='" + effectiveSecurity + '\'' + "\n" +
  194. ", folderType='" + folderType + '\'' + "\n" +
  195. ", id='" + id + '\'' + "\n" +
  196. ", inheritedDefaultSecurity='" + inheritedDefaultSecurity + '\'' + "\n" +
  197. ", name='" + name + '\'' + "\n" +
  198. ", owner='" + owner + '\'' + "\n" +
  199. ", parentID='" + parentID + '\'' + "\n" +
  200. ", viewType='" + viewType + '\'' + "\n" +
  201. ", workspaceID='" + workspaceID + '\'' + "\n" +
  202. ", workspaceName='" + workspaceName + '\'' + "\n" +
  203. ", wsType='" + wsType + '\'' + "\n" +
  204. ", author='" + author + '\'' + "\n" +
  205. ", authorDescription='" + authorDescription + '\'' + "\n" +
  206. ", iMClass='" + iMClass + '\'' + "\n" +
  207. ", iMSubclass='" + iMSubclass + '\'' + "\n" +
  208. ", customField=" + Arrays.toString(customField) + "\n" +
  209. ", hasDocuments=" + hasDocuments + "\n" +
  210. ", hasSubfolders=" + hasSubfolders + "\n" +
  211. ", containerSavedSearch=" + containerSavedSearch + "\n" +
  212. ", contentSavedSearch=" + contentSavedSearch + "\n" +
  213. ", externalAsNormal=" + externalAsNormal + "\n" +
  214. ", hidden=" + hidden + "\n" +
  215. '}';
  216. }
  217.  
  218. //<editor-fold desc="Getters"
  219.  
  220.  
  221. public JsonArray getFoldersJsonArray() {
  222. return foldersJsonArray;
  223. }
  224.  
  225. public String getDatabase() {
  226. return database;
  227. }
  228.  
  229. public String getDefaultSecurity() {
  230. return defaultSecurity;
  231. }
  232.  
  233. public String getEditDate() {
  234. return editDate;
  235. }
  236.  
  237. public String getEffectiveSecurity() {
  238. return effectiveSecurity;
  239. }
  240.  
  241. public String getFolderType() {
  242. return folderType;
  243. }
  244.  
  245. public String getId() {
  246. return id;
  247. }
  248.  
  249. public String getInheritedDefaultSecurity() {
  250. return inheritedDefaultSecurity;
  251. }
  252.  
  253. public String getName() {
  254. return name;
  255. }
  256.  
  257. public String getOwner() {
  258. return owner;
  259. }
  260.  
  261. public String getParentID() {
  262. return parentID;
  263. }
  264.  
  265. public String getViewType() {
  266. return viewType;
  267. }
  268.  
  269. public String getWorkspaceID() {
  270. return workspaceID;
  271. }
  272.  
  273. public String getWorkspaceName() {
  274. return workspaceName;
  275. }
  276.  
  277. public String getWsType() {
  278. return wsType;
  279. }
  280.  
  281. public String getAuthor() {
  282. return author;
  283. }
  284.  
  285. public String getAuthorDescription() {
  286. return authorDescription;
  287. }
  288.  
  289. public String getiMClass() {
  290. return iMClass;
  291. }
  292.  
  293. public String getiMSubclass() {
  294. return iMSubclass;
  295. }
  296.  
  297. public String[] getCustomField() {
  298. return customField;
  299. }
  300.  
  301. public boolean HasDocuments() {
  302. return hasDocuments;
  303. }
  304.  
  305. public boolean hasSubfolders() {
  306. return hasSubfolders;
  307. }
  308.  
  309. public boolean isContainerSavedSearch() {
  310. return containerSavedSearch;
  311. }
  312.  
  313. public boolean isContentSavedSearch() {
  314. return contentSavedSearch;
  315. }
  316.  
  317. public boolean isExternalAsNormal() {
  318. return externalAsNormal;
  319. }
  320.  
  321. public boolean isHidden() {
  322. return hidden;
  323. }
  324.  
  325. public void setDatabase(String database) {
  326. this.database = database;
  327. }
  328.  
  329. //</editor-fold>
  330.  
  331. //<editor-fold desc="Setters"
  332.  
  333.  
  334. public void setFoldersJsonArray(JsonArray foldersJsonArray) {
  335. this.foldersJsonArray = foldersJsonArray;
  336. }
  337.  
  338. public void setDefaultSecurity(String defaultSecurity) {
  339. this.defaultSecurity = defaultSecurity;
  340. }
  341.  
  342. public void setEditDate(String editDate) {
  343. this.editDate = editDate;
  344. }
  345.  
  346. public void setEffectiveSecurity(String effectiveSecurity) {
  347. this.effectiveSecurity = effectiveSecurity;
  348. }
  349.  
  350. public void setFolderType(String folderType) {
  351. this.folderType = folderType;
  352. }
  353.  
  354. public void setId(String id) {
  355. this.id = id;
  356. }
  357.  
  358. public void setInheritedDefaultSecurity(String inheritedDefaultSecurity) {
  359. this.inheritedDefaultSecurity = inheritedDefaultSecurity;
  360. }
  361.  
  362. public void setName(String name) {
  363. this.name = name;
  364. }
  365.  
  366. public void setOwner(String owner) {
  367. this.owner = owner;
  368. }
  369.  
  370. public void setParentID(String parentID) {
  371. this.parentID = parentID;
  372. }
  373.  
  374. public void setViewType(String viewType) {
  375. this.viewType = viewType;
  376. }
  377.  
  378. public void setWorkspaceID(String workspaceID) {
  379. this.workspaceID = workspaceID;
  380. }
  381.  
  382. public void setWorkspaceName(String workspaceName) {
  383. this.workspaceName = workspaceName;
  384. }
  385.  
  386. public void setWsType(String wsType) {
  387. this.wsType = wsType;
  388. }
  389.  
  390. public void setAuthor(String author) {
  391. this.author = author;
  392. }
  393.  
  394. public void setAuthorDescription(String authorDescription) {
  395. this.authorDescription = authorDescription;
  396. }
  397.  
  398. public void setiMClass(String iMClass) {
  399. this.iMClass = iMClass;
  400. }
  401.  
  402. public void setiMSubclass(String iMSubclass) {
  403. this.iMSubclass = iMSubclass;
  404. }
  405.  
  406. public void setCustomField(String[] customField) {
  407. this.customField = customField;
  408. }
  409.  
  410. public void setHasDocuments(boolean hasDocuments) {
  411. this.hasDocuments = hasDocuments;
  412. }
  413.  
  414. public void setHasSubfolders(boolean hasSubfolders) {
  415. this.hasSubfolders = hasSubfolders;
  416. }
  417.  
  418. public void setContainerSavedSearch(boolean containerSavedSearch) {
  419. this.containerSavedSearch = containerSavedSearch;
  420. }
  421.  
  422. public void setContentSavedSearch(boolean contentSavedSearch) {
  423. this.contentSavedSearch = contentSavedSearch;
  424. }
  425.  
  426. public void setExternalAsNormal(boolean externalAsNormal) {
  427. this.externalAsNormal = externalAsNormal;
  428. }
  429.  
  430. public void setHidden(boolean hidden) {
  431. this.hidden = hidden;
  432. }
  433.  
  434. //</editor-fold>
  435.  
  436. }
  437.  
  438.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:10: error: class Folder is public, should be declared in a file named Folder.java
public class Folder extends IMContainer{
       ^
Main.java:1: error: package com.google.gson does not exist
import com.google.gson.Gson;
                      ^
Main.java:2: error: package com.google.gson does not exist
import com.google.gson.JsonArray;
                      ^
Main.java:3: error: package com.google.gson does not exist
import com.google.gson.JsonObject;
                      ^
Main.java:4: error: package com.google.gson does not exist
import com.google.gson.JsonParser;
                      ^
Main.java:10: error: cannot find symbol
public class Folder extends IMContainer{
                            ^
  symbol: class IMContainer
Main.java:13: error: cannot find symbol
    Gson gson = new Gson();
    ^
  symbol:   class Gson
  location: class Folder
Main.java:14: error: cannot find symbol
    JsonParser parser = new JsonParser();
    ^
  symbol:   class JsonParser
  location: class Folder
Main.java:15: error: cannot find symbol
    JsonArray foldersJsonArray;
    ^
  symbol:   class JsonArray
  location: class Folder
Main.java:55: error: cannot find symbol
    public Folder(JsonObject folderProfile) {
                  ^
  symbol:   class JsonObject
  location: class Folder
Main.java:166: error: cannot find symbol
    public Folder addSubfolder(JsonObject folderProfile){
                               ^
  symbol:   class JsonObject
  location: class Folder
Main.java:221: error: cannot find symbol
    public JsonArray getFoldersJsonArray() {
           ^
  symbol:   class JsonArray
  location: class Folder
Main.java:334: error: cannot find symbol
    public void setFoldersJsonArray(JsonArray foldersJsonArray) {
                                    ^
  symbol:   class JsonArray
  location: class Folder
Main.java:13: error: cannot find symbol
    Gson gson = new Gson();
                    ^
  symbol:   class Gson
  location: class Folder
Main.java:14: error: cannot find symbol
    JsonParser parser = new JsonParser();
                            ^
  symbol:   class JsonParser
  location: class Folder
Main.java:123: error: cannot find symbol
            JsonObject imProfile = folderProfile.get("profile").getAsJsonObject();
            ^
  symbol:   class JsonObject
  location: class Folder
Main.java:187: error: method does not override or implement a method from a supertype
    @Override
    ^
17 errors
stdout
Standard output is empty