From 2fcc6a002d9eb104d7f15790111aaa3e61308e91 Mon Sep 17 00:00:00 2001 From: dolfinus Date: Thu, 9 May 2019 22:53:16 +0300 Subject: [PATCH] Add company methods to hoper.Hydra class --- .../latera/bss/connectors/hoper/Hydra.groovy | 3 +- .../bss/connectors/hoper/hydra/Company.groovy | 93 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/org/camunda/latera/bss/connectors/hoper/hydra/Company.groovy diff --git a/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy b/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy index 95b61dda..bc909a7a 100644 --- a/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy +++ b/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy @@ -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 diff --git a/src/org/camunda/latera/bss/connectors/hoper/hydra/Company.groovy b/src/org/camunda/latera/bss/connectors/hoper/hydra/Company.groovy new file mode 100644 index 00000000..0c658059 --- /dev/null +++ b/src/org/camunda/latera/bss/connectors/hoper/hydra/Company.groovy @@ -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) + } +} \ No newline at end of file