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