2022-11-28
(C) Questetra, Inc. (MIT License)
2
This item creates a URL to access the specified file on Box. Created with no expiration and/or no password
requests if you leave them blank.
この工程は、Box 上のファイルにアクセスできる URL を作成します。有効期限の指定が無い場合は無期限で、パスワードの指定が無い場合はパスワード要求無しで作成します。
https://support.questetra.com/bpmn-icons/service-task-box-file-link-create/
https://support.questetra.com/ja/bpmn-icons/service-task-box-file-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('conf_OAuth2', 'Box');
// 文字型データ項目を準備して、config に指定
const fileIdDef = engine.createDataDefinition('共有するファイルID', 1, 'q_fileId', 'STRING_TEXTFIELD');
configs.putObject('conf_FileId', fileIdDef);
// 文字型データ項目の値(共有するファイルID)を指定
engine.setData(fileIdDef, fileId);
// 日時型データ項目を準備して、config に指定
const unsharedDateDef = engine.createDataDefinition('有効期限', 2, 'q_dateTime', 'DATETIME');
configs.putObject('conf_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('conf_Password', passwordDef);
// 文字型データ項目の値(パスワード)を指定
engine.setData(passwordDef, password);
// 文字型データ項目を準備して、config に指定
const urlDef = engine.createDataDefinition('リンクURL', 4, 'q_urls', 'STRING_TEXTFIELD');
configs.putObject('conf_SharedLink', urlDef);
// 文字型データ項目の値(リンク URL を保存するデータ項目)を指定
engine.setData(urlDef, '事前文字列');
return {
fileIdDef,
unsharedDateDef,
passwordDef,
urlDef
};
};
/**
* リクエストのテスト(対象ファイルの共有リンク情報を取得)
* @param {Object} request
* @param request.url
* @param request.method
* @param fileId
*/
const assertGetRequest = ({url, method}, fileId) => {
expect(url).toEqual(`https://api.box.com/2.0/files/${fileId}?fields=shared_link`);
expect(method).toEqual('GET');
};
/**
* リクエストのテスト(ファイル共有リンク作成)
* @param {Object} request
* @param request.url
* @param request.method
* @param request.contentType
* @param request.body
* @param fileId
* @param unsharedDate
* @param password
* @param offsetInMinutes
*/
const assertPutRequest = ({url, method, contentType, body}, fileId, unsharedDate, password) => {
expect(url).toEqual(`https://api.box.com/2.0/files/${fileId}?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);
}
};
/**
* conf_FileId にデータ項目を設定しているが、そのデータ項目の値が空でエラーになる場合
*/
test('File ID is blank - FileId specified by String Data', () => {
prepareConfigs(null, '2020-03-14 23:45:00', 'word1');
expect(execute).toThrow('File ID is blank');
});
/**
* Box への API リクエストでエラー
* 対象ファイルの共有リンク情報の取得失敗
*/
test('GET Failed', () => {
prepareConfigs('12345678', '2022-01-01 00:00:00', 'word3');
httpClient.setRequestHandler((request) => {
assertGetRequest(request, '12345678');
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
expect(execute).toThrow('Failed to get file information. status:400');
});
/**
* 対象ファイルに共有リンクが既に有り、エラー
*/
test('Shared link was already created.', () => {
prepareConfigs('87654321', '2023-01-02 20:15:00', 'word4');
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetRequest(request, '87654321');
//レスポンスは、簡易版レプリゼンテーション+ field で指定した属性
const responseGetObj = {
"type": "file",
"id": "87654321",
"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": "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('11111111', '2020-03-14 23:45:00', 'word5');
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetRequest(request, '11111111');
//レスポンスは、簡易版レプリゼンテーション+ field で指定した属性
const responseGetObj = {
"type": "file",
"id": "87654321",
"etag": "0",
"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, '11111111', '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. status:400');
});
/**
* ファイル共有リンク作成成功
*/
test('200 Success', () => {
const {
fileIdDef,
unsharedDateDef,
passwordDef,
urlDef
} = prepareConfigs('87654321', '2020-03-14 23:45:00', 'word6');
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetRequest(request, '87654321');
//レスポンスは、簡易版レプリゼンテーション
const responseGetObj = {
"type": "file",
"id": "87654321",
"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, '87654321', '2020-03-14 23:45:00.0+09:00', 'word6');
//レスポンスは、簡易版レプリゼンテーション
const responsePutObj = {
"type": "file",
"id": "87654321",
"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-14T23:45:00-07: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' に設定する
//