建立全域函數
全域函數可用來包裝 Web 服務的業務邏輯,以便於在其他位置使用。
OCMCreateRepositoryCollectionFunction
若要建立將用於存取 OCMCreateRepositoryCollectionService Web 服務的「OCM 建立儲存區域集合」全域功能:
- 從左側導覽功能表中依序選擇通用設定和全域函數。
- 在「全域函數」頁面上,按一下新增全域函數圖示。
- 在「建立全域功能」頁面上,填好下列欄位:
- 在函數名稱欄位中,將函數的名稱指定為 OCMCreateRepositoryCollectionFunction 。
- 從返回 (Returns) 下拉式功能表選取字串 (String) 。
- 在描述欄位中,輸入「在指定的 OCMRepositoryId 中建立新 OCMCollectionName 並傳回新建立的集合 ID」文字。
- 在「參數」區段中,按一下新增參數圖示,然後新增下列欄位:
名稱 Type OCMRepositoryId 字串 OCMCollectionName 字串 - 在編輯指令碼欄位中,貼上下列指令碼:
println("Create OCM Collection " + OCMCollectionName + " within the Asset Repository Id: " + OCMRepositoryId); def params = [:] params.name = OCMCollectionName def OCMCollection = [:] try { def OCMCreateRepositoryCollectionService = adf.webServices.OCMCreateRepositoryCollectionService OCMCreateRepositoryCollectionService.requestHTTPHeaders = ['X-Requested-With': 'XMLHttpRequest'] OCMCollection = OCMCreateRepositoryCollectionService.POST(OCMRepositoryId, params) println("OCM Collection Created: " + OCMCollection) return OCMCollection.id } catch (Exception e) { println("OCM Create Respository(" + OCMRepositoryId + ") Collection(" + OCMCollectionName + ") Error: " + e) }
- 按一下儲存並關閉。
OCMGetDocumentsByFolderIdFunction
若要在新「建立全域功能」頁面中建立「依資料夾 ID 取得文件」全域功能 (將用來存取 OCMGetDocumentsByFolderIdService Web 服務),請完成下列欄位:
注意:
只有在 Oracle Sales 與 Service 業務物件具有解決選項且已設定 OCM 文件整合時,才需要此全域功能。請參閱 Learn About How to Extend Oracle Sales and Service Business Objects with Document Collaboration,瞭解 Document Integration 的詳細資訊。- 在函數名稱欄位中,將函數的名稱指定為 OCMGetDocumentsByFolderIdFunction 。
- 從返回 (Returns) 下拉式功能表選取清單 (List) 。
- 在描述欄位中,輸入文字「根據指定的 OCMFolderId 傳回 OCM 文件 ID 清單」(也包含子項資料夾)。
- 在「參數」區段中,按一下新增參數圖示。
在名稱欄位中,將名稱指定為 OCMFolderId ,然後從類型下拉式功能表中選取字串。
- 在編輯指令碼欄位中,貼上下列指令碼:
def response = [:] def items = [] try { response = adf.webServices.OCMGetDocumentsByFolderIdService.GET(OCMFolderId) for(item in response.items){ items.add(item["id"]) } println("OCM Get Documents By Folder Id " + OCMFolderId + " Result(" + items.size() + "): " + items) return items } catch (Exception e) { println("Get OCM Documents By Folder Id Error: " + e) }
- 按一下儲存並關閉。
OCMCopyDocumentsToRepositoryCollectionFunction
若要在新的「建立全域函數」頁面中建立「OCM 將文件複製到儲存庫集合」全域功能,該頁面將用來存取 OCMBulkOperationsService Web 服務,請完成下列欄位:
注意:
只有在 Oracle Sales 與 Service 業務物件具有解決選項且已設定 OCM 文件整合時,才需要此全域功能。請參閱 Learn About How to Extend Oracle Sales and Service Business Objects with Document Collaboration,瞭解 Document Integration 的詳細資訊。- 在函數名稱欄位中,將函數的名稱指定為 OCMCopyDocumentsToRepositoryCollectionFunction 。
- 從傳回下拉式功能表選取布林值。
- 在描述欄位中,輸入文字「將 OCM 指定的 OCMDocumentIds 清單複製至指定的 OCMRepositoryId 內的指定 OCMCollectionId」。
- 在「參數」區段中,按一下新增參數圖示,然後新增下列欄位:
名稱 Type OCMRepositoryId 字串 OCMCollectionId 字串 OCMDocumentIds 清單 - 在編輯指令碼欄位中,貼上下列指令碼:
// Create the structure required for the list of documents that will be used in the payload below def documents = [] for(OCMDocumentId in OCMDocumentIds) { def document = [ externalId: OCMDocumentId, // NOTE: The type value must match the name of the Asset Type that you created during the installation type: "Service-Request-Asset", collections: [ data: [OCMCollectionId] ] ] documents.add(document) } // Create the payload required to make the addToRepository bulk operation call def payload = [ operations: [ addToRepository: [ connectorId: "Documents", repositoryId: OCMRepositoryId, externalItems: documents ] ] ] try { def OCMBulkOperationsService = adf.webServices.OCMBulkOperationsService OCMBulkOperationsService.requestHTTPHeaders = ['X-Requested-With': 'XMLHttpRequest'] OCMBulkOperationsService.POST(payload) println("OCM Documents Copied To Repository: " + OCMRepositoryId + "(" + OCMCollectionId + "): (" + OCMDocumentIds + ")") return true } catch (Exception e) { println("Copy OCM Documents To Repository Error: " + e) return false }
注意:
上述指令碼中的類型值必須與您先前建立的資產類型名稱相符。 - 按一下儲存並關閉。
OCMIsRepositoryCollectionSharedAsContributorFunction
若要在新的「建立全域函數」頁面中建立「以提供者身分共用 OCM 是儲存庫集合」全域功能,該頁面將用來存取 OCMRepositoryCollectionPermissionsService Web 服務,請完成下列欄位:
- 在函數名稱欄位中,將函數的名稱指定為 OCMIsRepositoryCollectionSharedAsContributorFunction 。
- 從傳回下拉式功能表選取布林值。
- 在描述欄位中,輸入「如果指定的 OCMUserName 已與指定 OCMRespositoryId 中至少具有「提供者」角色的指定 OCMCollectionId 共用,則傳回 true」文字。
- 在「參數」區段中,按一下新增參數圖示,然後新增下列欄位:
名稱 Type OCMRepositoryId 字串 OCMCollectionId 字串 OCMUserName 字串 - 在編輯指令碼欄位中,貼上下列指令碼:
def response = [:] try { response = adf.webServices.OCMRepositoryCollectionPermissionsService.GET(OCMRepositoryId, OCMCollectionId) def responseItems = [:] responseItems = response.items for (item in responseItems) { // Ignore case as these could be different between the two security systems even though it is the same user if ((item['id'] as String).toLowerCase() == OCMUserName.toLowerCase()) { // If found make sure the user also has at least the contributor role if (item['roleName'] == 'contributor' || item['roleName'] == 'manager') { println("OCM User(" + OCMUserName + ") was found with enough role permissions to the repository collection: " + OCMRepositoryId + "(" + OCMCollectionId + ")") return true } else { println("OCM User(" + OCMUserName + ") was found but without enough role permissions to the repository collection: " + OCMRepositoryId + "(" + OCMCollectionId + ")") return false } } } println("OCM User(" + OCMUserName + ") does not have permissions to the repository: " + OCMRepositoryId) return false } catch (Exception e) { println("OCM Is Repository Collection Shared As Contributor Error: " + e) return false }
- 按一下儲存並關閉。
OCMShareCollectionFunction
若要在新的「建立全域功能」頁面中建立 OCM 共用收集全域功能,並用於存取 OCMPermissionOperationsService Web 服務,請完成下列欄位:
- 在函數名稱欄位中,將函數的名稱指定為 OCMShareCollectionFunction 。
- 從傳回下拉式功能表選取布林值。
- 在描述欄位中,輸入文字 「與指定的 OCMUserName 和 OCMRole 共用 OCM 中指定的 OCMCollectionId」。
- 在「參數」區段中,按一下新增參數圖示,然後新增下列欄位:
名稱 Type OCMCollectionId 字串 OCMUserName 字串 OCMRole 字串 - 在編輯指令碼欄位中,貼上下列指令碼:
// Create the payload required to make the permissions operation call def payload = [ operations: [ share: [ resource: [ id :OCMCollectionId, type :"collection", ], roles: [[ name :OCMRole, users: [[ name :OCMUserName, type :"user", ]], ]], ], ] ] def response = [:] try { def OCMPermissionOperationsService = adf.webServices.OCMPermissionOperationsService OCMPermissionOperationsService.requestHTTPHeaders = ['X-Requested-With': 'XMLHttpRequest', 'content-type': 'application/json'] response = OCMPermissionOperationsService.POST(payload) // Check the response to make sure we do not have a failure def hasFailedRoles = response?.operations?.share?.failedRoles if (hasFailedRoles == null) { println("OCM Collection Shared: " + OCMCollectionId + "(" + OCMUserName + ":" + OCMRole + ")") return true } else { println("Share OCM Collection Failed: " + response) return false } } catch (Exception e) { println("Share OCM Collection Error: " + e) return false }
- 按一下儲存並關閉。