-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add company methods to hoper.Hydra class
- Loading branch information
Showing
2 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/org/camunda/latera/bss/connectors/hoper/hydra/Company.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |