Skip to content

Commit

Permalink
Fix errors in hid.Hydra and helpers.Hydra address methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Nov 30, 2019
1 parent 5bfcd65 commit 08e91d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 55 deletions.
87 changes: 52 additions & 35 deletions src/org/camunda/latera/bss/connectors/hid/hydra/Address.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,14 @@ trait Address {
groupId : null,
objectId : null,
subnetAddressId : null,
operationDate : local(),
firmId : getFirmId()
]
if (input.containsKey('subnetAddress') && notEmpty(input.subnetAddress)) {
input.subnetAddressId = getAddressBy(code: input.subnetAddress, addrType: 'ADDR_TYPE_Subnet6')?.n_address_id
input.remove('subnetAddress')
}
LinkedHashMap params = mergeParams(defaultParams, input)

List addresses = []
String date = encodeDateStr(params.operationDate)

try {
if (this.version >= '5.1.2') {
Expand Down Expand Up @@ -1125,7 +1122,7 @@ trait Address {
String getFreeIPv6Subnet(Map input) {
String subnet = null
try {
subnet = "${getFreeIPv6(input)}/${getIPv6Mask()}"
subnet = "${getFreeIPv6(input)}/${getSubnetv6Mask()}"
} catch (Exception e){
logger.error_oracle(e)
}
Expand Down Expand Up @@ -1244,6 +1241,7 @@ trait Address {
groupId : null,
rootId : null,
mask : null,
vlanId : null,
operationDate : local(),
firmId : getFirmId()
]
Expand All @@ -1262,8 +1260,20 @@ trait Address {

List addresses = []
String date = encodeDateStr(params.operationDate)
String filter = params.mask ? "SI_ADDRESSES_PKG_S.GET_BITN_BY_MASK(A.N_MASK) = '${params.mask}'" : '1=1'
String notAssigned = """NOT EXISTS ( -- Не привязаны к оборудованию
String filter = params.mask ? "(SI_ADDRESSES_PKG_S.GET_BITN_BY_MASK(A.N_MASK) = '${params.mask}' OR A.N_MASK = '${params.mask}')" : '1=1'
String notAssigned = ''
if (this.version >= '5.1.2') {
notAssigned = """NOT EXISTS ( -- Не привязаны к оборудованию
SELECT 1
FROM
SI_V_OBJ_ADDRESSES OA
WHERE
OA.N_ADDR_STATE_ID = SYS_CONTEXT('CONST', 'ADDR_STATE_On')
AND OA.N_ADDRESS_ID = FA.N_SUBNET_ID
AND ${date} BETWEEN OA.D_BEGIN AND NVL(OA.D_END, ${date})
)"""
} else {
notAssigned = """NOT EXISTS ( -- Не привязаны к оборудованию
SELECT 1
FROM
SI_V_OBJ_ADDRESSES OA
Expand All @@ -1272,6 +1282,7 @@ trait Address {
AND OA.N_ADDRESS_ID = FA.N_ADDRESS_ID
AND ${date} BETWEEN OA.D_BEGIN AND NVL(OA.D_END, ${date})
)"""
}

String notAssignedChild = ''
if (this.version >= '5.1.2') {
Expand All @@ -1287,7 +1298,7 @@ trait Address {
AND ${date} BETWEEN OA.D_BEGIN AND NVL(OA.D_END, ${date})
AND A.N_PROVIDER_ID = ${params.firmId}
START WITH
A.N_PAR_ADDR_ID = FA.N_ADDRESS_ID
A.N_PAR_ADDR_ID = FA.N_SUBNET_ID
CONNECT BY PRIOR
A.N_ADDRESS_ID = A.N_PAR_ADDR_ID
)"""
Expand Down Expand Up @@ -1317,13 +1328,16 @@ trait Address {
if (this.version >= '5.1.2') {
addresses = hid.queryDatabase("""
WITH AVAILABLE_SUBNETS AS (
SELECT *
FROM SI_V_PROV_SUBNETS A
WHERE A.N_PROVIDER_ID = ${params.firmId}
SELECT
*
FROM
SI_V_PROV_SUBNETS A
WHERE
A.N_PROVIDER_ID = ${params.firmId}
CONNECT BY PRIOR
A.N_ADDRESS_ID = A.N_PAR_ADDR_ID
A.N_SUBNET_ID = A.N_PAR_SUBNET_ID
START WITH
A.N_PAR_ADDR_ID = ${params.rootId}
A.N_PAR_SUBNET_ID = ${params.rootId}
),
FILTERED_SUBNETS AS (
SELECT
Expand Down Expand Up @@ -1357,12 +1371,15 @@ trait Address {
} else {
addresses = hid.queryDatabase("""
WITH AVAILABLE_SUBNETS AS (
SELECT RA.*
FROM RG_PAR_ADDRESSES RA
WHERE RA.N_PROVIDER_ID = ${params.firmId}
SELECT
RA.*
FROM
RG_PAR_ADDRESSES RA
WHERE
RA.N_PROVIDER_ID = ${params.firmId}
CONNECT BY PRIOR
RA.N_ADDRESS_ID = RA.N_PAR_ADDR_ID
AND RA.N_ADDR_BIND_TYPE_ID = SYS_CONTEXT('CONST', 'ADDR_ADDR_TYPE_Parent')
AND RA.N_ADDR_BIND_TYPE_ID = SYS_CONTEXT('CONST', 'ADDR_ADDR_TYPE_Parent')
START WITH
RA.N_PAR_ADDR_ID = ${params.groupId ?: params.rootId}
),
Expand Down Expand Up @@ -1434,15 +1451,15 @@ trait Address {

String getSubnetByIP(CharSequence ip) {
def subnetId = getSubnetIdByIP(ip)
LinkedHashMap subnet = null
String subnet = null
if (subnetId) {
subnet = getAddress(addressId: subnetId, addrType: 'ADDR_TYPE_SUBNET')?.vc_code
}
return subnet
}

String getSubnetMaskById(def subnetId) {
String mask = ''
String mask = null
try {
mask = hid.queryFirst("""
SELECT SI_ADDRESSES_PKG_S.GET_BITN_BY_MASK(SI_ADDRESSES_PKG_S.GET_N_MASK_BY_SUBNET(${subnetId}))
Expand All @@ -1455,20 +1472,20 @@ trait Address {
}

String getSubnetMask(CharSequence subnet) {
String mask = ''
String mask = null
def subnetId = getAddress(code: subnet, addrType: 'ADDR_TYPE_SUBNET')
if (subnetId) {
mask = getSubnetMaskById(subnetId)
}
return mask
}

String getSuubnetv6Mask() {
String getSubnetv6Mask() {
return getIPv6Mask()
}

String getIPv6Mask() {
return getParamValue(param: 'PAR_IPv6SubnetLength', subjectId: getFirmId())
return getParamValueBy(param: 'PAR_IPv6SubnetLength', subjectId: getFirmId())?.n_value
}

List getParentSubnetAddresses(Map input) {
Expand All @@ -1479,7 +1496,7 @@ trait Address {
firmId : getFirmId()
]
if ((input.containsKey('address') && notEmpty(input.address)) || (input.containsKey('code') && notEmpty(input.code))) {
input.addressId = getAddressBy(code: input.address ?: input.code, type: 'ADDR_TYPE_Subnet')
input.addressId = getAddressBy(code: input.address ?: input.code, type: 'ADDR_TYPE_Subnet')?.n_address_id
input.remove('address')
}
LinkedHashMap params = mergeParams(defaultParams, input)
Expand All @@ -1498,11 +1515,11 @@ trait Address {
FROM
SI_V_PROV_SUBNETS A
WHERE
A.N_PROVIDER_ID = ${params.firmId}
A.N_PROVIDER_ID = ${params.firmId}
START WITH
A.N_ADDRESS_ID = ${params.addressId}"
A.N_SUBNET_ID = ${params.addressId ?: params.subnetId}"
CONNECT BY PRIOR
A.N_PAR_ADDR_ID = A.N_ADDRESS_ID
A.N_PAR_SUBNET_ID = A.N_SUBNET_ID
ORDER BY LEVEL ASC
""", true)
} else {
Expand All @@ -1517,14 +1534,14 @@ trait Address {
SI_V_ADDRESSES A,
RG_PAR_ADDRESSES RA
WHERE
RA.N_ADDRESS_ID = A.N_ADDRESS_ID
RA.N_ADDRESS_ID = A.N_ADDRESS_ID
AND ${date} BETWEEN RA.D_BEGIN AND NVL(RA.D_END, ${date})
AND RA.N_ADDR_BIND_TYPE_ID = SYS_CONTEXT('CONST', 'ADDR_ADDR_TYPE_Parent')
AND RA.N_PROVIDER_ID = ${params.firmId}
AND RA.N_PROVIDER_ID = ${params.firmId}
START WITH
A.N_ADDRESS_ID = ${params.addressId}"
A.N_ADDRESS_ID = ${params.addressId ?: params.subnetId}"
CONNECT BY PRIOR
RA.N_PAR_ADDR_ID = RA.N_ADDRESS_ID
RA.N_PAR_ADDR_ID = RA.N_ADDRESS_ID
ORDER BY LEVEL ASC
""", true)
}
Expand All @@ -1542,7 +1559,7 @@ trait Address {
firmId : getFirmId()
]
if ((input.containsKey('address') && notEmpty(input.address)) || (input.containsKey('code') && notEmpty(input.code))) {
input.addressId = getAddressBy(code: input.address ?: input.code, type: 'ADDR_TYPE_Subnet')
input.addressId = getAddressBy(code: input.address ?: input.code, type: 'ADDR_TYPE_Subnet')?.n_address_id
input.remove('address')
}
LinkedHashMap params = mergeParams(defaultParams, input)
Expand All @@ -1562,11 +1579,11 @@ trait Address {
FROM
SI_V_PROV_SUBNETS4 A
WHERE
A.N_PROVIDER_ID = ${params.firmId}
A.N_PROVIDER_ID = ${params.firmId}
START WITH
A.N_ADDRESS_ID = ${params.addressId}"
A.N_SUBNET_ID = ${params.addressId ?: params.subnetId}"
CONNECT BY PRIOR
A.N_PAR_ADDR_ID = A.N_ADDRESS_ID
A.N_PAR_SUBNET_ID = A.N_SUBNET_ID
ORDER BY LEVEL ASC
)
Expand All @@ -1577,7 +1594,7 @@ trait Address {
SUBNETS S,
SI_V_VLAN_ADDRESSES A
WHERE
S.N_ADDRESS_ID = A.N_ADDRESS_ID
S.N_SUBNET_ID = A.N_ADDRESS_ID
""", true)
} else {
address = hid.queryFirst("""
Expand All @@ -1598,7 +1615,7 @@ trait Address {
AND RA.N_ADDR_BIND_TYPE_ID = SYS_CONTEXT('CONST', 'ADDR_ADDR_TYPE_Parent')
AND RA.N_PROVIDER_ID = ${params.firmId}
START WITH
A.N_ADDRESS_ID = ${params.addressId}"
A.N_ADDRESS_ID = ${params.addressId ?: params.subnetId}"
CONNECT BY PRIOR
RA.N_PAR_ADDR_ID = RA.N_ADDRESS_ID
ORDER BY LEVEL ASC
Expand Down
28 changes: 8 additions & 20 deletions src/org/camunda/latera/bss/helpers/hydra/Address.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ trait Address {
])
}

void fetchEquipmentSubnet6(Map input = [:]) {
void fetchEquipmentVLAN(Map input = [:]) {
Map params = [
bindAddrType : 'Actual',
isMain : true,
Expand All @@ -193,11 +193,11 @@ trait Address {
] + input

fetchEquipmentAddress(params + [
addrType : 'Subnet6'
addrType : 'VLAN'
])
}

void fetchEquipmentVLAN(Map input = [:]) {
void fetchEquipmentSubnet(Map input = [:]) {
Map params = [
bindAddrType : 'Actual',
isMain : true,
Expand All @@ -211,11 +211,11 @@ trait Address {
] + input

fetchEquipmentAddress(params + [
addrType : 'VLAN'
addrType : 'Subnet'
])
}

void fetchEquipmentSubnet(Map input = [:]) {
void fetchEquipmentSubnet6(Map input = [:]) {
Map params = [
bindAddrType : 'Actual',
isMain : true,
Expand All @@ -229,7 +229,7 @@ trait Address {
] + input

fetchEquipmentAddress(params + [
addrType : 'Subnet'
addrType : 'Subnet6'
])
}

Expand Down Expand Up @@ -285,13 +285,7 @@ trait Address {
def addrType = 'Subnet6'
def prefix = "${capitalize(params.equipmentPrefix)}Equipment${capitalize(params.equipmentSuffix)}${capitalize(params.prefix)}"

def address = hydra.getFreeIPv6Subnet(
groupId : params.groupId,
objectId : params.objectId,
subnetAddress : params.subnetAddress,
subnetAddressId : params.subnetAddressId,
operationDate : params.operationDate
)
def address = hydra.getFreeIPv6Subnet(params)
if (address) {
order."${prefix}${addrType}" = address
}
Expand All @@ -311,13 +305,7 @@ trait Address {
def addrType = 'Telephone'
def prefix = "${capitalize(params.equipmentPrefix)}Equipment${capitalize(params.equipmentSuffix)}${capitalize(params.prefix)}"

def address = hydra.getFreePhoneNumber(
groupId : params.groupId,
objectId : params.objectId,
telCode : params.telCode,
telCodeId : params.telCodeId,
operationDate : params.operationDate
)
def address = hydra.getFreePhoneNumber(params)
if (address) {
order."${prefix}${addrType}" = address
}
Expand Down

0 comments on commit 08e91d8

Please sign in to comment.