(C) Questetra, Inc. (MIT License) 2 2022-06-06 This item copies the specified file/folder to the specified folder on OneDrive. この工程は、OneDrive 上のファイル / フォルダを複製し、指定フォルダに新規保存します。 https://support.questetra.com/bpmn-icons/onedrive-file-copy/ https://support.questetra.com/ja/bpmn-icons/onedrive-file-copy/ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADXUlEQVRYR8WXW0hUURSG/33GbC5e 8pJJF6nM6YKUmsFAIAZSONOM4FtqL/mQVg9GhXR5iCIiEAqF9KEMsvKpi06OZoRPGaRmVoSGU4om aqaMzeXYOLPjTJ7R41w8k8bZLwNn1r/Wt9dee+29CSQeRHR8vVEpd7vzGTAHKKXpADYDiJnTTwEY IIR0u+FuYxnmCYx6uxjfSwKotE2JbuoqB0EJALkYpwBYUNQwRHbDZtKNBtMEBVBqG0ooSAUAlcjA i81sBPSs3ZRXE0gfEECuM94mlJb+Y2CBjBJSzTbpT/jz5RdAoTU+BGjBSgSf90EeOUz6wsU+fQBW cuaLg/nLhABgbs2rV3bmQm8EtHRhTXgBPNUOV/8yCk4st42BbBu/O7wAitzGmyAoE+tlWXYUtxzN htOcj78AeqNS4aI/Q9jneH5Ng0x1DCLkMlhZFz59m0ZZ9UfPr4jBOmQkjmtWHgC5rqGIUFIXTHih QI3UzVHoH7HhsCYROzZF+JgPjNqxq/iViPgAJfQo25T3wAOg1BnvUkqP+VNGKsLQXpmF5PXCXmR1 zKJvyAqL3Yn4qHCoN0ZCHs6gvm0YxRXdS0IQQmrtTfpiD4BC2/gOANfffUbjVQ1yMtYKvnNZGJlg kZESDeVqGSy2WbzoHPdkpdtswcnKniUBAHQ7TIYMHmBywcEiEPfey0FSgsL7zWJzosc8jazdcQI7 l5tiwvIbUaowTE47UfXMjMqnX4OBTDlMhlgegC62TNmgwp0z6UhLjsaqMMbzN5f25o4x5O5bhwhF WNBZ2mdcyDn3Gu/NloB2DpOBBAToqs7GzqRIr/j7BIu+4V9I2xqN2KhwMSlGbcsgTlV9EAXgswSW Bp135pQCrV3jOJSZICowb2RjXWjtHEfh9U5/OsES+BThj8daqOQyb+q/DFuRkbImJADOmKuNg+Xt ePOZm6NgzBehv21YfzETek0iGIZgxun2OMjeEx8yACfIv/wWLR1jAq1gGwZqROePqLE/NRZjUzOo ezmE++V7ER8tbv35aFzm0o63+YALGlEorfhS0XZsSVSKysTgmANX6nr92QpbMWch7WHEncFSH8dc FiS9kPALJemVjIeQ9FL6PzIR8rWch5D0YcJDSPo0E3QQqR6nolreMoz+ACVfiTBvFfnjAAAAAElF TkSuQmCC { configs.put('conf_OAuth2', 'Microsoft'); configs.put('conf_newName', newName); // コピー元ファイル / フォルダの URL を保存する文字型データ項目(単数行)を準備 const sourceUrlDef = engine.createDataDefinition('コピー元ファイル / フォルダの URL', 1, 'q_source_url', 'STRING_TEXTFIELD'); engine.setData(sourceUrlDef, sourceUrl); configs.putObject('conf_sourceUrl', sourceUrlDef); // 保存先フォルダの URL を保存する文字型データ項目(単数行)を準備 const destUrlDef = engine.createDataDefinition('保存先フォルダの URL', 2, 'q_dest_url', 'STRING_TEXTFIELD'); engine.setData(destUrlDef, destUrl); configs.putObject('conf_destUrl', destUrlDef); // 新しいファイル / フォルダの URL を保存する文字型データ項目(単数行)を準備 const dataForUrlDef = engine.createDataDefinition('新しいファイル / フォルダの URL', 3, 'q_data_for_url', 'STRING_TEXTFIELD'); engine.setData(dataForUrlDef, '事前文字列'); configs.putObject('conf_dataForUrl', dataForUrlDef); return dataForUrlDef; }; /** * コピー元ファイル / フォルダの URLがnullでエラー */ test('Source file / folder URL is null', () => { prepareConfigs( null, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder1', 'file1' ); expect(execute).toThrow('Source file / folder URL is empty.'); }); /** * 新しいファイル / フォルダの名前が空でエラー */ test('New File / Folder Name is blank', () => { prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test2.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder2', '' ); expect(execute).toThrow('New file / folder name is empty.'); }); /** * GET リクエストのテスト - ドライブアイテム取得 * @param {Object} request * @param request.url * @param request.method * @param deleteUrl */ const assertGetRequest = ({url, method}, sharingUrl) => { const encodedUrl = encodeSharingUrl(sharingUrl); expect(url).toEqual(`${GRAPH_URI}shares/${encodedUrl}/driveItem`); expect(method).toEqual('GET'); }; /** * GET リクエストでエラー - コピー元ファイル / フォルダの URL */ test('GET Failed - Source Url', () => { prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test3.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder3', 'copy3.txt' ); httpClient.setRequestHandler((request) => { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test3.txt'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to get drive item. status: 400'); }); /** * GET リクエスト(ドライブアイテム取得)のレスポンスを準備 * @param id * @param driveId * @return {Object} responseObj */ const prepareDriveItemResponse = (id, driveId) => { return JSON.stringify( { "id":`${id}`, "parentReference":{ "driveId":`${driveId}` } } ); }; /** * GET リクエストでエラー - 保存先フォルダの URL */ test('GET Failed - Folder Url to save', () => { prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test4.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder4', 'copy3.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test4.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId004', 'DestDrive004')); } assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder4'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to get drive item. status: 400'); }); /** * POST リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param request.contentType * @param request.body * @param srcDriveId * @param srcId * @param destDriveId * @param destId * @param newName */ const assertPostRequest = ({url, method, contentType, body}, srcDriveId, srcId, destDriveId, destId, newName) => { expect(url).toEqual(`${GRAPH_URI}drives/${srcDriveId}/items/${srcId}/copy`); expect(method).toEqual('POST'); expect(contentType).toEqual("application/json; charset=UTF-8"); const bodyObj = JSON.parse(body); if (destDriveId !== null){ expect(bodyObj.parentReference.driveId).toEqual(destDriveId); } if (destId !== null){ expect(bodyObj.parentReference.id).toEqual(destId); } expect(bodyObj.name).toEqual(newName); }; /** * POST リクエストでエラー */ test('POST Failed', () => { prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test5.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder5', 'copy5.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test5.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId005', 'SrcDrive005')); } if (reqCount === 1) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder5'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId005', 'DestDrive005')); } assertPostRequest(request, 'SrcDrive005', 'SrcId005', 'DestDrive005', 'DestId005', 'copy5.txt'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to copy. status: 400'); }); /** * GET リクエストのテスト - ステータスレポート取得 * @param {Object} request * @param request.url * @param request.method * @param deleteUrl */ const assertGetStatusRequest = ({url, method}, sharingUrl) => { expect(url).toEqual(sharingUrl); expect(method).toEqual('GET'); }; /** * GET リクエストでエラー - コピー状況 */ test('GET Failed - Copy status', () => { prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test6.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder6', 'copy6.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test6.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId006', 'SrcDrive006')); } if (reqCount === 1) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder6'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId006', 'DestDrive006')); } if (reqCount === 2) { assertPostRequest(request, 'SrcDrive006', 'SrcId006', 'DestDrive006', 'DestId006', 'copy6.txt'); reqCount++; const response = httpClient.createHttpResponse(202, 'application/json', '{}'); response.addHeader('Location', 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive006/items/resourceId006'); return response; } assertGetStatusRequest(request, 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive006/items/resourceId006'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to get monitor. status: 400'); }); /** * GET リクエスト(ステータスレポートを取得)のレスポンスを準備 * @param resourceId * @param status * @return {Object} responseObj */ const prepareStatusResponse = (resourceId, status) => { return JSON.stringify( { "resourceId":`${resourceId}`, "status":`${status}` } ); }; /** * コピー状況が不明 */ test('Copy status is unknown', () => { prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test7.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder7', 'copy7.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test7.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId007', 'SrcDrive007')); } if (reqCount === 1) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder7'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId007', 'DestDrive007')); } if (reqCount === 2) { assertPostRequest(request, 'SrcDrive007', 'SrcId007', 'DestDrive007', 'DestId007', 'copy7.txt'); reqCount++; const response = httpClient.createHttpResponse(202, 'application/json', '{}'); response.addHeader('Location', 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive007/items/resourceId007'); return response; } assertGetStatusRequest(request, 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive007/items/resourceId007'); return httpClient.createHttpResponse(200, 'application/json', prepareStatusResponse('resourceId007', 'unknown')); }); expect(execute).toThrow('Copy is not in progress nor completed. status: unknown'); }); /** * GET リクエストのテスト - 新しいファイル / フォルダのメタデータ取得 * @param {Object} request * @param request.url * @param request.method * @param driveId * @param itemId */ const assertGetNewItemRequest = ({url, method}, driveId, itemId) => { expect(url).toEqual(`${GRAPH_URI}drives/${driveId}/items/${itemId}`); expect(method).toEqual('GET'); }; /** * GET リクエストでエラー - 新しいファイル / フォルダのURL */ test('GET Failed - New file / folder URL', () => { prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test8.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder8', 'copy8.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test8.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId008', 'SrcDrive008')); } if (reqCount === 1) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder8'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId008', 'DestDrive008')); } if (reqCount === 2) { assertPostRequest(request, 'SrcDrive008', 'SrcId008', 'DestDrive008', 'DestId008', 'copy8.txt'); reqCount++; const response = httpClient.createHttpResponse(202, 'application/json', '{}'); response.addHeader('Location', 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive008/items/resourceId008'); return response; } if (reqCount === 3) { assertGetStatusRequest(request, 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive008/items/resourceId008'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareStatusResponse('resourceId008', 'completed')); } assertGetNewItemRequest(request, 'DestDrive008', 'resourceId008'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to get file. status: 400'); }); /** * コピー成功 - 保存先フォルダの URL 指定 */ test('201 Success - Specify Folder URL to store', () => { const dataForUrlDef = prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test9.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder9', 'copy9.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test9.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId009', 'SrcDrive009')); } if (reqCount === 1) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder9'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId009', 'DestDrive009')); } if (reqCount === 2) { assertPostRequest(request, 'SrcDrive009', 'SrcId009', 'DestDrive009', 'DestId009', 'copy9.txt'); reqCount++; const response = httpClient.createHttpResponse(202, 'application/json', '{}'); response.addHeader('Location', 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive009/items/resourceId009'); return response; } if (reqCount === 3) { assertGetStatusRequest(request, 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive009/items/resourceId009'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareStatusResponse('resourceId009', 'completed')); } assertGetNewItemRequest(request, 'DestDrive009', 'resourceId009'); const responseObj = {"webUrl": "https://test-my.sharepoint.com/personal/aaa/Documents/folder9/test9.txt"}; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(responseObj)); }); execute(); // 文字型データ項目の値をチェック expect(engine.findData(dataForUrlDef)).toEqual('https://test-my.sharepoint.com/personal/aaa/Documents/folder9/test9.txt'); }); /** * コピー成功 - 保存先フォルダの URL がnull */ test('201 Success - Folder URL to store is null', () => { const dataForUrlDef = prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/folder10/test10.txt', null, 'copy10.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder10/test10.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId010', 'SrcDrive010')); } if (reqCount === 1) { assertPostRequest(request, 'SrcDrive010', 'SrcId010', null, null, 'copy10.txt'); reqCount++; const response = httpClient.createHttpResponse(202, 'application/json', '{}'); response.addHeader('Location', 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/SrcDrive010/items/resourceId010'); return response; } if (reqCount === 2) { assertGetStatusRequest(request, 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/SrcDrive010/items/resourceId010'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareStatusResponse('resourceId010', 'completed')); } const responseObj = {"webUrl": "https://test-my.sharepoint.com/personal/aaa/Documents/folder10/test10.txt"}; assertGetNewItemRequest(request, 'SrcDrive010', 'resourceId010'); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(responseObj)); }); execute(); // 文字型データ項目の値をチェック expect(engine.findData(dataForUrlDef)).toEqual('https://test-my.sharepoint.com/personal/aaa/Documents/folder10/test10.txt'); }); /** * コピー成功 - コピー状況がまだ始まってない */ test('201 Success - Copy status is notStarted', () => { const dataForUrlDef = prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test11.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder11', 'copy11.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test11.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId011', 'SrcDrive011')); } if (reqCount === 1) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder11'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId011', 'DestDrive011')); } if (reqCount === 2) { assertPostRequest(request, 'SrcDrive011', 'SrcId011', 'DestDrive011', 'DestId011', 'copy11.txt'); reqCount++; const response = httpClient.createHttpResponse(202, 'application/json', '{}'); response.addHeader('Location', 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive011/items/resourceId011'); return response; } assertGetStatusRequest(request, 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive011/items/resourceId011'); return httpClient.createHttpResponse(200, 'application/json', prepareStatusResponse('resourceId011', 'notStarted')); }); execute(); // 文字型データ項目の値をチェック - コピー状況がまだ始まってない場合、空文字列で上書きされる expect(engine.findData(dataForUrlDef)).toEqual(''); }); /** * コピー成功 - コピー状況が処理中 */ test('201 Success - Copy status is inProgress', () => { const dataForUrlDef = prepareConfigs( 'https://test-my.sharepoint.com/personal/aaa/Documents/test12.txt', 'https://test-my.sharepoint.com/personal/aaa/Documents/folder12', 'copy12.txt' ); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/test12.txt'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('SrcId012', 'SrcDrive012')); } if (reqCount === 1) { assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/folder12'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('DestId012', 'DestDrive012')); } if (reqCount === 2) { assertPostRequest(request, 'SrcDrive012', 'SrcId012', 'DestDrive012', 'DestId012', 'copy12.txt'); reqCount++; const response = httpClient.createHttpResponse(202, 'application/json', '{}'); response.addHeader('Location', 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive012/items/resourceId012'); return response; } assertGetStatusRequest(request, 'https://test-my.sharepoint.com/personal/aaa/_api/v2.0/drives/DestDrive012/items/resourceId012'); return httpClient.createHttpResponse(200, 'application/json', prepareStatusResponse('resourceId012', 'inProgress')); }); execute(); // 文字型データ項目の値をチェック - コピー状況が処理中の場合、空文字列で上書きされる expect(engine.findData(dataForUrlDef)).toEqual(''); }); ]]>