Skip to content

Commit

Permalink
Add company methods to hoper.Hydra class
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed May 9, 2019
1 parent 70804a5 commit 2fcc6a0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import org.camunda.latera.bss.connectors.hoper.hydra.Main
import org.camunda.latera.bss.connectors.hoper.hydra.Entity
import org.camunda.latera.bss.connectors.hoper.hydra.Subject
import org.camunda.latera.bss.connectors.hoper.hydra.Person
import org.camunda.latera.bss.connectors.hoper.hydra.Company

class Hydra implements Main, Entity, Subject, Person {
class Hydra implements Main, Entity, Subject, Person, Company {
private static Integer DEFAULT_FIRM = 100
Hoper hoper
def firmId
Expand Down
93 changes: 93 additions & 0 deletions src/org/camunda/latera/bss/connectors/hoper/hydra/Company.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.camunda.latera.bss.connectors.hoper.hydra

trait Company {
private static LinkedHashMap COMPANY_ENTITY_TYPE_V1 = [
parent : 'subjects',
one : 'company',
plural : 'companies'
]

private static LinkedHashMap COMPANY_ENTITY_TYPE_V2 = [
parent : 'subjects',
one : 'organization',
plural : 'organizations'
]

def getCompanyEntityType() {
if (hoper.version == 1) {
return COMPANY_ENTITY_TYPE_V1
}else if (hoper.version == 2) {
return COMPANY_ENTITY_TYPE_V2
}
}

LinkedHashMap getCompanyDefaultParams() {
return [
name : null,
code : null,
opfId : null,
inn : null,
kpp : null,
rem : null,
stateId : null,
firmId : null,
]
}

LinkedHashMap getCompanyParamsMap(LinkedHashMap params, LinkedHashMap additionalParams = [:]) {
def result = [
vc_name : params.name,
vc_code : params.code,
n_opf_id : params.opfId,
vc_inn : params.inn,
vc_kpp : params.kpp,
n_subj_state_id : params.stateId,
n_firm_id : params.firmId,
t_tags : params.tags,
vc_rem : params.rem
]
if (additionalParams) {
result.additional_values = params.additionalParams
}
return result
}

LinkedHashMap getCompanyParams(LinkedHashMap input, LinkedHashMap additionalParams = [:]) {
def params = getCompanyDefaultParams() + input
def data = getCompanyParamsMap(params + additionalParams)
return nvlParams(data)
}

List getCompanies(LinkedHashMap input = [:]) {
def params = getPaginationDefaultParams() + input
return getEntities(getCompanyEntityType(), params)
}

LinkedHashMap getCompany(def id) {
return getEntity(getCompanyEntityType(), id)
}
LinkedHashMap createCompany(LinkedHashMap input, LinkedHashMap additionalParams = [:]) {
LinkedHashMap params = getCompanyParams(input, additionalParams)
return createEntity(getCompanyEntityType(), params)
}

LinkedHashMap updateCompany(def id, LinkedHashMap input, LinkedHashMap additionalParams = [:]) {
LinkedHashMap params = getCompanyParams(input, additionalParams)
return updateEntity(getCompanyEntityType(), id, params)
}

LinkedHashMap putCompany(LinkedHashMap input, LinkedHashMap additionalParams = [:]) {
def companyId = input.companyId
input.remove('companyId')

if (companyId) {
return updateCompany(companyId, input, additionalParams)
} else {
return createCompany(input, additionalParams)
}
}

Boolean deleteCompany(def id) {
return deleteEntity(getCompanyEntityType(), id)
}
}

0 comments on commit 2fcc6a0

Please sign in to comment.