diff --git a/CHANGELOG.md b/CHANGELOG.md index 8247c2a1..1affa6aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ v1.4.1 [2020-02-14] - [#3](https://github.com/latera/camunda-ext/pull/3) Add methods to tag entities into hid.Hydra class - [#20](https://github.com/latera/camunda-ext/pull/20) Add newMessage method to MailSender class - [#3200317](https://github.com/latera/camunda-ext/commit/3200317) Allow to pass constant id with non-Integer type into getConstantCode method +- [#24](https://github.com/latera/camunda-ext/pull/24) Add methods for files to document attaching ### Refactoring - [#8](https://github.com/latera/camunda-ext/pull/8) Prettify runCommand, Add constants, use constants instead of magic numbers in logger, Update docs diff --git a/src/org/camunda/latera/bss/connectors/hoper/hydra/File.groovy b/src/org/camunda/latera/bss/connectors/hoper/hydra/File.groovy index 2a909e18..e791b1fd 100644 --- a/src/org/camunda/latera/bss/connectors/hoper/hydra/File.groovy +++ b/src/org/camunda/latera/bss/connectors/hoper/hydra/File.groovy @@ -16,6 +16,10 @@ trait File { return getFileEntityType(getSubjectEntityType(subjectId), id) } + Map getContractFileEntityType(def contractId, def id = null) { + return getFileEntityType(getContractEntityType(contractId), id) + } + private Map getFileDefaultParams() { return [ name : '', @@ -53,6 +57,23 @@ trait File { return result } + List getContractFiles(Map input = [:], def contractId) { + LinkedHashMap params = getPaginationDefaultParams() + input + + List result = [] + List files = getEntities(getContractFileEntityType(contractId), params) + if (files) { + files.each { it -> + result.add([ + n_doc_file_id : it.n_doc_file_id, + file_name : it.file_name, + content : Base64Converter.from(it.base64_content) + ]) + } + } + return result + } + Map getSubjectFile(def subjectId, def fileId) { LinkedHashMap file = getEntity(getSubjectFileEntityType(subjectId), fileId) if (file) { @@ -66,15 +87,37 @@ trait File { return file } + Map getContractFile(def contractId, def fileId) { + LinkedHashMap file = getEntity(getContractFileEntityType(contractId), fileId) + if (file) { + LinkedHashMap result = [ + n_doc_file_id : file.n_doc_file_id, + file_name : file.file_name, + content : Base64Converter.from(file.base64_content) + ] + return result + } + return file + } + Map getSubjectFile(Map input) { return getSubjectFile(input.subjectId, input.fileId) } + Map getContractFile(Map input) { + return getContractFile(input.contractId, input.fileId) + } + Map createSubjectFile(Map input = [:], def subjectId) { LinkedHashMap params = getFileParams(input) return createEntity(getSubjectFileEntityType(subjectId), params) } + Map createContractFile(Map input = [:], def contractId) { + LinkedHashMap params = getFileParams(input) + return createEntity(getContractFileEntityType(contractId), params) + } + List createSubjectFiles(Object[] input = [], def subjectId) { List result = [] input.each { Map item -> @@ -83,15 +126,32 @@ trait File { return result } + List createContractFiles(Object[] input = [], def contractId) { + List result = [] + input.each { Map item -> + result += createContractFile(item, contractId) + } + return result + } + List createSubjectFiles(def subjectId, List input) { return createSubjectFiles(input as Object[], subjectId) } + List createContractFiles(def contractId, List input) { + return createContractFiles(input as Object[], contractId) + } + Map updateSubjectFile(Map input = [:], def subjectId, def fileId) { LinkedHashMap params = getFileParams(input) return updateEntity(getSubjectFileEntityType(subjectId), fileId, params) } + Map updateContractFile(Map input = [:], def contractId, def fileId) { + LinkedHashMap params = getFileParams(input) + return updateEntity(getContractFileEntityType(contractId), fileId, params) + } + List updateSubjectFiles(Object[] input = [], def subjectId) { List result = [] input.each { Map item -> @@ -100,15 +160,35 @@ trait File { return result } + List updateContractFiles(Object[] input = [], def contractId) { + List result = [] + input.each { Map item -> + result += updateContractFile(item + [contractId: contractId]) + } + return result + } + List updateSubjectFiles(def subjectId, List input) { return updateSubjectFiles(input as Object[], subjectId) } + List updateContractFiles(def contractId, List input) { + return updateContractFiles(input as Object[], subjectId) + } + Boolean deleteSubjectFile(def subjectId, def fileId) { return deleteEntity(getSubjectFileEntityType(subjectId), fileId) } + Boolean deleteContractFile(def contractId, def fileId) { + return deleteEntity(getContractFileEntityType(contractId), fileId) + } + Boolean deleteSubjectFile(Map input) { return deleteSubjectFile(input.subjectId, input.fileId) } -} \ No newline at end of file + + Boolean deleteContractFile(Map input) { + return deleteContractFile(input.contractId, input.fileId) + } +}