001package com.box.sdk; 002 003import com.eclipsesource.json.JsonObject; 004 005/** Represents a Box File to be included in a sign request. */ 006public class BoxSignRequestFile { 007 private String fileId; 008 private String fileVersionId; 009 010 /** 011 * Constructs a BoxSignRequestFile with specific file version to be used during sign request 012 * creation. 013 * 014 * @param fileId id of the file. 015 * @param fileVersionId id of the file versionm. 016 */ 017 public BoxSignRequestFile(String fileId, String fileVersionId) { 018 this.fileId = fileId; 019 this.fileVersionId = fileVersionId; 020 } 021 022 /** 023 * Constructs a BoxSignRequestFile to be used during sign request creation. 024 * 025 * @param fileId id of the file. 026 */ 027 public BoxSignRequestFile(String fileId) { 028 this.fileId = fileId; 029 } 030 031 static BoxSignRequestFile fromFile(BoxFile.Info sourceFile) { 032 BoxSignRequestFile file = new BoxSignRequestFile(sourceFile.getID()); 033 if (sourceFile.getVersion() != null) { 034 file.setFileVersionId(sourceFile.getVersionNumber()); 035 } 036 037 return file; 038 } 039 040 /** 041 * Gets the file id of the file. 042 * 043 * @return file id of the file. 044 */ 045 public String getFileId() { 046 return this.fileId; 047 } 048 049 /** 050 * Sets the file id. 051 * 052 * @param fileId of the file. 053 * @return this BoxSignRequestFile object for chaining. 054 */ 055 public BoxSignRequestFile setFileId(String fileId) { 056 this.fileId = fileId; 057 return this; 058 } 059 060 /** 061 * Gets the file version id of the file. 062 * 063 * @return file version id of the file. 064 */ 065 public String getFileVersionId() { 066 return this.fileVersionId; 067 } 068 069 /** 070 * Sets the file version id. 071 * 072 * @param fileVersionId of the file. 073 * @return this BoxSignRequestFile object for chaining. 074 */ 075 public BoxSignRequestFile setFileVersionId(String fileVersionId) { 076 this.fileVersionId = fileVersionId; 077 return this; 078 } 079 080 /** 081 * Gets a JSON object representing this class. 082 * 083 * @return the JSON object representing this class. 084 */ 085 public JsonObject getJSONObject() { 086 JsonObject fileJSON = new JsonObject().add("id", this.fileId).add("type", "file"); 087 088 if (this.fileVersionId != null) { 089 JsonObject fileVersionJSON = new JsonObject(); 090 fileVersionJSON.add("id", this.fileVersionId); 091 fileVersionJSON.add("type", "file_version"); 092 fileJSON.add("file_version", fileVersionJSON); 093 } 094 095 return fileJSON; 096 } 097}