2022-10-13 (C) Questetra, Inc. (MIT License) 2 This item creates a URL to access the specified folder on Box. If no expiration date is specified, the URL will be created indefinitely. If no password is specified, the URL will be created without requiring a password. この工程は、Box 上のフォルダにアクセスできる URL を作成します。有効期限の指定が無い場合は無期限で、パスワードの指定が無い場合はパスワード要求無しで作成します。 https://support.questetra.com/bpmn-icons/box-folder-link-create https://support.questetra.com/ja/bpmn-icons/box-folder-link-create iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAEBElEQVRYR82Xb2jbRRjHP/fL2jXJ 0qSd65x11aK0YgJWZUwEWZ0DfSNaHYKKmgykbP7pH/SVghvCkIlb6kREwfyGOougbgxB2Yt1oGwg aietdOJoV21ty2ob26xdm+TkLsufJr+2Sdtt3pv8uDx3z+ee+z53zwmucRMF+ff/9ijEtwB1IDwI 9QtIOkGOA50I0UHIezTfeRcH8Pd64GITyGaE8OQ1sVQwIgiONsxqBTZvWxjA3+UHDuTtONuNBjEC mLcfmY9gfgB/dxBBU14rXsxIyiCmr8XKzBog0GWCeG6xeQv6X2JiegPZY3IBVnLlOVtCG6a3ObN7 LoDacyFCBa2sUGMpGjI1kQbQao/0Lllw+YJoYTqrk9mRAdC9G8Eb+c6zLDvJHkzvbjVHGiDQpXLX nZw4tOMGyp02Hjn457J8WQ5WUTB9ZWkAdcIJ+XWm8XCwFkexwLWrZ+UB9OmZ0EIiAhbKH2lLAKzZ eaUAEhmRAAh0dYBQZ3yqKQDnaoPDp8PUVZXo/pM9EV75Ylh/77q/jO2bSlmz2mBgLErjoUHad95I Z/80re0Jmw+e3UD1dcU8uP+8RRTlSUK++ssA3X3ATdkA61y2nIE/9k7Rd2GWx+4uxWZkAP8bo9Ru YAho+XyIUruNNxsqiMzE8bxgEUV1gZneO5MAMtuTioACUM7e+W4Uj8Pg5W1rdV9cwvSsxPx+nNPn LvLStnI2VdsZi8TwOGyMTsY0nNth493j/9DSPmSto5BXLAigsmDLW7388MeUnuDVh9ay74n1+vvI zxM0vJfOkNGDtdiLDH7pn+beW+3a5kRPhK37rMJ/mScDIGcLBvfXsM61isrWs4xMxPSIpza7+ayx Un8rbTz94UBqZX8fqNFp+82vkzTc5dL9n54K88xHaZu5YZBnCPnq5hXhqdequecWO2rPH3j7PBvc qzjWVEXN9cV6HhVmJbwvf5rgcGMlT2526y1wldiYiUl9wKhtUHp4/8TYIiK0SMP6WgdfvbiRMqeN yKU4NkNQUiToH51lcDyq4aIxtMjcdoOpGYkSkrJpOz6qt6OxvowLkzEqms7mAsjMNLQ4iNSIrbc5 2bu9QqdSNC7pHrjEjo8H+GssyifPV3JfjQNHscFQOMqeoyPsfXw9vw/P8HBbv3b4bWsVG8uL8L5+ zgIg8yBSf2cdxdayXaleGSbk0+Xd/+gyUtexiPRlXkgrtd4s9YeRzptzr2NldU0LkiTmlS3JUnVA 0t3VK0qRhwj5VJk/p12lsjxdAeUPoDWhCpW4KtFTlVJhwpRhpOFf2sMkpQn9NGtGyOb8QZRj/TQL Lu9plr1c/TiV9QipHqUeEHckTOQZYBwpOkF0LLTiwragsHgvyfo/g3CBMFgjn40AAAAASUVORK5C YII= { configs.put("OAuth2", "Box"); // 文字型データ項目を準備して、config に指定 const folderIdDef = engine.createDataDefinition( "フォルダ ID", 1, "q_folderId", "STRING_TEXTFIELD" ); configs.putObject("FolderId_V2", folderIdDef); // 文字型データ項目の値(フォルダ ID)を指定 engine.setData(folderIdDef, folderId); // 日時型データ項目を準備して、config に指定 const unsharedDateDef = engine.createDataDefinition( "有効期限", 2, "q_dateTime", "DATETIME" ); configs.putObject("unsharedAt", unsharedDateDef); // 日時型データ項目の値(有効期限)を指定 if (unsharedDate !== null) { const datetime = java.sql.Timestamp.valueOf(unsharedDate); engine.setData(unsharedDateDef, datetime); } else { engine.setData(unsharedDateDef, null); } // 文字型データ項目を準備して、config に指定 const passwordDef = engine.createDataDefinition( "パスワード", 3, "q_password", "STRING_TEXTFIELD" ); configs.putObject("DownloadPass", passwordDef); // 文字型データ項目の値(パスワード)を指定 engine.setData(passwordDef, password); // 文字型データ項目を準備して、config に指定 const urlDef = engine.createDataDefinition( "リンクURL", 4, "q_urls", "STRING_TEXTFIELD" ); configs.putObject("DownloadUrlItem", urlDef); // 文字型データ項目の値(リンク URL を保存するデータ項目)を指定 engine.setData(urlDef, "事前文字列"); return { unsharedDateDef, passwordDef, urlDef, }; }; /** * リクエストのテスト(対象ファイルの共有リンク情報を取得) * @param {Object} request * @param request.url * @param request.method * @param folderId */ const assertGetRequest = ({ url, method }, folderId) => { expect(url).toEqual( `https://api.box.com/2.0/folders/${folderId}?fields=shared_link` ); expect(method).toEqual("GET"); }; /** * リクエストのテスト(ファイル共有リンク作成) * @param {Object} request * @param request.url * @param request.method * @param request.contentType * @param request.body * @param folderId * @param unsharedDate * @param password * @param offsetInMinutes */ const assertPutRequest = ( { url, method, contentType, body }, folderId, unsharedDate, password ) => { expect(url).toEqual( `https://api.box.com/2.0/folders/${folderId}?fields=shared_link` ); expect(method).toEqual("PUT"); expect(contentType).toEqual("application/json; charset=UTF-8"); const bodyObj = JSON.parse(body); if (unsharedDate !== null) { expect(bodyObj.shared_link.unshared_at).toEqual(unsharedDate); } else { //unsharedDate が空の場合、bodyObj に time の指定がないことを確認 expect(bodyObj.shared_link.unshared_at === undefined).toEqual(true); } if (password !== null) { expect(bodyObj.shared_link.password).toEqual(password); } else { //password が空の場合、bodyObj に password の指定がないことを確認 expect(bodyObj.shared_link.password === undefined).toEqual(true); } }; /** * folderId が空の場合 */ test("folder ID is blank", () => { prepareConfigs(configs, null, "2021-04-15 10:00:00", "word2"); expect(execute).toThrow("Folder ID is blank"); }); /** * Box への API リクエストでエラー * 対象ファイルの共有リンク情報の取得失敗 */ test("GET Failed", () => { prepareConfigs(configs, "12345", "2022-01-01 00:00:00", "word3"); httpClient.setRequestHandler((request) => { assertGetRequest(request, "12345"); return httpClient.createHttpResponse(400, "application/json", "{}"); }); expect(execute).toThrow("Failed to get folder information"); }); /** * 対象ファイルに共有リンクが既に有り、エラー */ test("Shared link was already created.", () => { prepareConfigs(configs, "12345", "2023-01-02 20:15:00", "word4"); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, "12345"); //レスポンスは、簡易版レプリゼンテーション+ field で指定した属性 const responseGetObj = { type: "folder", id: 12345, etag: 12345, name: "Contracts", sequence_id: 3, shared_link: { access: "open", download_count: 3, download_url: "https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg", effective_access: "company", effective_permission: "can_download", is_password_enabled: true, permissions: { can_download: true, can_preview: true, }, preview_count: 3, unshared_at: "2023-01-02T20:15:00-07:00", url: "https://www.box.com/s/vspke7y05sb214wjokpk", vanity_name: "my_url", vanity_url: "https://acme.app.box.com/v/my_url/", }, }; reqCount++; return httpClient.createHttpResponse( 200, "application/json", JSON.stringify(responseGetObj) ); } }); expect(execute).toThrow("Shared link(https://www.box.com/s/vspke7y05sb214wjokpk) was already created."); }); /** * Box への API リクエストでエラー * ファイル共有リンク作成失敗 */ test("PUT Failed", () => { prepareConfigs(configs, "12345", "2020-03-14 23:45:00", "word5"); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, "12345"); //レスポンスは、簡易版レプリゼンテーション+ field で指定した属性 const responseGetObj = { type: "folder", id: "12345", etag: 1, sequence_id: 3, shared_link: null, }; reqCount++; return httpClient.createHttpResponse( 200, "application/json", JSON.stringify(responseGetObj) ); } // timezone = 'GMT' なので、有効期限は 2020-03-14 23:45:00.0+00:00 assertPutRequest(request, "12345", "2020-03-14 23:45:00.0+00:00", "word5"); return httpClient.createHttpResponse(400, "application/json", "{}"); }); engine.setTimeZoneOffsetInMinutes(0); // テストスクリプトではタイムゾーンの値をコントロール可能。timezone = 'GMT'に設定する expect(execute).toThrow("Failed to create Shared Link"); }); /** * ファイル共有リンク作成成功 */ test("200 Success", () => { const { unsharedDateDef, passwordDef, urlDef } = prepareConfigs( configs, "12345", "2020-03-14 23:45:00", "word6" ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, "12345"); //レスポンスは、簡易版レプリゼンテーション const responseGetObj = { type: "folder", id: "12345", etag: "0", shared_link: null, }; reqCount++; return httpClient.createHttpResponse( 200, "application/json", JSON.stringify(responseGetObj) ); } // timezone = 'GMT+09:00' なので、有効期限は 2020-03-14 23:45:00.0+09:00 assertPutRequest( request, "12345", "2020-03-14 23:45:00.0+09:00", "word6" ); //レスポンスは、簡易版レプリゼンテーション const responsePutObj = { type: "folder", id: "12345", etag: "0", shared_link: { access: "open", download_count: 3, download_url: "https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg", effective_access: "company", effective_permission: "can_download", is_password_enabled: true, permissions: { can_download: true, can_preview: true, }, preview_count: 3, unshared_at: "2020-03-14 23:45:00.0+09:00", url: "https://www.box.com/s/vspke7y05sb214123456", vanity_name: "my_url", vanity_url: "https://acme.app.box.com/v/my_url/", }, }; return httpClient.createHttpResponse( 200, "application/json", JSON.stringify(responsePutObj) ); }); engine.setTimeZoneOffsetInMinutes(540); // テストスクリプトではタイムゾーンの値をコントロール可能 timezone = 'GMT+09:00' に設定する //