diff --git a/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy b/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy index bc909a7a..360acb73 100644 --- a/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy +++ b/src/org/camunda/latera/bss/connectors/hoper/Hydra.groovy @@ -9,8 +9,9 @@ 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 +import org.camunda.latera.bss.connectors.hoper.hydra.Address -class Hydra implements Main, Entity, Subject, Person, Company { +class Hydra implements Main, Entity, Subject, Person, Company, Address { private static Integer DEFAULT_FIRM = 100 Hoper hoper def firmId diff --git a/src/org/camunda/latera/bss/connectors/hoper/hydra/Address.groovy b/src/org/camunda/latera/bss/connectors/hoper/hydra/Address.groovy new file mode 100644 index 00000000..bf80be9d --- /dev/null +++ b/src/org/camunda/latera/bss/connectors/hoper/hydra/Address.groovy @@ -0,0 +1,198 @@ +package org.camunda.latera.bss.connectors.hoper.hydra + +trait Address { + private static LinkedHashMap ADDRESS_ENTITY_TYPE = [ + one : 'address', + plural : 'addresses' + ] + private static Integer DEFAULT_ADDRESS_TYPE_ID = 1006 // 'ADDR_TYPE_FactPlace' + private static Integer DEFAULT_ADDRESS_BIND_TYPE_ID = 6016 // 'BIND_ADDR_TYPE_Serv' + private static Integer DEFAULT_ADDRESS_STATE_ID = 1029 // 'ADDR_STATE_On' + + def getAddressEntityType(def parentType, def parentId) { + def parent = "${parentType.parent}/${parentType.plural}/${parentId}" + return ADDRESS_ENTITY_TYPE + [parent: parent] + } + + def getPersonAddressEntityType(def subjectId) { + return getAddressEntityType(getPersonEntityType(), subjectId) + } + + def getCompanyAddressEntityType(def subjectId) { + return getAddressEntityType(getCompanyEntityType(), subjectId) + } + + def getDefaultAddressTypeId() { + return DEFAULT_ADDRESS_TYPE_ID + } + + def getDefaultAddressBindTypeId() { + return DEFAULT_ADDRESS_BIND_TYPE_ID + } + + def getDefaultAddressStateId() { + return DEFAULT_ADDRESS_STATE_ID + } + + LinkedHashMap getAddressDefaultParams() { + return [ + addrTypeId : getDefaultAddressTypeId(), + parAddressId : null, + code : null, + regionId : null, + rawAddress : null, + flat : null, + floor : null, + entrance : null, + intercomCode : null, + rem : null, + bindAddrTypeId : getDefaultAddressBindTypeId(), + stateId : getDefaultAddressStateId(), + isMain : null, + beginDate : null, + endDate : null + ] + } + + LinkedHashMap getAddressParamsMap(LinkedHashMap params) { + return [ + n_addr_type_id : params.addrTypeId, + n_par_addr_id : params.parAddressId, + vc_code : params.code, + n_region_id : params.regionId, + vc_address : params.rawAddress, + vc_flat : params.flat, + n_floor_no : params.floor, + vc_entrance_no : params.entrance, + vc_intercom_code : params.intercomCode, + vc_rem : params.rem, + n_subj_addr_type_id : params.bindAddrTypeId, + n_addr_state_id : params.stateId, + c_fl_main : params.isMain, + d_begin : params.beginDate, + d_end : params.endDate + ] + } + + LinkedHashMap getAddressParams(LinkedHashMap input) { + def params = getAddressDefaultParams() + input + def data = getAddressParamsMap(params) + return nvlParams(data) + } + + Boolean getAddresses(def entityType = 'person', def entityId) { + if (entityType == getPersonEntityType().one) { + return getPersonAddresses(entityId) + } else if (entityType == getCompanyEntityType().one) { + return getCompanyAddresses(entityId) + } + } + + List getPersonAddresses(def personId, LinkedHashMap input = [:]) { + def params = getPaginationDefaultParams() + input + return getEntities(getPersonAddressEntityType(personId), params) + } + + List getCompanyAddresses(def companyId, LinkedHashMap input = [:]) { + def params = getPaginationDefaultParams() + input + return getEntities(getCompanyAddressEntityType(companyId), params) + } + + Boolean getAddress(def entityType = 'person', def entityId, def entityAddressId) { + if (entityType == getPersonEntityType().one) { + return getPersonAddress(entityId, entityAddressId) + } else if (entityType == getCompanyEntityType().one) { + return getCompanyAddress(entityId, entityAddressId) + } + } + + LinkedHashMap getPersonAddress(def personId, def subjAddressId) { + return getEntity(getPersonAddressEntityType(personId), subjAddressId) + } + + LinkedHashMap getCompanyAddress(def companyId, def subjAddressId) { + return getEntity(getCompanyAddressEntityType(companyId), subjAddressId) + } + + Boolean createAddress(def entityType = 'person', def entityId, LinkedHashMap input) { + if (entityType == getPersonEntityType().one) { + return createPersonAddress(entityId, input) + } else if (entityType == getCompanyEntityType().one) { + return createCompanyAddress(entityId, input) + } + } + + LinkedHashMap createPersonAddress(def personId, LinkedHashMap input) { + LinkedHashMap params = getAddressParams(input) + return createEntity(getPersonAddressEntityType(personId), params) + } + + LinkedHashMap createCompanyAddress(def companyId, LinkedHashMap input) { + LinkedHashMap params = getAddressParams(input) + return createEntity(getCompanyAddressEntityType(companyId), params) + } + + Boolean updateAddress(def entityType = 'person', def entityId, def entityAddressId, LinkedHashMap input) { + if (entityType == getPersonEntityType().one) { + return updatePersonAddress(entityId, entityAddressId, input) + } else if (entityType == getCompanyEntityType().one) { + return updateCompanyAddress(entityId, entityAddressId, input) + } + } + + LinkedHashMap updatePersonAddress(def personId, def subjAddressId, LinkedHashMap input) { + LinkedHashMap params = getAddressParams(input) + return updateEntity(getPersonAddressEntityType(personId), subjAddressId, params) + } + + LinkedHashMap updateCompanyAddress(def companyId, def subjAddressId, LinkedHashMap input) { + LinkedHashMap params = getAddressParams(input) + return updateEntity(getCompanyAddressEntityType(companyId), subjAddressId, params) + } + + Boolean putAddress(def entityType = 'person', def entityId, LinkedHashMap input) { + if (entityType == getPersonEntityType().one) { + return putPersonAddress(entityId, input) + } else if (entityType == getCompanyEntityType().one) { + return putCompanyAddress(entityId, input) + } + } + + LinkedHashMap putPersonAddress(def personId, LinkedHashMap input) { + def subjAddressId = input.subjAddressId + input.remove('subjAddressId') + + if (subjAddressId) { + return updatePersonAddress(personId, subjAddressId, input) + } else { + return createPersonAddress(personId, input) + } + } + + LinkedHashMap putCompanyAddress(def companyId, LinkedHashMap input) { + def subjAddressId = input.subjAddressId + input.remove('subjAddressId') + + if (subjAddressId) { + return updateCompanyAddress(companyId, subjAddressId, input) + } else { + return createCompanyAddress(companyId, input) + } + } + + Boolean deleteAddress(def entityType = 'person', def entityId, def entityAddressId) { + if (entityType == getPersonEntityType().one) { + return deletePersonAddress(entityId, entityAddressId) + } else if (entityType == getCompanyEntityType().one) { + return deleteCompanyAddress(entityId, entityAddressId) + } + } + + Boolean deletePersonAddress(def personId, def subjAddressId) { + return deleteEntity(getPersonAddressEntityType(personId), subjAddressId) + } + + Boolean deleteCompanyAddress(def companyId, def subjAddressId) { + return deleteEntity(getCompanyAddressEntityType(companyId), subjAddressId) + } +} \ No newline at end of file