(C) Questetra, Inc. (MIT License) 2023-10-23 3 2 This item moves the specified file/folder to the specified folder on OneDrive. The file/folder cannot be moved between drives. この工程は、OneDrive 上のファイル / フォルダを、指定フォルダに移動します。ドライブをまたぐ移動はできません。 https://support.questetra.com/bpmn-icons/service-task-onedrive-file-move/ https://support.questetra.com/ja/bpmn-icons/service-task-onedrive-file-move/ 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 { const oauth2 = httpClient.createAuthSettingOAuth2( 'OneDrive', 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize', 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token', 'https://graph.microsoft.com/Files.ReadWrite.All offline_access', 'client_id', 'client_secret', 'access_token' ); configs.putObject('conf_OAuth2', oauth2); // 移動させるファイル / フォルダの URL を保存する文字型データ項目(単一行)を準備 const sourceUrlDef = engine.createDataDefinition('移動させるファイル / フォルダの URL', 1, 'q_source_url', 'STRING_TEXTFIELD'); engine.setData(sourceUrlDef, sourceUrl); configs.putObject('conf_SourceUrl', sourceUrlDef); if (isFixed) { // 移動先フォルダの URL を固定値で指定 configs.put('conf_DestUrl', destUrl); } else { // 移動先フォルダの URL を保存する文字型データ項目(単一行)を準備 const destUrlDef = engine.createDataDefinition('移動先フォルダの URL', 2, 'q_dest_url', 'STRING_TEXTFIELD'); engine.setData(destUrlDef, destUrl); configs.putObject('conf_DestUrl', destUrlDef); } // 移動後のファイル / フォルダの URL を保存する文字型データ項目(単一行)を準備 const newUrlDef = engine.createDataDefinition('移動後のファイル / フォルダの URL', 3, 'q_data_for_url', 'STRING_TEXTFIELD'); engine.setData(newUrlDef, '事前文字列'); configs.putObject('conf_NewUrl', newUrlDef); return newUrlDef; }; /** * 異常系のテスト * @param func * @param errorMsg */ const assertError = (func, errorMsg) => { try { func(); fail(); } catch (e) { expect(e.toString()).toEqual(errorMsg); } }; /** * ファイル / フォルダ URL を文字型データ項目で指定し、値が空でエラー */ test('Source file / folder URL is blank', () => { const destUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder'; prepareConfigs(null, destUrl, false); assertError(main, 'Source file / folder URL is blank.'); }); /** * ファイル / フォルダ URL を文字型データ項目で指定し、値が空でエラー */ test('Destination folder URL is blank - Set by data item', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; prepareConfigs(sourceUrl, null, false); assertError(main, 'Destination folder URL is blank.'); }); /** * ファイル / フォルダ URL を固定値で指定し、値が空でエラー */ test('Destination folder URL is blank - Set as fixed value', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; prepareConfigs(sourceUrl, '', true); assertError(main, 'Destination folder URL is blank.'); }); /** * GET リクエストのテスト - ドライブアイテム取得 * @param {Object} request * @param request.url * @param request.method * @param sharingUrl */ const assertGetRequest = ({ url, method }, sharingUrl) => { const encodedUrl = encodeSharingUrl(sharingUrl); const expectedUrl = `${GRAPH_URI}shares/${encodedUrl}/driveItem` + `?select=${encodeURIComponent('id,parentReference/driveId')}`; expect(url).toEqual(expectedUrl); expect(method).toEqual('GET'); }; /** * GET リクエストでエラー - コピー元ファイル / フォルダの URL */ test('GET Failed - Source Url', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; const destUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder'; prepareConfigs(sourceUrl, destUrl, false); httpClient.setRequestHandler((request) => { assertGetRequest(request, sourceUrl); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); assertError(main, 'Failed to get drive item. status: 400'); }); /** * GET リクエスト(ドライブアイテム取得)のレスポンスを準備 * @param id * @param driveId * @return {String} responseBody */ const prepareDriveItemResponse = (id, driveId) => { return JSON.stringify( { id, parentReference: { driveId } } ); }; /** * GET リクエストでエラー - 移動先フォルダの URL */ test('GET Failed - Destination Url', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; const destUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder'; prepareConfigs(sourceUrl, destUrl, false); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, sourceUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FileId001', 'DriveId001')); } assertGetRequest(request, destUrl); return httpClient.createHttpResponse(403, 'application/json', '{}'); }); assertError(main, 'Failed to get drive item. status: 403'); }); /** * 異なるドライブ間の移動はできない */ test('Cannot move between drives', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; const destUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder'; prepareConfigs(sourceUrl, destUrl, false); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, sourceUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FileId001', 'DriveId001')); } assertGetRequest(request, destUrl); return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FolderId001', 'DriveId002')); }); assertError(main, 'Cannot move between drives. Copy the file/folder instead.'); }); /** * PATCH リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param request.contentType * @param request.body * @param srcDriveId * @param srcId * @param destId */ const assertPatchRequest = ({ url, method, contentType, body }, srcDriveId, srcId, destId) => { expect(url).toEqual(`${GRAPH_URI}drives/${srcDriveId}/items/${srcId}`); expect(method).toEqual('PATCH'); expect(contentType).toEqual('application/json'); const bodyObj = JSON.parse(body); expect(bodyObj.parentReference.id).toEqual(destId); }; /** * PATCH リクエストでエラー */ test('PATCH Failed', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; const destUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder'; prepareConfigs(sourceUrl, destUrl, false); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, sourceUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FileId001', 'DriveId002')); } if (reqCount === 1) { assertGetRequest(request, destUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FolderId001', 'DriveId002')); } assertPatchRequest(request, 'DriveId002', 'FileId001', 'FolderId001'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); assertError(main, 'Failed to move. status: 400'); }); /** * 成功 - 移動先フォルダの URL を文字型データ項目で指定 */ test('Succeed - Destination URL is set by data item', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; const destUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder'; const newUrlDef = prepareConfigs(sourceUrl, destUrl, false); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, sourceUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FileId001', 'DriveId001')); } if (reqCount === 1) { assertGetRequest(request, destUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FolderId001', 'DriveId001')); } const responseObj = { webUrl: 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder/test1.txt' }; assertPatchRequest(request, 'DriveId001', 'FileId001', 'FolderId001'); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(responseObj)); }); expect(main()).toEqual(undefined); // 文字型データ項目の値をチェック expect(engine.findData(newUrlDef)).toEqual('https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder/test1.txt'); }); /** * 成功 - 移動先フォルダの URL を固定値で指定 */ test('Succeed - Destination URL is set as fixed value', () => { const sourceUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test2.txt'; const destUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder2'; const newUrlDef = prepareConfigs(sourceUrl, destUrl, true); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetRequest(request, sourceUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FileId010', 'DriveId002')); } if (reqCount === 1) { assertGetRequest(request, destUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse('FolderId100', 'DriveId002')); } const responseObj = { webUrl: 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder2/test2.txt' }; assertPatchRequest(request, 'DriveId002', 'FileId010', 'FolderId100'); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(responseObj)); }); expect(main()).toEqual(undefined); // 文字型データ項目の値をチェック expect(engine.findData(newUrlDef)).toEqual('https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder2/test2.txt'); }); ]]>