2023-10-13 (C) Questetra, Inc. (MIT License) 3 2 This item creates a URL to access the specified file/folder in OneDrive so that anyone who knows the link can view it. この工程は、OneDrive 内の指定ファイル / フォルダにアクセスできる URL を作成し、リンクを知っているすべての人が閲覧できるようにします。 https://support.questetra.com/bpmn-icons/service-task-onedrive-file-link-create/ https://support.questetra.com/ja/bpmn-icons/service-task-onedrive-file-link-create/ 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); if (isFixed) { configs.put('conf_DriveItemUrl', driveItemUrl); } else { const driveItemUrlDef = engine.createDataDefinition('ファイル / フォルダ URL', 1, 'q_driveItemUrl', 'STRING_TEXTFIELD'); engine.setData(driveItemUrlDef, driveItemUrl); configs.putObject('conf_DriveItemUrl', driveItemUrlDef); } const sharingLinkDef = engine.createDataDefinition('共有リンク', 2, 'q_sharingUrl', 'STRING_TEXTFIELD'); engine.setData(sharingLinkDef, '事前文字列'); configs.putObject('conf_SharingLink', sharingLinkDef); return sharingLinkDef; }; /** * 異常系のテスト * @param func * @param errorMsg */ const assertError = (func, errorMsg) => { try { func(); fail(); } catch (e) { expect(e.toString()).toEqual(errorMsg); } }; /** * ファイル / フォルダ URL を文字型データ項目で指定し、値が空でエラー */ test('File / Folder URL is blank', () => { prepareConfigs(null, false); assertError(main, 'File / Folder URL is blank.'); }); /** * ドライブアイテム取得の GET リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param sharingUrl */ const assertGetDriveItemRequest = ({ url, method }, sharingUrl) => { const encodedUrl = encodeSharingUrl(sharingUrl); const expectedUrl = `${GRAPH_URI}shares/${encodedUrl}/driveItem` + `?select=${encodeURIComponent('id,parentReference')}`; expect(url).toEqual(expectedUrl); expect(method).toEqual('GET'); }; /** * ドライブアイテム取得の GET リクエストでエラー */ test('Fail in GET request', () => { const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; prepareConfigs(fileUrl, false); httpClient.setRequestHandler((request) => { assertGetDriveItemRequest(request, fileUrl); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); assertError(main, 'Failed to get drive item. status: 400'); }); /** * ドライブアイテム取得の GET リクエストのレスポンスを準備 * @param driveId * @param id * @return {Object} responseObj */ const prepareDriveItemResponse = (driveId, id) => { return JSON.stringify( { id, parentReference: { driveId } } ); }; /** * 共有リンク作成の POST リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param driveId * @param id */ const assertCreateLinkRequest = ({ url, method, contentType, body }, driveId, id) => { expect(url).toEqual(`${GRAPH_URI}drives/${driveId}/items/${id}/createLink`); expect(method).toEqual('POST'); expect(contentType).toEqual('application/json'); const bodyObj = JSON.parse(body); expect(bodyObj.type).toEqual('view'); expect(bodyObj.scope).toEqual('anonymous'); }; /** * 共有リンク作成の POST リクエストでエラー */ test('Fail in POST request', () => { const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; prepareConfigs(fileUrl, false); let reqCount = 0; const driveId = 'driveId-1'; const id = 'fileId-1'; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetDriveItemRequest(request, fileUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, id)); } assertCreateLinkRequest(request, driveId, id); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); assertError(main, 'Failed to create sharing link. status: 400'); }); /** * 共有リンク作成の POST リクエストのレスポンスを準備 * @param id * @param webUrl * @return {Object} responseObj */ const prepareCreateLinkResponse = (id, webUrl) => { return JSON.stringify( { id, link: { webUrl } } ); }; /** * 成功 * URL は文字型データ項目で指定 * 共有リンクが新たに作成された場合(レスポンスステータス 201) * 共有リンクの ID は保存しない */ test('Succeed - set URL by data item, response status 201', () => { const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt'; const sharingLinkDef = prepareConfigs(fileUrl, false); let reqCount = 0; const driveId = 'driveId-1'; const id = 'fileId-1'; const sharingLink = 'https://test-my.sharepoint.com/:i:/g/personal/aaa/1234567890'; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetDriveItemRequest(request, fileUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, id)); } assertCreateLinkRequest(request, driveId, id); return httpClient.createHttpResponse(201, 'application/json', prepareCreateLinkResponse('link-1', sharingLink)); }); expect(main()).toEqual(undefined); expect(engine.findData(sharingLinkDef)).toEqual(sharingLink); }); /** * 成功 * URL は固定値で指定 * 既存の共有リンクが返される場合(レスポンスステータス 200) * 共有リンクの ID を保存する */ test('Succeed - set URL as fixed value, response status 200', () => { const folderUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder'; const sharingLinkDef = prepareConfigs(folderUrl, true); const sharingLinkIdDef = engine.createDataDefinition('共有リンクの ID', 3, 'q_sharingLinkId', 'STRING_TEXTFIELD'); engine.setData(sharingLinkIdDef, '事前文字列'); configs.putObject('conf_SharingLinkId', sharingLinkIdDef); let reqCount = 0; const driveId = 'driveId-2'; const id = 'folderId-1'; const sharingLink = 'https://test-my.sharepoint.com/:i:/g/personal/bbb/0987654321'; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetDriveItemRequest(request, folderUrl); reqCount++; return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, id)); } assertCreateLinkRequest(request, driveId, id); return httpClient.createHttpResponse(200, 'application/json', prepareCreateLinkResponse('link-2', sharingLink)); }); expect(main()).toEqual(undefined); expect(engine.findData(sharingLinkDef)).toEqual(sharingLink); expect(engine.findData(sharingLinkIdDef)).toEqual('link-2'); }); ]]>