22 * Xero Files API
33 * These endpoints are specific to Xero Files API
44 *
5- * The version of the OpenAPI document: 2.10.1
5+ * The version of the OpenAPI document: 2.10.3
6677 *
88 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -53,7 +53,7 @@ public class FilesApi {
5353 private ApiClient apiClient ;
5454 private static FilesApi instance = null ;
5555 private String userAgent = "Default" ;
56- private String version = "4.8.1 " ;
56+ private String version = "4.8.2 " ;
5757 static final Logger logger = LoggerFactory .getLogger (FilesApi .class );
5858
5959 /** FilesApi */
@@ -1493,14 +1493,13 @@ public HttpResponse updateFolderForHttpResponse(
14931493 }
14941494
14951495 /**
1496- * Uploads a File
1496+ * Uploads a File to the inbox
14971497 *
14981498 * <p><b>201</b> - A successful request
14991499 *
15001500 * <p><b>400</b> - invalid input, object invalid
15011501 *
15021502 * @param xeroTenantId Xero identifier for Tenant
1503- * @param folderId pass an optional folder id to save file to specific folder
15041503 * @param body The body parameter
15051504 * @param name exact name of the file you are uploading
15061505 * @param filename The filename parameter
@@ -1512,7 +1511,6 @@ public HttpResponse updateFolderForHttpResponse(
15121511 public FileObject uploadFile (
15131512 String accessToken ,
15141513 String xeroTenantId ,
1515- UUID folderId ,
15161514 File body ,
15171515 String name ,
15181516 String filename ,
@@ -1521,8 +1519,7 @@ public FileObject uploadFile(
15211519 try {
15221520 TypeReference <FileObject > typeRef = new TypeReference <FileObject >() {};
15231521 HttpResponse response =
1524- uploadFileForHttpResponse (
1525- accessToken , xeroTenantId , folderId , body , name , filename , mimeType );
1522+ uploadFileForHttpResponse (accessToken , xeroTenantId , body , name , filename , mimeType );
15261523 return apiClient .getObjectMapper ().readValue (response .getContent (), typeRef );
15271524 } catch (HttpResponseException e ) {
15281525 if (logger .isDebugEnabled ()) {
@@ -1541,14 +1538,13 @@ public FileObject uploadFile(
15411538 }
15421539
15431540 /**
1544- * Uploads a File
1541+ * Uploads a File to the inbox
15451542 *
15461543 * <p><b>201</b> - A successful request
15471544 *
15481545 * <p><b>400</b> - invalid input, object invalid
15491546 *
15501547 * @param xeroTenantId Xero identifier for Tenant
1551- * @param folderId pass an optional folder id to save file to specific folder
15521548 * @param body The body parameter
15531549 * @param name exact name of the file you are uploading
15541550 * @param filename The filename parameter
@@ -1560,7 +1556,6 @@ public FileObject uploadFile(
15601556 public HttpResponse uploadFileForHttpResponse (
15611557 String accessToken ,
15621558 String xeroTenantId ,
1563- UUID folderId ,
15641559 File body ,
15651560 String name ,
15661561 String filename ,
@@ -1570,6 +1565,18 @@ public HttpResponse uploadFileForHttpResponse(
15701565 if (xeroTenantId == null ) {
15711566 throw new IllegalArgumentException (
15721567 "Missing the required parameter 'xeroTenantId' when calling uploadFile" );
1568+ } // verify the required parameter 'body' is set
1569+ if (body == null ) {
1570+ throw new IllegalArgumentException (
1571+ "Missing the required parameter 'body' when calling uploadFile" );
1572+ } // verify the required parameter 'name' is set
1573+ if (name == null ) {
1574+ throw new IllegalArgumentException (
1575+ "Missing the required parameter 'name' when calling uploadFile" );
1576+ } // verify the required parameter 'filename' is set
1577+ if (filename == null ) {
1578+ throw new IllegalArgumentException (
1579+ "Missing the required parameter 'filename' when calling uploadFile" );
15731580 }
15741581 if (accessToken == null ) {
15751582 throw new IllegalArgumentException (
@@ -1580,18 +1587,161 @@ public HttpResponse uploadFileForHttpResponse(
15801587 headers .setAccept ("application/json" );
15811588 headers .setUserAgent (this .getUserAgent ());
15821589 UriBuilder uriBuilder = UriBuilder .fromUri (apiClient .getBasePath () + "/Files" );
1583- if (folderId != null ) {
1584- String key = "FolderId" ;
1585- Object value = folderId ;
1586- if (value instanceof Collection ) {
1587- uriBuilder = uriBuilder .queryParam (key , ((Collection ) value ).toArray ());
1588- } else if (value instanceof Object []) {
1589- uriBuilder = uriBuilder .queryParam (key , (Object []) value );
1590- } else {
1591- uriBuilder = uriBuilder .queryParam (key , value );
1590+ String url = uriBuilder .build ().toString ();
1591+ GenericUrl genericUrl = new GenericUrl (url );
1592+ if (logger .isDebugEnabled ()) {
1593+ logger .debug ("POST " + genericUrl .toString ());
1594+ }
1595+
1596+ Map <String , String > parameters = Maps .newHashMap ();
1597+ parameters .put ("name" , name );
1598+ parameters .put ("filename" , filename );
1599+
1600+ // Add parameters
1601+ MultipartContent content =
1602+ new MultipartContent ()
1603+ .setMediaType (
1604+ new HttpMediaType ("multipart/form-data" )
1605+ .setParameter ("boundary" , "__END_OF_PART__" ));
1606+
1607+ for (String key : parameters .keySet ()) {
1608+ MultipartContent .Part part =
1609+ new MultipartContent .Part (new ByteArrayContent (null , parameters .get (key ).getBytes ()));
1610+ part .setHeaders (
1611+ new HttpHeaders ()
1612+ .set ("Content-Disposition" , String .format ("form-data; name=\" %s\" " , key )));
1613+ content .addPart (part );
1614+ }
1615+
1616+ FileContent fileContent = new FileContent (mimeType , body );
1617+ MultipartContent .Part part = new MultipartContent .Part (fileContent );
1618+ part .setHeaders (
1619+ new HttpHeaders ()
1620+ .set (
1621+ "Content-Disposition" ,
1622+ String .format ("form-data; name=\" content\" ; filename=\" %s\" " , filename )));
1623+ content .addPart (part );
1624+ Credential credential =
1625+ new Credential (BearerToken .authorizationHeaderAccessMethod ()).setAccessToken (accessToken );
1626+ HttpTransport transport = apiClient .getHttpTransport ();
1627+ HttpRequestFactory requestFactory = transport .createRequestFactory (credential );
1628+ return requestFactory
1629+ .buildRequest (HttpMethods .POST , genericUrl , content )
1630+ .setHeaders (headers )
1631+ .setConnectTimeout (apiClient .getConnectionTimeout ())
1632+ .setReadTimeout (apiClient .getReadTimeout ())
1633+ .execute ();
1634+ }
1635+
1636+ /**
1637+ * Uploads a File to a specific folder
1638+ *
1639+ * <p><b>201</b> - A successful request
1640+ *
1641+ * <p><b>400</b> - invalid input, object invalid
1642+ *
1643+ * @param xeroTenantId Xero identifier for Tenant
1644+ * @param folderId pass required folder id to save file to specific folder
1645+ * @param body The body parameter
1646+ * @param name exact name of the file you are uploading
1647+ * @param filename The filename parameter
1648+ * @param mimeType The mimeType parameter
1649+ * @param accessToken Authorization token for user set in header of each request
1650+ * @return FileObject
1651+ * @throws IOException if an error occurs while attempting to invoke the API *
1652+ */
1653+ public FileObject uploadFileToFolder (
1654+ String accessToken ,
1655+ String xeroTenantId ,
1656+ UUID folderId ,
1657+ File body ,
1658+ String name ,
1659+ String filename ,
1660+ String mimeType )
1661+ throws IOException {
1662+ try {
1663+ TypeReference <FileObject > typeRef = new TypeReference <FileObject >() {};
1664+ HttpResponse response =
1665+ uploadFileToFolderForHttpResponse (
1666+ accessToken , xeroTenantId , folderId , body , name , filename , mimeType );
1667+ return apiClient .getObjectMapper ().readValue (response .getContent (), typeRef );
1668+ } catch (HttpResponseException e ) {
1669+ if (logger .isDebugEnabled ()) {
1670+ logger .debug (
1671+ "------------------ HttpResponseException "
1672+ + e .getStatusCode ()
1673+ + " : uploadFileToFolder -------------------" );
1674+ logger .debug (e .toString ());
15921675 }
1676+ XeroApiExceptionHandler handler = new XeroApiExceptionHandler ();
1677+ handler .execute (e );
1678+ } catch (IOException ioe ) {
1679+ throw ioe ;
15931680 }
1594- String url = uriBuilder .build ().toString ();
1681+ return null ;
1682+ }
1683+
1684+ /**
1685+ * Uploads a File to a specific folder
1686+ *
1687+ * <p><b>201</b> - A successful request
1688+ *
1689+ * <p><b>400</b> - invalid input, object invalid
1690+ *
1691+ * @param xeroTenantId Xero identifier for Tenant
1692+ * @param folderId pass required folder id to save file to specific folder
1693+ * @param body The body parameter
1694+ * @param name exact name of the file you are uploading
1695+ * @param filename The filename parameter
1696+ * @param mimeType The mimeType parameter
1697+ * @param accessToken Authorization token for user set in header of each request
1698+ * @return HttpResponse
1699+ * @throws IOException if an error occurs while attempting to invoke the API
1700+ */
1701+ public HttpResponse uploadFileToFolderForHttpResponse (
1702+ String accessToken ,
1703+ String xeroTenantId ,
1704+ UUID folderId ,
1705+ File body ,
1706+ String name ,
1707+ String filename ,
1708+ String mimeType )
1709+ throws IOException {
1710+ // verify the required parameter 'xeroTenantId' is set
1711+ if (xeroTenantId == null ) {
1712+ throw new IllegalArgumentException (
1713+ "Missing the required parameter 'xeroTenantId' when calling uploadFileToFolder" );
1714+ } // verify the required parameter 'folderId' is set
1715+ if (folderId == null ) {
1716+ throw new IllegalArgumentException (
1717+ "Missing the required parameter 'folderId' when calling uploadFileToFolder" );
1718+ } // verify the required parameter 'body' is set
1719+ if (body == null ) {
1720+ throw new IllegalArgumentException (
1721+ "Missing the required parameter 'body' when calling uploadFileToFolder" );
1722+ } // verify the required parameter 'name' is set
1723+ if (name == null ) {
1724+ throw new IllegalArgumentException (
1725+ "Missing the required parameter 'name' when calling uploadFileToFolder" );
1726+ } // verify the required parameter 'filename' is set
1727+ if (filename == null ) {
1728+ throw new IllegalArgumentException (
1729+ "Missing the required parameter 'filename' when calling uploadFileToFolder" );
1730+ }
1731+ if (accessToken == null ) {
1732+ throw new IllegalArgumentException (
1733+ "Missing the required parameter 'accessToken' when calling uploadFileToFolder" );
1734+ }
1735+ HttpHeaders headers = new HttpHeaders ();
1736+ headers .set ("xero-tenant-id" , xeroTenantId );
1737+ headers .setAccept ("application/json" );
1738+ headers .setUserAgent (this .getUserAgent ());
1739+ // create a map of path variables
1740+ final Map <String , Object > uriVariables = new HashMap <String , Object >();
1741+ uriVariables .put ("FolderId" , folderId );
1742+
1743+ UriBuilder uriBuilder = UriBuilder .fromUri (apiClient .getBasePath () + "/Files/{FolderId}" );
1744+ String url = uriBuilder .buildFromMap (uriVariables ).toString ();
15951745 GenericUrl genericUrl = new GenericUrl (url );
15961746 if (logger .isDebugEnabled ()) {
15971747 logger .debug ("POST " + genericUrl .toString ());
0 commit comments