Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCX-12 Add methods for files to document attaching #24

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ v1.4.1 [unreleased]
- [#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
Expand Down
82 changes: 81 additions & 1 deletion src/org/camunda/latera/bss/connectors/hoper/hydra/File.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ trait File {
return getFileEntityType(getSubjectEntityType(subjectId), id)
}

Map getContractFileEntityType(def contractId, def id = null) {
return getFileEntityType(getContractEntityType(contractId), id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is not really how it works.
Firstly, getContractEntityType requires not only contract id itself, but also parent entity url part because for contract creation/update/delete urls should looks like subjects/customers/:customer_id/contracts/:contract_id. You cannot just skip parent part here because url will be malformed. Also calling this method without passing a parent will cause exception.

Secondly, there is no entpoint like subjects/customers/:customer_id/contracts/:contract_id/files you're trying to use for attaching files to contract. Real url should look like documents/:document:id/files.

Thirdly, you can attach files to any document as well as any subject. Currently there are methods to work with any subject files like getSubjectFiles. So here should be getDocumentFiles instead of getContractFiles.

}

private Map getFileDefaultParams() {
return [
name : '',
Expand Down Expand Up @@ -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) {
Expand All @@ -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 ->
Expand All @@ -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 ->
Expand All @@ -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)
}
}

Boolean deleteContractFile(Map input) {
return deleteContractFile(input.contractId, input.fileId)
}
}